Skip to content

Allow uninstalling built-in plugins that are no longer bundled - #4240

Closed
ymichael wants to merge 1 commit into
mainfrom
bb/investigate-bb-ai-plugin-uninstall-failure-thr_xd5escd86j
Closed

ymichael wants to merge 1 commit into
mainfrom
bb/investigate-bb-ai-plugin-uninstall-failure-thr_xd5escd86j

Conversation

@ymichael

@ymichael ymichael commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

DELETE /api/v1/plugins/:id returned 409 for every installed row with builtin provenance, whether or not that plugin was still bundled. Startup reconciliation only walks plugins that are still bundled and never prunes the rest, so a built-in that leaves the registry keeps its row forever. bb-ai is an example: #4230 bundled it and #4232 reverted it. The row can be disabled, but bb plugin uninstall bb-ai and the Settings UI both refuse to remove it. The server already reports these rows as isOrphanedBuiltin: true (added in #673 so they could be removed). The later 409 guard didn't respect that flag, and the UI stopped using it.

What changed

  • apps/server: PluginService.isBuiltin is replaced by isBundledBuiltin, which returns false for orphaned rows. isOrphanedBuiltin and the delete guard now share a single orphan check. Orphaned built-ins go through the existing remove path, which tombstones built-in rows, so a plugin that is bundled again later stays uninstalled.
  • apps/app: the Uninstall action in PluginDetail and in usePluginRemoval is enabled for orphaned built-ins. Built-ins that are still bundled keep the "Included with BB; disable this plugin instead." message.
  • apps/cli: bb plugin requests pass 409 bodies through, so bb plugin uninstall prints the server's error instead of failed: HTTP 409.

No wire or daemon protocol changes.

How you verified

  • New server test in builtin-plugins.test.ts: a bundled built-in is protected; once dropped from the registry it can be removed; it stays removed after bundling it again. It fails before the fix because isBuiltin returned true for the orphaned row.
  • New app test in ToolsView.plugin-detail.test.tsx: Uninstall is enabled for an orphaned built-in and calls onDelete.
  • pnpm exec turbo run typecheck lint --filter=@bb/server --filter=@bb/app --filter=@bb/cli passes.
  • turbo run test --filter=@bb/server -- test/services/plugins/builtin-plugins.test.ts: 35/35. turbo run test --filter=@bb/app -- src/views/ToolsView.plugin-detail.test.tsx src/components/plugin: 548/548.
  • Live before/after in a disposable pnpm start:worktree instance, fresh data dir, one checkout replaying the real history:
    • Add bb cloud AI: hosted titles and commit messages for signed-in accounts #4230 (2bbdf66124): bb-ai auto-installs as a running built-in.
    • PR base (4277998ed7): bb-ai and bb-account report isOrphanedBuiltin: true. Source-CLI bb plugin uninstall bb-ai prints Error: /api/v1/plugins/bb-ai failed: HTTP 409, and in Settings the Uninstall action is blocked with "Included with BB; disable this plugin instead."
    • PR head (bc93555e80): Uninstall in Settings → confirm removes bb-ai with a "Plugin uninstalled" toast. Source-CLI bb plugin uninstall bb-account prints Removed bb-account., and bb plugin uninstall bb-guide (still bundled) prints Built-in plugins can be disabled, but not deleted. with exit 1. After a server restart and browser reload, both removed plugins stay gone (rows tombstoned with removed_at) and bb-guide is unchanged.

AGENT GENERATED

🤖 Generated with Claude Code

The plugin delete route refused every row with builtin provenance, so a
builtin dropped from the registry (bb-ai after #4232) could never be
removed. Only protect builtins that are still bundled, re-enable the
Uninstall action for orphaned builtins in Settings, and have the CLI
print the server's 409 message instead of a bare status code.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@ymichael
ymichael force-pushed the bb/investigate-bb-ai-plugin-uninstall-failure-thr_xd5escd86j branch 3 times, most recently from 096760b to bc93555 Compare September 24, 2026 18:40
@ymichael ymichael closed this Sep 24, 2026
ymichael added a commit that referenced this pull request Sep 24, 2026
## Human comments

## What was wrong

When bb stops bundling a built-in plugin, its installed row stays.
Startup (`reconcileBundled`) only walks plugins that are currently
bundled: it installs new ones and never looks at rows whose built-in is
gone. After #4232 reverted #4229/#4230, data dirs that had run those
builds kept `bb-ai` and `bb-account` forever, showing as "Missing:
Plugin files are missing. Update or reinstall bb." The delete route
refuses built-ins, so users couldn't remove them either. #4240 made the
manual uninstall possible; this makes cleaning them up by hand
unnecessary.

## What changed

`apps/server/src/services/plugins/plugin-service.ts`:
- After bundled reconciliation and before `loadAll()`, startup deletes
every installed built-in whose name is no longer in this build's
registry. It uses the existing orphan check behind `isOrphanedBuiltin`,
now a shared `isOrphanedBuiltinRow` helper.
- It also deletes the plugin's settings, secrets and schedules through
the same helper manual removal uses (`deleteRemovedPluginData`,
extracted from `remove()`). That includes `onPluginUnregistered`, which
re-dispatches queued messages the plugin was holding.
- The row is deleted outright rather than tombstoned, so a plugin that
is bundled again later installs fresh.
- Startup deletes the row only after settings, schedules, and secret
cleanup succeeds. If secret removal fails, the row remains so the next
startup retries cleanup.
- Rows a user already uninstalled (tombstoned) are left alone, because
`listInstalledPlugins` skips them.
- Each removal is logged: `plugin <id> removed because bb no longer
bundles builtin:<name>; its settings, secrets, and schedules were
deleted`.
- The check compares against the static registry, not what loaded, so a
broken or partial build can't delete bundled plugins.

No wire or daemon protocol changes. No CLI or UI changes.

## How you verified

- `builtin-plugins.test.ts`: the old "marks a persisted builtin as
orphaned" test is replaced by "removes a builtin and its data once bb no
longer bundles it". It seeds a setting, a schedule and a secret file,
restarts without the built-in, and asserts the row, settings, schedule
and secrets directory are gone and the list is empty. It then re-bundles
and asserts a fresh, enabled install. It fails with the startup call
removed and passes with it.
- `builtin-plugins.test.ts` also simulates one secret removal failure,
confirms the registration remains, then confirms a second startup
removes the secret and row.
- `pnpm exec turbo run test --filter=@bb/server -- --run
test/services/plugins/builtin-plugins.test.ts`: 35/35.
- `pnpm exec turbo run typecheck --filter=@bb/server`: clean.
- `pnpm exec turbo run typecheck lint --filter=@bb/server`: clean.
- `turbo run test --filter=@bb/server -- test/services/plugins`:
521/521.
- Live, in a disposable `pnpm start:worktree` instance whose data dir
really went through #4230 then the revert, so it had `bb-ai` and
`bb-account` rows with their folders missing, plus one seeded `bb-ai`
setting. After restarting on this branch, both rows and the setting were
gone, the API listed no orphans, `bb-guide` was unchanged, and the
server log had both removal lines.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

> AGENT GENERATED

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[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.

1 participant