GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(provider): preserve redacted_thinking blocks and fix signature validation by DonaldoDes · Pull Request #12131 · anomalyco/opencode

Conversation

@DonaldoDes

@DonaldoDes DonaldoDes commented Feb 4, 2026

Copy link
Copy Markdown

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-actions

github-actions Bot commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found related PRs that deal with thinking/reasoning blocks, but they appear to be addressing different issues:

Related PRs (not exact duplicates):

  1. fix: strip incompatible thinking blocks when switching to Claude (improved) #11882 - "fix: strip incompatible thinking blocks when switching to Claude (improved)"

    • Related to handling thinking blocks but focuses on stripping them when switching models, not preserving them
  2. fix: strip reasoning parts when switching to non-interleaved models #11572 - "fix: strip reasoning parts when switching to non-interleaved models"

    • Similar theme of handling reasoning blocks during model switching
  3. fix: strip incompatible thinking blocks when switching to Claude #8958 - "fix: strip incompatible thinking blocks when switching to Claude"

    • Earlier version addressing thinking block compatibility

These are related to thinking/reasoning blocks but address model switching scenarios, whereas PR #12131 focuses on preserving the integrity of redacted_thinking blocks during message processing and multi-turn conversations.

No exact duplicate PRs found - PR #12131 appears to be the only one addressing the specific issue of signature validation and block ordering for extended thinking with Claude.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@DonaldoDes
DonaldoDes force-pushed the fix/redacted-thinking-blocks branch 2 times, most recently from e962b09 to e255791 Compare February 4, 2026 13:53
cryptictech
cryptictech reviewed Feb 4, 2026
View reviewed changes

@cryptictech cryptictech left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I went through an AI assisted code review of this PR, as I've faced similar issues with OpenRouter models and was hoping this may help indirectly. Unfortunately, it appears it doesn't, however, it also doesn't impact other model providers. Here is the summary of my AI assisted code review:

Code Review: PR #12131 - Fix "Invalid data in redacted_thinking block" Errors

Summary

This PR fixes signature validation errors when using extended thinking with Claude by removing overly strict handling of redacted_thinking blocks.

Changes Overview

1. packages/opencode/src/provider/transform.ts

Lines 44-85 - normalizeMessages() function:

  • Removed: Special handling for preserving redacted_thinking blocks (blocks with providerMetadata?.anthropic)
  • Removed: Reordering of content blocks to place reasoning first for Anthropic
  • Rationale: The previous strict handling was causing signature validation errors when replaying assistant messages

2. packages/opencode/src/session/message-v2.ts

Lines 586-596 - toModelMessages() function:

  • Removed: Comment about preserving ALL reasoning parts including redacted_thinking blocks
  • Rationale: The comment was documenting behavior that was causing issues

3. packages/opencode/src/session/processor.ts

Lines 88-104 - reasoning-end case:

  • Changed: Removed comment about NOT trimmingEnd() thinking text
  • Changed: Added part.text = part.text.trimEnd() to trim trailing whitespace
  • Rationale: The signature is computed on the exact text including trailing whitespace; modifying it invalidates the signature

4. packages/opencode/src/session/prompt.ts

Lines 968-991 - File handling:

  • Changed: Added .catch(() => undefined) to Bun.file(filepath).stat()
  • Changed: Added optional chaining stat?.isDirectory() for safer directory check
  • Changed: Added .catch(() => []) to LSP.documentSymbol(filePathURI)
  • Rationale: Prevents failures when file parts reference missing files

5. packages/opencode/test/session/prompt-missing-file.test.ts

New file: Test to ensure prompt does not fail when a file part is missing

6. packages/app/e2e/actions.ts & packages/app/e2e/session/session.spec.ts

UI/UX improvements: More robust session menu interactions and state management

Impact Analysis

Affected Providers

  • Anthropic models (including Claude on Bedrock): These changes directly affect Anthropic models by removing strict redacted_thinking block handling

NOT Affected Providers

  • OpenRouter: Has separate handling in variants() and providerOptions() functions
  • OpenAI: Has its own interleaved reasoning handling
  • Google Gemini: Has its own interleaved reasoning handling
  • Mistral: Has its own tool call ID normalization
  • GitHub Copilot: Has its own provider-specific handling

Testing

  • New test added: prompt-missing-file.test.ts verifies graceful handling of missing files
  • Existing E2E tests updated for more robust session menu interactions

Concerns

  1. Breaking change for Anthropic: Removing the strict redacted_thinking block handling may affect existing sessions that rely on this behavior
  2. Trailing whitespace: Trimming thinking text may affect signature validation if the API expects exact text

Recommendation

Approve with caution. The changes fix a known issue with extended thinking on Claude, but the removal of strict redacted_thinking block handling should be monitored for any unexpected side effects.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

DonaldoDes reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@DonaldoDes
DonaldoDes force-pushed the fix/redacted-thinking-blocks branch from e255791 to 75b800c Compare February 5, 2026 00:00
@DonaldoDes DonaldoDes mentioned this pull request Feb 5, 2026
Claude Models Thinking block error #10970
Closed
DonaldoDes added 2 commits February 6, 2026 17:32
@DonaldoDes
fix(session): preserve thinking text whitespace for signature integrity
e8d6d1c
The Anthropic API computes a cryptographic signature on the exact
thinking text including trailing whitespace. Calling trimEnd()
invalidates the signature, causing "Invalid data in
redacted_thinking block" errors when thinking blocks are replayed
in subsequent API calls.

Closes anomalyco#10970
@DonaldoDes
fix(provider): reorder reasoning blocks first in assistant messages
993c109
The Anthropic API requires thinking/redacted_thinking blocks to
appear before other content blocks in assistant messages. Add
reordering logic in normalizeMessages() and preserve all reasoning
blocks including redacted_thinking in toModelMessages().

Ref anomalyco#10970
@DonaldoDes
DonaldoDes force-pushed the fix/redacted-thinking-blocks branch from 25b0b05 to 993c109 Compare February 6, 2026 16:38
@github-actions github-actions Bot mentioned this pull request Feb 20, 2026
fix: preserve thinking block signatures and fix compaction headroom asymmetry #14393
Closed
3 of 6 tasks
@renbou

renbou commented Mar 2, 2026

Copy link
Copy Markdown

@thdxr @adamdotdevin (just tagging some subset of contributors who seem like they're working on opencode)

Can this PR get reviewed and merged? We've been encountering similar issues with redacted thinking block errors for a few weeks, and spent some time triaging it to discover the same bugs as described here still present in the latest version. There's also this PR related to thinking block issues when compaction happens: #14393

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@altendky altendky mentioned this pull request Mar 9, 2026
normalizeMessages() removes empty text parts between reasoning blocks, invalidating Anthropic thinking block signatures #16748
Closed
This was referenced Mar 9, 2026
fix(provider): skip empty-text filtering for assistant messages in normalizeMessages (#16748) #16750
Closed
fix(provider): resolve bedrock compaction failures for Claude models #17043
Closed
@github-actions github-actions Bot mentioned this pull request Mar 25, 2026
fix(openrouter): prevent reasoning block signature corruption with extended thinking #19048
Closed
3 of 6 tasks
@chan1103 chan1103 mentioned this pull request Apr 10, 2026
fix: replace empty text in reasoning messages to preserve thinking block positions #21860
Closed
3 tasks done
@opencode-agent
opencode-agent Bot force-pushed the dev branch from 2f2ed11 to 9f201d6 Compare April 16, 2026 21:55
This was referenced Apr 17, 2026
fix(opencode): preserve reasoning providerMetadata across model switches #23104
Closed
fix: preserve thinking/redacted_thinking blocks in Anthropic message transforms #23755
Closed
@github-actions github-actions Bot mentioned this pull request Apr 29, 2026
fix: preserve Anthropic thinking block signatures when switching Claude models #25003
Closed
3 tasks done
@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot closed this May 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@cryptictech cryptictech cryptictech left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Claude Models Thinking block error

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@DonaldoDes @renbou @cryptictech
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.