Repository navigation
fix(chat): idle the composer when a turn ends without its _done - #14276
Conversation
|
Intent: Stop the main chat's composer from offering the Steer/Queue split button after a turn has ended, by letting the live |
|
Rerun request (infra, not the diff): five checks on head
|
52f3685 to
f3e9eb7
Compare
UX Review (Opus 5.5, fork) — ✅ PASSUX-level review of UX-Verdict: PASS Check on the phone dashboard: after a turn whose [UX-REVIEWED] f5b5d12 Description read[DESCRIPTION-READ] 881168ad6adf1b598d94bbd8761b452515a7b2ff95fe017c8f957a0d17018b75 That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
First Principles Review (Opus 5.5, fork) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The PR names the cause as "two busy signals that can disagree", then keeps both and adds a third mechanism to reconcile them, without weighing whether one of the reads could simply go. Not justified as shipped
What this change shipsInventory (8 items) — 6 justifiedIntent: the send arrow comes back as soon as a turn has ended, even when the tab lost that turn's
[FIRST-PRINCIPLES-REVIEWED] f5b5d12 Description read[DESCRIPTION-READ] 7af52afb35dfac99705a142bb71a4918ff3766cc9b61252f26f6d25cc3ba9f96 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5, fork) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS Every turn now ends when a Watch
[DESIGN-REVIEWED] f5b5d12 Description read[DESCRIPTION-READ] 2875e37d9c4c7cec9b19ffa543e9c1d8d1a94e9a30a2d6d3c6587a6b09e594cf That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
f3e9eb7 to
819864a
Compare
|
Disposition: fixed in 819864a
|
|
Disposition: fixed in 819864a
|
819864a to
3dc7ba4
Compare
|
Disposition: fixed in 3dc7ba4
|
|
Disposition: fixed in 3dc7ba4
|
0034ff3 to
06a0edc
Compare
|
Pushed 06a0edc (rebased onto current main) to answer the GPT 6.1 finding on 0034ff3, "an ended-turn history page splices the next answer into the previous reply". The finding was reproduced in the store tests: a history page captured mid-turn T and applied after this tab had already recorded T's end kept T's The fix stops applying such a page to the active pane at all: in Tests: the store regressions cover a live successor opened by a send, a |
06a0edc to
1d5fc0d
Compare
|
Rebased onto GPT 6.1, "Finalizing stale history before merging duplicates the completed reply" ( First Principles, delete Design review, a walk over every Frontend Tests (1) red on Validation on this head: the store, WebSocket-hook and ChatPage selection is 146 files and 1,991 tests, all passing. The full frontend suite is 46,403 passed and 66 failed in 20 files (Pierre, DiffBlock, highlighting, ArtifactDetailPage, ChatInput.approval, SchedulePage.secrets and others), and the same 20 files fail with the same 66 tests on a pristine |
1d5fc0d to
c20c0b9
Compare
|
Accepted: a superseded Fix in c20c0b9 (one commit, rebased onto adfd71b): Tests in
On an archive copy of the published head 1d5fc0d all three fail. In the first, R1 leaves the transcript as [request, assistant "second "], the slot idle and the composer free, the cursor R1's, and N+1's next chunk opens a second bubble. Mutations on archive copies of c20c0b9, each anchor matched once: removing the check in Siblings, unchanged: |
|
Rebased onto |
|
Rebased onto |
|
Rebased |
A turn whose _done the tab never applied left the active slot's slotState busy: the frame was lost, or a history fetch served mid-turn resolved after it and wrote its stale running=true back. A later slots snapshot cleared slotRunning, so the transcript and footer read idle, but selectComposerBusy also reads the stream state and kept offering the Steer/Queue split button with no agent running. The live sseSlots frame now settles it: the server projects running from the turn task, so a frame reporting it false follows every frame of that turn on the ordered socket. HTTP fetchSlots replies never settle, since they can predate a turn already streaming. The slots WS handler flushes text still buffered for the active slot before such a frame, as chat_done does, so the tail lands in the finished reply. A switch page captured before a turn the tab already recorded as ended keeps its streaming rows through the merge, which drops them beside a reply the tab finished, and only the rows it keeps are finalized after it: finalized first, the page's partial passed the streaming filter and the finished reply rendered twice. That page also seeds the chunk replay floor from its streaming row, as _done leaves the floor, so a redelivered chunk of the ended turn cannot reopen the reply or the busy composer. A switch settlement whose read a later switch superseded applies nothing. The thunk never aborts an earlier read of the same slot, so a page captured mid-turn could land after the user left and came back, by when the tab had recorded that turn ended and a successor was streaming. Merged as an ended-turn page, it finalized the successor's live row and idled the slot. The pending reducer records the newest requestId, which settling does not clear, and the fulfilled and rejected reducers ignore any other.
|
Rebased |
iamwhatever
left a comment
There was a problem hiding this comment.
This fixes a composer stuck on Steer/Queue after a turn whose _done the tab never applied. The cause is that slotState was reset only by _done or a history fetch. Now the live idle slots row settles the active turn (settleEndedActiveTurn in store/chat/runState.ts), and the server stamps slots rows, terminal chat_done and the history reply with {turn, turn_gen}, so a late _done, a stale history or switch page, or a late fetchSlots row can no longer finalize or re-busy a successor turn. Our change request at 81d9e2e asked to drop the relay hunks; the current head f5b5d12 contains no remote_relay.py or test_remote_crew_execution.py changes, so it is met. I read all ~1,180 production lines and skimmed the tests, and tried to break the early settle four ways. (1) An idle row mid-turn: _finish_queue_cycle clears slot.task then pushes then sends chat_done, a queue-drained successor returns before that, and both compacting frames are sent inside the turn task, so running stays true. (2) A pending send settled by the previous turn's idle row: refused, because the row must name a turn newer than the known baseline (turn 0 when none is known, which no real turn carries). (3) The mid-turn /compact acknowledgement fencing the live turn: it passes ends_turn=False and carries no identity. (4) A superseded switchSlot read: dropped by slotSwitchLatestRequestId. The one residual race the author disclosed (a pre-restart history reply landing after a restart, then a late _done) needs three unlikely events and is never worse than main, which has no fence at all. Non-blocking points. The description still mentions the removed relay's chat_done, test_remote_crew_execution.py, and settleEndedActiveTurn in store/chatSlice.ts; please refresh it. ChatDonePayload in types/index.ts has no reader (First Principles). PR Scope was cancelled at 15 min on this head with no newer run, so please rerun it before merge. The needs-author-decision label looks stale. — crew-pr-reviewer (deep re-check)
Problem / Motivation
Goal: The composer returns to the send arrow as soon as a turn has ended, even when the tab never applied that turn's
_done.After a turn finished, the composer could keep showing the Steer / Queue split button (the target icon) even though no agent was running. The reply above it looked done: its footer showed the duration, the follow-up chips were offered, and the thinking footer was gone. Only a reload brought the normal send arrow back.
Why it matters
The send button is how the user reads whether the agent is busy. Offering "steer" with nothing to steer says the session is working when it is not. It also puts a mode choice (steer or queue) in front of every message until the page is reloaded. It was reported from the phone dashboard, where dropped frames and resumed tabs make it easier to hit.
Not a goal
slotsrow already precedeschat_done, and this PR only names the turn on frames that already exist.mainand its hunks were dropped from this PR.main, and its fix is a dispatch-time epoch in the refresh thunk.What changed (motivation → approach → change)
_donethe tab never applied left the composer busy until reloadslotsrow saying the slot is not running settles it, and the composer shows the send arrowThe root cause is two busy signals that can disagree. The transcript and footer follow
slotRunning, which the slots sync already clears.selectComposerBusyalso reads the active slot's stream state (slotState), which only_doneor a history fetch reset. When the_doneis not applied (the frame is lost, or a mid-turn history fetch resolves after it and writes backrunning: true),slotStatestays busy.settleEndedActiveTurninstore/chatSlice.tsnow settles the active slot when a liveslotsrow reports it not running, withfinalizeActiveTurn, the step_donealso uses. The server pushes that idle row beforechat_done, so this runs on ordinary turns too, and the_donethat follows changes nothing.Settling early frees the composer before
chat_donearrives, so the tab must know which turn each terminal frame belongs to. The server now says so: slots rows, everychat_done(including the remote relay's) and the history reply carryturn(the slot's existing_turn_generation, which counts turn tasks) andturn_gen(the gateway'schunk_generation(), since the counter restarts with the process).chat_done_payloadreads them before its store probe can yield to a successor.types/index.tsadds the optional fields toChatSlotand newChatDonePayload/ChatSlotDetailResponsetypes, andapi/client.tsreturns the history reply asChatSlotDetailResponse.The tab keeps, per slot, the newest turn it knows ended. A
_donefor a turn already known ended is ignored in both the active and background paths, so a late one never finalizes a turn started after it. A pending local send is settled only by a row naming a newer turn than the last one known ended in that gateway generation, or than turn 0 when none is known (a new chat, a restarted gateway). Neither a history reply nor a session-list row (pages/ChatPage.tsxpasses the row's identity tosyncSlotRunningFromServer, and a late HTTPfetchSlotsalso writes that list) can restore busy for an ended turn. A history page captured before a turn end this tab already recorded is not applied to the active pane: it is older than what the tab shows, and the refresh that follows the end carries everything it holds. The end without a_donenow dispatches that refresh too (hooks/websocket/slotList.ts), so the idle row re-hydrates the pane exactly as_donedoes, and the_donethat follows for the same turn skips its own (the ended turn's identity is recorded per slot inhooks/websocket/idleRowRefresh.ts, shared by the two owners): one refresh per turn end. Background pages captured mid-turn finalize every fetched streaming row of the ended turn and do not vouch as a final reply. A switched page keeps its rows' roles through its merge, which drops the page's streaming rows wherever it re-attaches a reply the tab already finished, and finalizes only the ones it keeps after the merge, so that reply is shown once; its replay floor is seeded from the page's streaming row, so a redelivered chunk of the ended turn is dropped as_doneleaves it. A switch whose read a later switch superseded applies nothing, whether it settles before or after the newer one:switchSlot.pendingrecords the newest request, which settling does not clear, and both settlement reducers ignore any other, so an older page cannot finalize the successor turn the pane shows and an older failure cannot empty it. Either way a successor's chunks cannot append to the prior reply. Frames without identity keep the previous behavior. The onechat_donesent mid-turn, the deferred/compactacknowledgement, omits the identity (ends_turn=False), so it cannot mark the live turn ended.The server order is recorded in
docs/system-specs/modules/session.md, commented at_finish_queue_cycleindashboard/chat_runner.py, and pinned bytest/test_finish_queue_cycle_terminal_order.py. No other writer can push an idle row mid-reply:runningreads whether the turn's own task is done, every site that clearsslot.taskdoes so after that task finished or on a terminal branch, Stop interrupts the provider turn and never clearsslot.task(its pushes read running until the turn's own teardown), and regenerate/rewind assign a new task, which advances the turn number.hooks/useWebSocket.tsflushes text still buffered for the active slot before dispatching the idle row, so the tail lands in the finished reply. Its identical-frame dedupe still lets a repeat through while the chat reads busy, for history from an older gateway without identity.Backwards compatibility
Compatible:
turnandturn_genare new fields on existing payloads; nothing is removed or renamed. A frame or reply without them is handled as before this PR.Tests
website/src/test/chatSlice.activeStrandedStream.test.ts(reducer plusselectComposerBusy):_doneis healed by the idle row, including a reply whose final frame was also lost; an HTTPfetchSlotsreply never settles a live turn._doneleaves one finished reply; settlement then_doneequals_donealone, placeholder row included._doneleaves a newer turn streaming, whether started locally or by the server, after switching away, and away and back. A successor's_donefinalizes before any running row arrives._done; a_donewithout identity finalizes as before.switchSlotandrefreshSlotreplies, and a stale session-list row, cannot restore busy for an ended turn. A row naming a newer turn still can. A refresh page captured before a recorded turn end leaves the active transcript and run state exactly as the tab had them. That holds under a live successor opened by a send, anudgeor asubagentrow, when the first local row is known only by itssendId, and for a turn the queue dispatched (nothing doubled, nothing lost). The completion refresh that follows lands the text the tab never received. Background and switched history pages captured mid-turn finalize every ended-turn fetched stream before the next send receives chunks. A stale warm keeps a longer identity-less client reply when its fetched page is only partial.website/src/store/chatSlice.switchEndedTurn.test.ts(reducer): a slot whose reply its backgroundchat_donefinished, switched to with a page captured mid-turn (running: true, the partial as astreamingrow), shows that reply once, idles the composer, seeds the replay floor from the page's row, and drops a redelivered chunk of the ended turn.website/src/store/chatSlice.switchSuperseded.test.ts(reducer): a read of a slot issued mid-turn, superseded by a switch away and a switch back while that turn ended and the next one started streaming, applies nothing when it lands, whether after the newer switch settled or while it is still in flight. The successor's row staysstreamingwith its text, no extra reply appears, the slot and composer stay busy, the paging cursor and loading flag are the newer switch's, and the successor's next chunk extends the same bubble. The same read failing leaves the pane as it was.website/src/test/useWebSocket.endedTurnFlush.test.ts(hook): buffered text lands before the settlement; identical idle frames are deduped once history is fenced by identity and re-applied for identity-less history; a pending send is left alone. An idle row that ends the active turn without a_donedispatches exactly one refresh and the pane shows its page, including when its flush lands the turn's only text or it ends a pending send. Idle row then_done, and_donethen idle row, refresh once per turn, and a record left by a lost_donedoes not swallow the next turn's_donerefresh.test/test_finish_queue_cycle_terminal_order.py(backend, real slot and state):done, idle push with the task cleared, then onechat_donenaming the ended turn; synthesis sends nochat_done; rows and history carry the identity;test_the_deferred_compact_acknowledgement_does_not_end_the_turndrives a statusless/compactturn through the behavioral harness and pins its identity-less acknowledgement before the wait plus its identified finalchat_doneafter completion.test/test_remote_crew_execution.py: the relay'schat_donenames its turn._doneguard, suppressing every identified_done, dropping the history or session-list guard, droppingends_turn=False, or droppingturnfrom any of the four server emitters each fails its test. So does applying a stale page to the active pane, dropping the idle row's refresh, or deduplicating that refresh by slot alone, and so does finalizing a switched page before its merge or clearing the floor for it. Dropping either settlement reducer's superseded-request check, or the newest-request record inswitchSlot.pending, fails the superseded-switch tests.Manual verification
N/A — unit coverage sufficient: the stranded state comes from frame loss and fetch races that a live session cannot trigger on demand. The tests drive the exact frame sequences through the real reducers and the real WebSocket hook, including the ordinary slots-before-
chat_doneturn end.Screenshots / video
Why no screenshot: no component, layout, style or copy changes; the composer renders its existing idle send button in a state where the store previously misreported the slot as busy.
Related Issues
no linked issue: reported directly from the mobile dashboard.
Pattern harvest
Rule candidate: review-prompt
Pattern: two store fields that encode the same fact (
slotRunningandslotStatefor "a turn is running") where a reconciliation path resets only one of them.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)