Skip to content

fix(chat): idle the stream state when a reconnect refresh finds the turn gone - #18288

Merged
iamwhatever merged 1 commit into
kirodotdev:mainfrom
Pearcekieser:fix/resume-after-restart
Oct 9, 2026
Merged

iamwhatever merged 1 commit into
kirodotdev:mainfrom
Pearcekieser:fix/resume-after-restart

Conversation

@Pearcekieser

Copy link
Copy Markdown
Contributor

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

What changed (motivation → approach → change)

The tab never gets the dead turn's _done frame, so its store keeps slotState === 'streaming'. On reconnect, refreshSlot returns running: false plus the interruption row. Its reducer cleared slotRunning but reset slotState only on the row-stall watchdog path, the one that passes meta.recoveryRevision. selectComposerBusy treats any non-idle slotState as busy, so the composer kept Stop and composer-continue never rendered. A reload works because a fresh store starts idle.

refreshSlot.fulfilled in website/src/store/chat/slotRefresh.ts now 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 records liveFrameSeq when 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 liveFrameSeqAtDispatch field. 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.ts drives the real reducer and the composer selectors:

Case Locks in
streaming tab, refresh returns running: false + interruption row slotState goes idle, no streaming row remains, and the composer gate offers Resume (fails on main)
a live chunk lands during the fetch the new turn stays streaming and busy
refresh returns running: true still busy, no Resume
Stop card at the tail idle composer offering Send, not Resume (fails on main: stuck on Stop)

Gates: tsc -p tsconfig.app.json, the full frontend suite in 4 shards (2,712 files passed), and npm run i18n:check with I18N_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.

Run Store after reconnect Composer
main, same-tab reconnect slotRunning: false, slotState: 'streaming', interruption row present Stop, card Resume only
main, reload slotState: 'idle' Resume
fix, same-tab reconnect slotState: 'idle' Resume; one press sends exactly one POST /continue and a new turn starts
fix, reload slotState: 'idle' Resume; one press sends exactly one POST /continue

On 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.

before

After the fix: the composer offers Resume.

after

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 slotRunning from a server snapshot must settle slotState in the same branch, because selectComposerBusy reads both.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@Pearcekieser
Pearcekieser requested review from a team and KiroCrewCaptain as code owners October 9, 2026 00:45
@Pearcekieser
Pearcekieser requested a review from CrysisDeu October 9, 2026 00:45
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — 🟡 CONCERNS

UX-level review of 59c18608f0b5768d395f7bb533074836be442694 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

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

  • Stop-card state not pictured. The fix also changes a second state: a refresh that ends on a Stop card now leaves the composer on Send, not stuck on Stop. That case is described in the PR's "Stop card at the tail" test row, but neither attachment shows it, so nobody has checked that the idle composer reads correctly there. This happens less often than the restart path and has low impact. Fix: attach a still of that composer state.
  • Two Resume buttons at once. attachment-02.png shows the same "Resume" label on the interruption card and in the composer. They do the same thing, so this is not misleading. The duplication was already in the product before this PR; this fix only makes it show up more consistently.

[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 .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 9, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of 59c18608f0b5768d395f7bb533074836be442694 via the fork AI-review pipeline — 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: PASS

Check one case before merge: a refresh that returns running: false while a send has no first frame yet (pendingTurnSlot set) now also idles slotState.

What this change ships

Inventory (3 items) — 3 justified

Intent: 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).

  1. After a reconnect refresh reports the slot not running, the streaming tab's composer goes from Stop to idle and offers Resume. — justified
  2. A refresh does not idle a new turn whose live frame arrived while the fetch was in flight. — justified
  3. The refresh payload carries a client-only liveFrameSeqAtDispatch (1 consumer: the refreshSlot.fulfilled reducer; it reuses the existing liveAtStart sample). — justified

Sibling check: I grepped state.slotRunning = and found 15 sites. The other reducer that settles from a snapshot, switchSlot.fulfilled, already sets slotState (slotSwitch.ts:499). settleStopNotRunning and syncSlotRunningFromServer already idle the stream state. No sibling is left unfixed.

[FIRST-PRINCIPLES-REVIEWED] 59c1860

Description read

[DESCRIPTION-READ] a4dfcc37a64761890f0b5b033a756665c0b00305731dc74b933c9eca15e02b85

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 9, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 59c18608f0b5768d395f7bb533074836be442694 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Check the in-flight guard: a compacting frame sets slotState without calling countLiveFrame, so a stale running: false refresh can still idle a compaction.

[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 .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 9, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed 59c18608f0b5768d395f7bb533074836be442694 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 59c1860

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed 59c18608f0b5768d395f7bb533074836be442694 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 59c1860

@Pearcekieser
Pearcekieser force-pushed the fix/resume-after-restart branch from a6cebaa to 0e2d64b Compare October 9, 2026 01:18
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 9, 2026
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

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.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

self-added: no
note (non-blocking): rebutted, the blind first-time read is not needed for this change

The diff changes no control, label or copy. It changes only the store reducer in slotRefresh.ts, so the composer shows the Resume button it already had after a same-tab reconnect.
A reload on main already shows that same Resume state to every user, so this PR adds no new state for a newcomer to read.
Attachment-01 shows the stuck Stop square on main and attachment-02 shows Resume on this head. One press sent exactly one POST /continue in the harness gateway.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

note (non-blocking): the Integration (in-process gateway) failure on 0e2d64b is unrelated to this diff

test_owner_only_boot.py::test_a_fresh_boot_leaves_nothing_readable_by_others found one 0644 file under an inbound-spool directory after boot. This PR changes only website/src/store/chat/slotRefresh.ts and its test, so no backend code runs differently. The same check passed on 9 other PRs opened in the last few hours, #18278 to #18294. I will retrigger it once with a same-tree push in the next clear CI slot.

@Pearcekieser
Pearcekieser force-pushed the fix/resume-after-restart branch from 0e2d64b to c89c430 Compare October 9, 2026 01:44
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 9, 2026
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

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 test_a_fresh_boot_leaves_nothing_readable_by_others again with six paths: autonudge.json, inbound-spool/ at 0755, crew-log/members at 0755, and the member unit's .lock, .lease and .legacy-activity-folded. That is the exact list in the #18224 description, which says these writers run on executor threads after /api/sessions returns, so the result depends on runner speed. This PR changes only website/src/store/chat/slotRefresh.ts and its test. The test also fails locally on a clean origin/main at 96c00c1. I will rebase onto main once #18224 lands.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

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

session-tags-e2e.spec.ts > 17b failed once and passed on its retry, which the zero-retry ceiling counts as a failure. The spec covers right-clicking another sidebar row while the Tags picker is open. This PR changes only the composer's busy state in website/src/store/chat/slotRefresh.ts, and that state is not read by the sidebar menu or the Tags picker. The rebase onto main after #18224 lands will run it again.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 9, 2026
@Pearcekieser
Pearcekieser force-pushed the fix/resume-after-restart branch from c89c430 to 59c1860 Compare October 9, 2026 07:58
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Rebased on main to pick up #18224, which fixes the owner-only boot race behind the Integration red. No behaviour change. The regression test and ChatInput.lexicalKeys pass locally on 59c1860.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 9, 2026
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 9, 2026

@iamwhatever iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@iamwhatever
iamwhatever enabled auto-merge (squash) October 9, 2026 19:32
@iamwhatever
iamwhatever merged commit 0009453 into kirodotdev:main Oct 9, 2026
104 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 9, 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.

Resume missing after a gateway restart cuts off the reply you are watching

2 participants