Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Dec 26, 2025

Summary

Fixes ROO-312

When extended thinking is enabled, Anthropic's API returns signature_delta events that contain cryptographic signatures for thinking blocks. These signatures are required when passing thinking blocks back to the API for tool use continuations.

Reference: Anthropic Extended Thinking Documentation

The Problem

Without the signature, thinking blocks were stored as generic 'reasoning' blocks which get filtered out by anthropic-filter.ts, causing the API validation error:

Expected thinking or redacted_thinking, but found tool_use

Before (Bug)

1. API streams thinking block + signature_delta ← signature IGNORED
2. getThoughtSignature() returns undefined
3. Thinking stored as: { type: "reasoning", text: "..." }
4. anthropic-filter.ts filters out "reasoning" blocks  
5. API sees: [tool_use block without thinking] → ERROR

After (Fixed)

1. API streams thinking block + signature_delta ← signature CAPTURED  
2. getThoughtSignature() returns "sig_abc123"
3. Thinking stored as: { type: "thinking", thinking: "...", signature: "sig_abc123" }
4. anthropic-filter.ts passes "thinking" blocks through
5. API sees: [thinking block with signature, then tool_use] → SUCCESS

Relevant Documentation Sections

From Anthropic Extended Thinking Docs:

  1. Streaming signature format:
event: content_block_delta
data: {"type": "content_block_delta", "index": 0, "delta": {"type": "signature_delta", "signature": "EqQBCgIYAhIM..."}}
  1. Thinking block format with signature:
{
  "type": "thinking",
  "thinking": "Let me analyze this step by step...",
  "signature": "WaUjzkypQ2mUEVM36O2TxuC06KN8xyfbJwyem2dw3URve/op91XWHOEBLLqIOMfFG/UvLEczmEsUjavL...."
}
  1. Signature purpose: "Full thinking content is encrypted and returned in the signature field. This field is used to verify that thinking blocks were generated by Claude when passed back to the API."

Changes

  • Add lastThinkingSignature property to store captured signature
  • Add getThoughtSignature() method to expose signature to Task.ts
  • Handle signature_delta events in content_block_delta
  • Emit thinking_complete chunk when thinking block finishes with signature
  • Add comprehensive tests for signature capture functionality

Testing

  • All 34 Anthropic provider tests pass
  • Added 5 new tests for signature capture scenarios

Fixes ROO-312

When extended thinking is enabled, Anthropic's API returns signature_delta events
that contain cryptographic signatures for thinking blocks. These signatures are
required when passing thinking blocks back to the API for tool use continuations.

Without the signature, thinking blocks were stored as generic 'reasoning' blocks
which get filtered out by anthropic-filter.ts, causing the API validation error:
'Expected thinking or redacted_thinking, but found tool_use'

Changes:
- Add lastThinkingSignature property to store captured signature
- Add getThoughtSignature() method to expose signature to Task.ts
- Handle signature_delta events in content_block_delta
- Emit thinking_complete chunk when thinking block finishes with signature
- Add comprehensive tests for signature capture functionality
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Dec 26, 2025
@roomote
Copy link
Contributor

roomote bot commented Dec 26, 2025

Rooviewer Clock   See task on Roo Cloud

Review completed. No issues found.

The implementation correctly captures extended thinking signatures for tool use continuations in the Anthropic provider. The code is well-structured with proper type definitions, signature accumulation, per-request reset, and comprehensive test coverage.

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Dec 26, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 26, 2025
@daniel-lxs daniel-lxs merged commit 2eebf3c into main Dec 26, 2025
24 checks passed
@daniel-lxs daniel-lxs deleted the fix/roo-312-extended-thinking-signature-capture branch December 26, 2025 22:11
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Dec 26, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Dec 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants