Skip to content

provider: replay signed thinking on Claude route - #2274

Open
eniyos wants to merge 4 commits into
1jehuang:masterfrom
eniyos:fix/claude-signed-thinking-replay
Open

eniyos wants to merge 4 commits into
1jehuang:masterfrom
eniyos:fix/claude-signed-thinking-replay

Conversation

@eniyos

@eniyos eniyos commented Nov 21, 2026

Copy link
Copy Markdown

Closes #2265

Problem

On the default Claude route (Anthropic OAuth or API key through MultiProvider), Claude's extended thinking wasn't being preserved or echoed back on subsequent turns.

This happened because:

  • MultiProvider::name() returns "Claude" for ActiveProvider::Claude.
  • stores_reasoning_content_for_context() only checked "openrouter" | "anthropic" | "openai", so store_reasoning_content evaluated to false.
  • push_reasoning_blocks() only created ContentBlock::AnthropicThinking if provider_name.eq_ignore_ascii_case("anthropic"). For "Claude", it fell through to generic reasoning trace or dropped the signed block.

Without the signed thinking block echoed back on subsequent tool-turn calls, Claude had to re-plan from scratch on every turn, causing significantly longer thinking latencies and token costs.

Solution

  1. In stores_reasoning_content_for_context(), accept "claude" in addition to "anthropic", "openrouter", and "openai".
  2. In push_reasoning_blocks(), accept both "anthropic" and "claude" so ContentBlock::AnthropicThinking with cryptographic signatures is created and preserved.
  3. Added unit tests for push_reasoning_blocks with provider name "Claude" and stores_reasoning_content_for_context("Claude").

Verification

  • Tested with cargo test -p jcode-base --lib message::tests: all 60 tests passed.
  • Ran python3 scripts/check_dependency_boundaries.py: passed.

@greptile-apps

greptile-apps Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; both previous thinking-replay issues are fixed.

Summary

The PR preserves signed thinking on the default Claude route.

  • Claude turns keep each signed thinking region for later requests.
  • macOS launches can detect Kitty and open new sessions in it.
  • The local jcode-wiki/ folder stays out of version control.

Both previous findings are addressed. No new actionable issues were found.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Thinking text and signature] --> B[ThinkingEnd]
  B --> C[Save one separate block]
  C --> D[Store assistant message]
  D --> E[Replay each signed block unchanged]
Loading

Reviews (2) · Last reviewed commit: "fix(provider): preserve separate signed ..." · Reviewed by Greptile

Comment thread crates/jcode-base/src/provider/mod.rs Resolved
Comment thread crates/jcode-base/src/message.rs Resolved
@eniyos eniyos closed this Nov 21, 2026
@eniyos eniyos reopened this Nov 21, 2026
@eniyos

eniyos commented Nov 21, 2026

Copy link
Copy Markdown
Author

Both review items have been resolved in commit 01021d6:

  1. Preserve separate signed thinking blocks:

    • In turn_streaming_mpsc.rs, turn_loops.rs, and crates/jcode-tui/src/tui/app/turn.rs, reasoning blocks (content, signature) are now finalized on StreamEvent::ThinkingEnd into a list of reasoning blocks. Separate thinking phases (e.g. before and after native web search or tool calls) are preserved as distinct ContentBlock::AnthropicThinking blocks instead of appending strings and signatures together.
    • Added regression tests run_turn_streaming_mpsc_preserves_separate_signed_thinking_blocks_on_claude_route and run_turn_preserves_separate_signed_thinking_blocks_on_claude_route in agent_tests.rs.
  2. Keep empty signed thinking blocks:

    • In push_reasoning_blocks(), allow blocks where reasoning_content is empty if a valid signature is present and replay is enabled, preserving ContentBlock::AnthropicThinking { thinking: "", signature }.
    • Added unit tests push_reasoning_blocks_claude_route_empty_signed_replay and push_reasoning_blocks_anthropic_empty_signed_replay, while verifying unsigned empty blocks remain skipped.

xenking added a commit to xenking/jcode that referenced this pull request Nov 22, 2026
Recognize the MultiProvider Claude route and keep every completed signed block, including empty ones, in its original position among provider-native blocks. Keep unsigned reasoning in the readable trace and honor the existing replay setting.

Upstream-PR: 1jehuang#2266
Related-Upstream-PR: 1jehuang#2274

Co-authored-by: Lili Karashchuk <[email protected]>
Co-authored-by: eniyanyosuva <[email protected]>

This branch has not been deployed

No deployments
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.

Claude route never replays signed thinking (provider name "Claude" vs "anthropic" check)

1 participant