Skip to content

Messages API: skip historical thinking blocks to avoid 400s#318076

Merged
bhavyaus merged 1 commit into
mainfrom
dev/bhavyau/skip-historical-thinking-messages-api
May 23, 2026
Merged

Messages API: skip historical thinking blocks to avoid 400s#318076
bhavyaus merged 1 commit into
mainfrom
dev/bhavyau/skip-historical-thinking-messages-api

Conversation

@bhavyaus
Copy link
Copy Markdown
Collaborator

@bhavyaus bhavyaus commented May 23, 2026

Anthropic's Extended Thinking docs explicitly allow omitting thinking blocks from prior assistant turns. This drops 'messages' from apiSupportsHistoricalThinking so 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.

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).
Copilot AI review requested due to automatic review settings May 23, 2026 04:45
@bhavyaus bhavyaus enabled auto-merge (squash) May 23, 2026 04:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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

@bhavyaus bhavyaus merged commit 9687270 into main May 23, 2026
26 checks passed
@bhavyaus bhavyaus deleted the dev/bhavyau/skip-historical-thinking-messages-api branch May 23, 2026 08:10
@vs-code-engineering vs-code-engineering Bot added this to the 1.122.0 milestone May 23, 2026
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.

3 participants