fix: preserve Anthropic thinking block signature for multi-turn conversations#218
Open
wnxd wants to merge 2 commits into
Open
fix: preserve Anthropic thinking block signature for multi-turn conversations#218wnxd wants to merge 2 commits into
wnxd wants to merge 2 commits into
Conversation
…rsations
When using Anthropic models with thinking/reasoning enabled, follow-up
requests fail with 'thinking.signature: Field required' because the
extension discards the signature_delta from streaming responses.
VS Code's proposed API does not preserve LanguageModelThinkingPart
(id, metadata, or even the part itself) across conversation turns, so
previous approaches to carry the signature through metadata or ID-based
caches all failed.
This fix uses a static cache keyed by the assistant's text content
(which VS Code always preserves) to store thinking+signature pairs:
- During streaming: accumulate assistant text + thinking content + signature
- On stream end: cache {thinking, signature}[] keyed by assistant text
- In convertMessages(): look up cached thinking blocks by assistant text
- If no cache hit: skip thinking block entirely (avoiding 400 error)
Fixes: multi-turn Anthropic conversations with thinking enabled
JohnnyZ93
reviewed
Apr 30, 2026
- Reset _pendingThinkingEntries to undefined after caching to prevent redundant writes if the code path is reached twice - Remove dead code branch: the else-if checking thinkingSignatures can never execute since LanguageModelThinkingPart has no signature field - Remove unused variables: thinkingParts, thinkingSignatures, joinedThinking
wnxd
commented
May 1, 2026
Author
wnxd
left a comment
There was a problem hiding this comment.
Thanks for the thorough review! All three points have been addressed in commit 5c5e8e1:
1. _pendingThinkingEntries not reset — Fixed. Added this._pendingThinkingEntries = undefined; right after the cache write, and captured entryCount beforehand for the logger.
2. Dead code branch (else if (thinkingSignatures.some(...))) — Removed. Since LanguageModelThinkingPart has no signature field, the thinkingSignatures array was always empty, making this branch unreachable.
3. thinkingSignatures always empty — Removed the variable entirely, along with thinkingParts and joinedThinking which were only consumed by the deleted branch.
Owner
|
There are two issues to consider:
|
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.
Fixes #217
Problem
When using Anthropic models with thinking enabled, follow-up requests fail with thinking.signature: Field required because the extension discards signature_delta from streaming responses.
Solution
Uses a static cache keyed by the assistant text content (which VS Code always preserves) to store thinking+signature pairs.
Files Changed
Testing
Tested with Claude models using thinking: {type: adaptive} — multi-turn conversations now work correctly.