[PR #12131] fix(provider): preserve redacted_thinking blocks and fix signature validation #14083

Open
opened 2026-02-16 18:18:53 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/12131

State: open
Merged: No


Summary

Fix "Invalid data in redacted_thinking block" errors when using extended thinking with Claude.

Problem

When extended thinking is enabled, the Anthropic API returns thinking and redacted_thinking blocks with cryptographic signatures. Two issues caused these blocks to be rejected on subsequent API calls:

  1. trimEnd() on thinking text — The signature is computed on the exact text including trailing whitespace. Trimming invalidates it.
  2. Block ordering — The API requires thinking/redacted_thinking blocks to appear first in assistant message content arrays.

Changes

  • processor.ts: Remove trimEnd() call on thinking text to preserve signature integrity
  • transform.ts: Add reordering logic to place reasoning blocks first in normalizeMessages()
  • message-v2.ts: Preserve all reasoning blocks including redacted_thinking in toModelMessages()

Testing

Reproduced the error by enabling extended thinking (High) with Claude Opus 4.5, triggering the error on the 2nd message of a session. After the fix, multi-turn conversations with extended thinking work without errors.

Closes #10970

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/12131 **State:** open **Merged:** No --- ## Summary Fix "Invalid data in redacted_thinking block" errors when using extended thinking with Claude. ## Problem When extended thinking is enabled, the Anthropic API returns `thinking` and `redacted_thinking` blocks with cryptographic signatures. Two issues caused these blocks to be rejected on subsequent API calls: 1. **`trimEnd()` on thinking text** — The signature is computed on the exact text including trailing whitespace. Trimming invalidates it. 2. **Block ordering** — The API requires thinking/redacted_thinking blocks to appear first in assistant message content arrays. ## Changes - **processor.ts**: Remove `trimEnd()` call on thinking text to preserve signature integrity - **transform.ts**: Add reordering logic to place reasoning blocks first in `normalizeMessages()` - **message-v2.ts**: Preserve all reasoning blocks including redacted_thinking in `toModelMessages()` ## Testing Reproduced the error by enabling extended thinking (High) with Claude Opus 4.5, triggering the error on the 2nd message of a session. After the fix, multi-turn conversations with extended thinking work without errors. Closes #10970
yindo added the pull-request label 2026-02-16 18:18:53 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14083