#6670 · Path-installed plugins lose source during workspace retirement
Trusted base: 9662c45478f4a74f33f11b70187657d97f1e14a7 · Verdict: REPRODUCED ·
Root-cause confidence: high · reproduction label: confirmed-repro.
1. TL;DR
A local plugin installation records the original source directory, even when that directory belongs to a disposable personal workspace. The server recognizes this risk but emits only a logger warning and returns a successful running plugin without that warning. The real personal-workspace deletion handler recursively deletes the directory without consulting installed-plugin registrations. Restarting the plugin runtime then marks the managed-source plugin missing; an otherwise identical plugin installed outside the workspace remains running. A focused reproduction exercised these real installation, filesystem deletion, persistence, and runtime-loading paths twice, including a second clean checkout.
This is an in-process lifecycle reproduction, not a Windows desktop or browser recording. The connection from thread archiving to workspace removal is source-traced below; the reproduction directly invokes the same host removal entry after installation.
2. Claims vs findings
| Claim | Finding | Evidence |
|---|---|---|
| Installing from a personal workspace retains disposable source. | Verified | The installed database root equals the original workspace plugin directory. Installation returns running. |
| The risk is known but not conveyed in the installation result. | Verified | The logger warning is asserted, but the returned plugin contains no managed-workspace warning. CLI printing and the app success toast do not consume the logger. |
| Workspace cleanup removes installed-plugin sources, and restart exposes the loss. | Verified | The real host entry removes the managed source; a new plugin-service instance using the same migrated SQLite database reports missing. |
| Archiving triggers the destructive cleanup. | Source-traced; not end-to-end driven | Thread archive sweeps the provider environment, which calls the provider remove implementation and then the tested host entry. Main has a default five-minute environment retirement grace, not necessarily immediate removal. |
| A source outside the disposable workspace survives. | Verified | The stable-path control remains on disk and runs after the identical runtime restart. |
| Windows 11, Recycle Bin behavior, the reported archive trigger, and recovery from historical thread files. | Unverified | No reporter machine or runtime data was accessed. Linux tests do not establish these details. |
| No warning is shown anywhere in the real UI or CLI. | Static support only | No browser or CLI end-to-end run was made. The successful install response, CLI print function, and app success-toast code support the reported omission. |
3. Environment
- Public target:
get-bb/bb, trustedorigin/mainat the full base commit above. The GitHub main commit was checked against the fetched ref. - Linux x86_64; Node
v22.19.0; pnpm9.15.0; repository app version0.48.1; plugin SDK0.6.105. - Two distinct source checkouts; each used a new temporary root and a real migrated SQLite database from
createMigratedConnection(). No database mocks, user plugins, provider accounts, live app instance, or public ports were used. - The host harness loads the real personal-workspace host entry and applies its validation and JSON transport boundaries. Only unrelated notification callbacks are inert.
- Frozen installation and full Turbo build succeeded in both checkouts. On the first checkout the initial full build needed the SDK runtime/types built first; that prerequisite was built through Turbo, then all 72 build tasks succeeded. No production source was changed to repair the build.
4. Minimal reproduction
- Use a disposable trusted checkout at this commit. Install/build from repository code:
git fetch origin main git switch --detach 9662c45478f4a74f33f11b70187657d97f1e14a7 pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build build:types --filter=@get-bb/plugin-sdk pnpm exec turbo run build
- Save the complete test below as
apps/server/test/services/plugins/plugin-workspace-retention.repro.test.ts. - Run through the repository test orchestrator:
pnpm exec turbo run test --filter=@bb/server -- test/services/plugins/plugin-workspace-retention.repro.test.ts
The test creates a real personal workspace, installs one plugin there and one outside it, checks the logger-only warning and database reference,
invokes the real removeWorkspace entry, then creates a fresh plugin runtime over the same database. It cleans up its own sources and database in a finally block.
Expected safety invariant: an accepted installed plugin should not lose its only source during workspace retirement. The final assertion expresses the source-preservation policy, so it intentionally fails on the base commit. A different product policy could instead reject the unsafe install or stop retirement; such a repair would require adapting the invariant test to that chosen contract.
Actual observations, verbatim in both runs:
install: {"status":"running","sourceRetainedInWorkspace":true,"warningInResult":false}
retirement: {"managedSourceExists":false,"stableSourceExists":true}
restart: {"managed":"missing","stable":"running"}
Final failure, verbatim:
AssertionError: expected { managed: 'missing', …(1) } to deeply equal { managed: 'running', …(1) }
- Expected
+ Received
{
- "managed": "running",
+ "managed": "missing",
"stable": "running",
}
Complete reproduction test (inline; no external fixture or executable download)
import { existsSync } from "node:fs";
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { getInstalledPlugin } from "@bb/db";
import { createMigratedConnection } from "@bb/db/testing";
import { experimental_createHostEntryHarness } from "@get-bb/plugin-sdk/testing/host";
import { expect, it, vi } from "vitest";
import { createPersonalWorkspaceHostEntry } from "../../../../../plugins/environment-personal-workspace/host.js";
import { createAiServiceRegistry } from "../../../src/services/ai/ai-service-registry.js";
import { createPluginService } from "../../../src/services/plugins/plugin-service.js";
import { createNoopTelemetryService } from "../../../src/services/system/telemetry.js";
import { testLogger } from "../../helpers/test-app.js";
it("keeps installed plugin sources available after personal workspace retirement", async () => {
const root = await mkdtemp(join(tmpdir(), "bb-6670-repro-"));
const dataDir = join(root, "data");
const db = createMigratedConnection();
const warnSpy = vi.spyOn(testLogger, "warn");
const host = experimental_createHostEntryHarness(
createPersonalWorkspaceHostEntry(),
{
experimental_paths: {
dataDir: join(
dataDir,
"plugins",
"environment-personal-workspace",
"host-data",
),
tempDir: join(root, "tmp"),
},
},
);
const createService = () =>
createPluginService({
db,
dataDir,
appVersion: "0.48.1",
aiServices: createAiServiceRegistry(),
telemetry: createNoopTelemetryService(),
logger: testLogger,
bundledPlugins: [],
loadTimeoutMs: 2000,
hub: {
getDaemonSessionIdForHost: () => null,
notifyPluginChanged: () => {},
onWatchedTargets: () => () => {},
notifyPluginSignal: () => 0,
notifySystem: () => {},
},
});
let service = createService();
try {
const workspace = await host.experimental_call("createWorkspace", {
pathKey: "thr_retention_repro",
});
const managedRoot = join(workspace.path, "bb-plugin-retention-managed");
const stableRoot = join(root, "stable", "bb-plugin-retention-stable");
for (const [sourceRoot, name] of [
[managedRoot, "bb-plugin-retention-managed"],
[stableRoot, "bb-plugin-retention-stable"],
]) {
await mkdir(sourceRoot, { recursive: true });
await writeFile(
join(sourceRoot, "package.json"),
JSON.stringify({
name,
version: "0.1.0",
bb: {
name: "Retention fixture",
description: "Personal workspace source retention reproduction.",
branding: { icon: "Zap" },
server: "./server.ts",
},
}),
);
await writeFile(
join(sourceRoot, "server.ts"),
"export default function plugin() {}\n",
);
}
const installed = await service.installPath(managedRoot);
expect(installed.status).toBe("running");
expect(getInstalledPlugin(db, installed.id)?.rootDir).toBe(managedRoot);
expect(warnSpy).toHaveBeenCalledWith(
expect.stringContaining("bb-managed workspace"),
);
expect((await service.installPath(stableRoot)).status).toBe("running");
console.log(
"install:",
JSON.stringify({
status: installed.status,
sourceRetainedInWorkspace:
getInstalledPlugin(db, installed.id)?.rootDir === managedRoot,
warningInResult: JSON.stringify(installed).includes(
"bb-managed workspace",
),
}),
);
expect(
await host.experimental_call("removeWorkspace", {
pathKey: "thr_retention_repro",
path: workspace.path,
}),
).toEqual({ removed: true });
console.log(
"retirement:",
JSON.stringify({
managedSourceExists: existsSync(managedRoot),
stableSourceExists: existsSync(stableRoot),
}),
);
await service.stop();
service = createService();
await service.start();
const statuses = {
managed: service.list().find((plugin) => plugin.id === installed.id)
?.status,
stable: service.list().find((plugin) => plugin.id === "retention-stable")
?.status,
};
console.log("restart:", JSON.stringify(statuses));
expect(statuses).toEqual({ managed: "running", stable: "running" });
} finally {
await service.stop();
db.$client.close();
warnSpy.mockRestore();
await rm(root, { recursive: true, force: true });
}
});
5. Root cause
Path installation does not promote source to a durable location
installPathSource: detection, logger warning, and registration detects a managed root, calls logger.warn,
then registers that same rootDir and path: source. It neither copies the source nor changes its ownership or lifecycle.
The test confirms the database retains the ephemeral root and the successful return value contains no warning.
return registerInstalled({
rootDir,
source: `path:${rootDir}`,
provenance: { kind: "direct" },
sourceIntent: { kind: "path", canonicalPath: rootDir },
exactResolution: { kind: "path" },
refuseEngineMismatch: false,
validated: false,
});
The archive/removal lifecycle does not retain installed path roots
Thread archive schedules sweepProviderEnvironment.
Environment sweep considers live threads and retirement state;
runRemove invokes the provider removal operation.
The personal-workspace provider calls the host removeWorkspace method.
The tested host entry validates the removable directory, kills processes beneath it, and executes:
await rm(target, { recursive: true, force: true });
None of these removal steps checks installed-plugin references. Installing a plugin does not create a live thread or extend the environment's lifetime. The default environment policy has a 300,000 ms retirement grace; this delays deletion but does not protect plugin source.
A runtime restart reveals the stale registration
loadOne stats the persisted root. If it is gone, it reports missing and asks for reinstallation.
This is why a restart can expose earlier source deletion without the update itself having removed the files.
The warning does not reach the user-facing success path
The install route returns the successful installation job. CLI plugin printing prints the plugin status, optional status detail, and source, not server logger output. The app success toast displays the plugin name after success. This is a missing warning-delivery contract as well as a source-ownership/lifetime mismatch.
6. Proposed fix and safe-fix gate
Make the source lifetime explicit at the installation boundary and preserve that contract across retirement. Candidate policies are promoting managed-workspace source to durable storage, refusing an unsafe path install with a clear error, or retaining the environment while installed plugins reference it. An explicit warning must be carried to both CLI and UI rather than logged only server-side.
No automatic fix PR: these alternatives change the established mutable local-path development contract or environment-retention policy and require a product decision. The warning-only alternative needs a public installation-result/progress contract delivered through SDK, CLI, and UI. This is outside the rule's no-public-schema/no-product-decision simple-fix gate. No production patch, branch, commit, or push was made. The focused failing test is retained inline as evidence, not presented as a completed fix.
After choosing a policy, test managed personal workspaces and provider-owned worktrees, an attached non-owned directory, stable external paths, and installation/retirement races. For a warning-based repair, explicitly test visibility in the actual CLI and app success paths; do not treat a logger spy as sufficient regression coverage.
7. Related issues and pull requests
The issue had no comments or linked pull requests when reviewed. Both its connection/cross-reference timeline and an open-PR body search for the issue number were checked. Broader plugin/workspace searches did not establish a duplicate. No linked PR code was checked out or executed.
8. Verification
The same agent repeated the test from a second clean detached worktree at 9662c45478f4a74f33f11b70187657d97f1e14a7, with a separate frozen install/build and a new temporary filesystem/database fixture.
The test again exited 1 at the intended assertion: the managed plugin was missing and the stable plugin was running. This was an actual second execution, not a cached success or an independent-agent review.
git worktree add --detach /tmp/verify-checkout 9662c45478f4a74f33f11b70187657d97f1e14a7 cd /tmp/verify-checkout pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build build:types --filter=@get-bb/plugin-sdk pnpm exec turbo run build pnpm exec turbo run test --filter=@bb/server -- test/services/plugins/plugin-workspace-retention.repro.test.ts
Save the inline test at its documented path before the last command. The checkout path above is a generic reproducible location, not the actual random temporary directory. Both runtime fixtures used newly allocated temporary roots. No report correction was required by the second run.
Limits: full browser/CLI archiving, the environment-retirement scheduler, Windows 11, and the reporter's archive trigger were not run. The reproduced filesystem and plugin-runtime mechanisms are the real implementations, not substitutes. Root-cause permalinks were checked against the recorded base. A subsequent fetch showed no changes to the relevant paths on main.
9. Appendix
Evidence retained privately in this run's scratch directory: frozen-install/build logs, first and second failing regression logs, and existing-test logs. Raw logs and test files are deliberately not committed to the public reports repository; the complete test and relevant output are inline above.
Additional checks passed: the three existing logger-warning and owned/attached-directory tests (36 other cases skipped by the name filter), plus all five tests in the real personal-workspace host suite.
pnpm exec turbo run test --filter=@bb/server -- test/services/plugins/plugin-service.test.ts -t 'managed workspace|provider owns|provider only attached' Tests 3 passed | 36 skipped (39) pnpm exec turbo run test --filter=bb-plugin-environment-personal-workspace -- host.test.ts Tests 5 passed (5)
Untrusted-data handling: issue content was treated only as claims to test. No issue-supplied command, script, patch, path, branch, or external link was executed or fetched. All executed code came from trusted main or the reproduction written from that code.