Repository navigation
fix(chat): idle the stream state when a reconnect refresh finds the turn gone - #18288
Conversation
UX Review (Opus 5.5, fork) — 🟡 CONCERNSUX-level review of UX-Verdict: CONCERNS No first-time reader has seen the restored composer Resume, and the Stop-card case, now idling to Send, has no screenshot. Watch
[UX-REVIEWED] 59c1860 Description read[DESCRIPTION-READ] 05de8fb879a7734edd9b88513083894b9ddcb519083ad0d1dae3bbe79cbb3d81 That sha256 names everything this verdict read: the PR description, plus the 5 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 |
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Check one case before merge: a refresh that returns What this change shipsInventory (3 items) — 3 justifiedIntent: when a gateway restart cuts off a reply, the tab that was watching it stream should offer Resume without a page reload. This is a FIX (closes #18202, and the added test fails on main).
Sibling check: I grepped [FIRST-PRINCIPLES-REVIEWED] 59c1860 Description read[DESCRIPTION-READ] a4dfcc37a64761890f0b5b033a756665c0b00305731dc74b933c9eca15e02b85 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Check the in-flight guard: a [DESIGN-REVIEWED] 59c1860 Description read[DESCRIPTION-READ] bf6df48c244e6204e6c813f3ae46fced9285ca71e5151ae5a93b3ecfbc06d75d 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 |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
a6cebaa to
0e2d64b
Compare
|
Rebased on main, no behaviour change. Shard 4 failed on the Ctrl+Shift+Enter test in ChatInput.lexicalKeys.test.tsx because the old base predates #16429. The test passes on current main both with and without this commit. |
|
self-added: no
|
|
note (non-blocking): the Integration (in-process gateway) failure on 0e2d64b is unrelated to this diff
|
0e2d64b to
c89c430
Compare
|
note (non-blocking): the Integration (in-process gateway) red on c89c430 is the boot-time owner-only race that #18224 fixes The same-tree retrigger failed |
|
note (non-blocking): the E2E (stub ACP backend, offline) red on c89c430 is a spec that passed on retry, in code this PR does not touch
|
c89c430 to
59c1860
Compare
iamwhatever
left a comment
There was a problem hiding this comment.
This fixes a bug after a gateway restart: the tab that was streaming kept Stop instead of offering Resume. The root cause is fixed: refreshSlot.fulfilled in website/src/store/chat/slotRefresh.ts reset slotState only on the watchdog (recoveryRevision) path. Any refresh that reports running: false now idles the stream state, unless a live frame has reduced since dispatch. I confirmed that liveAtStart is captured before the await and that the thunk already drops a payload when liveFrameSeq moved (line 190), so a stale snapshot cannot idle a new turn. The new test drives the real reducer and composer selectors. It covers the restart case and the Stop-card case, which both fail on main, plus the live-chunk race and running: true. Base is main, checks are green, there is no change request, and Design and First Principles are PASS. The UX CONCERNS (no still of the Stop-card state) has a rebuttal disposition and is advisory. — crew-pr-reviewer
Problem / Motivation
Goal: A chat whose reply is cut off by a gateway restart offers Resume in the tab that was watching it stream, without a reload.
You watch a reply stream, the gateway restarts, and the tab reconnects on its own. The transcript then shows the partial reply and the "This turn was interrupted when the app restarted" card, but the composer still shows Stop instead of Resume. Reloading the page brings Resume back. A user who doesn't reload has to type "resume" by hand.
Why it matters
Recovery after a restart is the moment the Resume button exists for. The tab most likely to be open during a restart is the one streaming the reply, and that is the tab that loses the button. Every other chat interrupted by the same restart keeps it, so the failure looks random.
Not a goal
gateway_restart_interruptionrow, or how/continueauthorizes a press.queuedrow blocks Resume on purpose.syncSlotRunningFromServeralready idles theirslotRunfrom the slots snapshot.What changed (motivation → approach → change)
The tab never gets the dead turn's
_doneframe, so its store keepsslotState === 'streaming'. On reconnect,refreshSlotreturnsrunning: falseplus the interruption row. Its reducer clearedslotRunningbut resetslotStateonly on the row-stall watchdog path, the one that passesmeta.recoveryRevision.selectComposerBusytreats any non-idleslotStateas busy, so the composer kept Stop andcomposer-continuenever rendered. A reload works because a fresh store starts idle.refreshSlot.fulfilledinwebsite/src/store/chat/slotRefresh.tsnow applies the watchdog's idle settlement to any refresh whose snapshot says the slot is not running:slotState = 'idle',slotStopping = false, and the trailing streaming row finalized. The thunk recordsliveFrameSeqwhen it is dispatched. If a live frame from a newer turn reduces while the fetch is in flight, the settlement is skipped, so a stale snapshot cannot idle a turn that just started.Backwards compatibility
Compatible: the refresh payload gains a client-only
liveFrameSeqAtDispatchfield. No server contract or persisted shape changes, and every path that was already idle stays idle.Removes nothing: the reducer only adds an idle settlement for a slot the server reports as not running.
Tests
website/src/store/chatSlice.refreshSlotRestartResume.test.tsdrives the real reducer and the composer selectors:running: false+ interruption rowslotStategoes idle, nostreamingrow remains, and the composer gate offers Resume (fails on main)running: trueGates:
tsc -p tsconfig.app.json, the full frontend suite in 4 shards (2,712 files passed), andnpm run i18n:checkwithI18N_BASE_REF=origin/main.Manual verification
A disposable harness gateway on a fixed loopback port, running the fake ACP backend with synthetic prompts. Headless Chromium sends a
[[SLOW]]prompt in a chat that has already had one turn. Once text streams, the gateway restarts on the same port. Probes at 2, 5, 10 and 20 s after the restart read the Redux store and the DOM.slotRunning: false,slotState: 'streaming', interruption row presentslotState: 'idle'slotState: 'idle'POST /continueand a new turn startsslotState: 'idle'POST /continueOn the first turn of a brand-new chat, the restart lands before the reply's first segment is persisted. The restore then leaves
[user]with no interruption row, and both main and the fix show Resume through the unanswered-user rule.Screenshots / video
Same-tab reconnect after a restart, before the fix: the card has Resume but the composer shows Stop.
After the fix: the composer offers Resume.
Related Issues
Closes #18202
Refs #16780. The "one chat kept Resume, another lost it" split there matches this mechanism: only the slot the open tab was streaming keeps the stale state.
Pattern harvest
Rule candidate: review-prompt
Pattern: a reducer that settles
slotRunningfrom a server snapshot must settleslotStatein the same branch, becauseselectComposerBusyreads both.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)