Skip to content

fix: replay signed thinking for the Claude (MultiProvider) route - #2266

Open
lambdaloop wants to merge 1 commit into
1jehuang:masterfrom
lambdaloop:fix-claude-thinking-replay
Open

lambdaloop wants to merge 1 commit into
1jehuang:masterfrom
lambdaloop:fix-claude-thinking-replay

Conversation

@lambdaloop

@lambdaloop lambdaloop commented Nov 21, 2026 •

Copy link
Copy Markdown

Closes #2265

Symptom

On the default Claude route (MultiProvider, which reports its name as "Claude"), signed thinking blocks are never replayed to the Anthropic API. The model re-plans every tool-loop step and thinks far longer than it needs to.

Root cause

stores_reasoning_content_for_context (provider/mod.rs) and push_reasoning_blocks (message.rs) gate replay on the provider name "anthropic". But MultiProvider::name() returns "Claude" for ActiveProvider::Claude, which dispatches to the Anthropic runtime. So the signature-bearing AnthropicThinking block is never stored.

Fix

  • Both checks now also accept "claude" (case-insensitive, like the existing checks).
  • The AnthropicThinking block is inserted at the front of the assistant content instead of after the text. Anthropic expects thinking to lead the assistant turn, and the request builder sends blocks in stored order.
  • A regression test (push_reasoning_blocks_claude_multiprovider_replays_signed_thinking_first) fails before the fix and passes after.

The diff is 3 files, +38/−7. I kept it deliberately minimal. A more structural option would be a provider capability (for example Provider::reasoning_replay()) that asks the runtime for its wire format instead of matching names. I'm happy to follow up with that if you prefer.

Measured effect

Opus 5.5, medium effort, comparable agent workloads, before vs after replay was fixed:

before after
p90 thinking per model call 2,379 chars 467 chars
calls with more than 5k chars of thinking 116 0

Tests

cargo test -p jcode-base --lib: the new test and the existing push_reasoning_blocks_* tests pass.

@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, with a non-blocking test-isolation issue.

Findings

  1. P2 Local settings break the test ▶
Fix with agent prompt
### Issue 1
crates/jcode-base/src/message/tests.rs:930-934
If `preserve_reasoning_context` is disabled in the user's config file or through `JCODE_PRESERVE_REASONING_CONTEXT=false`, this test fails at `assert!(store)` even though the code correctly honors that setting. Give the test a controlled configuration, or test the provider-name match separately from the configuration gate.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Fixes signed thinking replay for the default Claude route.

  • Claude turns now replay signed thinking before assistant text.

Reviews (2) · Last reviewed commit: "fix: replay signed thinking for the Clau..." · Reviewed by Greptile

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]>
xenking added a commit to xenking/jcode that referenced this pull request Nov 22, 2026
Upstream-PR: 1jehuang#1357
Upstream-PR-Commit: 1jehuang#1357 0da5e81
Upstream-PR: 1jehuang#1362
Upstream-PR-Commit: 1jehuang#1362 5962058
Upstream-PR: 1jehuang#1486
Upstream-PR-Commit: 1jehuang#1486 fadc624
Upstream-PR: 1jehuang#1733
Upstream-PR-Commit: 1jehuang#1733 01f3415
Upstream-PR: 1jehuang#1750
Upstream-PR-Commit: 1jehuang#1750 1ac0c82
Upstream-PR: 1jehuang#1822
Upstream-PR-Commit: 1jehuang#1822 73f85fc
Upstream-PR: 1jehuang#1912
Upstream-PR-Commit: 1jehuang#1912 36d7682
Upstream-PR: 1jehuang#1978
Upstream-PR-Commit: 1jehuang#1978 0f55643
Upstream-PR: 1jehuang#2007
Upstream-PR-Commit: 1jehuang#2007 638f87c
Upstream-PR: 1jehuang#2213
Upstream-PR-Commit: 1jehuang#2213 c5e1487
Upstream-PR: 1jehuang#2234
Upstream-PR-Commit: 1jehuang#2234 0d4d5d4
Upstream-PR: 1jehuang#2266
Upstream-PR-Commit: 1jehuang#2266 217ddc2
Upstream-PR: 1jehuang#2267
Upstream-PR-Commit: 1jehuang#2267 e98c40b
Comment on lines +930 to +934
let store = crate::provider::stores_reasoning_content_for_context("Claude");
assert!(
store,
"Claude turns must keep their signed thinking for replay"
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Local settings break the test

If preserve_reasoning_context is disabled in the user's config file or through JCODE_PRESERVE_REASONING_CONTEXT=false, this test fails at assert!(store) even though the code correctly honors that setting. Give the test a controlled configuration, or test the provider-name match separately from the configuration gate.

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-base/src/message/tests.rs
Line: 930-934

Comment:
**Local settings break the test**

If `preserve_reasoning_context` is disabled in the user's config file or through `JCODE_PRESERVE_REASONING_CONTEXT=false`, this test fails at `assert!(store)` even though the code correctly honors that setting. Give the test a controlled configuration, or test the provider-name match separately from the configuration gate.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

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