Repository navigation
Keep the reply text that had streamed when a build is cut off - #192
Closed
reynaldichernando wants to merge 2 commits into
Closed
reynaldichernando wants to merge 2 commits into
reynaldichernando wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
A moderate active issue remains because the watchdog’s non-throwing abort path can return without persisting or explicitly discarding the partial streamed reply.
1 open issue
What changed in this PR
This pull request preserves partially streamed assistant replies when a build is stopped, allowing the saved text to survive reloads and be included when the build resumes.
Changes:
- Saves buffered assistant text during aborted stream cleanup.
- Passes the turn sequence into stream context to prevent stale replies from being persisted.
- Adds regression coverage for stopped, stalled, superseded, empty, and normally completed replies.
| File | Description |
|---|---|
| src/js/handleMessageStream.js | Adds persistence for partial assistant replies during aborted stream cleanup with safeguards for stalled and superseded turns. |
| src/js/app.js | Passes the active turn sequence into the stream context for stale-turn protection. |
| scripts/test-stopped-reply-kept.mjs | Adds regression tests covering stopped, stalled, superseded, empty, and normally completed replies. |
| package.json | Registers the new stopped-reply regression test in the main test suite. |
Review effort: Lite
The AI's text was saved only around tool calls and at the end of a turn. A Stop in the middle of a reply left the sentence in progress on screen but out of the history: it vanished on reload, and Resume didn't send it to the AI, which then wrote it again. Now the stream commits that text when it is aborted. Not for the stall watchdog's abort, whose retry rewrites the reply, and not once a newer turn has started in the chat. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FWCxozAPzozxrNQPgyy2WP
The first commit kept the text on Stop. A reply can also be cut off in other ways, and each one lost the text that had streamed. - Stall watchdog, quiet end. Its abort can end the stream without an AbortError, so no retry runs and the backstop offers Resume. The backstop now keeps the text (review comment on #192). - Errors that end the turn, such as a 402 insufficient_funds line mid-reply. The text is kept ahead of the error card. - Network errors past the retries. The text is kept for Resume instead of being dropped for a retry that never comes. - A tab closed, reloaded or killed mid-reply. While text streams, the turn is saved 3 s after its first unsaved chunk, at once when the page is hidden, and on pagehide. The save writes the text after the history (historyWithPendingReply), so the chat reopens interrupted with it. keepStoppedReply is now keepCutOffReply, and its abort check moved to the stream's finally. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
reynaldichernando
force-pushed
the
claude/funny-mayer-f44e5t
branch
from
November 23, 2026 20:10
1894b49 to
11c5e23
Compare
| // nothing will, so keep it as a Stop does. Resume continues | ||
| // after it. | ||
| if (!stallRecovery && attempt >= MAX_TURN_RETRIES) keepCutOffReply(context); | ||
| else removeUncommittedBubble(context); |
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
The AI's text was saved to the chat history only around tool calls and at the end of a turn. When a reply was cut off partway, the text that had streamed stayed on screen but was never saved. It disappeared after a reload, and Resume or "continue" didn't send it to the AI, so the AI often wrote it again and it appeared twice.
A reply can be cut off in these ways, and each one lost the text.
Fix
handleMessageStream.js.keepCutOffReply(context)saves the text that has streamed so far (saveCurrentMessage). The stream'sfinallycalls it when the stream was aborted. It skips two cases._stallRecovery). The automatic retry removes the unsaved bubble and writes the reply again.sendChatMessageinapp.js.turnSeqis passed on the stream context for the newer-turn check.app.js. While text streams, the turn is saved 3 seconds after its first unsaved chunk, right away when the page is hidden, and onpagehide.saveCurrentChatwrites the uncommitted text after the history (historyWithPendingReply), so the chat reopens as interrupted with the text, and Resume continues after it. This adds at most one chat file write every 3 seconds, only while a reply is streaming. Text that was committed, or removed for a retry, before the timer fires is not saved again.A closed tab can still lose up to the last 3 seconds of text. The
pagehidesave is fire-and-forget and may not finish before the page is gone.Tests
scripts/test-stopped-reply-kept.mjsruns the realhandleMessageStream.js, plus the stall backstop, the error-card catch and the reply-checkpoint blocks fromapp.js. It covers Stop, the watchdog cases, credit errors (stream cut short and error line), the retry give-up, the checkpoint timer and saving on page hide. It also checks that nothing is saved twice or for a turn a newer one replaced. The new checks fail on the code before this change.scripts/test-chat-list-entry.mjspasses the new helper into its slice ofsaveCurrentChatUnlocked.npm test. The full suite andvite buildpass.🤖 Generated with Claude Code