fix(provider): preserve assistant message content when reasoning blocks present#21370
Open
edevil wants to merge 1 commit intoanomalyco:devfrom
Open
fix(provider): preserve assistant message content when reasoning blocks present#21370edevil wants to merge 1 commit intoanomalyco:devfrom
edevil wants to merge 1 commit intoanomalyco:devfrom
Conversation
…ks present normalizeMessages() unconditionally filtered empty text parts from all message roles, including assistant. When Anthropic adaptive thinking (Opus 4.6, Sonnet 4.6) emits an empty text part between two reasoning blocks, removing it shifts thinking block positions and invalidates the cryptographic signatures, causing the API to reject with: 'thinking blocks in the latest assistant message cannot be modified' Skip the empty-text filter for assistant messages that contain reasoning blocks. These messages must be replayed verbatim since thinking block signatures encode positional context. Assistant messages without reasoning blocks continue to be filtered normally. Closes anomalyco#16748
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate Found:
This PR appears to be directly related or a potential duplicate. It addresses the same issue (#16748) with the same root cause (empty-text filtering in |
Contributor
Author
|
It seems this error message predates adaptive thinking so it must be something else. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue for this PR
Closes #16748
Type of change
What does this PR do?
normalizeMessages()intransform.tsunconditionally filters out empty text parts from all message roles, including assistant. When Anthropic adaptive thinking (Opus 4.6, Sonnet 4.6) emits a whitespace-only text part between two reasoning blocks,processor.tstrims it to"", and thennormalizeMessagesremoves it. This shifts the block arrangement from[thinking, text, thinking, text, tool_use]to[thinking, thinking, text, tool_use], invalidating the positionally-sensitive cryptographic signatures on the thinking blocks. The Anthropic API then rejects with: "thinking blocks in the latest assistant message cannot be modified".The fix is one line: skip the empty-text filter for assistant messages that contain reasoning blocks. These messages must be replayed verbatim since thinking block signatures encode positional context. Assistant messages without reasoning blocks (e.g. plain text responses, compaction summaries) continue to be filtered normally.
The empty-text filter was added on Jan 5 (
c285304a) before adaptive thinking existed (Feb 13,0d90a22f9), so it was correct at the time. The bug is an emergent interaction with Opus 4.6's signature-sensitive thinking blocks.How did you verify your code works?
[reasoning(sig1), text(""), reasoning(sig2), text("answer"), tool_use]— asserts all 5 parts are preservedScreenshots / recordings
N/A — backend logic change, no UI impact.
Checklist