Skip to content

Add allowEmptySignature compat option for Anthropic-compatible providers#4971

Open
pandada8 wants to merge 1 commit into
earendil-works:mainfrom
pandada8:add-allow-empty-thinking-signature
Open

Add allowEmptySignature compat option for Anthropic-compatible providers#4971
pandada8 wants to merge 1 commit into
earendil-works:mainfrom
pandada8:add-allow-empty-thinking-signature

Conversation

@pandada8
Copy link
Copy Markdown

Some Anthropic-compatible providers return thinking blocks with empty thinkingSignature but still accept them on replay. Previously, empty signatures caused thinking blocks to be rewritten as plain text blocks, which breaks prompt caching and causes some providers to return 400.

Add allowEmptySignature to AnthropicMessagesCompat (default: false). When
true, empty signatures are passed through as type: "thinking" with
signature: "" instead of being downgraded to text blocks.

Copilot AI review requested due to automatic review settings May 25, 2026 06:34
@pandada8
Copy link
Copy Markdown
Author

this should fix #4464

Copy link
Copy Markdown

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 adds an Anthropic-compatibility toggle to preserve thinking blocks even when thinkingSignature is empty, addressing prompt-caching/replay issues with Anthropic-compatible proxies that accept empty signatures.

Changes:

  • Added allowEmptySignature to AnthropicMessagesCompat (default false).
  • Wired the compat flag through Anthropic provider parameter building into message conversion.
  • Added Vitest coverage for default behavior vs. allowEmptySignature: true behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/ai/src/types.ts Adds the allowEmptySignature compat option with documentation and default semantics.
packages/ai/src/providers/anthropic.ts Passes the compat flag into message conversion and conditionally preserves empty-signature thinking blocks.
packages/ai/test/anthropic-allow-empty-thinking-signature.test.ts Verifies default downgrade-to-text behavior and opt-in preservation behavior for empty signatures.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/ai/src/providers/anthropic.ts Outdated
blocks.push({
type: "thinking",
thinking: sanitizeSurrogates(block.thinking),
signature: block.thinkingSignature ?? "",
Some Anthropic-compatible providers return thinking blocks with empty
thinkingSignature but still accept them on replay. Previously, empty
signatures caused thinking blocks to be rewritten as plain text blocks,
which breaks prompt caching and causes some providers to return 400.

Add allowEmptySignature to AnthropicMessagesCompat (default: false). When
true, empty signatures are passed through as type: "thinking" with
signature: "" instead of being downgraded to text blocks.
@pandada8 pandada8 force-pushed the add-allow-empty-thinking-signature branch from 4b5dc88 to 04e9c78 Compare May 25, 2026 06:43
@pandada8 pandada8 requested a review from Copilot May 25, 2026 06:44
Copy link
Copy Markdown

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 200000,
maxTokens: 32000,
compat: { allowEmptySignature },
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.

2 participants