Skip to content

fix: preserve providerMetadata on reasoning chunks in applyChunkToParts#1301

Merged
threepointone merged 2 commits intomainfrom
fix/reasoning-provider-metadata
Apr 13, 2026
Merged

fix: preserve providerMetadata on reasoning chunks in applyChunkToParts#1301
threepointone merged 2 commits intomainfrom
fix/reasoning-provider-metadata

Conversation

@threepointone
Copy link
Copy Markdown
Contributor

@threepointone threepointone commented Apr 13, 2026

Summary

  • applyChunkToParts in message-builder.ts was silently dropping chunk.providerMetadata on reasoning-end and reasoning-delta chunks. For Anthropic models with extended/adaptive thinking, the thinking block signature arrives on reasoning-end.providerMetadata.anthropic.signature — without it, @ai-sdk/anthropic cannot reconstruct the thinking block on subsequent turns and silently drops it, making extended thinking effectively single-turn.
  • Both reasoning handlers now merge chunk.providerMetadata onto the persisted part via a new mergeProviderMetadata helper, matching the behavior of source and tool chunk handlers in the same file.
  • Added 5 test cases covering: signature preservation on reasoning-end, metadata on reasoning-delta, merge across delta+end, no-op when metadata is absent, and fallback part creation with metadata.

Fixes #1299.

Test plan

  • All 937 existing workers tests pass (npx nx run agents:test:workers)
  • 5 new test cases in stream-accumulator.test.ts cover the fix
  • No lint errors, formatting clean
  • Verify with a real Anthropic extended thinking flow that the signature round-trips across turns (manual)

Made with Cursor


Open with Devin

The reasoning-end and reasoning-delta handlers in message-builder.ts
were not copying chunk.providerMetadata onto the persisted reasoning
part. For Anthropic models with extended thinking, the signature
arrives on reasoning-end.providerMetadata — dropping it means
subsequent turns cannot round-trip the thinking block, silently
breaking multi-turn extended thinking.

Both handlers now merge chunk.providerMetadata onto the part,
matching the behavior of source and tool chunk handlers. Fixes #1299.

Made-with: Cursor
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 13, 2026

🦋 Changeset detected

Latest commit: 83071fa

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
agents Patch

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

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 13, 2026

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@1301

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@1301

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@1301

hono-agents

npm i https://pkg.pr.new/hono-agents@1301

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@1301

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@1301

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@1301

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@1301

commit: 83071fa

@threepointone threepointone merged commit d501291 into main Apr 13, 2026
2 checks passed
@threepointone threepointone deleted the fix/reasoning-provider-metadata branch April 13, 2026 17:15
This was referenced Apr 13, 2026
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.

applyChunkToParts drops providerMetadata on reasoning-end, breaking Anthropic thinking round-trip

1 participant