Repository navigation
fix(chat): stop the last reply of a turn from showing twice - #583
Merged
Merged
Conversation
The final reply of a turn often appeared twice while streaming and became one again after a refresh. Recorded from the Claude SDK, the saved assistant message arrives before content_block_stop and message_stop, and the server re-sends it once the stop reason is known. Since the delta stream (#579), a stream end created a placeholder when none was left, so the late stops left an empty one behind. The re-sent message then claimed that placeholder before it was matched to the copy already on screen by id. A catch-up snapshot answered after newer events could also recreate a placeholder for text that was already saved: the reply carried the turn's whole message history and went out in chunks that live events overtook. A saved message now updates its copy by id before it may claim a placeholder, and replacing a placeholder settles that block: no later end, update or snapshot about it touches the transcript again. An end never creates a placeholder. The snapshot drops the message history, carries the stream's sequence so an older one can only extend existing text, and the server stops treating text as live before saving its message rather than after. A reasoning stop no longer emits a text end, and an end is sent only for a block still being streamed. The placeholder rules move to stream-placeholders.ts, where the recorded event order is replayed in tests.
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.
Summary
Show the final reply of a turn once, not twice until a refresh.
Why
Claude sends the saved assistant message before
content_block_stop/message_stop, and the server re-sends it with its stop reason. Since #579 a lateendrecreated an empty placeholder, which the re-sent message claimed before being matched to its existing copy by id. Catch-up snapshots carried the turn's whole history and went out in chunks that newer events overtook.Changes
endnever creates a placeholder; snapshots drop the message history and carryseqstream-placeholders.ts, tested with the recorded event order