Repository navigation
Send plugin failures to the plugin's own log - #7875
Merged
ymichael merged 4 commits intoNov 20, 2026
Merged
Conversation
ymichael
force-pushed
the
bb/plugin-failures-reach-bb-plugin-logs-thr_ij4avtzfv8
branch
from
November 20, 2026 04:27
c2b1f11 to
8ba1b1a
Compare
Factory throws, onInstall/handler/RPC/CLI throws, service crashes and
host-worker output reached only the server (or daemon) log, so
`bb plugin logs` showed bb.log lines and nothing else. Every
plugin-attributed server log line now goes through one createPluginEventLog
path that writes the server log and the plugin's plugin.log, with the
error's stack.
- contributeInstructions throws are contained and logged against the plugin
where contributions are listed; deriveProviderOptions throws are logged
and fail the command with a 502 provider_options_failed that names the
plugin, as its JSDoc promised.
- Host workers' stdout (previously discarded) and stderr are forwarded to the
server as plugin-host.worker-output, and worker-exited carries the exit
reason (daemon protocol 273).
- Server access provider failures name the plugin and keep its error text.
- Plugin CLI failures the host reports (thrown command, unknown plugin, not
running, no CLI) carry the core --json envelope { ok: false, error }; the
output-limit envelope gains ok: false. Real and fake hosts share
pluginCliFailureResult.
- BbHttpError moves to @bb/sdk/http-error with a Symbol.for brand and
Symbol.hasInstance, and @get-bb/plugin-sdk exports it as
experimental_BbHttpError (+0.6 KB to the SDK bundle).
- Bundled plugins use instanceof experimental_BbHttpError instead of
duck-typing status/code, and drop their catch-all PluginCliError wrappers.
- Plugin SDK 0.6.167.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ct tests Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
force-pushed
the
bb/plugin-failures-reach-bb-plugin-logs-thr_ij4avtzfv8
branch
from
November 20, 2026 09:17
8ba1b1a to
e75209e
Compare
Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/plugin-failures-reach-bb-plugin-logs-thr_ij4avtzfv8
branch
November 20, 2026 21:44
This was referenced Nov 20, 2026
ymichael
added a commit
that referenced
this pull request
Nov 24, 2026
… the plugin (#8080) ## 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 #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 #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](https://claude.com/claude-code) > AGENT GENERATED --------- 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.
Human comments
What was wrong
Every failure a plugin's code caused went only to the server log. That covers factory throws,
onInstall, handler, RPC and CLI throws, service crashes and uncaught errors. Onlybb.logand build warnings also reached the plugin's own log, sobb plugin logs <id>showed nothing about why a plugin broke. Three other gaps:contributeInstructionswas logged with the server logger only.deriveProviderOptionswas called raw, so its error reached the user without the plugin's name, contradicting its JSDoc.On the CLI side, the host wrote empty stdout for any failure even under
--json, anddefineClirethrows non-PluginCliErrorerrors, so 8 bundled plugins wrapped every command by hand.bb.sdkthrowsBbHttpError, but the class lives in private@bb/sdk, and a plugin's bundled copy could notinstanceofthe host's instance, so bundled and community plugins duck-typedstatus/code. (Plugin API audit, findings F2–F4.)What changed
Plugin log
apps/server/src/services/plugins/plugin-log.ts:createPluginEventLogis the one path for plugin-attributed lines. It writes[plugin:<id>] <message>to the server log and{ts, level, message, stack?}toplugins/<id>/logs/plugin.log.plugin-runtime,plugin-serviceandplugin-registrationuse it, as dobb.log, build warnings andmanaged-plugin-artifacts.Agent hooks
listInstructionContributionscontains a throwingcontributeInstructionsprovider: the failure is logged against the plugin and contributes nothing. The ad-hoc catch inthread-runtime-config.tsis deleted.deriveProviderOptionsis logged against the plugin and fails the command with502 provider_options_failed:The "<plugin>" plugin's deriveProviderOptions for provider "<id>" failed: …, withdetails: { pluginId, providerId }.Host workers (wire change,
HOST_DAEMON_PROTOCOL_VERSION272 → 273)plugin-host.worker-outputmessage, bounded per stream like stderr already was.plugin-host.worker-exitedgainsreason.worker-outputis not fenced during a server move, liketerminal.output.CLI
pluginCliFailureResult, in the SDK's internal host-policy and shared by the real and fake hosts, gives every host-side failure exit 1 with the same stderr text as before.--json, stdout is the core envelope{ "ok": false, "error": { "code", "message" } }. Codes:command_failed(the command threw),plugin_not_found,plugin_not_running,plugin_cli_not_registered.ok: false.experimental_BbHttpError(new experimental public API)BbHttpErrormoves to@bb/sdk/http-errorwith aSymbol.forbrand andSymbol.hasInstance, and@get-bb/plugin-sdkexports it asexperimental_BbHttpError.@bb/sdkroot grewdist/index.jsfrom 38 KB to 611 KB; this way it adds about 0.6 KB.docs/api_to_audit.mdhas an entry, and the Plugin Guide "The bb SDK" card lists the symbol.Bundled plugins
instanceof experimental_BbHttpError: tasks, git, github-pr-status, secrets, connect, storage-retention, the codex/claude-code/acp usage sources, workflows, automations, side-chat, inline-vis and bb-account.pairErrormapping stays), docs, modal-sandbox, github, secrets and workflows.Docs and versions
bb plugin logsdescription in the CLI, guide template anddocs/configuration.md.bb.log, testing, the CLI failure contract andBbHttpError.User-visible changes
PluginCliErrornow printsbb <name> failed: <message>with codecommand_failed. Before, it printed the bare message withpool_command_failed,automation_failed,connect_failedoroperation_failed. Nothing in the repo referenced those codes. Like every other plugin's CLI throw, these now also set the plugin's running status detail shown inbb plugin list. That detail does not trigger the attention glyph.[plugin:<id>] …. For example,plugin X failed to load: …becomes[plugin:X] failed to load: ….Community plugins (503-repo scan)
experimental_BbHttpErrorneedsbbPluginSdk >=0.6.167, because an older server's errors lack the brand.console.logwill see that output, bounded, in their plugin log.Not done
experimental_providerBridgeexport ("Provider X exited unexpectedly") still reaches only the server log, through the model-catalog, health-check and session paths.provider-states.tsstill has a barecatch {}.{ code, message }: unknown plugin, not running, auth failure and bad caller token (routes/plugins.ts).tasksCLI guard, browser-automation'sbrowserCliFailure(itscommand_failedfallback could go), and gitserver/cli.tshttpErrorBody, which also reads hostApiErrors.commit-errors.ts. Its frontend parse withlifecycleApiErrorSchemastays as is.How you verified
Tests that fail before and pass after
apps/server/test/services/plugins/plugin-failure-log.test.ts: a 10-row table covering factory throw,onInstall, service crash, RPC, CLI,contributeInstructions,deriveProviderOptions(including the 502 shape), and host stderr, stdout and exit. Each row asserts the line is in the plugin's log tail. Withapps/server/srcreverted to main, all 10 fail.plugin-cli.test.ts: a table asserting each host-side failure, with and without--json, gets the envelope. It fails on main.--jsonenvelope test.plugin-host-manager.test.tscase asserting a real worker's stdout and stderr are forwarded with their generation, and that the exit reason is reported.Commands run
pnpm exec turbo run testfor@bb/server(plugins, threads, providers, internal and server-move tests),@bb/host-daemon,@bb/sdk,@get-bb/plugin-sdk,@bb/cli,@bb/templates, plugin-api-docs, bb-guide and the 18 migrated plugins.--filter='...@bb/sdk' --filter='...@bb/host-daemon-contract' --filter='...@get-bb/plugin-sdk', 92 tasks.lint:type-awareandoxfmt.Live check
pnpm start:worktreewith two QA plugins, one that throws in its factory and one that fails in every callback, running the identical script on main and on the branch:bb plugin logs fail-factoryis empty, andfail-everywhereshows only itsbb.logline.bb failqa throw --jsongives empty stdout.contributeInstructionsandderiveProviderOptionsfailures (most with stacks), plus host stdout, host stderr andhost worker on <host> stopped unexpectedly: host plugin worker exited (1).--jsonprints{"ok":false,"error":{"code":"command_failed","message":"bb failqa failed: QA cli boom"}}.The "fail-everywhere" plugin's deriveProviderOptions for provider "failqa" failed: ….bb.sdk404 isinstanceof experimental_BbHttpErrorwithstatus=404 code=thread_not_found.🤖 Generated with Claude Code