Skip to content

Env destroy deletes registered path-sourced plugins (no plugin-source guard before rm -rf) #1565

Closed

Description

@PennybagsCX

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

  1. Create a thread (managed env env_A provisioned under <dataDir>/personal-workspaces/env_A/).
  2. Build a plugin inside it and install from the local path:
    cd ~/.bb/personal-workspaces/env_A/bb-plugin-mine
    bb plugin install . --yes
    
  3. Archive the thread → after the env grace window, destroyEnvironment fires and rm -rfs env_A/.
  4. bb plugin list now 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)

  1. Warn at install time (cheapest, highest leverage): when bb plugin install <path> resolves a source_path for which isBbManagedWorkspacePath(...) 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.

  2. Guard at destroy time: in destroyEnvironment (or in provisionPersonalWorkspace's destroyFn), before rm -rf, scan installed_plugins for any row whose source LIKE 'path:%' resolves inside targetPath; 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.

  3. Refuse managed-path installs by default unless --in-managed-env is 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions