SMOODEV-2534: fix transient double-newline during streaming#33
Merged
Conversation
The streamed token render (raw accumulation) and the finalized render (responseParts.join) were two independent paths that could disagree on blank-line count mid-stream, showing an extra blank line that vanished when the message finalized. Share one PARAGRAPH_SEP + normalizeParagraphs between both paths so the streaming render matches the finalized render; the finalized output stays byte-identical for well-formed responses. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: b33676d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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
During streaming, the widget briefly showed an extra blank line (a double newline) that disappeared when the message finalized — jarring on every reply. The streamed token render (raw
assistant.text += tokenaccumulation) and the finalized render (responseParts.join('\n\n')) were two independent code paths that could disagree on blank-line count mid-stream.Solution
PARAGRAPH_SEPconstant andnormalizeParagraphs()(collapses runs of 3+ newlines to a single\n\n), used by BOTH the streaming accumulator and the finalizedextractFinalTextjoin.normalizeParagraphsis idempotent and a no-op on well-formed text, so the finalized output stays byte-identical for well-formed responses — only the mid-stream flicker changes.Tests
normalizeParagraphsunit tests (collapse + idempotence/no-op).responseParts.join('\n\n'), and the last mid-stream render already agrees with the finalized render.Release
Patch changeset added (
0.14.0 → 0.14.1). The changesets release bot opens the "🦋 New version release" PR; merging it publishes to npm.🤖 Generated with Claude Code