Repository navigation
fix: keep rows pushed while a chat's open page loads - #47879
winnythedev wants to merge 2 commits into
Conversation
Opening a chat reads one page of its transcript, then replaces the view with that page. A page is read at one instant, so the rows the gateway pushed during the read (a finalized segment, a tool row, a card) reached the view through live frames but not the page. The switch kept only the person's own sends and the trailing reply, so the text before a tool call and that call's card vanished until the turn ended, or the text before and after the call ran into one bubble. switchSlot now records the row identities the view held when the switch began, and its fulfilled reducer keeps the server rows a live frame added after that which the page does not carry, in view order, ahead of the trailing reply. A row the view already held is left to the page, so a row the server since dropped is not carried back. An idle page that lacks such a live row was read before the turn that wrote it, so the chat keeps the run state that turn set. Fixes #47857
UX Review (Opus 5.5) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing to check. The diff changes only a store reducer, a spec and tests. It adds or changes no control, label or string, so there are no evidence gaps despite the blind read not being performed. [UX-REVIEWED] 4cafa8c Description read[DESCRIPTION-READ] b84f52cc48d1f2dbcdbbb2bc0e7d7583ac7872d7e65c9562094fd07d24c52d6e 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 |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. The fix keeps only rows a live frame added after dispatch, using the same rules Notes
[DESIGN-REVIEWED] 4cafa8c Description read[DESCRIPTION-READ] 88d96a7faddd5a102ae589fce96df0ecda31173ac9b7b34799245b76ef48f265 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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS This fixes a defect a new test proves: three of its cases fail on base. The note below is about a second record of "what was on screen when the switch began" kept in the same reducer. It is not a duplicate that blocks. Notes
What this change shipsInventory (5 items) — 4 justifiedIntent: someone who opens or returns to a chat while a turn is running sees every segment and tool card the gateway sent while the page was loading. FIX.
[FIRST-PRINCIPLES-REVIEWED] fd93488 Description read[DESCRIPTION-READ] e31331ace4bc65aa09bf25bbe740ee749bf59e7444ef444b5e52e4f20b617525 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — 🔴 changes requested (blocking)GPT 6.1 found at least one blocking issue that must be resolved before merging This comment is updated in place on each push. BLOCKING -- website/src/store/chat/slotSwitch.ts:226 -- Overlapping live and page reads duplicate stop cards [BLOCK-MERGE] fd93488 Adjudication (Opus 5.5) — is blocking on each finding proportionate?I'm upholding F1, so it keeps blocking the merge. The harm is LOW to MEDIUM, but the fix is cheap. F1 — what goes wrong is visible but recoverable: the pane shows two stop cards, and one stays stuck at "Stopping" until the next refresh. I confirmed the conditions in code:
The real fix is small: also match stop cards by False positive or not applicable? A repository writer can comment: |
The page rebuilds the meta of a row with a JSON cls from that cls alone, so its copy of a stop card carries no meta.mid. A stop card pressed while the chat's page loaded was therefore kept beside the page's own copy: two cards, one stuck at Stopping. Such a row is now matched by its meta.id, and any other JSON-cls row is left to the page.
|
self-added: yes
|
Problem / Motivation
Goal: A chat opened, or switched back to, while its turn is running shows every message segment and tool card the gateway sent while the chat was loading.
When a person opens a chat whose turn is running, the text written just before a tool call and that call's card can go missing. They stay missing until the turn ends or the person switches away and back. Sometimes the text from before and after the call runs together in one bubble with no tool card between. It happens whenever a tool call starts while the chat's first page is loading (about 57 ms on a local gateway, longer over a slow link).
Why it matters
Anyone who opens or switches into a busy chat can lose the record of what the agent did: the tool card that says what ran and the text that led up to it. The view looks complete, so nothing tells the person a part is missing, and on a slow or remote link the window is wide enough to hit often.
Not a goal
refreshSlot, which already has its own rescue for rows that race its read.warmSlotCache,hydrateSlotMessages), which merge with their own rules.What changed (motivation → approach → change)
switchSlotreads one page, thenswitchSlot.fulfilledreplaces the view with that page. A page is read at one instant. The rows the gateway pushed during the read reach the view through live frames but are not on the page. The reducer kept only the person's own sends (liveSends) and the trailing reply, so every other server row from that window was dropped. The page also still folds the flushed segment's text into its streaming row, which is how the text before and after the tool call ended up in one bubble.website/src/store/chat/slotSwitch.ts):idsAtDispatch), asrefreshSlotalready does.rowsLandedDuringFetchpicks the server rows (meta.mid) that a live frame added after that and that the page does not carry (tailNotInPage). LikeliveSendsSince, it looks only below the last row that was on screen at dispatch, skipping queued bubbles, so older rows another read wrote into the view stay above the page.clsfrom thatclsalone, so its copy has nometa.mid(inject rows keep theirs). A stop card of that kind is matched by itsmeta.id; any other JSON-clsrow is left to the page, as on main.docs/system-specs/modules/history.md, "Bounded reads", gains the rule.Backwards compatibility
Compatible: only rows that live frames already put on screen are kept; a page that carries them, or a switch with no live frames during the read, lands as before.
Removes nothing: the change keeps rows the reducer used to drop and takes no path, record, key or function away.
Tests
website/src/store/chatSlice.switchLiveRows.test.tsdrives the real chat slice reducers with the frames the server writes: the pre-tool segment flush as anassistantchat_messagewithmeta.mid, thetoolchat_messageafter it, chunks withseqandgen, and a page whose open segment is folded into onestreamingrow.clsrow to the page, which holds it without itsmid.Proof: not provable -- frontend test (prove.py runs Python only)
By hand instead: on main 4fe9089 the first three cases fail (
expected [ 'user:q', 'streaming:f' ] to deeply equal [ 'user:q', 'assistant:abcde', 'tool:ls', 'streaming:f' ], and twiceexpected [ 'user:q', 'streaming:abcde' ] to deeply equal [ 'user:q', 'assistant:abcde', 'tool:ls' ]). The queued-send, older-rows and idle-page cases each fail when their own part of the fix is taken out (the queued skip in the walk, the walk's bound, the run-state guard). On head fd93488 the stop-card-on-page and other-JSON-row cases fail (expected [ 'stopping', 'stopping' ] to deeply equal [ 'stopping' ]); leaving every JSON-clsrow out without themeta.idmatch fails the pressed-after-read case.Determinism: the file passes 20 of 20 runs with
--sequence.shuffleand seeds 1 to 20. The tests use no timers, sleeps orDate; the page race is injected synchronously inside the mocked read, andbeforeEachresets the module state.Other runs on this head: 274 related frontend files (5,142 tests: the 163 files naming switch, refresh, warm or streaming, all of
src/storeandsrc/lib),CarriedMockAnswerRatchetand thechatSlice.ownershipguard,test/test_flake_pattern_ratchet.py(81 passed), eslint on the two changed files,tsc -p tsconfig.app.json --noEmit,scripts/docs-lint.sh,check_comment_history.py,check_brand_name.py,check_file_line_cap.py, andsemgrep scan --config semgrep/ --baseline-commit <base> --error(1.78.0, 0 findings).scripts/local-gate.py --tree-scanswas started but had not finished when this was pushed: the docs change pulls in about 1,600 cross-surface backend test files. Its backend half is left to CI.Review (multi-model interrogate)
Independent reviewers read the full diff against CI's lane contracts.
shortcut:comment marks the limit.sendId) during the read is still dropped. That is outside this PR's goal and unchanged from main.meta.mid. Fixed in a second commit: stop cards are matched bymeta.id, other JSON-clsrows are left to the page, with three tests.idsAtDispatchis a second record, beside_switchLiveFrom, of what was on screen when the switch began. Folding the two is a refactor ofliveSendsoutside this fix.AGENTS.md.shortcut:comment.Manual verification
N/A -- unit coverage sufficient: the defect and the fix live in one reducer, and the tests drive it with the frames the server sends. No live dashboard run was done, and no gateway was started.
Real-machine verification
Machine: Linux x86_64 developer host, Node with the repository's pinned website dependencies (
npm ci).Before (main 4fe9089):
cd website && NO_COLOR=1 npx vitest run src/store/chatSlice.switchLiveRows.test.ts --coverage.enabled=false-> the first three cases fail as quoted under Tests.After (head): the same command ->
Tests 8 passed (8).Cleanup: own computer; vitest only, on the real chat slice reducers. No browser run, no gateway and no dashboard token were used.
Screenshots / video
Why no screenshot: The change only stops a chat from dropping rows during its first page load; no layout, style or component changes, and the rows look as they already do.
Related Issues
Fixes #47857
Sibling sweep
Swept:
git grep -n "tailNotInPage\|idsAtDispatch" -- website/src/store/chat/Sibling: website/src/store/chat/slotRefresh.ts -- not affected -- refreshSlot already keeps raced sends and the raced streaming reply through liveSendsSince and racedStreamingRows
Sibling: website/src/store/chat/slotSwitch.ts -- changed here -- JSON-cls rows whose page copy has no mid: stop cards matched by meta.id, the rest left to the page (swept with git grep -n "slot.append(" -- src/kiro_crew/dashboard/)
Sibling: website/src/store/chat/messages.ts -- not affected -- hydrateSlotMessages and warmSlotCache (slotRefresh.ts) merge a background pane by their own rules, out of this PR's scope
Pattern harvest
Not generalizable: the defect is one reducer replacing the view with a page read before frames it already applied; the sibling reads already guard the same race.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commitsContribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.