Skip to content

fix(ai): preserve providerMetadata on all smoothStream word-boundary chunks#14988

Open
Mmartinrusso wants to merge 2 commits into
vercel:mainfrom
Mmartinrusso:fix/smooth-stream-preserve-provider-metadata
Open

fix(ai): preserve providerMetadata on all smoothStream word-boundary chunks#14988
Mmartinrusso wants to merge 2 commits into
vercel:mainfrom
Mmartinrusso:fix/smooth-stream-preserve-provider-metadata

Conversation

@Mmartinrusso
Copy link
Copy Markdown
Contributor

@Mmartinrusso Mmartinrusso commented May 5, 2026

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

  • All commits are signed (PRs with unsigned commits cannot be merged)
  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run `pnpm changeset` in the project root)
  • I have reviewed this pull request (self-review)

@Mmartinrusso Mmartinrusso force-pushed the fix/smooth-stream-preserve-provider-metadata branch from 85746be to b3f3855 Compare May 5, 2026 13:35
Mmartinrusso and others added 2 commits May 5, 2026 11:24
…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>
@Mmartinrusso Mmartinrusso force-pushed the fix/smooth-stream-preserve-provider-metadata branch from b3f3855 to bc129b5 Compare May 5, 2026 14:25
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