Skip to content

Send plugin failures to the plugin's own log - #7875

Merged
ymichael merged 4 commits into
mainfrom
bb/plugin-failures-reach-bb-plugin-logs-thr_ij4avtzfv8
Nov 20, 2026
Merged

ymichael merged 4 commits into
mainfrom
bb/plugin-failures-reach-bb-plugin-logs-thr_ij4avtzfv8

Conversation

@ymichael

@ymichael ymichael commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

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. Only bb.log and build warnings also reached the plugin's own log, so bb plugin logs <id> showed nothing about why a plugin broke. Three other gaps:

  • A throwing contributeInstructions was logged with the server logger only.
  • deriveProviderOptions was called raw, so its error reached the user without the plugin's name, contradicting its JSDoc.
  • Host workers' stdout was discarded, and their stderr and exit reason stayed in the daemon log on that machine.

On the CLI side, the host wrote empty stdout for any failure even under --json, and defineCli rethrows non-PluginCliError errors, so 8 bundled plugins wrapped every command by hand. bb.sdk throws BbHttpError, but the class lives in private @bb/sdk, and a plugin's bundled copy could not instanceof the host's instance, so bundled and community plugins duck-typed status/code. (Plugin API audit, findings F2–F4.)

What changed

Plugin log

  • apps/server/src/services/plugins/plugin-log.ts: createPluginEventLog is the one path for plugin-attributed lines. It writes [plugin:<id>] <message> to the server log and {ts, level, message, stack?} to plugins/<id>/logs/plugin.log.
  • About 35 call sites in plugin-runtime, plugin-service and plugin-registration use it, as do bb.log, build warnings and managed-plugin-artifacts.
  • Failures carry the error's stack.

Agent hooks

  • listInstructionContributions contains a throwing contributeInstructions provider: the failure is logged against the plugin and contributes nothing. The ad-hoc catch in thread-runtime-config.ts is deleted.
  • A throwing deriveProviderOptions is logged against the plugin and fails the command with 502 provider_options_failed: The "<plugin>" plugin's deriveProviderOptions for provider "<id>" failed: …, with details: { pluginId, providerId }.
  • Server access provider failures name the plugin and keep its error text. Before, they read "Server access provider failed".

Host workers (wire change, HOST_DAEMON_PROTOCOL_VERSION 272 → 273)

  • The daemon pipes worker stdout and forwards stdout and stderr lines as the new plugin-host.worker-output message, bounded per stream like stderr already was.
  • plugin-host.worker-exited gains reason.
  • The server writes both to the plugin log after a generation check. worker-output is not fenced during a server move, like terminal.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.
  • Under --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.
  • The output-limit envelope gains ok: false.
  • A thrown command error still reaches the plugin log with its stack.

experimental_BbHttpError (new experimental public API)

  • 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.
  • It is in its own module because re-exporting from the @bb/sdk root grew dist/index.js from 38 KB to 611 KB; this way it adds about 0.6 KB.
  • docs/api_to_audit.md has an entry, and the Plugin Guide "The bb SDK" card lists the symbol.

Bundled plugins

  • About 20 duck-typing sites now use 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.
  • The catch-all CLI wrappers are deleted in account-pool, automations, connect (its pairError mapping stays), docs, modal-sandbox, github, secrets and workflows.

Docs and versions

  • bb plugin logs description in the CLI, guide template and docs/configuration.md.
  • Plugin authoring references: bb.log, testing, the CLI failure contract and BbHttpError.
  • Plugin SDK 0.6.167.

User-visible changes

  • CLI error codes. In the account-pool, automations, connect, docs, modal, github, secrets and workflows CLIs, an error a command throws without building a PluginCliError now prints bb <name> failed: <message> with code command_failed. Before, it printed the bare message with pool_command_failed, automation_failed, connect_failed or operation_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 in bb plugin list. That detail does not trigger the attention glyph.
  • Server log prefix. Plugin lines in the server log now consistently read [plugin:<id>] …. For example, plugin X failed to load: … becomes [plugin:X] failed to load: ….

Community plugins (503-repo scan)

  • Nothing public is removed or renamed.
  • 17 repos duck-type the SDK error and 10 hand-wrap CLI errors; both keep working.
  • Adopting experimental_BbHttpError needs bbPluginSdk >=0.6.167, because an older server's errors lack the brand.
  • 5 repos whose host entries console.log will see that output, bounded, in their plugin log.

Not done

  • Provider bridge failures. For example, a missing experimental_providerBridge export ("Provider X exited unexpectedly") still reaches only the server log, through the model-catalog, health-check and session paths. provider-states.ts still has a bare catch {}.
  • Plugin-RPC route errors. Four routes still return bare string errors instead of { code, message }: unknown plugin, not running, auth failure and bad caller token (routes/plugins.ts).
  • Mapping helpers that do real work stay: the tasks CLI guard, browser-automation's browserCliFailure (its command_failed fallback could go), and git server/cli.ts httpErrorBody, which also reads host ApiErrors.
  • Git commit-errors.ts. Its frontend parse with lifecycleApiErrorSchema stays as is.

How you verified

Tests that fail before and pass after

  • New 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. With apps/server/src reverted 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.
  • The fake-host --json envelope test.
  • A plugin-host-manager.test.ts case asserting a real worker's stdout and stderr are forwarded with their generation, and that the exit reason is reported.

Commands run

  • Tests: pnpm exec turbo run test for @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.
  • Typecheck over every dependent: --filter='...@bb/sdk' --filter='...@bb/host-daemon-contract' --filter='...@get-bb/plugin-sdk', 92 tasks.
  • lint:type-aware and oxfmt.

Live check
pnpm start:worktree with 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:

  • Before (main 9f4c156):
    • bb plugin logs fail-factory is empty, and fail-everywhere shows only its bb.log line.
    • bb failqa throw --json gives empty stdout.
    • The provider thread errors with "QA deriveProviderOptions boom" and no plugin named.
    • Host stdout appears nowhere.
  • After:
    • Both logs contain the factory failure, install handler failure, service crash, RPC, CLI, contributeInstructions and deriveProviderOptions failures (most with stacks), plus host stdout, host stderr and host worker on <host> stopped unexpectedly: host plugin worker exited (1).
    • --json prints {"ok":false,"error":{"code":"command_failed","message":"bb failqa failed: QA cli boom"}}.
    • The thread error reads The "fail-everywhere" plugin's deriveProviderOptions for provider "failqa" failed: ….
    • The plugin's bb.sdk 404 is instanceof experimental_BbHttpError with status=404 code=thread_not_found.

🤖 Generated with Claude Code

AGENT GENERATED

@ymichael
ymichael force-pushed the bb/plugin-failures-reach-bb-plugin-logs-thr_ij4avtzfv8 branch from c2b1f11 to 8ba1b1a Compare November 20, 2026 04:27
ymichael and others added 3 commits November 20, 2026 01:14
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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael force-pushed the bb/plugin-failures-reach-bb-plugin-logs-thr_ij4avtzfv8 branch from 8ba1b1a to e75209e Compare November 20, 2026 09:17
@ymichael
ymichael merged commit bce7015 into main Nov 20, 2026
95 of 97 checks passed
@ymichael
ymichael deleted the bb/plugin-failures-reach-bb-plugin-logs-thr_ij4avtzfv8 branch November 20, 2026 21:44
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]>
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