Skip to content

Keep a live turn running when a steer times out - #7010

Merged
ymichael merged 2 commits into
mainfrom
bb/a-timed-out-steer-fails-a-live-turn-thr_t8ptafx4dy
Nov 4, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/a-timed-out-steer-fails-a-live-turn-thr_t8ptafx4dy

Conversation

@ymichael

@ymichael ymichael commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

When a steer got no answer from the provider bridge within the daemon's 30 s JSON-RPC timeout, sendJsonRpcRequest rejected with a plain Error("JSON-RPC request timed out: turn/steer"). The daemon reported that as command_failed, and settleThreadCommandFailure (apps/server/src/services/threads/thread-lifecycle.ts) treated it as a refusal. It wrote client/turn/rejected and system/error, then applied run.failed while the turn was still running. The provider still had the steer. After it recovered it applied the steer and finished the turn, but the thread stayed in error, showing "Steer failed", the error row, and a duplicate accepted copy of the same message. A second timeout in the Codex bridge made this worse: it gave up on Codex's turn/steer after 60 s and dropped Codex's late answer, so for a long freeze bb never received the acceptance at all.

What changed

A timed-out steer now counts as unconfirmed, not refused:

  • packages/provider-bridge-protocol (bridge-kit): request timeouts throw a typed JsonRpcRequestTimeoutError. The message is unchanged.
  • packages/agent-runtime: steerTurn returns { status: "unconfirmed" } for that timeout. Other errors still throw.
  • apps/host-daemon: an unconfirmed steer is reported as steer_unconfirmed (STEER_UNCONFIRMED_ERROR_CODE in @bb/host-daemon-contract). The daemon does not retry it as a new turn.
  • apps/server (unconfirmed-steers.ts): for steer_unconfirmed, the server does not write a rejection or a system error and does not fail the thread. The steer stays pending while its turn runs. If the provider later accepts it, it becomes a normal steer. If the turn ends while the steer is still unconfirmed, the server writes client/turn/rejected (reason: steer_unconfirmed), so the message stays visible as "Steer failed" instead of disappearing. That path adds no system error and changes no thread status. Pending steers are tracked in memory, so after a server restart one falls back to today's command-timeout behavior: it stays unresolved.
  • packages/thread-view: an acceptance outranks an earlier rejection of the same request. Claude Code can apply a late steer as the next turn, with the acceptance arriving after the original turn's turn/completed; this rule covers that.
  • plugins/provider-codex: turn/steer no longer has a 60 s child timeout. Codex's eventual answer, which carries the acceptance, still reaches bb, and the connection rejects the request if Codex exits.
  • tests/scripted-echo-provider: new steerResponseDelayMs option for the runtime test.

Explicit refusals (provider_rpc_error, competing_turn, stale turns, and so on) settle exactly as before.

Wire compatibility: no HOST_DAEMON_PROTOCOL_VERSION bump. steer_unconfirmed is a new value of the existing free-form errorCode string. An older server settles it the way it settles today's command_failed, and an older daemon keeps sending command_failed. The fix takes effect wherever the server and the daemon are both updated.

turn/start timeouts (reported, not fixed here): reproduced live on main with the same freeze. turn/start times out after 30 s, and bb records client/turn/rejected plus system/error and sets the thread to error. After kill -CONT, Codex starts the turn, accepts the message and completes it. The thread recovers to idle, but the false "Command turn.submit failed / JSON-RPC request timed out: turn/start" row stays (dev threads below). The server settlement is shared with steers, but the daemon side is a separate path: runtime.runTurn rolls back its own turn-start state (pendingTurnStarts, markHostedProviderSessionIdle) on the timeout. Fixing it means treating that rollback as unknown as well, so it is left for a follow-up.

How you verified

Live on pnpm start:worktree, before on origin/main and after on this branch, same data dir, shared via bb connect expose. Faults were real process freezes only (kill -STOP / kill -CONT on the literal provider PID). The lost-steer case adds a kill -9 of the frozen app-server.

Thread Build What happened
BEFORE (main): Codex steer while app-server frozen main Rejected + system/error at 30 s, thread error. After CONT, Codex accepted and replied STEER-APPLIED; thread stayed error, showing "Steer failed", the error row, and a duplicate "Steer".
BEFORE (main): Claude Code steer while claude frozen main Same at 30 s (steer changed reasoning level, so the bridge waits on claude). After CONT the steer ran as the next turn; "Steer failed" and the error row stayed.
BEFORE (main): Codex turn/start while app-server frozen main turn/start variant described above.
AFTER (fix): Codex steer, app-server frozen 2 min branch "Steer pending" for 2 min, thread active, no rejection or error. On CONT, turn/input/accepted arrived at once, turn completed, thread idle, "Steer", STEER-APPLIED.
AFTER (fix): Claude Code steer while claude frozen branch Frozen 70 s: "Steer pending", no rejection or error. On CONT, accepted; thread idle, STEER-APPLIED.
AFTER (fix): Codex steer lost (app-server frozen, then killed) branch Pending through the freeze. kill -9 ended the turn (failed, from the crash), and the steer was recorded as steer_unconfirmed and shown as "Steer failed" with its text kept.

Tests (each new one fails without the change):

  • apps/server/test/threads/thread-send-dispatch.test.ts › unconfirmed steers: late acceptance keeps the thread active with no rejection. A turn that ends unconfirmed produces only a steer_unconfirmed rejection and an idle thread. Both fail on the old settlement (expected 'error' to be 'active').
  • packages/agent-runtime/src/runtime.input-accepted.test.ts: a real scripted bridge answers turn/steer late. The runtime returns unconfirmed at 30 s and still records the late turn/input/accepted.
  • apps/host-daemon/test/command/thread-dispatch.test.ts: an unconfirmed steer is reported as steer_unconfirmed and is not retried as a new turn.
  • packages/thread-view/test/build-thread-timeline.test.ts: rejection followed by acceptance renders one accepted steer.
  • pnpm exec turbo run typecheck lint for server, host-daemon, agent-runtime, thread-view, provider-bridge-protocol, host-daemon-contract, provider-codex and scripted-echo-provider. Full thread-view suite (511) and the touched server, daemon, runtime and Codex bridge test files pass locally; CI runs the full suites.

🤖 Generated with Claude Code

AGENT GENERATED

ymichael and others added 2 commits November 4, 2026 10:43
A steer that got no answer within the daemon's 30 s bridge request
timeout was reported as command_failed. The server treated it as a
refusal: it rejected the request, recorded a system error and failed the
thread, although the agent later applied the steer and finished the turn.

A timeout now means the steer's delivery is unknown:

- The runtime returns an unconfirmed steer result for a request timeout,
  and the daemon reports it as steer_unconfirmed.
- The server keeps the turn and thread running and leaves the steer
  pending. A later provider acceptance makes it a normal steer.
- If the turn ends with the steer still unconfirmed, the server records
  client/turn/rejected (steer_unconfirmed) so the message stays visible as
  a failed steer, without a thread error.
- The timeline lets an acceptance win over an earlier rejection of the
  same request, for providers such as Claude Code that apply a late steer
  as the next turn.
- The Codex bridge no longer gives up on turn/steer after 60 s, so a late
  Codex acceptance still reaches bb. The connection rejects the request
  if Codex exits.

Explicit refusals keep their existing settlement.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael force-pushed the bb/a-timed-out-steer-fails-a-live-turn-thr_t8ptafx4dy branch from 690da00 to 4cf94a7 Compare November 4, 2026 18:44
@ymichael
ymichael merged commit 882de6e into main Nov 4, 2026
92 of 93 checks passed
@ymichael
ymichael deleted the bb/a-timed-out-steer-fails-a-live-turn-thr_t8ptafx4dy branch November 4, 2026 18:53
ymichael added a commit that referenced this pull request Nov 4, 2026
)

## Human comments

## What was wrong

When a new message's `turn/start` got no answer from the provider bridge
within the daemon's 30 s JSON-RPC timeout, `runtime.runTurn`
(`packages/agent-runtime/src/runtime.ts`) rolled back its turn-start
state (`pendingTurnStarts`, `markHostedProviderSessionIdle`) and rethrew
the timeout. The daemon reported it as `command_failed`, and
`settleThreadCommandFailure` treated that as a refusal: it wrote
`client/turn/rejected` plus `system/error` ("Command turn.submit failed
/ JSON-RPC request timed out: turn/start") and failed the run. The
provider still had the request. Once it recovered it started the turn,
accepted the message and finished, and reconciliation brought the thread
back to `idle`. The false error row and the "failed" copy of the message
stayed. #7010 fixed the same bug for steers and listed this turn/start
case as a follow-up.

## What changed

A timed-out turn start now counts as **unconfirmed**, reusing #7010's
path:

- `packages/agent-runtime`: `runTurn` returns `{ status: "started" |
"unconfirmed" }`. On `JsonRpcRequestTimeoutError` it keeps the pending
turn start, so the thread stays live, competing starts are refused and
the 2-minute watchdog still applies. It also records the runtime config
the provider was sent. Other errors still roll back and throw.
`startThread` with initial input treats an unconfirmed start as a
constructed session.
- `apps/host-daemon`: an unconfirmed start is reported as
`turn_start_unconfirmed` (`TURN_START_UNCONFIRMED_ERROR_CODE` in
`@bb/host-daemon-contract`). Staged attachments are kept for unconfirmed
steers and starts, because the provider may still read them.
- `apps/server` (`unconfirmed-steers.ts` is renamed to
`unconfirmed-turn-requests.ts`): for `turn_start_unconfirmed` the server
writes nothing and the thread stays `active`. A late `turn/started` /
`turn/input/accepted` then runs the turn as usual. If the run has
already ended when the report arrives, the request is rejected at once.
- **What settles a start that really was lost.** Two things, both read
from persisted events at settlement time, so neither depends on server
memory and both survive a server restart:
1. The provider process exits while the start is pending. This is the
existing thread-scoped `system/error` `provider_process_exited`.
2. The provider answers the timed-out request with an error.
bridge-kit's `sendJsonRpcRequest` gets an optional `afterTimeout`
handler. The runtime uses it to clear the pending start and emit
`system/error` `provider_turn_start_failed`. Without this, killing only
Codex's app-server left the bridge alive, the bridge's late error went
unread, and the thread stayed `active` (seen live on an intermediate
build of this branch).

On either signal the server fails the run (as it already did for
`provider_process_exited`). It rejects the latest unresolved
`client/turn/requested` after the last completed root turn with `reason:
turn_start_unconfirmed` ("The agent did not start a turn for this
message"). The runtime allows only one pending start per thread, so that
request is the pending start. Telemetry counts
`provider_turn_start_failed` as `start_failed`, as the old
`thread_command_failed` was counted.
- **Why not the 2-minute watchdog:** it fires on elapsed time only. A
provider frozen past 2 minutes (machine sleep, CPU starvation, this
repro) still starts the turn afterwards, so settling on the watchdog
would bring back the false failure this PR removes. It still warns, and
stop still interrupts.
- `plugins/provider-codex`: `turn/start` and `thread/compact/start` no
longer have a 60 s child timeout. When that timeout fired, the bridge
rolled back the turn-start request id, so a late turn lost its
acceptance. The connection still rejects the request if Codex exits.
- `packages/db`: `findLatestUnresolvedClientTurnRequestIdAfterSequence`.
- `tests/scripted-echo-provider`: `turnStartErrorAfterMs` option for the
runtime test.

Real refusals (`provider_rpc_error`, `competing_turn`, a turn/start
error answered within the timeout, and so on) settle exactly as before.

**Steers:** they keep #7010's in-memory set. The same DB query can't
replace it. At a turn's end, an unresolved steer can still be
legitimately in flight: the daemon may be about to start it as the next
turn after a stale-steer answer. Rejecting every unresolved steer at
that point would write false rejections. That gap is unchanged: after a
server restart, a pending unconfirmed steer stays unresolved.

**Wire compatibility:** no `HOST_DAEMON_PROTOCOL_VERSION` bump.
`turn_start_unconfirmed` is a new value of the free-form `errorCode`,
and `provider_turn_start_failed` is a new value of the free-form
`system/error.code`. An older server settles the first as
`command_failed`, which is today's behaviour, and shows the second as an
ordinary error row. An older daemon keeps sending `command_failed`.

## How you verified

Live on `pnpm start:worktree` with real Codex and Claude Code. BEFORE
ran on `origin/main` (a67ada1, before #7010). AFTER ran on this
branch with the same data dir, shared via `bb connect expose`. The only
faults were real process freezes and kills (`kill -STOP` / `kill -CONT`
/ `kill -9` on literal PIDs).

| Thread | Build | What happened |
| --- | --- | --- |
| BEFORE (main): Codex turn/start while app-server frozen | main |
Frozen 45 s. `client/turn/rejected` + `system/error` "JSON-RPC request
timed out: turn/start" at 30 s. After CONT, Codex started the turn,
accepted the message and replied; the error row and the failed message
stayed. |
| BEFORE (main): Claude Code turn/start while claude frozen | main |
Same at 30 s (the message changed the reasoning level, so the bridge
waits on `claude`). After CONT the turn ran; the error row stayed. |
| AFTER (fix): Codex turn/start while app-server frozen 90s | branch |
Past both the 30 s runtime timeout and the old 60 s bridge timeout.
Sampled at 20/35/60/85 s: `active`, 0 rejections and 0 errors. Daemon
logged `turn_start_unconfirmed` at 30 s. On CONT, `turn/started` +
`turn/input/accepted` arrived at once, the reply came back, and the
thread went `idle`. |
| AFTER (fix): Claude Code turn/start while claude frozen 70s | branch |
Same result: `active` with no rejection or error through the freeze,
accepted on CONT, `idle`. |
| AFTER (fix): Codex turn/start lost (app-server frozen, then killed) |
branch | `active` with no rejection or error at 40 s. `kill -9` of the
app-server produced one `system/error` `provider_turn_start_failed`
("…codex app-server exited (code null, signal SIGKILL)"), the message
rejected as `turn_start_unconfirmed`, and the thread `error`. |
| AFTER (fix): Claude Code turn/start lost (bridge frozen, then killed)
| branch | `active` at 40 s. `kill -9` of the frozen bridge produced the
existing `provider_process_exited` error, the message rejected as
`turn_start_unconfirmed`, and the thread `error`. |

Tests (each new one fails without the change):

- `packages/agent-runtime/src/runtime.turn-start-watchdog.test.ts`: a
real scripted bridge that never answers `turn/start` gives `unconfirmed`
at 30 s, the thread stays live and a competing start is refused. On
main's runtime: `promise rejected "JsonRpcRequestTimeoutError…" instead
of resolving`. A second test: a bridge that answers the timed-out
request with an error later produces `provider_turn_start_failed` and
clears the pending start.
- `apps/host-daemon/test/command/thread-dispatch.test.ts`: an
unconfirmed start is reported as `turn_start_unconfirmed` and keeps its
staged attachment.
- `apps/server/test/threads/thread-send-dispatch.test.ts` › unconfirmed
turn starts: a late start keeps the thread `active` with no rejection or
error, then `idle`. `provider_process_exited` and
`provider_turn_start_failed` each produce exactly one
`turn_start_unconfirmed` rejection and their own error row, and fail the
run. All three fail on the old settlement (`expected 'error' to be
'active'`).
- `pnpm exec turbo run typecheck lint` for server, host-daemon,
agent-runtime, db, host-daemon-contract, provider-bridge-protocol,
provider-codex and scripted-echo-provider. Run locally: the touched
server, daemon and runtime test files; the agent-runtime input-accepted,
lifecycle and process-lifecycle suites; the daemon command tests; the
Codex bridge tests; and provider-bridge-protocol. CI runs the full
suites.

🤖 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