Repository navigation
Keep a new message's thread running when its turn start times out - #7031
Merged
ymichael merged 1 commit intoNov 4, 2026
Merged
Conversation
A turn/start that gets no answer within the daemon's 30 s JSON-RPC timeout is now unconfirmed rather than refused: the runtime keeps its pending turn start, the daemon reports turn_start_unconfirmed and keeps staged attachments, and the server writes no rejection or system error and leaves the thread active. A late turn/started settles it normally. A start that is really lost is settled from persisted events when the provider process exits or the provider answers the timed-out request with an error (provider_turn_start_failed): the latest unresolved request since the last completed turn is rejected as turn_start_unconfirmed and the run fails. The Codex bridge no longer gives up on turn/start or compaction starts after 60 s. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/a-timed-out-turn-start-fails-a-live-thread-thr_24uvdtnf8n
branch
November 4, 2026 20:38
ymichael
added a commit
that referenced
this pull request
Nov 4, 2026
## Human comments ## What was wrong #7011 (updateWhenIdle settings) reverted two PRs that had merged about 30 minutes before its commit was created: #7028 (merge child notices while the parent is blocked, skip `/compact` turns) and #7030 (count only the latest workflow run in GitHub PR check status). Its body mentions neither, so it looks accidental. - #7011 is a single commit, `6b17f1bc04`, whose parent is #7028's merge commit `920804af63`. Even so, the commit's own diff rewrites 11 files to their earlier content: - In #7028's 9 files it is an exact inverse of #7028, apart from four exports #7011 added to `packages/db/src/data/index.ts`. - #7030's 3 files in `plugins/github-pr-status/host/` went back to their pre-#7030 content. - That pattern fits a branch whose files came from an older checkout and were committed onto a newer base. - CI stayed green because each revert also removed the matching tests. - No other PR was affected. Every file the commit touched was compared with its earlier versions on main; only these two PRs match. What users got back after #7011: - **#7028:** a parent blocked on a question, a starting turn or an offline host collects a separate notice for every child update again (on Nov 3 one parent got ten from one child). `/compact` turns on a child send the parent "No final output was recorded." - **#7030:** bb shows green PRs as failing ("22 passed, 4 failed") when GitHub cancelled a duplicate CI run. ## What changed - Cherry-picks `b0e91c38f8` (#7030) and `920804af63` (#7028) onto current main with `-x`. #7030 applies unchanged. - #7028 conflicted only in `coalesced-system-notices.ts`, because #7029 (merged after #7011) added withdrawing a pending notice there. The result is #7028's version with #7029's withdraw path kept: the pending lookup has no `now` and a merge writes `windowEndsAt`. This is the combination #7029 was tested with before #7011 landed. `child-thread-notifications.ts` resolved to main's existing version, which already guards on a scheduled row. - Restores the #7029 test that depends on #7028: an ownership change undone after its 2 s window but before delivery is withdrawn. Its test helper comes back with it. - `internal/events.ts` and `db/data/events.ts` merged cleanly with the later #7031 and #7033 changes. - No daemon wire, CLI, config or plugin SDK surface change; `check-plugin-sdk-version` reports the surface unchanged. ## How you verified - With main's current code and the restored tests, 7 tests fail. With this branch they pass: - `thread-ownership-notices`: "withdraw a move undone after its window but before delivery" - `system-notice-dispatch`: "merge later outcomes into a row still waiting on the parent" - `child-completion-turn-output`: "does not notify the parent for a turn that only compacted context" - `github-pr-status` `git-host` / `batch`: superseded workflow runs, including on a later checks page and for drafts found through `gh pr view` - Server: ownership notices, notice dispatch, child completion output, notice kinds, child outcomes, parenting, plugin events, queue updates, sidebar status and child notifications all pass (112 tests). - `turbo run test` for the GitHub PR Status plugin, `@bb/db` and `@bb/templates` passes (10/10 tasks). `turbo run typecheck` for server, db, app and the plugin passes (10/10 tasks). > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- 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
When a new message's
turn/startgot 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 ascommand_failed, andsettleThreadCommandFailuretreated that as a refusal: it wroteclient/turn/rejectedplussystem/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 toidle. 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:runTurnreturns{ status: "started" | "unconfirmed" }. OnJsonRpcRequestTimeoutErrorit 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.startThreadwith initial input treats an unconfirmed start as a constructed session.apps/host-daemon: an unconfirmed start is reported asturn_start_unconfirmed(TURN_START_UNCONFIRMED_ERROR_CODEin@bb/host-daemon-contract). Staged attachments are kept for unconfirmed steers and starts, because the provider may still read them.apps/server(unconfirmed-steers.tsis renamed tounconfirmed-turn-requests.ts): forturn_start_unconfirmedthe server writes nothing and the thread staysactive. A lateturn/started/turn/input/acceptedthen 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:
system/errorprovider_process_exited.sendJsonRpcRequestgets an optionalafterTimeouthandler. The runtime uses it to clear the pending start and emitsystem/errorprovider_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 stayedactive(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 unresolvedclient/turn/requestedafter the last completed root turn withreason: 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 countsprovider_turn_start_failedasstart_failed, as the oldthread_command_failedwas 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/startandthread/compact/startno 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:turnStartErrorAfterMsoption 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_VERSIONbump.turn_start_unconfirmedis a new value of the free-formerrorCode, andprovider_turn_start_failedis a new value of the free-formsystem/error.code. An older server settles the first ascommand_failed, which is today's behaviour, and shows the second as an ordinary error row. An older daemon keeps sendingcommand_failed.How you verified
Live on
pnpm start:worktreewith real Codex and Claude Code. BEFORE ran onorigin/main(a67ada1, before #7010). AFTER ran on this branch with the same data dir, shared viabb connect expose. The only faults were real process freezes and kills (kill -STOP/kill -CONT/kill -9on literal PIDs).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.claude). After CONT the turn ran; the error row stayed.active, 0 rejections and 0 errors. Daemon loggedturn_start_unconfirmedat 30 s. On CONT,turn/started+turn/input/acceptedarrived at once, the reply came back, and the thread wentidle.activewith no rejection or error through the freeze, accepted on CONT,idle.activewith no rejection or error at 40 s.kill -9of the app-server produced onesystem/errorprovider_turn_start_failed("…codex app-server exited (code null, signal SIGKILL)"), the message rejected asturn_start_unconfirmed, and the threaderror.activeat 40 s.kill -9of the frozen bridge produced the existingprovider_process_exitederror, the message rejected asturn_start_unconfirmed, and the threaderror.Tests (each new one fails without the change):
packages/agent-runtime/src/runtime.turn-start-watchdog.test.ts: a real scripted bridge that never answersturn/startgivesunconfirmedat 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 producesprovider_turn_start_failedand clears the pending start.apps/host-daemon/test/command/thread-dispatch.test.ts: an unconfirmed start is reported asturn_start_unconfirmedand keeps its staged attachment.apps/server/test/threads/thread-send-dispatch.test.ts› unconfirmed turn starts: a late start keeps the threadactivewith no rejection or error, thenidle.provider_process_exitedandprovider_turn_start_failedeach produce exactly oneturn_start_unconfirmedrejection 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 lintfor 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