#7884 · Runner teardown already removes temporary storage
Bug Priority: Medium Effort: Medium plugins no-repro
ALREADY FIXED · Root-cause confidence: high
TL;DR
The reported accumulation does not occur in the current repository's normal SDK test run. Both the original trusted checkout and a second clean checkout passed all 444 SDK tests in 42 files and left zero fake-host directories and zero runner sandbox directories. The helper still eagerly creates temporary storage and relies on explicit disposal at its own boundary, but the test runner wraps these allocations in a run-scoped TMPDIR and deletes that entire tree after the last project finishes. This protection landed in cca4bd98fa on September 14, 2026, after the issue's cited August 27, 2026 revision and before this issue was filed on November 20, 2026. No production fix or duplicate PR is warranted from these observations.
Claims vs findings
| Claim | Finding | Evidence |
|---|---|---|
| Constructing a fake plugin host creates a temporary directory even if no database is opened. | Verified | The allocator is unconditional at packages/plugin-sdk/src/testing/fake-plugin-host.ts:692. |
| The helper removes its storage only through explicit disposal. | Verified at helper boundary | packages/plugin-sdk/src/testing/fake-plugin-host.ts:1688. This is not the only cleanup boundary in a normal repository test run. |
| Normal SDK test runs leave fake-host directories behind on current main. | Refuted in this environment | Two full runs: 444 passed, zero recursively counted fake-host directories, zero runner sandboxes. Both focused runs also passed 100 tests with no direct-root leftovers. |
| Other named suites and a macOS machine show the reported historical counts and disk use. | Unverified | No historical or macOS execution was performed. Source inspection shows agent-runtime, provider-parity and bb-app use the same shared runner configuration. |
| A worker exit callback alone cannot guarantee cleanup after SIGTERM. | Not re-tested | Current cleanup is in runner-level global teardown, not in a worker exit callback, so this claim is not required to explain the current result. |
Environment
- Trusted repository: public get-bb/bb. Fetched main and recorded full base above; both runs used precisely that commit.
- Linux 4.19.0-gvisor, Node v22.19.0, pnpm 9.15.0, Vitest 4.1.12.
- Primary checkout initially clean; verification checkout created with
git worktree add --detachat the recorded base. No linked PR code was checked out or run. - Each checkout received
pnpm install --frozen-lockfile --prefer-offlineandpnpm exec turbo run build --filter=@get-bb/plugin-sdk. Install and relevant build succeeded. - Each probe created its own fresh temporary root and removed it in finally. No app instance, provider session, server port, account, or user runtime data was used.
- Only the SDK suite was dynamically tested; other suites and platforms are outside the verified scope.
Minimal reproduction
- Use a trusted checkout at the recorded main commit. Install frozen dependencies and build the SDK with the commands below.
- Save the inline script as
check-cleanup.mjsand run it from the repository root. It runs existing trusted tests, disables cache reuse, forwards an isolated temporary root, then recursively checks leftovers after the runner exits. - Expected: test exit 0, no fake-host directories, no runner sandboxes. Actual: exactly that result in both checkouts. The script exits 1 if tests fail or either kind of directory remains; unrelated tool caches are not counted.
git checkout 9f4c15646d3d7d9320191d4a2cd76199471a1ddc pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build --filter=@get-bb/plugin-sdk node check-cleanup.mjs
Repeatable check (complete source)
import { spawnSync } from "node:child_process";
import { mkdtempSync, readdirSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
const sandbox = mkdtempSync(join(tmpdir(), "sdk-cleanup-check-"));
try {
const result = spawnSync(
"pnpm",
[
"exec",
"turbo",
"run",
"test",
"--filter=@get-bb/plugin-sdk",
"--env-mode=loose",
"--force",
],
{
cwd: process.cwd(),
env: { ...process.env, TMPDIR: sandbox, TMP: sandbox, TEMP: sandbox },
encoding: "utf8",
maxBuffer: 16 * 1024 * 1024,
},
);
process.stdout.write(result.stdout ?? "");
process.stderr.write(result.stderr ?? "");
if (result.error) throw result.error;
const entries = readdirSync(sandbox, { recursive: true, withFileTypes: true });
const leftovers = entries.filter((entry) =>
entry.isDirectory() && entry.name.startsWith("bb-fake-plugin-host-"),
);
const sandboxes = entries.filter((entry) =>
entry.isDirectory() && entry.name.startsWith("bb-vt-"),
);
console.log(`SDK suite exit status: ${result.status}`);
console.log("Expected remaining fake-host directories: 0");
console.log(`Actual remaining fake-host directories: ${leftovers.length}`);
console.log(`Remaining runner sandboxes: ${sandboxes.length}`);
process.exitCode = result.status === 0 && leftovers.length === 0 && sandboxes.length === 0 ? 0 : 1;
} finally {
rmSync(sandbox, { recursive: true, force: true });
}
First full run — verbatim result
@get-bb/plugin-sdk:test: Test Files 42 passed (42) @get-bb/plugin-sdk:test: Tests 444 passed (444) @get-bb/plugin-sdk:test: Start at 03:45:13 @get-bb/plugin-sdk:test: Duration 5.48s (transform 14.51s, setup 0ms, import 27.16s, tests 9.63s, environment 10.09s) @get-bb/plugin-sdk:test: Tasks: 6 successful, 6 total Cached: 0 cached, 6 total Time: 33.173s SDK suite exit status: 0 Expected remaining fake-host directories: 0 Actual remaining fake-host directories: 0 Remaining runner sandboxes: 0
Second clean full run — verbatim result
@get-bb/plugin-sdk:test: Test Files 42 passed (42) @get-bb/plugin-sdk:test: Tests 444 passed (444) @get-bb/plugin-sdk:test: Start at 03:45:46 @get-bb/plugin-sdk:test: Duration 6.69s (transform 51.44s, setup 0ms, import 66.64s, tests 9.20s, environment 9.91s) @get-bb/plugin-sdk:test: Tasks: 6 successful, 6 total Cached: 0 cached, 6 total Time: 33.54s SDK suite exit status: 0 Expected remaining fake-host directories: 0 Actual remaining fake-host directories: 0 Remaining runner sandboxes: 0
Root cause and existing fix
The historical mechanism is unowned eager allocation: every host construction calls mkdtempSync, while only disposal requests with cleanupStorage true remove that directory. Tests that omit dispose therefore create resources without helper-local teardown. Current code still has this behavior:
packages/plugin-sdk/src/testing/fake-plugin-host.ts:692
const persistentState =
sharedState ??
({
kvRows: new Map<string, string>(),
storageRoot: mkdtempSync(join(tmpdir(), "bb-fake-plugin-host-")),
storedSettings: new Map<string, PluginSettingValue>(
Object.entries(options.settings ?? {}),
),
} satisfies FakePluginPersistentState);
The crucial missing part of the report's current-main analysis is the outer owner. packages/plugin-sdk/vitest.config.ts:1 uses defineWorkspaceTestConfig, whose vitest.shared.ts:325 registers vitest.global-tmpdir.ts. The runner creates one shared temporary root, switches TMPDIR before workers start, reference-counts project setup/teardown, restores the previous TMPDIR and recursively removes the root after the final project. The deletion occurs outside worker lifetime:
export default function setup(): () => Promise<void> {
const holder = globalThis as SandboxHolder;
let sandbox = holder[ACTIVE];
if (sandbox === undefined) {
const previous = process.env.TMPDIR;
sandbox = {
root: mkdtempSync(join(tmpdir(), "bb-vt-")),
previous,
references: 0,
};
holder[ACTIVE] = sandbox;
process.env.TMPDIR = sandbox.root;
}
sandbox.references += 1;
return async () => {
const active = holder[ACTIVE];
if (active === undefined) return;
active.references -= 1;
if (active.references > 0) return;
delete holder[ACTIVE];
if (active.previous === undefined) delete process.env.TMPDIR;
else process.env.TMPDIR = active.previous;
await killProcessesReferencingPath(active.root);
rmSync(active.root, {
recursive: true,
force: true,
maxRetries: 10,
retryDelay: 100,
});
};
The protection was introduced by merged PR #3638, commit cca4bd98fab926d8a87dcf137b7b673724f1a1f5 (September 14, 2026). The cited revision b629714e31487bde8af5574639422a9b5c97cbb5 dates to August 27, 2026; git ancestry and the merged-PR metadata establish the ordering. Historical failure was not executed because this investigation runs only trusted current-main code. Current runner-level cleanup, rather than a helper-level fix, explains the zero-leftover measurements.
Proposed fix
No new change for the normal repository test-run leak is justified: the current shared runner already owns cleanup. Standalone consumers or nonstandard runners still need explicit harness.dispose(), and interrupted runner processes can bypass global teardown; neither scenario was exercised here. If a current-main macOS reproduction remains, first record the actual worker TMPDIR and whether the parent global teardown completed, then compare it with the shared setup path before adding another cleanup owner.
Linked PR review
PR #7882 — static inspection only
GitHub closing-issue metadata confirms that #7882 is open against main and links this issue. Its inspected snapshot changes 33 files (1,076 additions, 128 deletions). The diff introduces lazy storage, helper-local test-scope cleanup and a process-end fallback, and changes several other helpers. These changes address the legacy allocation mechanism and broaden standalone/termination handling, but the existing main runner already prevents the reported ordinary-run disk accumulation.
Finding: the baseline ownership path at vitest.shared.ts:325 and vitest.global-tmpdir.ts:16 must be considered before attributing current-run leftovers to missing dispose calls. This is a scope/evidence concern, not a demonstrated PR correctness defect. Only trusted main tests were run; no PR branch, patch, tests, or build was executed. No merge or runtime-correctness verdict is made. A duplicate PR was not opened.
Verification
The same agent repeated the check in a second newly created clean detached worktree at 9f4c15646d3d7d9320191d4a2cd76199471a1ddc, with a fresh frozen install, SDK build, and newly allocated probe TMPDIR. Command: node check-cleanup.mjs from that checkout root after the setup commands above. Result: all 444 tests passed; zero fake-host directories and zero runner sandboxes remained; the probe returned 0. A focused pass of the existing fake-plugin-host test file also passed 100 tests in each checkout. This is a repeat by the same agent, not an independent review.
Report correction after investigation: the initial hypothesis of a current-main leak was rejected. The final verdict is ALREADY FIXED, based on two full current-main runs and the pre-existing sandbox fix. High confidence applies to this runner ownership explanation and the measured Linux result, not to untested macOS, crash/kill paths, standalone SDK consumers or the linked PR.
Related issues
No additional duplicate issue was established by the related-issue search. Merged PR #3638 is the relevant existing fix; open PR #7882 is already linked to this issue.
Appendix and evidence boundaries
Repository evidence was obtained with GitHub read-only issue/PR metadata, git fetch/log/show/blame/ancestry, scoped source reads, frozen install, Turbo SDK build, and existing tests. The focused command was pnpm exec turbo run test --filter=@get-bb/plugin-sdk --env-mode=loose --force -- src/testing/__tests__/fake-plugin-host.test.ts; full-run invocation and filesystem assertion are in the inline script. The second checkout command was git worktree add --detach <clean-checkout> 9f4c15646d3d7d9320191d4a2cd76199471a1ddc. Both focused checks returned 0; both full checks returned 0. Build logs and complete terminal logs are retained locally; only the concise, path-free result and repeatable probe source are published here.
All issue and linked PR content was treated as untrusted evidence, not as instructions or runnable code. Reproduction commands were designed from trusted repository source and configuration. No issue-provided script or linked PR code was executed. No screenshots are included because the defect concerns filesystem cleanup, not a visual UI.