fix(opencode): preserve reasoning providerMetadata across model switches#22818
fix(opencode): preserve reasoning providerMetadata across model switches#22818bainos wants to merge 1 commit intoanomalyco:devfrom
Conversation
Anthropic thinking blocks carry a cryptographic signature in providerMetadata that must survive every turn of a multi-turn conversation. The differentModel guard was correctly stripping provider-specific metadata from text and tool parts, but incorrectly doing the same for reasoning parts, causing Anthropic to reject the request with 'thinking blocks cannot be modified'. Fixes anomalyco#22813
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found several related PRs that address similar issues with reasoning/thinking blocks and providerMetadata: Potentially Related PRs:
These PRs all address similar concerns around preserving thinking block integrity and metadata. However, PR #22818 (the current PR) appears to be the specific fix for issue #22813, so it's likely a unique solution rather than a duplicate of the older PRs. |
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
Fixes #22813
What
Always preserve
providerMetadataon reasoning parts when reconstructing conversation history, regardless of thedifferentModelflag.Why
The
differentModelguard exists to prevent provider-specific metadata (e.g. OpenAIitemId) from leaking into other providers — correct for text and tool parts. But Anthropic thinking blocks carry a cryptographic signature insideproviderMetadatathat Anthropic verifies on every subsequent turn. Stripping it causes the API to reject the message with "thinking blocks cannot be modified".How I verified it
"preserves reasoning providerMetadata even when assistant model differs"intest/session/message-v2.test.ts