Skip to content

Keep path plugins when bb deletes their thread storage or workspace, and say so at install - #6973

Merged
ymichael merged 3 commits into
mainfrom
bb/plugins-installed-from-thread-storage-are-delete-thr_d5g2kma75k
Nov 4, 2026
Merged

ymichael merged 3 commits into
mainfrom
bb/plugins-installed-from-thread-storage-are-delete-thr_d5g2kma75k

Conversation

@ymichael

@ymichael ymichael commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

bb plugin install <path> registers a plugin by its folder and loads it from there. When an agent built and installed a plugin inside a folder bb later deletes, the plugin broke. One such folder is $BB_THREAD_STORAGE (<dataDir>/thread-storage/<threadId>), deleted with the thread. The other is a thread's provider-owned workspace (personal workspace or git worktree), deleted when the environment is removed, for example after the thread is archived. The source disappeared and the plugin became "plugin directory not found", then missing after a restart.

Users weren't warned either. The install-time warning from #1566 was a server log line only, and it didn't cover thread-storage/. See #6971 (thread storage, live repro on main) and #6670 (personal workspace, lost on archive).

What changed

Keep the plugin when bb deletes its folder

  • Before the server deletes a thread's storage folder, it calls the plugin service's new preservePathPluginsInside(directory). This covers requestThreadStorageDeletion (thread delete, project delete, the lifecycle sweep, Storage Retention) and orphan cleanup.
  • The environment engine's runRemove calls it too, right before the provider's remove deletes a workspace it owns. This covers git worktrees and personal workspaces, whether the environment is removed by archive, delete, retirement or bb environment delete.
  • For each path plugin whose folder is inside that directory, it copies the folder to <dataDir>/plugins/<id>/preserved-source (staged, then renamed into place). It then moves the install through installPathSource, the same flow as bb plugin install path:<new dir>, so settings, secrets and schedules are kept.
  • If the copy fails, bb keeps the folder. Thread-storage deletion logs a warning and is retried on the next sweep. Environment teardown is marked failed and retried with its existing backoff, so the provider's remove isn't called.
  • If the plugin won't start from the copy, the path-move flow keeps the old registration, the copy stays on disk, and the warning names the bb plugin install command to run.

Tell the user at install

  • InstalledPlugin gains sourceNotice: string | null, computed by the server for path plugins:
    • inside thread storage: "Installed from a thread's storage folder. When bb deletes that thread, it copies this plugin to … and runs it from there."
    • inside a live provider-owned workspace: "Installed from a bb-managed workspace. When bb removes that workspace, it copies this plugin to … and runs it from there."
    • inside other bb-managed folders (legacy worktrees/ and personal-workspaces/, plugin data dirs), where nothing copies it out: "…where bb can delete it. Reinstall it from a folder outside to keep it." This replaces the old log-only warning.
  • After the move the notice is null, because preserved-source is stable.
  • Surfaces:
    • CLI: bb plugin install and bb plugin list print it as note:.
    • App: the install toast becomes a warning toast with the notice, and Plugin details shows it under Source.
    • The server still logs it at install.
  • The contract field defaults to null, so the SDK and CLI still parse responses from older servers.

Other

  • Docs: the bb guide plugins chapter and the bb-plugin-authoring quickstart.
  • No daemon or protocol changes.

I chose copying at deletion over copying at install. Install-time copying would break the documented in-place bb plugin install . + bb plugin dev loop.

How you verified

Live, pnpm start:worktree + source CLI (env -u BB_CLI -u BB_SERVER_URL):

  • main: install from thread-storage/thr_45jajad99g/…, then bb thread delete. bb plugin reload storagedemo fails with plugin directory not found: …/thread-storage/thr_45jajad99g/bb-plugin-storagedemo (reinstall). There's no warning at install.
  • Thread storage (thr_he4xywtg9e):
    • Install prints note: Installed from a thread's storage folder….
    • After bb thread delete, the folder is gone, storagedemo is running from …/plugins/storagedemo/preserved-source with no note, and greeting = "hello-from-storage" is kept.
  • Personal workspace (thr_7c8tcxvmbt, env_j2g4g2buh4):
    • Install from inside the workspace prints note: Installed from a bb-managed workspace….
    • After bb thread delete, the environment retired, then went destroyed/removed and the workspace folder was deleted. wsdemo is running from …/plugins/wsdemo/preserved-source, and bb plugin reload wsdemo succeeds.
  • App: installed through Install from source from a thread's storage. A warning toast "Toast demo installed" shows the notice, and Plugin details shows it under Source. Checked at 1280×800 and 390×844.

Tests:

  • provider-orchestration.test.ts:
    • A real path plugin inside a provider-owned workspace has the workspace notice; removing the environment moves it to preserved-source, running, with no notice.
    • When the copy fails, the provider's remove isn't called and the environment stays failed with the error.
  • plugin-service.test.ts:
    • Thread-storage notice at install, cleared after the move; copy-out keeps a secret setting; a plugin outside the directory is untouched.
    • When the plugin can't start from the copy, it stays at its old path.
    • A legacy personal-workspaces path gets the "reinstall" notice; a folder a provider only attached to gets none.
  • thread-stop-retry.test.ts: preservation runs before thread.storage.delete is queued, and nothing is deleted when it fails.
  • PluginInstallJobsHost.test.ts: a plugin with a notice gets the warning toast with that notice, not the success toast.
  • pnpm exec turbo run typecheck lint --filter='...[origin/main]': 174/174.

Fixes #6971
Fixes #6670

AGENT GENERATED

🤖 Generated with Claude Code

@ymichael ymichael changed the title Keep plugins installed from a thread's storage when the thread is deleted Keep path plugins when bb deletes their thread storage or workspace, and say so at install Nov 4, 2026
ymichael and others added 3 commits November 4, 2026 15:25
…eted

A path plugin installed from $BB_THREAD_STORAGE loaded from that folder, and
deleting the thread (by hand or through Storage Retention) removed the folder
with no warning, leaving the plugin "directory not found".

Before bb deletes a thread's storage folder, or removes an orphaned one, it now
copies every path plugin installed from inside it to
<dataDir>/plugins/<id>/preserved-source and moves the install there through the
same path-move flow as `bb plugin install path:<new dir>`, so settings, secrets
and schedules are kept. If the copy fails the storage is kept and the deletion
retried later. If the plugin cannot start from the copy, the copy stays on disk
and the server log names it.

Fixes #6971

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… at install

A path plugin installed from inside a bb-managed workspace (such as a
thread's worktree or personal workspace) broke when that environment was
removed, just as plugins installed from thread storage did. Environment
removal now copies such plugins to <dataDir>/plugins/<id>/preserved-source
before the provider deletes the workspace, and keeps the workspace (the
teardown fails and retries) when the copy fails.

The install-time warning for these folders used to be a server log line
only, and it did not cover thread storage. Installed plugins now carry a
server-computed sourceNotice that says where the plugin will be copied.
`bb plugin install` and `bb plugin list` print it as `note:`, the app shows
it in the install toast and on Plugin details, and the server still logs it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael force-pushed the bb/plugins-installed-from-thread-storage-are-delete-thr_d5g2kma75k branch from 7932661 to a8b28a7 Compare November 4, 2026 23:27
@ymichael
ymichael merged commit bb789fe into main Nov 4, 2026
51 checks passed
@ymichael
ymichael deleted the bb/plugins-installed-from-thread-storage-are-delete-thr_d5g2kma75k branch November 4, 2026 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant