Add allowEmptySignature compat option for Anthropic-compatible providers#4971
Open
pandada8 wants to merge 1 commit into
Open
Add allowEmptySignature compat option for Anthropic-compatible providers#4971pandada8 wants to merge 1 commit into
pandada8 wants to merge 1 commit into
Conversation
Author
|
this should fix #4464 |
There was a problem hiding this comment.
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
allowEmptySignaturetoAnthropicMessagesCompat(defaultfalse). - Wired the compat flag through Anthropic provider parameter building into message conversion.
- Added Vitest coverage for default behavior vs.
allowEmptySignature: truebehavior.
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.
| 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.
4b5dc88 to
04e9c78
Compare
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.
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.