Skip to content

fix: downgrade reasoning parts to text when metadata is stripped#550

Open
sudashannon wants to merge 1 commit into
Opencode-DCP:masterfrom
sudashannon:fix/strip-reasoning-metadata-downgrade-to-text
Open

fix: downgrade reasoning parts to text when metadata is stripped#550
sudashannon wants to merge 1 commit into
Opencode-DCP:masterfrom
sudashannon:fix/strip-reasoning-metadata-downgrade-to-text

Conversation

@sudashannon
Copy link
Copy Markdown

When stripStaleMetadata removes provider metadata (including bedrock.signature) from reasoning parts after a model change, the parts were kept as type: "reasoning". Switching back to a thinking-enabled model (e.g., Claude Opus 4-7) causes the AI SDK to create {type: "thinking"} blocks without the required signature field, resulting in API validation errors ("messages.N.content.0.thinking.signature: Field required").

Fix: when metadata is stripped from a reasoning part, downgrade it to type: "text" — the thinking content is preserved as readable text, but the SDK won't construct invalid thinking blocks.

Root cause flow:

  1. Fork (or model change) triggers stripStaleMetadata
  2. Metadata containing bedrock.signature is stripped from reasoning parts
  3. But type: "reasoning" was retained
  4. On switching back to a thinking model, the AI SDK converts stored reasoning parts to {type: "thinking"} blocks
  5. Without the signature field the API schema validation rejects the request

When stripStaleMetadata removes provider metadata (including
bedrock.signature) from reasoning parts after a model change,
the parts were kept as type "reasoning". Switching back to a
thinking-enabled model (e.g., Claude Opus 4-7) causes the AI SDK
to create "{type: \"thinking\"}" blocks without the required
signature field, resulting in API validation errors
("messages.N.content.0.thinking.signature: Field required").

Fix: when metadata is stripped from a reasoning part, downgrade
it to type "text" — the thinking content is preserved as readable
text, but the SDK won't construct invalid thinking blocks.
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