Messages API: skip historical thinking blocks to avoid 400s#318076
Merged
Conversation
Anthropic returns 400 (`messages.N.content.M: 'thinking' or 'redacted_thinking' blocks in the latest assistant message cannot be modified` and `Invalid 'data' in 'redacted_thinking' block`) when historical thinking/redacted_thinking blocks have lost or rotated their signature/data on round-trip — most visibly on claude-haiku-4.5 / claude-sonnet-4.6 in agent mode (~18k hits/day). The Anthropic Extended Thinking docs explicitly allow omitting thinking blocks from prior assistant role turns, and on Opus 4.5+/Sonnet 4.6+ omission is neutral for quality. Pre-#315406 (≤ 0.47) we already did this; #315406 added 'messages' to apiSupportsHistoricalThinking, which is what flipped the behavior. Reverts only the 'messages' membership; 'responses' (OpenAI Responses API) still needs to round-trip encrypted reasoning blocks across turns and is unaffected. Flips the matching unit test and renames model fixtures to claude-haiku-4-5 (the dominant in-prod offender).
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates Copilot’s prompt rendering for tool-calling rounds to avoid sending historical “thinking” opaque parts when targeting Anthropic’s Messages API, preventing request failures caused by re-sending prior thinking/redacted_thinking blocks. The Responses API behavior is preserved to continue round-tripping reasoning metadata where required.
Changes:
- Stop treating the Messages API as supporting historical thinking; only the Responses API will include historical thinking parts.
- Update unit tests to assert that historical thinking is omitted for Messages API even when the modelId matches.
- Refresh modelIds used in the tests to align with the updated behavior expectations.
Show a summary per file
| File | Description |
|---|---|
| extensions/copilot/src/extension/tools/node/test/toolCalling.spec.tsx | Updates tests to verify historical thinking is excluded for Messages API but still included for Responses API when modelId matches. |
| extensions/copilot/src/extension/prompts/node/panel/toolCalling.tsx | Changes the include-thinking logic so historical thinking is only emitted for apiType === 'responses', not messages. |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 0
dmitrivMS
approved these changes
May 23, 2026
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.
Anthropic's Extended Thinking docs explicitly allow omitting thinking blocks from prior assistant turns. This drops
'messages'fromapiSupportsHistoricalThinkingso historical thinking is no longer emitted on the Messages API. The Responses API (OpenAI) still needs to round-trip encrypted reasoning and is unchanged.Test updated to assert the new behavior on the Messages API.