Repository navigation
Report a failed plugin reload instead of exit 0 - #2155
Merged
Merged
Conversation
SawyerHood
marked this pull request as ready for review
August 21, 2026 05:59
`bb plugin reload` answered ok:true and exited 0 even when the reload
left the plugin unusable: a previous service that ignored its abort put
the plugin in degraded with nothing loaded (its CLI command gone, its
closed database handles still ticking under the orphaned service), or
the new sources failed to load and the previous instance was kept.
`PluginService.reload` returned void, so neither POST /plugins/reload
nor the CLI could tell.
`loadOne` now resolves the load problem (null once the row's current
sources are running or the plugin stays disabled). `reload` collects the
problems per targeted plugin and returns a PluginReloadOutcome; the route
answers 422 { ok: false, error, plugins } on failure, so the CLI prints
the entries and the reason and exits 1, the dev loop logs "reload
failed", and the app/mobile SDK callers surface the error. The builtin
source watcher's reload throws the same problem. No daemon wire change.
The committed-artifact rebuild in the same issue (#2029 defect 1) is the
documented path-install cache policy and is tracked by #1863.
Co-Authored-By: Claude <[email protected]>
SawyerHood
force-pushed
the
bb/fix-2029-plugin-reload-orphans
branch
from
August 21, 2026 16:48
8d19397 to
c7cd438
Compare
ymichael
added a commit
that referenced
this pull request
Nov 18, 2026
## Human comments
## What was wrong
When a question or permission request ended for any reason other than
the user, each bridge chose its own answer, usually the protocol's "the
user cancelled" or a bare error, and nobody told the user. The runtime
gives a bridge only an error string when bb stops waiting. ACP answered
`cancel`/`decline`/`cancelled`, and Pi answered `{cancelled:true}`.
Codex answered `cancel` for MCP elicitations and a bare JSON-RPC error
for approvals and requestUserInput, which Codex itself reports to the
model as the user declining (#4645). Claude Code denied with an internal
message. ACP also silently cancelled the open question of an
agent-initiated turn when the user sent a new prompt, so the card stayed
open in bb and any later answer went nowhere. Two other places had the
same shape. `ask-user-question` turned every non-timeout cancellation
into "the user dismissed the question" (#7347). The plugin enable and
settings-save routes returned `ok` when the plugin failed to load,
because the service dropped `loadOne`'s problem. #5534 patched enable in
the CLI only.
Reproduced live on main (1fa400d) before the fix. In a source build,
a Pi extension command opened a `select` whose title was 9,010
characters. The bridge failed validation and answered
`{cancelled:true}`, and the extension recorded `answer: null`. The
thread showed nothing: no pending interaction and no warning. This is
the #4264 / #7647 shape.
## What changed
- **Guard, derived from each bridge's question kinds.**
`packages/provider-bridge-protocol/src/contract-tests/unanswered-interactions.test.ts`
loads each first-party bridge in-process and drives every question kind
it routes through six cases: unshowable request, runtime error (bb
stopped waiting), unreadable resolution, unmappable answer, withdrawn
question, and stopped turn. Each bridge's rows come from a list its own
dispatch code uses: ACP from `ACP_QUESTION_REQUEST_METHODS` (the handler
map `handleAgentRequest` dispatches through), Pi from
`PI_EXTENSION_DIALOG_METHODS` (the enum its request schema validates)
and Codex from `CODEX_QUESTION_REQUEST_METHODS` (the gate
`decodeCodexInteractiveRequest` switches over). A kind added to any of
them fails the guard until it has a surface. Claude Code's three
surfaces (AskUserQuestion, ExitPlanMode, any other tool's permission)
are listed by hand; see "Left out" below. **The rule:** every answer the
user did not give sends a `provider.warning`, whatever the provider
receives. A JSON-RPC error alone does not count. A stopped turn adds no
warning. A case a surface cannot reach must say why. The result is 88
rows. Turbo test inputs for `@bb/provider-bridge-protocol` include Pi
and ACP, so a change in any bridge re-runs the guard.
- **One owner.** In the bridge kit, `unansweredInteractionWarning({
cause, answer })` builds the warning and
`unansweredInteractionErrorMessage(cause)` gives the agent-facing error
or deny text. The SDK exports them as `experimental_*`, with an audit
entry, Plugin Guide symbols and a `provider-plugin-api.md` section. The
causes are unshowable request, runtime error, unreadable resolution,
unmappable answer and withdrawn. Every bridge site that answers without
the user goes through them:
- **ACP**: runtime errors, unreadable resolutions, answers that do not
fit a field, Accept/Decline confirmations or the offered permission
options, questions asked during compaction, and questions withdrawn when
a new prompt starts. Each gets a JSON-RPC error that says why, plus the
warning. #6518's bespoke unshowable-form text moved onto the owner.
- **Pi**: invalid dialogs (the validation issue is named), send
failures, runtime errors, unreadable resolutions and unmappable answers.
Each still sends `{cancelled:true}`, since Pi has no failure answer, but
now with the warning.
- **Codex**: every question kind. Unreadable or unmatched question
requests, plus runtime errors, unreadable resolutions and unmappable
answers, now go through one helper. `buildCodexInteractiveResult`
returns a typed `answered | unanswered` result for every payload kind.
MCP elicitations keep `cancel`; approvals and requestUserInput keep the
error, now carrying the owner's text. Unknown non-question server
requests still get METHOD_NOT_FOUND and no warning.
- **Claude Code**: invalid AskUserQuestion/ExitPlanMode input, runtime
errors, unreadable resolutions and unmappable answers deny with the
owner's text, plus the warning. Policy auto-denies and stop or teardown
denies are unchanged.
- **ask-user-question** (#7347): an exhaustive `switch` over
`PluginInteractionCancelReason`. Only `user` reads as a dismissal; other
reasons name themselves.
- **Plugin lifecycle routes**: `setEnabled` and `updateSettings` return
`{ ok, error?, … }` with the load problem. `POST /plugins/:id/enable`
and `PUT /plugins/:id/settings` answer 422 (`plugin "x" did not start:
…`), like reload. A route table covers reload, enable and settings save.
The #5534 CLI special case is deleted, and the CLI guide notes that
enable exits 1 with the load error.
- Plugin SDK 0.6.159. There are no server/daemon wire changes.
## Issues this root cause produced
| Issue | State | Mechanism | Would the guard/fix have prevented it? |
|---|---|---|---|
| #4264 | closed | Pi validation failure answered as a user decline |
Yes. Pi "unshowable request" rows. |
| #7647 | open | Pi confirm over 8,192 characters silently returns false
| Partly. It is no longer silent; Pi still gets `cancelled` because its
protocol has no failure answer. #7660 shortens the text. |
| #6266 | closed | ACP form over 4 fields; the decline reached the agent
as a user cancel | Yes. The ACP form "unshowable request" row. |
| #6508 | closed | ACP omp forms with 3+ questions declined | Yes, the
same row. |
| #4645 | closed | Codex Browser Use auto-declined; Codex told the model
the user declined | Yes, now. The rule no longer accepts an error
without a warning, and the Codex "unshowable request" rows cover a
question bb could not handle. |
| #7347 | open | ask-user-question calls an interruption "user
dismissed" | Fixed here. This overlaps open PR #7375. |
| #4940 | closed | `bb plugin enable` exits 0 / `ok:true` on a failed
load | Fixed at the route (enable row). |
| #2029 | closed | plugin reload reports success on failure | Reload row
(fixed by #2155). |
On main, the first version of the guard failed 12 of 25 rows. With this
PR's behavior reverted (Claude without warnings, Codex error answers
without warnings, ACP's silent cancel on a new prompt), the expanded
guard fails 29 of 88 rows. The settings-save row fails with the old
settings route.
**Patches deleted:** the #5534 enable workaround in the CLI; #6518's
ACP-local "could not show" wording; Codex's MCP-only cancel special case
(`buildCodexInteractiveResult` now handles every kind); and the Pi and
Codex tests that asserted a silent cancel as correct behavior.
## Left out, deliberately
- **Who stopped the turn.** Codex's `stopsRequested` (and ACP's and Pi's
stop handling) treats every interrupt as a stop, including workflow
`stopChild` and archive. The bridge cannot do better: `thread/stop`
carries only `intent`, and workflow `stopChild` calls the same
`threads.stop` API as the user, so even the server records it as a
manual stop. A stopped turn is never silent, though. The server marks
the open question `interrupted` with its reason in the timeline, and for
the agent `cancelled` is the protocol's meaning of a cancelled turn.
Carrying a stop origin to bridges would be a server, daemon and bridge
wire change (`HOST_DAEMON_PROTOCOL_VERSION`) that adds nothing the
timeline doesn't already show. The guard calls this case "turn-stopped"
rather than "user-stop".
- **Claude's rows are listed by hand.** Claude Code's `canUseTool`
special-cases two tool names and treats every other tool as a
permission. There is no list in its dispatch to derive from, and adding
one only for the test would be a test-only production seam.
- **Unreachable cases** are named in the guard with their reason: ACP
permission requests are never unshowable once well-formed; Codex command
and file-change approvals have no decision that fails to map; only ACP
ever withdraws a question; and Claude shows any tool's raw input.
## Decisions for review
- **New timeline warning.** "bb answered the agent without you" (details
name the answer sent and the cause) appears on ACP, Pi, Codex and Claude
Code threads whenever a question or permission request ends without the
user. It never appears for a stopped turn. ACP's existing
unshowable-form warning changes its summary to this one.
- **Error texts the agent sees change** to "The user did not answer: …"
for ACP errors, Codex approval/requestUserInput errors and Claude Code
failure denies. ACP agents get an error instead of
`cancel`/`decline`/`cancelled` for these failures, including permission
requests and questions withdrawn by a new prompt.
- **Saving settings that leave a plugin failing to start**, and enabling
such a plugin, now return an error (422, so the existing toast paths
show it), where before they reported success. The settings are still
saved. The SDK's `plugins.enable` and `plugins.updateSettings` throw.
- **ask-user-question** tells the model "The question closed before the
user answered (<reason>); the user has not responded…" for non-user
cancellations.
## How you verified
- Guard on the first revision's main: 12 of 25 failed, all real members.
Expanded guard: 88 of 88 pass. With the old behaviors restored it fails
29 rows: all of Claude's non-stop rows, every Codex kind, and both ACP
withdrawn rows. An earlier mutation check showed the Codex stop counter
keeps the turn-stopped row quiet.
- Lifecycle-route table: the enable row returned 200 on main, and the
settings-save row fails with the old route; both return 422 now.
- Targeted tests pass: the provider-bridge-protocol guard,
`@bb/provider-bridge-acp` `bridge.test.ts` and `elicitation.test.ts`, Pi
`extension-ui*`, Codex `interactive-requests`, `bridge.elicitation`,
`bridge.native-question` and `bridge.calibration`, Claude Code
`bridge.test.ts`, ask-user-question `server-harness`, the server plugin
service/route/settings/update/safe-mode/logo/icon/app-bundle suites,
heroes, echo-provider, provider-management, and the CLI `plugin-enable`.
- `turbo run typecheck lint` for the protocol, ACP, plugin SDK, Pi,
Codex, Claude Code, Plugin Guide and server packages.
- Live after the first revision, with the same Pi fixture: the thread
records `provider/warning` "bb answered the agent without you" ("…with
"cancelled" because it could not show the question: title: Too big:
expected string to have <=8192 characters"), and it is visible in the
thread timeline.
Fixes #7347
> AGENT GENERATED
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
bb plugin reloadreported success for a reload that left the plugin unusable.PluginService.reload()returnedvoid,POST /api/v1/plugins/reloadanswered{ ok: true }unconditionally, and the CLI exited 1 only onok: falseor an unknown id. So when a background service ignored its abort signal, the runtime correctly refused to double-start it, marked the plugindegraded, closed the old instance's database handles, and unloaded it (itsbbcommand gone, the orphaned service tickingThe database connection is not openevery second), and the reload still returned exit 0 /ok: true. The same held when the new sources failed to load and the runtime kept the previous instance (runningwithreload failed: …). Issue: #2029 (defect 2). Report: https://get-bb.github.io/reports/issues/2029.htmlDefect 1 in the issue (the host rebuilding
dist/app.*into a path-installed plugin root) is the documented path-install cache policy (isMutableAppBundleStale, covered by existing tests) and is tracked by #1863; this PR does not change it.What changed
apps/server/src/services/plugins/plugin-runtime.ts:loadOne(row)resolves the load problem (string | null) instead ofvoid. Null means the row's current sources are running now, or the plugin stays disabled by the user's switch. Every failure exit returns its reason; a reload that kept the previous instance says so (… (the previous instance is still running)); the two hung-service exits sharehungServicesDetail. Statuses and log lines are unchanged.apps/server/src/services/plugins/plugin-service.ts:reload(id?)returnsPluginReloadOutcome:{ ok: true, plugins }or{ ok: false, error, plugins }whereerrorlists each targeted plugin that did not come up andpluginsis the inventory after the reload. The builtin source-watcher'sreloadPluginthrows the same problem so the dev loop logsreload failed: …instead ofreloaded.apps/server/src/routes/plugins.ts: the route answers422 { ok: false, error, plugins }on failure; success body is unchanged (pluginReloadResponseSchemastill matches). SDK callers (webPluginHealthBanner, mobileuseReloadPlugins) already surface a thrownBbHttpErrorwith the server's message. No host daemon wire change, so noHOST_DAEMON_PROTOCOL_VERSIONbump.apps/cli/src/commands/plugin.ts:bb plugin reloadprints the targeted entries (status and detail) before the error and exit 1;--jsonalready exited 1 onok: false.bb plugin devalready throws on!okand its loop logs it.packages/templates/src/templates/bb-guide-plugins.md) and bb-cli skill (apps/server/src/services/skills/builtin-skills/bb-cli/SKILL.md): document the exit code.plugin-registration.ts,plugin-activation.ts:loadOnedep type follows.How you verified
Tests that fail on
origin/mainand pass here:apps/server/test/services/plugins/plugin-background.test.tsmarks the plugin degraded when a service ignores its abortnow asserts the outcome. Before:AssertionError: expected undefined to deeply equal { ok: false, …(2) }.reports a failed reload that kept the previous instance(new): broken edit →running+reload failed: boom on load, outcomeok: falsewithplugin "keeper" reload failed: boom on load (the previous instance is still running); reload-all reports it; a fixed edit reloadsok: true.apps/server/test/services/plugins/plugin-reload-route.test.ts(new, real app harness): success → 200{ ok: true, plugins }; broken sources → 422{ ok: false, error, plugins: [{ status: "running", statusDetail: "reload failed: boom on load" }] }. Before:AssertionError: expected 200 to be 422.Commands (from the committed tree):
pnpm exec turbo run typecheck --filter=@bb/server --filter=@bb/cli --filter=@bb/templates→Tasks: 6 successful, 6 totalpnpm exec turbo run test --filter=@bb/cli --filter=@bb/templates→Tasks: 8 successful, 8 total(453 + 41 tests)pnpm exec turbo run test --filter=@bb/server→ 1825 passed, 1 failed:test/internal/internal-skill-trees.test.ts(mode: 420vs436), the known local umask-0002 failure unrelated to this change; it passes in CI.Manual repro on my own dev instance with the report's fixture (a path plugin whose
lane-watcherservice capturesbb.storage.database()and ignores abort):Before this change the same reload printed the degraded entry and exited 0 with
"ok": true(report step 3).Fixes #2029
Independent verification
Checked out
bb/fix-2029-plugin-reload-orphans(8d19397, one commit on top of origin/main f6fb434; origin/main has not moved since) in a separate worktree and dev instance.Commands:
pnpm install --frozen-lockfile --prefer-offline && pnpm exec turbo run build(18/18 tasks).git checkout origin/main -- apps/cli/src/commands/plugin.ts apps/server/src/routes/plugins.ts apps/server/src/services/plugins/{plugin-activation,plugin-registration,plugin-runtime,plugin-service}.ts, thenpnpm exec vitest run test/services/plugins/plugin-background.test.ts test/services/plugins/plugin-reload-route.test.tsfromapps/server: 3 failed / 15 passed.marks the plugin degraded when a service ignores its abort:AssertionError: expected undefined to deeply equal { ok: false, …(2) }reports a failed reload that kept the previous instance:TypeError: Cannot read properties of undefined (reading 'ok')atexpect(healthy.ok).toBe(true)answers ok:false with the load problem when the new sources did not load (#2029):AssertionError: expected 200 to be 422git checkout HEAD -- <same files>, same vitest run: 18/18 passed.pnpm exec turbo run typecheck --filter=@bb/server --filter=@bb/cli --filter=@bb/templates:Tasks: 6 successful, 6 total.pnpm exec turbo run test --filter=@bb/server --filter=@bb/cli --filter=@bb/templates: cli 453/453, templates 41/41, server 1825 passed / 1 failed (test/internal/internal-skill-trees.test.tsmode 420 vs 436, the known local umask-0002 failure; unrelated, green in CI).Repro on the fixed branch (own dev instance, report fixture: path plugin whose
lane-watcherservice capturesbb.storage.database()and ignores abort):On main the same reload exits 0 with
ok: true(report step 3). The orphaned service still logsThe database connection is not openevery tick, which is the documented degraded contract and out of scope here.Review notes: root cause (reload outcome never propagated) is fixed in the server, which owns the policy; no host-daemon wire change, so no protocol bump needed. CLI
callPluginsalready passes 422 bodies through, the dev loop catches the thrown reload, and the SDK surfaces the 422 asBbHttpErrorwith the server message (web banner toasts, mobile mutation toasts). Guide and bb-cli skill document the exit code. Minor, non-blocking:pluginReloadResponseSchemain server-contract still types only the success body, so SDK callers see the failure viaBbHttpError.bodyuntyped; webPluginHealthBannerdoes not invalidate the plugin list on error and relies on theplugins-changedbroadcast for the refreshed status. Defect 1 (rebuild into a path plugin root) is intentionally left to #1863.Rebase
Rebased onto origin/main
85eec4da6(was 33 commits behind; still one commit, nowc7cd438b3).git rebase origin/mainapplied with no conflicts. Main's changes in the touched files are orthogonal to this fix:plugin-runtime.tsgained providerinstallRankand per-command settings reads (#2148),plugin-service.tsgained agent-tool presentation for grammar v3 (#2164), and the guide/skill docs gained unrelated lines. None of that touchesloadOne's exits orreload, so thestring | nullload problem and thePluginReloadOutcomeplumbing map onto the new code unchanged.Re-proved on the new base. With the six non-test source files reverted to origin/main,
plugin-background.test.ts+plugin-reload-route.test.ts: 3 failed / 15 passed (expected undefined to deeply equal { ok: false, …(2) },Cannot read properties of undefined (reading 'ok'),expected 200 to be 422); restored: 18/18 passed. From the committed tree:turbo typecheck --filter=@bb/server --filter=@bb/cli --filter=@bb/templates --filter=@bb/host-daemon --filter=@bb/sdk→Tasks: 8 successful, 8 total;turbo test --filter=@bb/cli --filter=@bb/templates→Tasks: 8 successful, 8 total(453 + 41 tests);turbo test --filter=@bb/server→ 1898 passed, 2 failed: the known local umaskinternal-skill-treesfailure and a 5s timeout inplugin-update.test.ts(waits one full interval…) on a box at load average 128 with swap full; that file passes 27/27 when run alone.Independent verification (post-rebase)
Re-verified the rebased head
c7cd438b3(one commit; merge base with origin/main is75d6fc4d4, and the only newer main commit,85eec4da6, is a TestFlight CI change) in a fresh worktree and own dev instance.git merge --no-commit origin/mainis clean. Main's intervening changes toplugin-runtime.ts(#2148 providerinstallRank, per-command settings reads) andplugin-service.ts(#2164 grammar-v3 agent-tool presentation) do not add any exit toloadOne; every exit in the rebasedloadOnereturns its problem (string | null) and the final path returnsnull. No provider-bridge-protocol, provider plugin, or agent-runtime file is touched, so no parity run was needed and noHOST_DAEMON_PROTOCOL_VERSIONbump is required.Commands:
pnpm install --frozen-lockfile --prefer-offline && pnpm exec turbo run build(18/18 tasks).git checkout origin/main -- apps/cli/src/commands/plugin.ts apps/server/src/routes/plugins.ts apps/server/src/services/plugins/{plugin-activation,plugin-registration,plugin-runtime,plugin-service}.ts, thenpnpm exec vitest run test/services/plugins/plugin-background.test.ts test/services/plugins/plugin-reload-route.test.tsfromapps/server: 3 failed / 15 passed.marks the plugin degraded when a service ignores its abort:AssertionError: expected undefined to deeply equal { ok: false, …(2) }reports a failed reload that kept the previous instance:TypeError: Cannot read properties of undefined (reading 'ok')answers ok:false with the load problem when the new sources did not load (#2029):AssertionError: expected 200 to be 422git checkout HEAD -- <same files>, same run: 18/18 passed.git status --porcelainempty):pnpm exec turbo run typecheck --filter=@bb/server --filter=@bb/cli --filter=@bb/templates --filter=@bb/sdk --filter=@bb/host-daemon→Tasks: 8 successful, 8 total.pnpm exec turbo run test --filter=@bb/server --filter=@bb/cli --filter=@bb/templates: cli 453/453, templates 41/41, server 1899 passed / 1 failed (test/internal/internal-skill-trees.test.tsmode 420 vs 436, the known local umask-0002 failure; unrelated, green in CI).c7cd438b3: all checks pass (Checks, Package Smoke ubuntu + macos, Tests app-1/2/3, integration, packages, server, version check); iOS simulator and Node compat smoke are conditional skips.Repro on the rebased branch (own dev instance, report fixture: path plugin whose
lane-watchercapturesbb.storage.database()and ignores abort):On main the same reload exits 0 with
ok: true(report step 3). Residual, unchanged from the first verification: the orphaned service still logsThe database connection is not openevery tick (documented degraded contract);pluginReloadResponseSchematypes only the success body, so SDK callers see the 422 as aBbHttpErrorwith the server message; defect 1 (rebuild into a path plugin root) is left to #1863.