Skip to content

fix(chat): keep a send made during a refresh fetch and leave its run state - #19546

Closed
mbriones98 wants to merge 1 commit into
kirodotdev:mainfrom
mbriones98:fix/19267-refresh-live-send
Closed

mbriones98 wants to merge 1 commit into
kirodotdev:mainfrom
mbriones98:fix/19267-refresh-live-send

Conversation

@mbriones98

Copy link
Copy Markdown
Contributor

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

  • No change to the count-matched refresh, its paging, or the scrollback-preserving head merge — only live sends made during the fetch are added.

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.

switchSlot already 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 refreshSlot the same two pieces: a dispatch-time row-count baseline (liveFromAtDispatch), the user's sendId rows past it that the page does not already carry (tailNotInPage), and a pagePredatesLiveSend guard that leaves slotRunning / pendingTurnSlot / the stream state alone when the idle page predates a live send. The pre-existing liveFrameSeq guard only ever protected slotState, 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 server slots frame; 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

…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
@github-actions github-actions Bot added the fork Pull request from a fork (external contributor) label Oct 12, 2026
@mbriones98

Copy link
Copy Markdown
Contributor Author

Superseded by #19570 (same change, cut from a repo branch so CI runs).

@mbriones98 mbriones98 closed this Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refreshSlot.fulfilled drops a send made during the refresh fetch and idles the slot under its turn (reconnect / chat_done sibling of #19263)

1 participant