Repository navigation
Conversation
#7310 holds a root turn/completed while a steer is on its way to the daemon. A new-turn request has the same window: the server applies run.started at send, and if another root turn (for example a Claude Code background-task notification turn) ends before the start reaches the daemon, the thread went idle. The next send then went out as a second start, the daemon started A's turn first, and refused the second message with competing_turn. The start path now tracks its live command the same way, so a root completion that arrives while a start is in flight is held until the start settles. The in-flight counter is renamed from steers to turn requests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/keep-a-thread-active-while-a-new-turn-request-is-thr_mrjgbn8x5q
branch
November 10, 2026 04:01
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
#7310 holds a root
turn/completedwhile a steer is on its way to the daemon. A new-turn request (turn.submitwithtarget: start, orthread.startfor edits and forks) has the same window, but nothing held it. The server appliesrun.startedwhen the message is sent. If a different root turn ends while the start is still on its way to the daemon,applyTurnCompletedEventappliesrun.succeededand the thread goes idle. The next message is then sent as a second start. The daemon starts A's turn first and refuses the second withcompeting_turn, and the user's message is lost.The other root turn is any turn the provider opens by itself. For Claude Code, that includes the turn the CLI runs when a background Bash command finishes (bb doesn't hold the turn for background shells). In the original trace it was the Claude Code drift fixed in #7321 (dev DB of thr_kskphedncm, thread
thr_i7fdv3ia4f, events 501–515). That drift is one way to trigger it, not the cause: the server window exists without it.What changed
apps/server/src/services/threads/thread-send.ts: the start path tracks its live command as in flight and settles it inonSettled. The history-replacementonCommandSettledstill runs first. A root completion that arrives while a start is in flight is held, exactly as for steers:apps/server/src/internal/turn-completed-events.ts,thread-lifecycle.ts: the in-flight counter now covers steers and starts, so it is renamed fromtrackInFlightSteer/settleInFlightSteertotrackInFlightTurnRequest/settleInFlightTurnRequest. Its behaviour is unchanged.Visible difference, as in #7310: if a turn ends before its own start command settles, the thread stays "running" until the start settles, usually one daemon round-trip. A start that fails still settles the thread as
errorwith later sends left queued, the same as without the race. No wire change.How you verified
Two new cases in
apps/server/test/threads/thread-send-dispatch.test.ts, in the Hold the turn until in-flight steers settle #7310 describe (renamed to "a turn request in flight when a turn ends"). They use a real migrated DB and the same fake daemon, which refusesstartwithcompeting_turnwhile a turn is active:errorwith B queued, which matches a failed start without the race.On
origin/mainboth fail withAssertionError: expected 'idle' to be 'active'. With the fix, all 52 tests in the file pass.npx vitest run test/threads test/public test/internal test/system test/routes: 168 files, 1773 tests passed. The rest of the server suite passed: 4024 tests; one shell-script test ininstall-machine-script.test.tstimed out under load and passes on rerun (54/54).pnpm exec turbo run typecheck lint --filter=@bb/serverpassed.Live,
pnpm start:worktreewith a Claude Code (haiku) thread. Each round asks Claude to runsleep 8in the background, so the CLI later opens its own notification turn X. It then sends start A with 20–40 × 34 MB attachments, so the daemon stages A for seconds and X runs and ends while A is in flight. B is sent the moment X ends:origin/main:3 round(s) raced; 3 with a rejected message, eachA accepted(t18); B rejected:competing_turn;6 round(s) raced; 0 with a rejected message, eachA accepted(t15); B accepted(t15), with B steered into A's turn.🤖 Generated with Claude Code