Skip to content

fix(chat): stop the last reply of a turn from showing twice - #583

Merged
ArgaFairuz merged 1 commit into
mainfrom
fix/duplicate-turn-reply
Nov 18, 2026
Merged

ArgaFairuz merged 1 commit into
mainfrom
fix/duplicate-turn-reply

Conversation

@ArgaFairuz

Copy link
Copy Markdown
Collaborator

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 late end recreated 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

  • Saved messages update their copy by id before claiming a placeholder; a replaced placeholder settles its block for good
  • end never creates a placeholder; snapshots drop the message history and carry seq
  • Server: text stops being live before its message is saved; a reasoning stop no longer emits a text end
  • Placeholder rules moved to stream-placeholders.ts, tested with the recorded event order

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.
@ArgaFairuz
ArgaFairuz merged commit 00e2a93 into main Nov 18, 2026
1 check passed
@ArgaFairuz
ArgaFairuz deleted the fix/duplicate-turn-reply branch November 18, 2026 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant