Repository navigation
fix(chat): keep a send made during a refresh fetch and leave its run state - #19546
Closed
mbriones98 wants to merge 1 commit into
Closed
mbriones98 wants to merge 1 commit into
mbriones98 wants to merge 1 commit into
Conversation
…state refreshSlot.fulfilled rebuilt the transcript from a count-matched page and kept only the head above the page's first row (olderHeadAbovePage), then copied the page's run verdict. A send made while the fetch was in flight (the refresh fires on socket reconnect and on chat_done) is newer than the page, so the rebuild dropped the user's row, and the page -- read before the send -- idled the slot (slotRunning, pendingTurnSlot) under the turn the send opened, offering Resume on a running turn. The liveFrameSeq guard protected only slotState. Give refreshSlot a dispatch-time baseline (liveFromAtDispatch), keep the user rows past it with a sendId the page does not carry (tailNotInPage), and skip the page's idle run verdict when such rows exist -- the pagePredatesLiveSend guard switchSlot.fulfilled already uses (kirodotdev#18658 / kirodotdev#19263). Fixes kirodotdev#19267
Contributor
Author
|
Superseded by #19570 (same change, cut from a repo branch so CI runs). |
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.
Problem / Motivation
Goal: A message you send right as a chat reconnects (or right as a turn ends) stays on screen, and the slot keeps running the turn you just started instead of offering Resume.
Send a message at the moment the socket reconnects or a turn finishes, and your row vanishes and the slot goes idle under the turn you just opened — the composer briefly shows the interrupted-turn placeholder and offers Resume, until the reply's first chunk arrives.
Why it matters
The refresh that drops the send fires on every socket reconnect (phone lock/unlock, flaky network) and after every agent turn (
chat_done), so this hits normal use, not an edge case. For those seconds the user sees their own message disappear and a Resume button on a turn that is actually running — they can re-send or hit Resume and double the turn.Not a goal
What changed (motivation → approach → change)
The slot refresh rebuilds the on-screen transcript from a freshly fetched page and keeps only the history sitting above that page's first row. A message sent while the fetch is in flight is newer than the page, so that merge never keeps it, and the page — read before the send — reports the slot idle, which the reducer copied over the running turn the send opened.
switchSlotalready solved this exact race for the deep-link open (#18658 / #19263): it marks a baseline when the fetch goes out and keeps the user's own sends past it, and it skips a stale idle page's run verdict when such a send exists.This gives
refreshSlotthe same two pieces: a dispatch-time row-count baseline (liveFromAtDispatch), the user'ssendIdrows past it that the page does not already carry (tailNotInPage), and apagePredatesLiveSendguard that leavesslotRunning/pendingTurnSlot/ the stream state alone when the idle page predates a live send. The pre-existingliveFrameSeqguard only ever protectedslotState, which is why the run state leaked through before.Backwards compatibility
Compatible: adds one optional payload field (
liveFromAtDispatch) and only adds rows / skips a stale write; a payload without the field falls back to the current row count, i.e. no live sends. Removes nothing.Tests
website/src/test/chatSlice.refreshSlotLiveSend.test.ts(new, 10 cases): a still-optimistic bubble and an echoed one survive a stale page; a send the page caught is not doubled; a row already on screen at dispatch is not rescued; the slot stays running (and off Resume) under an idle page, whether the turn was confirmed by a local start or a serverslotsframe; the chunk floor a reply raised during the fetch is kept; a turn the send failed to open is not revived; a page that caught the send, and a running page, land their verdict as before. Reverting the production change fails 5 of the 10.Manual verification
N/A — the regression is a reducer-level state race fully covered by unit tests; it has no manual repro that the tests do not already assert.
Screenshots / video
Why no screenshot: This changes only Redux store reconciliation in
website/src/store/chat/slotRefresh.ts; it renders no new or changed UI, so a before/after would be identical.Related Issues
Fixes #19267