fix(ai): preserve providerMetadata on all smoothStream word-boundary chunks#14988
Open
Mmartinrusso wants to merge 2 commits into
Open
fix(ai): preserve providerMetadata on all smoothStream word-boundary chunks#14988Mmartinrusso wants to merge 2 commits into
Mmartinrusso wants to merge 2 commits into
Conversation
85746be to
b3f3855
Compare
…chunks The while loop that emits word/line boundary chunks was not forwarding providerMetadata, so Anthropic thinking signatures and any other provider-specific metadata were silently dropped for every intermediate chunk. Only the final remainder (flushed via flushBuffer) retained the metadata. Apply the same spread pattern already used in flushBuffer so all emitted chunks carry the original providerMetadata. Fixes vercel#14373 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
b3f3855 to
bc129b5
Compare
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.
Background
`smoothStream` buffers text and emits multiple chunks from a single input chunk when a word boundary is detected (the `while` loop). The `providerMetadata` from the input chunk (e.g. Anthropic thinking signatures) was only forwarded on the first chunk — subsequent chunks emitted from the same burst lost the metadata entirely.
Summary
Spread `providerMetadata` onto every chunk emitted inside the `while` loop, not just the first. Chunks without metadata are unaffected (the spread is conditional on `providerMetadata != null`).
Manual Verification
Verified via unit test: all three word-boundary chunks emitted from a single input carry the original `providerMetadata`.
Checklist