Keep non-text response segments when a stream finalizes - #16
Open
ActuallyTaylor wants to merge 1 commit into
Open
Keep non-text response segments when a stream finalizes#16ActuallyTaylor wants to merge 1 commit into
ActuallyTaylor wants to merge 1 commit into
Conversation
finalizeStreamedTranscript replaced the trailing response entry's whole segments array with a single text segment, so every segment ahead of the streamed text was dropped the moment the stream ended. appendStreamingResponse appends a new text segment whenever the trailing segment is not text, so a response that already carried a structure or image segment reaches finalization with two segments and loses the first one. Mirror appendStreamingResponse instead: replace the trailing text segment in place, carrying its ID over, or append a new one when the trailing segment is not text, and leave everything earlier untouched. Neither streaming mutator had test coverage, so cover both. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
ActuallyTaylor
commented
Aug 6, 2026
ActuallyTaylor
left a comment
Collaborator
Author
There was a problem hiding this comment.
Looks good
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
Transcript.finalizeStreamedTranscriptreplaced the trailing response entry's entiresegmentsarray with a single text segment, discarding every segment ahead of the streamed text the moment the stream ended.This is reachable today.
appendStreamingResponseappends a new text segment whenever the trailing segment isn't text, so a response entry that already carried a structure or image segment arrives at finalization with two segments — and loses the first one.It also blocks upcoming work: surfacing model reasoning as a separate segment on the response is pointless while finalization deletes it.
Fix
Mirror
appendStreamingResponse: replace the trailing text segment in place, carrying its ID over, or append a new one when the trailing segment isn't text — and leave every earlier segment untouched. Mutating theResponsein place also preservesidstructurally instead of re-plumbing it by hand.Tests
Neither streaming mutator had any coverage. Four cases added; the first fails against the old implementation (expects 2 segments, old code produced 1), the rest guard the paths this touches.
Verification
swift test— 329 tests across 37 suites. The 13 failures are pre-existing and environmental, not from this change:model 'qwen3:8b' not found(404 from the local server — the model isn't pulled).withClientTools: live API 400. Confirmed by stashing the change and re-running the Gemini suite on a clean tree, where it also fails — and that run additionally flakedmultimodalWithImageURL, which passed in the run with the change. Those live tests are unstable independent of this work.🤖 Generated with Claude Code