Repository navigation
Description
Summary
Destroying (or archiving-into-destroy) a managed environment recursively deletes the environment's directory without checking whether a registered path-sourced plugin lives inside it. If a plugin was installed via bb plugin install <path> from inside a personal-workspaces/env_*/ directory, archiving the thread that owns that env silently deletes the plugin's source, leaving it permanently missing (reinstall).
This is a data-loss footgun: the plugin is gone, the registration still points at a path that no longer exists, and the only recovery is reconstructing the source from session transcripts (if they were retained).
Reproduction
- Create a thread (managed env
env_Aprovisioned under<dataDir>/personal-workspaces/env_A/). - Build a plugin inside it and install from the local path:
cd ~/.bb/personal-workspaces/env_A/bb-plugin-mine bb plugin install . --yes - Archive the thread → after the env grace window,
destroyEnvironmentfires andrm -rfsenv_A/. bb plugin listnow shows:[email protected] missing (plugin directory not found: ~/.bb/personal-workspaces/env_A/bb-plugin-mine (reinstall))
Real-world impact
I hit this on a single machine and lost six plugins this way (browser-preview, automaker, file-explorer, prime-agent-ui, terminal-dock, thread-ops), one of them twice (terminal-dock — restored once, then destroyed again by the same mechanism). The env→archive→destroy path is the normal lifecycle for short-lived feature-build threads, and bb plugin install . from the just-scaffolded plugin dir is the natural workflow, so the two collide frequently.
Root cause
The personal-workspace destroy function unconditionally rm -rfs the target path with no plugin awareness:
packages/host-workspace/src/provision.ts:733-763
async function provisionPersonalWorkspace(opts) {
...
return new ProvisionedHostWorkspace({
path: targetPath,
managed: true,
...
destroyFn: () => rm(targetPath, { recursive: true, force: true }), // line 762 — no plugin check
});
}Called from the host daemon's environment teardown, also with no plugin awareness:
apps/host-daemon/src/runtime-manager.ts:1092-1106
async destroyEnvironment(environmentId: string): Promise<void> {
...
await entry.workspace.destroy(); // line 1104 — invokes the rm above
...
}Neither the install path (bb plugin install <path>) nor the destroy path consults the other: install happily registers a source_path under a managed env, and destroy happily deletes a directory containing a registered plugin's source. The predicate to detect "this path is bb-managed" already exists but is only used for thread path claims:
apps/server/src/services/threads/worktree-paths.ts:87-96
export function isBbManagedWorkspacePath(args: { dataDir: string; path: string }): boolean { ... }Suggested fixes (any one, in rough order of effort)
-
Warn at install time (cheapest, highest leverage): when
bb plugin install <path>resolves asource_pathfor whichisBbManagedWorkspacePath(...)is true, warn that the source lives inside a managed env and will be deleted when that env is destroyed, and offer to copy it to a stable location first. This alone would have prevented all six losses. -
Guard at destroy time: in
destroyEnvironment(or inprovisionPersonalWorkspace'sdestroyFn), beforerm -rf, scaninstalled_pluginsfor any row whosesource LIKE 'path:%'resolves insidetargetPath; if found, either (a) block + error with the plugin ids, (b) migrate the source to<dataDir>/plugins-rescued/<id>and rewrite the registration, or (c) at minimum log a clear "destroyed plugin source X" warning instead of the current silent deletion. -
Refuse managed-path installs by default unless
--in-managed-envis passed, pointing the user at~/.bb/plugins/<name>or an external repo instead.
Option 1 + 2 together would close the hole end-to-end: prevent new footguns and rescue existing ones.
Environment
- bb 0.37.0 (
@bb/desktop) - macOS
- All six affected plugins were
path:-sourced from inside~/.bb/personal-workspaces/env_*/
Happy to open a PR for option 1 (install-time warning) if a maintainer confirms the desired behavior — it's a small change around the plugin install handler with a reuse of the existing isBbManagedWorkspacePath predicate.
Activity
fix(plugins): warn when installing a path plugin from a managed works…
fix(plugins): warn when installing a path plugin from a managed works…
chore: sync upstream 2026-08-18 (#6)