Skip to content

fix: thinking block signature lost when model differs, breaking multi-turn with extended thinking #22813

@bainos

Description

@bainos

Description

When using an Anthropic model with extended thinking enabled, the following error appears mid-conversation:
The model returned the following errors: messages.N.content.1: thinking or redacted_thinking blocks in the latest assistant message cannot be modified.

Root cause is in packages/opencode/src/session/message-v2.ts. When reconstructing conversation history, reasoning parts strip providerMetadata when the message was produced by a different model:

...(differentModel ? {} : { providerMetadata: part.metadata }),

This is correct for text and tool parts — it prevents provider-specific data (e.g. OpenAI itemId) from leaking into other providers. But Anthropic's thinking blocks carry a cryptographic signature inside providerMetadata. Anthropic verifies this signature on every subsequent turn. If it is missing, the block is considered modified and the request is rejected.
The fix is to always preserve providerMetadata for reasoning parts regardless of the differentModel flag.


Steps to reproduce

  1. Enable extended thinking on a Claude 3.7+ model
  2. Have a conversation long enough to accumulate thinking blocks in history, or switch models mid-session and switch back to Anthropic
  3. Continue the conversation — the error fires on any turn that replays a thinking block without its signature

OpenCode version: 1.4.6
OS: WSL
Terminal: Alacritty

Plugins

No response

OpenCode version

1.4.6

Steps to reproduce

  1. Enable extended thinking on a Claude 3.7+ model
  2. Have a conversation long enough to accumulate thinking blocks in history, or switch models mid-session and switch back to Anthropic
  3. Continue the conversation — the error fires on any turn that replays a thinking block without its signature

Screenshot and/or share link

No response

Operating System

Win 11 (WSL)

Terminal

Alacritty

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions