Skip to content

Report provider-bridge, plugin-RPC and orphaned tool-call failures to the plugin - #8080

Merged
ymichael merged 6 commits into
mainfrom
bb/plugin-failures-reach-the-plugin-provider-bridge-thr_y8v7eqi52e
Nov 24, 2026
Merged

ymichael merged 6 commits into
mainfrom
bb/plugin-failures-reach-the-plugin-provider-bridge-thr_y8v7eqi52e

Conversation

@ymichael

@ymichael ymichael commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Three plugin failures still never reached the plugin. This is the residue of plugin API audit findings c-backend F2, F3 and F15, which #7875 left as "Not done".

  • F2. Provider bridge failures. A bridge process that crashed, for example a host artifact with no experimental_providerBridge export, reached only the server log through the model catalog, the health check and the session path. The health check in provider-states.ts was a bare catch {} that said "Provider readiness could not be checked." with no reason. The plugin still showed plain "running". The daemon reported the crash as a generic command_failed, so the server had no way to tell a bridge crash apart from any other command failure.
  • F3. Plugin RPC route errors. POST /plugins/:id/rpc/:method returned bare strings for four failures: unknown plugin, plugin not running, a bad caller token, and a local-auth failure. Through bb.sdk, an experimental_BbHttpError therefore had code: null, and only the HTTP status told them apart. bb-account, connect and the mobile push client branched on 404/503 or on the message text. Connect's check also showed "the bb account plugin is off" for any gateway 503.
  • F15. Orphaned tool calls. When a plugin was reloaded, updated or disabled while its tool call waited on requestInput, PluginToolCallRegistry dropped the result with an info log. The agent had been told "A successful result will arrive separately", so it waited forever.

What changed

Provider bridges (F2). Wire change: HOST_DAEMON_PROTOCOL_VERSION 280 → 281.

  • ProviderProcessExitedError (agent-runtime) carries code: "provider_process_exited" for an unexpected exit, the same code the mid-session system/error event already uses. The daemon's getErrorCode passes it through as the host-RPC errorCode (it was command_failed). An expected shutdown keeps no code.
  • ProviderRegistration.reportBridgeFailure({ hostId, operation, message }) is server-internal. The plugin runtime implements it with Send plugin failures to the plugin's own log #7875's pluginLog.warn and the same running-status detail invokeWrapped sets. It is a no-op after the registration is disposed.
  • It is called from two places:
    • callHostOnlineRpcWithRetry, when a response fails with provider_process_exited and the command carries a bridgeLaunch. This covers provider.health, provider.list_models, list_commands, usage, installation, thread.start, turn.submit and the other bridge commands.
    • The system/error provider_process_exited event branch in internal/events.ts, for a bridge that dies mid-session.
  • Normal provider results such as "not installed" are not bridge exits, so they stay out of the plugin log.
  • The health check reports its reason: Provider readiness could not be checked: <first line of the error>.

Plugin RPC route (F3)

  • The four failures return { ok: false, error: { code, message } } with these codes: plugin_not_found 404, plugin_not_running 503, invalid_caller 403, and forbidden_origin 403 / unsupported_media_type 415 for local auth. Statuses and messages are unchanged.
  • BrowserRequestProblem now carries its own code (forbidden_host, forbidden_origin or unsupported_media_type). server.ts, files.ts and desktop-browsers.ts use it instead of each re-deriving the code from the status.
  • SDK: the PluginRpcErrorCode union gains those five codes, so the app's experimental_PluginRpcCallError.code names them instead of mapping them to unknown_error.
  • First-party callers now read code:
    • plugins/bb-account/src/client.ts
    • plugins/connect/app.tsx (isUnavailableError)
    • apps/mobile/.../push-subscriptions-api.ts, which keeps its message match as a fallback for older servers.

Orphaned tool calls (F15)

  • PluginToolCallRegistry settles an abandoned call immediately instead of waiting for the plugin's handler to return.
  • When the plugin is disposed, a detached call delivers Tool "<name>" failed: the "<plugin>" plugin stopped before the call finished (it was reloaded, updated or disabled, or bb restarted), so its result will not arrive. Call the tool again if you still need it. It is delivered through the existing tool-result-delivered system message with wakeIdleThread: true, so an idle agent wakes.
  • A graceful server stop disposes every plugin, so it takes the same path. Shutdown calls deferDeliveriesToRestart() before stopping plugins, so these notices are queued without starting a turn (the plugin the agent would call again is being torn down), then settleDeliveries() waits until they are written. The periodic idle-thread queue sweep sends them once bb is back.
  • Thread stop and thread delete still drop the result. User dismissals and timeouts still don't wake an idle thread, as Let plugin tools awaiting user input outlive their turn #3878 intended.

Docs.

  • docs/api_to_audit.md: the experimental_BbHttpError and experimental_PluginRpcCallError entries.
  • The Plugin Guide RPC card in surfaces.ts.
  • The bb-plugin-authoring skill: backend-events.md (now exactly 500 lines), backend-sdk.md and backend-cli-agents.md.
  • The PluginAgentToolContext.signal JSDoc.
  • Plugin SDK 0.6.195.

Community callers (not edited, 504-repo corpus). Statuses and messages are unchanged, so the status checks and message regexes keep working. That covers:

  • bitcomplete/bb-plugins (linear, github-watcher, stewards source-contract.ts:791; its code regex also matches plugin_not_found)
  • wy3z/bb-cursor-suite cursor-sidebar/src/change-requests.ts:270
  • kalindudc/bb-marketplace shuttle bb-port.ts:73 and tavern burn.ts:16

One repo changes behaviour: pascal-de-ladurantaye/bb-autoresearch src/bench-provider/client.ts:58 requires code === null before it treats a failure as a missing provider. With plugin_not_found it will now report a generic provider error.

Not done

  • The plugin http and WebSocket routes still return bare string errors. They are not part of this finding, and changing their body shape could break external clients.
  • The fake plugin host still never detaches, so authors can't test the detached path (F15's second bullet).

Found, not fixed

  • A detached tool call is lost when the server crashes or is killed. Its agent keeps waiting. A graceful stop or restart delivers the failure (above), but the registry is in memory and pending_interactions rows don't record the tool call, so recovering after a crash needs a schema change.
  • apps/server/test/app/install-machine-script.test.ts is flaky on main. It fails 2–3 different tests per run on a clean origin/main worktree too ("bb host daemon exited before it connected"). It is unrelated to this change.

How you verified

Tests that fail on main and pass here. Checked by swapping the non-test sources back to origin/main.

  • plugin-failure-log.test.ts, two new rows:
    • bridge-exit-health asserts the plugin log line, the status detail and the health statusMessage.
    • bridge-exit-session covers a daemon system/error event.
  • plugin-wire.test.ts: a four-row table that checks each RPC route failure has a structured { code, message }.
  • internal-tool-call-regressions.test.ts: an idle thread whose waiting tool's plugin is disposed gets a tool-result-delivered turn carrying the failure.
  • plugin-tool-calls.test.ts: plugin disposal delivers a waking failure at once, and the handler's late result is ignored.
  • internal-tool-call-regressions.test.ts and plugin-tool-calls.test.ts (shutdown): after deferDeliveriesToRestart(), the failure is queued without a turn, settleDeliveries() resolves only once it is written, and an idle-recovery dispatch then sends it. Each test fails if shutdown dispatches immediately or does not wait.
  • runtime.process-lifecycle.test.ts: a crashed bridge rejects with code: "provider_process_exited".
  • plugin-sdk-hooks.test.ts (app): the route codes reach experimental_PluginRpcCallError.code.
  • push-subscriptions-api.test.ts (mobile): the structured unavailable codes map to the settings status.

Commands

  • pnpm exec turbo run typecheck lint and pnpm exec turbo run test --continue for @bb/server, @bb/agent-runtime, @bb/host-daemon, @bb/host-daemon-contract, @get-bb/plugin-sdk, @bb/mobile, @bb/app, @bb/domain, bb-account, connect, plugin-api-docs and bb-guide. Everything is green except install-machine-script.test.ts (see "Found, not fixed").
  • oxfmt --check on the changed files.

Live, pnpm start:worktree, same script on main and on this branch

  • F2. QA plugin bridgeqa registers a provider whose host artifact has no bridge export.
    • Before: health showed Provider readiness could not be checked., bb plugin logs bridgeqa had only "loaded", and bb plugin list showed plain running.
    • After: health shows Provider readiness could not be checked: Provider "bridgeqa" exited unexpectedly (code 1). The plugin log has provider.health, provider.list_models and thread.start lines, each with the bridge's stderr. bb plugin list shows running (provider "bridgeqa" thread.start failed: Provider "bridgeqa" exited unexpectedly (code 1)). The logs of provider-acp, codex, claude-code and pi got no lines.
  • F3. QA plugin rpcqa calls bb.sdk.plugins.callRpc and prints the error.
    • Before: unknown plugin gave code: null with status 404, and not running gave code: null with status 503. A bad caller token and text/plain got bare-string bodies.
    • After: plugin_not_found, plugin_not_running, invalid_caller and unsupported_media_type, each with its message. With bb-account disabled, bb connect --code … still says "the bb account plugin isn't running", now through the code.
  • F15. A Codex thread called AskUserQuestion and ended its turn, then bb plugin reload ask-user-question ran.
    • Before: the interaction went interrupted, the server logged "Dropped a detached plugin tool result…", and the thread stayed idle.
    • After: the thread received the failure as a tool-result-delivered turn, replied "I'll retry the question.", and asked again on the reloaded plugin.
  • F15 across a graceful restart. A Codex thread asked "Pick a fruit" and went idle, then the server got SIGTERM and the launcher restarted it.
    • At exit: the queue held the tool-result-delivered notice ("…or bb restarted…") and the thread's turn-request count was unchanged, so no turn started during shutdown.
    • After start: within seconds the notice was sent (queue empty, one new turn) and the agent asked "Pick a fruit" again.

🤖 Generated with Claude Code

AGENT GENERATED

@ymichael
ymichael force-pushed the bb/plugin-failures-reach-the-plugin-provider-bridge-thr_y8v7eqi52e branch 3 times, most recently from 03fd66e to 2de666d Compare November 24, 2026 06:05
ymichael and others added 5 commits November 24, 2026 11:15
… the plugin

Provider bridges: an unexpected bridge exit now carries the code
provider_process_exited from the daemon (HOST_DAEMON_PROTOCOL_VERSION
280). The server writes it to the provider plugin's own log and status
detail, from the host-RPC response for every bridge command and from the
mid-session system/error event. A failed health check shows its reason
instead of a bare catch.

Plugin RPC route: unknown plugin, not running, bad caller token and
non-JSON body return { code, message } (plugin_not_found,
plugin_not_running, invalid_caller, unsupported_media_type), and
PluginRpcErrorCode names them. BrowserRequestProblem carries its own code.
bb-account, connect and the mobile push client read the code instead of
the status or message.

Detached tool calls: when a plugin is disposed while its tool call waits
on requestInput, the agent is told at once that the call failed, waking an
idle thread, instead of the result being dropped.

Plugin SDK 0.6.191.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A graceful server stop disposes every plugin, so a tool call waiting on
requestInput was settled with the "plugin stopped" failure. That delivery
was fire-and-forget: nothing waited for it, and it tried to start a turn
while the plugin the agent would call again was being torn down.

Shutdown now switches the tool call registry to queue these notices
without dispatching them and waits until they are written. The periodic
idle-thread queue sweep sends them once bb is back. The failure text now
also names a bb restart.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael force-pushed the bb/plugin-failures-reach-the-plugin-provider-bridge-thr_y8v7eqi52e branch from f4f2ec4 to e2c8b5d Compare November 24, 2026 19:16
@ymichael
ymichael merged commit a3c543c into main Nov 24, 2026
95 of 97 checks passed
@ymichael
ymichael deleted the bb/plugin-failures-reach-the-plugin-provider-bridge-thr_y8v7eqi52e branch November 24, 2026 19:36
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