Skip to content

fix(plugins): warn when installing a path plugin from a managed workspace - #1566

Merged
SawyerHood merged 1 commit into
get-bb:mainfrom
PennybagsCX:fix/warn-on-managed-workspace-plugin-install
Aug 14, 2026
Merged

SawyerHood merged 1 commit into
get-bb:mainfrom
PennybagsCX:fix/warn-on-managed-workspace-plugin-install

Conversation

@PennybagsCX

Copy link
Copy Markdown
Contributor

Summary

Cheapest of the three fixes proposed in #1565. When a user runs bb plugin install <path> (or installPath) and the resolved source_path lives inside a bb-managed workspace (<dataDir>/personal-workspaces/env_*/ or <dataDir>/worktrees/), emit a logger.warn so they know the source is ephemeral — it will be deleted when that environment is destroyed (e.g. when the owning thread is archived).

This does not change install behavior; it only surfaces the hazard. It reuses the existing isBbManagedWorkspacePath predicate (already used for thread path-claims in worktree-paths.ts), so there's no new concept to maintain.

Why

I lost six plugins this way on a single machine (browser-preview, automaker, file-explorer, prime-agent-ui, terminal-dock, thread-ops), one of them twice. The natural workflow — scaffold a plugin inside the thread's env via bb plugin new, then bb plugin install . — collides with the normal archive→env-destroy lifecycle. The plugin source is silently rm -rf'd by provisionPersonalWorkspace's destroyFn (packages/host-workspace/src/provision.ts:762), leaving a dangling missing (reinstall) registration.

A warning at install time is high-leverage and zero-risk: it teaches the user the model the first time, before any data is lost. The destroy-time guard (option 2 in the issue) is the stronger fix and is worth doing separately, but this PR stands on its own.

Changes

  • apps/server/src/services/plugins/plugin-registration.ts: in installPathSource, after resolving rootDir, check isBbManagedWorkspacePath({ dataDir: deps.dataDir, path: rootDir }) and logger.warn(...) if true.
  • apps/server/test/services/plugins/plugin-service.test.ts: new test asserts the warning fires for an install under <dataDir>/personal-workspaces/env_test/....

Test plan

  • pnpm vitest run in apps/server — 19/19 plugin-service tests pass (including the new one)
  • tsc --noEmit clean
  • eslint clean on both changed files

Closes #1565 (install-time-warning portion).

@SawyerHood

Copy link
Copy Markdown
Collaborator

Ohhh man this is horrible! Let me make sure we do this! TY For the PR

…pace (get-bb#1565)

A path-sourced plugin installed from inside a bb-managed workspace
(<dataDir>/personal-workspaces/env_*/ or <dataDir>/worktrees/) is silently
deleted when that environment is destroyed (e.g. when the owning thread is
archived). The env teardown path in packages/host-workspace/src/provision.ts
recursively removes the workspace directory with no awareness of registered
plugins whose source_path lives beneath it, leaving the plugin permanently
"missing (reinstall)" with its source gone.

This is the cheapest of the three fixes proposed in get-bb#1565: emit a logger.warn
at install time so users know the source is ephemeral and can reinstall from a
stable path. It reuses the existing isBbManagedWorkspacePath predicate already
used for thread path-claims, and does not change install behavior.

Tested: new case in plugin-service.test.ts asserts the warning fires for an
install under <dataDir>/personal-workspaces/env_*.

Refs get-bb#1565
@SawyerHood
SawyerHood force-pushed the fix/warn-on-managed-workspace-plugin-install branch from dce1d63 to d3459d5 Compare August 14, 2026 20:47
@SawyerHood
SawyerHood merged commit 85df639 into get-bb:main Aug 14, 2026
9 checks passed
ymichael added a commit that referenced this pull request Nov 4, 2026
…and say so at install (#6973)

## 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 <dataDir>
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](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants