Skip to content

Let plugin tools awaiting user input outlive their turn - #3878

Merged
ymichael merged 18 commits into
mainfrom
bb/investigate-ask-mode-bug-thr_3wjm5e2y3z
Sep 18, 2026
Merged

ymichael merged 18 commits into
mainfrom
bb/investigate-ask-mode-bug-thr_3wjm5e2y3z

Conversation

@ymichael

@ymichael ymichael commented Sep 17, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

A plugin tool awaiting user input could be cancelled when its calling turn ended, losing the eventual answer. Plugin forms also lacked useful timeline history and blocked CLI/API messages while open.

What changed

  • Opening a form through bb.ui.requestInput() lets the enclosing tool outlive its request. The agent receives a waiting notice immediately; the eventual successful result resumes the agent or starts a new turn. Errors and dismissals do not wake idle threads.
  • Ordinary tools still abort through ctx.signal when their request is cancelled. Thread stop/delete and plugin disposal also abort tools waiting on forms.
  • Forms gain optional presentation and describeSubmission fields for timeline labels and submission summaries. Omitted fields produce a generic row. AskUserQuestion records answers; Secrets records names and paths without secret values. Concurrent submissions cannot describe or resolve the same form twice.
  • Open plugin forms allow CLI/API messages through. The UI continues showing the form, with a loading state while its renderer loads. Late-result rows read “Delivered result” and respect suppression.
  • SDK 0.4.102 uses PluginRowLabels / PluginRowPresentation and PluginCommandContext / PluginCommandRegistration. Removed the four old type aliases; compiled-plugin runtime compatibility is unchanged. Updated Plugin Guide references and verification recipes.

No database migration or daemon protocol bump is needed. Form descriptions and result delivery are handled on the server; plugin form resolution does not send the new description fields to the daemon.

How you verified

  • Focused Turbo tests passed for tool cancellation and late delivery, submission races, timeline rendering, presentation validation, SDK exports, and plugin-authoring docs. The latest cleanup runs passed 236 tests, plus 28 export/documentation tests.
  • Turbo typechecks passed for @bb/server, @bb/app, @bb/thread-view, and @get-bb/plugin-sdk.
  • Formatting and diff checks passed.

Earlier live Codex checks covered answering after turn completion, sending past an open form, dismissal, and Secrets. Browser/provider flows were not rerun after the final lifetime changes; those changes were verified with registry and HTTP integration tests.

AGENT GENERATED

@ymichael
ymichael force-pushed the bb/investigate-ask-mode-bug-thr_3wjm5e2y3z branch from 4458f42 to 2461014 Compare September 17, 2026 23:02
ymichael and others added 15 commits September 17, 2026 16:51
Codex's current models run dynamic tool calls in code mode, where an exec
cell yields after ~30s and the model continues without the result. bb held
the AskUserQuestion call open for the length of a human decision, so the
turn ended first, the card was cancelled with it, and the user's answer
went nowhere while the agent reported it was never answered.

The tool now returns once the card is on screen and the answer reaches the
agent as turn input: a running turn is steered, a finished one is started
again. The card is no longer bound to the tool call's abort signal, so it
outlives the turn that opened it. Only the user's own non-answers — a
dismissal or the 30 minute expiry — are reported, and only to a turn that
is still running; a card taken away by a stopped thread, a reloaded plugin
or a restarted server says nothing.

The fake plugin host can now settle an interaction with any of the host's
cancel reasons, not just "user".

Verified against Codex 0.153.3 on gpt-6-astra: the tool call completes in
19ms, the agent ends its turn with a short wait note, the card survives
turn completion, and answering it afterwards starts a turn that uses the
answer. A plugin reload mid-question left the thread untouched. The
mid-turn steer path is covered by tests only — Codex ends its turn after
the acknowledgement, so it cannot be staged live there.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A plugin tool ran at the end of the daemon's tool-call round trip, so when
Codex's code mode moved on after ~30s, or any provider's transport gave up
after undici's 300s default, the server aborted the tool and its result had
no reader. Every plugin that waited for a person inside a tool hit this, and
several marketplace plugins hand-rolled the same return-early workaround.

Core now keeps a plugin tool call running after its round trip is gone and
delivers whatever it returns as turn input: a running turn is steered, an
idle thread is started, and a failed result only steers. Before the
transport cap the server answers the round trip with a stub saying the
result arrives as a message, and it tells the agent so once in the thread
instructions. The tool's ctx.signal now fires only when the thread is
stopped or deleted or the plugin is disposed.

The delivered message is a system-initiated turn request with a tool-call
subject. Thread-view hides it when the tool row is suppressed, so a question
tool whose dedicated row already records the answer leaves no duplicate.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Core now keeps a plugin tool call alive past its turn and delivers a late
result as turn input, so the plugin no longer needs its own return-early
and redeliver machinery. It awaits the card and returns the answer as the
tool result again, keeping the 30 minute card timeout. The fake plugin
host's cancel-reason argument existed only for the removed delivery tests.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
bb.ui.requestInput gains a second request arm: { kind: "user_question",
questions }. bb draws it with the same question card a provider's native
question uses, persists the questions and the answers, projects the same
"Answered … — …" timeline row, and answers it from bb thread interactions
answer. The existing plugin-form arm is unchanged; its data is still never
stored, which is what keeps the secrets plugin safe.

In the domain a user_question interaction may now carry a plugin origin and
no turn. The server resolves such an interaction by settling the plugin's
waiting promise with the typed answers instead of sending the daemon a
resolve command, and cancels it the way it cancels a plugin form. The
question card's Cancel stops the turn for a provider question and only
cancels the interaction for a plugin one, since there is no turn to stop.

AskUserQuestion raises the core kind, so its own card, renderer id, and
shared payload contract are deleted.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
A plugin form's data and answer are never persisted, so its lifecycle record
carries only the title and status, and the timeline showed nothing for it.
Every interaction now leaves a row: bb's own question kinds show the ask and
the answer, and a plugin form shows its title with whether it was submitted
or cancelled. A secrets request reads as "Submitted Add secrets to .env"
without a value ever reaching the transcript.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
A pending interaction queued every send. That was right for a provider's
question or approval, which holds the turn, and wrong for a plugin's card,
which has no turn and can now sit on an idle thread for as long as its
timeout allows. Only turn-bound interactions block dispatch, message edits,
context clears, and parent notices now; a plugin's card stays open and its
answer steers or starts a turn when it comes.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The plugin guide describes the user_question request arm and the tool-call
lifetime, the symbol index lists the new SDK types, the verify-bb recipe
covers the timeline row and sending past an open card, and the banner tests
mock the new cancel hook. The SDK's published surface changed, so its patch
version moves.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
A tool that called bb.ui.requestInput kept its round trip open until the
provider gave up or the four minute deadline passed, so on Codex the call
was recorded as failed before the stub could fire. Core now answers the
round trip as soon as a plugin tool call raises an interaction, with a
notice that the call is waiting on the person, and the eventual result
reaches the agent as a message. The deadline remains only as the transport
fallback for tools that are merely slow.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Replace the core-owned user_question request arm with two fields on the
plugin form request. `presentation` is the row header, in the same shape a
native tool declares, filled by the server with "Waiting for <title>" /
"Submitted <title>" and the plugin's branding glyph. `describe(value)` runs
once on submission, contained and time-boxed, and whatever it returns —
title, Markdown detail, optional payload — is the only thing bb persists
about the answer. Cancellations are titled by bb from the pending
presentation. The form row carries the presentation and payload, resolves a
plugin's `experimental_timelineRenderer` registered as
"<pluginId>/<rendererId>", and shows the Markdown detail otherwise.

bb no longer knows what a question is. AskUserQuestion keeps its card and
contract and describes its answers as "Answered <prompt> — <choice>"; the
secrets form reads "Provided API_KEY for .env" and never sees a value
persisted.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…able

A pending plugin form resolved its renderer against the slot store and
treated a miss as proof that no renderer exists, so a cold page load showed
"The plugin form is unavailable" until the plugin's frontend bundle
finished importing and the real form replaced it. Plugin frontends register
asynchronously and the boot batch only holds 150ms, which a bundle fetch
comfortably outlasts. The card now waits on usePluginFrontendsSettled and
shows a skeleton until frontends settle; "unavailable" means the plugin
loaded without that renderer, or failed to load. The signal covers live
reconciles too, so installing or re-enabling a plugin does not flash the
fallback either.

The copy was reachable before this branch but not often. A plugin form used
to die with its turn, so a pending card at page-load time was a race. Now
that forms outlive their turn, opening a thread that sits on an open
question is the ordinary path.

Two long-standing problems in the same paragraph go with it. The card
attributed the ask to the raw plugin id dressed up with CSS capitalize,
printing "Ask-User-Question" where the plugin declares "Ask User Question";
it now reads the registered display name. And it chose between "Requested
by" and "The agent asks through" by inspecting `dismissal`, a prop that
names the back-out affordance rather than the asker — correct only while the
two stayed correlated through a two-step derivation. The composer now takes
the fact both were derived from: `origin` is "plugin" or "provider", and the
phrasing, the dismiss label, and the mutation all follow from it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`ui.requestInput`'s two row fields read as if they shaped the form the
person sees. They shape the row the form leaves behind, so say so:
`describe` is `describeSubmission`, and the presentation type is
`PluginRowPresentation` (`PluginRowLabels` for its labels) rather than
`PluginAgentToolPresentation`, which named a tool in a field on a UI form.
Both old names stay as deprecated type aliases, recorded in the
compatibility-window section of the audit.

SDK 0.4.101: 0.4.99 is published and main already holds 0.4.100.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The contract suites now reach inside arrays, so a plugin form's row is
audited where it is actually served, not only where it is unreachable. Ten
of the fourteen are on the pending-interactions response: the payload's
presentation and its members, which go in the groups that already explain
them, and the description a submission leaves, which gets its own reason
because those four fields are the entire record bb keeps of what happened.

The other four are the resolve route's body, which is the persisted
resolution union and so admits an arm no caller can send: a plugin
interaction is submitted through the respond route, and the resolve route
rejects every plugin interaction before a resolution is read. Same story on
the daemon side, where the arm never reaches the wire at all, which is why
the protocol version stands.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
main shipped 0.4.101 while this branch was open, so the branch's bump stopped
being one and the lockstep check failed. Take 0.4.102 and move the two
deprecation notes and the compatibility-window entry with it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
#3884 took the unbounded path out of the card title and let the card shell
wrap it instead. The two row strings this branch adds are the same shape and
were not covered: describeSubmission still built a 160 character row title
around the absolute destination, and the row labels had nothing holding them
under 80 as secret names accumulate.

Follow the same rule. The row title names the variables and the destination
moves to the detail, which has room for it, and both label halves are
clamped.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
#3884 added a header-wrapping test against dismissal, which this branch has
since renamed to origin. The merge is clean textually and only the types
catch it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@ymichael
ymichael force-pushed the bb/investigate-ask-mode-bug-thr_3wjm5e2y3z branch from 70d1909 to 77280fd Compare September 18, 2026 00:00
@ymichael ymichael changed the title Let a plugin tool call outlive the turn that made it Let plugin tools awaiting user input outlive their turn Sep 18, 2026
@ymichael
ymichael merged commit 0b5c238 into main Sep 18, 2026
16 checks passed
@ymichael
ymichael deleted the bb/investigate-ask-mode-bug-thr_3wjm5e2y3z branch September 18, 2026 17:58
albrand added a commit to alb-hold/bb that referenced this pull request Sep 18, 2026
Resolved 12 conflicts with fork behavior kept and upstream API shape taken:
dispatch-attempt keeps the fork file plus upstream get-bb#3816/get-bb#3878 deltas;
openThreadInSplit keeps fork side/SplitOpenResult and adds upstream state;
plugin tools keep fork waitsForUserInput on upstream PluginRowPresentation;
guide chapters union spend + json; contract optional-group limit 46.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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