Skip to content

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

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

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

Conversation

@mbriones98

@mbriones98 mbriones98 commented Oct 12, 2026 •

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.

Pattern harvest

Rule candidate: the three slot-detail reducers that rebuild messages from a fetched page — switchSlot.fulfilled, refreshSlot.fulfilled, warmSlotCache.fulfilled — must share the same baseline-and-guard contract for rows that arrive while the fetch is in flight. switchSlot grew the live-send baseline and the pagePredatesLiveSend run-verdict guard (#18658 / #19263) while refreshSlot carried neither, which is this bug. A lint/review check that flags a page-replacing reducer in website/src/store/chat/ lacking the live-send baseline + pagePredatesLiveSend guard would catch the family drifting apart again.

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

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of d85deddcd2e6b2c91266bb82c8820302cab3473c — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

UX-Verdict: PASS

Nothing to check.

[UX-REVIEWED] d85dedd

Description read

[DESCRIPTION-READ] 3fe45cdb0be82d610f93a3c96f8ac57a02c1989b686d3fc94409499d453c52d3

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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of d85deddcd2e6b2c91266bb82c8820302cab3473c — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Check the switchSlot.fulfilled change before merge. It now leaves the preserved olderHead out of liveSends, which changes deep-link-open behaviour, and the description never mentions it.

[DESIGN-REVIEWED] d85dedd

Description read

[DESCRIPTION-READ] 1cd6a3891392544a3e4845f57fade8353ee8b0cebfa7723348996a56553ca02a

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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — 🟡 CONCERNS

Premise-level review of d85deddcd2e6b2c91266bb82c8820302cab3473c — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

The refresh fix is justified by #19267, but it also quietly changes switchSlot's live-send rescue to skip rows in the older head, with no switchSlot defect or test behind it.

Not justified as shipped

  • Item 4 — undeclared, rides along, inherited: the description says only "This gives refreshSlot the same two pieces". But the diff also changes switchSlot, replacing tailNotInPage(existing.slice(liveFrom)…, preserved) with liveSendsSince(existing, liveFrom, preserved, olderHead). Its only test (loadOlderMessages prepends during the fetch) drives refreshSlot.fulfilled. The switchSlot change rests on symmetry with the new refresh path, not on a reported switchSlot defect.
    Subtraction: revert the slotSwitch.ts call to its base form (no olderHead exclusion, priorServerRows/olderHead back where they were), keeping only the shared pagePredatesLiveSend call.
    Clears when: the exclusion is reverted in switchSlot, or a switchSlot.fulfilled test that fails on base shows a historical sendId row duplicated to the tail.

What this change ships

Inventory (5 items) — 4 justified

Intent: a message sent as a chat reconnects or a turn ends stays on screen, and its turn keeps running instead of offering Resume. FIX.

  1. A send made during a refresh fetch stays in the transcript — justified
  2. The slot stays running and doesn't offer Resume when an idle page predates the send — justified
  3. The reply's chunk floor survives a stale idle page — justified
  4. switchSlot's live-send rescue now skips rows in the preserved older head — undeclared, rides along, inherited (symmetry)
  5. The two rescue checks become shared helpers in transcript.ts, each with 2 consumers — justified

[FIRST-PRINCIPLES-REVIEWED] d85dedd

Description read

[DESCRIPTION-READ] 0ba68471e11b26a16b38c40eb29cc2cd7f2c31590bd8519f30765062c41b234a

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of d85deddcd2e6b2c91266bb82c8820302cab3473c and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] d85dedd

False positive or not applicable? A repository writer can comment:
/ai-review override gpt d85deddcd2e6b2c91266bb82c8820302cab3473c: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed d85deddcd2e6b2c91266bb82c8820302cab3473c — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] d85dedd

Verdict parsed from the review's SHA-scoped output markers for commit d85deddcd2e6b2c91266bb82c8820302cab3473c.

False positive or not applicable? A repository writer can comment:
/ai-review override fable d85deddcd2e6b2c91266bb82c8820302cab3473c: <one-sentence reason>

@mbriones98
mbriones98 force-pushed the fix/refresh-live-send-19267 branch from c2f298a to b707f39 Compare October 12, 2026 22:34
@mbriones98

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: shared liveSendsSince / pagePredatesLiveSend helpers in transcript.ts

  • Item 1 (span=9106dc38d33b): fixed — the duplicated liveSends expression is now a single definition.

Extracted liveSendsSince(view, liveFrom, page) into website/src/store/chat/transcript.ts; both refreshSlot.fulfilled and switchSlot.fulfilled now call it. One definition, no copy. Fixed in b707f39.

@mbriones98

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: shared pagePredatesLiveSend helper in transcript.ts

  • Item 2 (span=23493149edbe): fixed — the duplicated pagePredatesLiveSend guard is now defined once.

Added pagePredatesLiveSend(running, liveSends) to website/src/store/chat/transcript.ts; both reducers import and call it, and each keeps a local boolean for its own run-verdict and chunk-floor branches. Defined once. Fixed in b707f39.

…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 (#18658 / #19263).

Fixes #19267
@mbriones98
mbriones98 force-pushed the fix/refresh-live-send-19267 branch from b707f39 to d85dedd Compare October 12, 2026 23:24
@mbriones98

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: liveSendsSince now excludes the already-preserved olderHead

  • span=8d3da0b34990: fixed — the live-send rescue no longer re-adds a preserved historical send.

Real reordering bug: liveFromAtDispatch is a row index, and loadOlderMessages prepending during the in-flight fetch slid it onto historical sendId rows already kept in olderHead, so last-wins dedup moved them to the tail. Fixed by passing the preserved head as an extra exclusion to liveSendsSince in both refreshSlot and switchSlot. Regression test added (fails without the fix). Fixed in d85dedd.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Oct 13, 2026
@mbriones98

Copy link
Copy Markdown
Contributor Author

Closing this draft: the issue is owned and being worked by its assignee, so this is withdrawn to avoid duplicate effort. The branch is left in place if any of it is useful.

@mbriones98 mbriones98 closed this Oct 13, 2026
@github-actions github-actions Bot removed the readiness: checking Automated validation is still running label Oct 13, 2026
@bolichen97
bolichen97 deleted the fix/refresh-live-send-19267 branch November 6, 2026 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge conflict Branch has merge conflicts with its base — author must resolve before merge

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