fix(anthropic): preserve signed thinking blocks on Kimi-family replay (#66948 salvage) - #67391
Merged
Merged
Conversation
…replay _manage_thinking_signatures treated every Kimi-family endpoint with the #13848-era contract: strip signed Anthropic thinking blocks from replayed history, assuming the upstream cannot validate Anthropic signatures. Live probing shows that contract is outdated for the whole Kimi family: - Kimi For Coding (api.kimi.com/coding) issues AND validates its own thinking signatures (K3+): both verbatim and content-mutated signed blocks replay with HTTP 200; - Moonshot's Anthropic surface (api.moonshot.cn/anthropic) accepts signed blocks the same way (200 on both verbatim and mutated); - every other harness that replays signed blocks to KFC (Claude Code, pi, Kilo Code) round-trips fine. Stripping signed blocks there silently discarded the model's prior chain-of-thought in multi-turn conversations — e.g. a two-turn recall probe loses the reasoning between turns while the text answer survives (agent.log: turn-2 input ≈ turn-1 input + a few dozen tokens instead of +thinking). With this change, the same probe recalls the exact hidden values from turn-1 thinking (+230 tokens on turn 2). So: on _is_kimi_family_endpoint, keep signed and unsigned thinking blocks unchanged on replay — one uniform rule for the whole Kimi family, no /coding-vs-Moonshot split. DeepSeek keeps the #16748 contract (strip signed, preserve unsigned). Third-party and direct-Anthropic behavior is untouched. Add tests/agent/test_anthropic_kimi_signed_thinking_replay.py pinning the unified behavior (Kimi /coding + Moonshot keep signed and unsigned) and the unchanged neighbors (DeepSeek strips, direct Anthropic keeps).
teknium1
force-pushed
the
hermes/hermes-cc28a546
branch
from
July 19, 2026 08:32
b57db55 to
51f8ed0
Compare
Contributor
Related to open #66948: both preserve signed Kimi thinking replay, but this salvage broadens coverage from the Kimi /coding endpoint to the Kimi family while retaining DeepSeek handling. This is competing scope, not a duplicate. |
This was referenced Jul 19, 2026
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.
Summary
Salvage of #66948 by @FuryMartin — Kimi-family Anthropic endpoints now replay thinking blocks as-is (signed and unsigned) instead of stripping signed ones, restoring cross-turn reasoning recall on Kimi For Coding / Moonshot.
Root cause: the #13848-era contract assumed Kimi cannot validate Anthropic thinking signatures and stripped every signed block on replay. Live probes show the whole Kimi family accepts signed blocks (HTTP 200 even with mutated signatures) — the strip silently deleted the model's prior reasoning each turn.
Changes
agent/anthropic_adapter.py:_manage_thinking_signaturessplits the shared Kimi/DeepSeek branch — Kimi family replays thinking unchanged; DeepSeek keeps strip-signed/keep-unsigned (DeepSeek /anthropic (V4 thinking): stripped thinking blocks cause HTTP 400 on replay #16748); third-party and direct Anthropic untouched.tests/agent/test_anthropic_kimi_signed_thinking_replay.py: 6 new regression tests, incl. orphan-tool-turn case verifying the internal_thinking_signature_invalidatedmarker never reaches the wire.contributors/emails/fanyu@moonshot.cn: contributor mapping for @FuryMartin.Validation
Cherry-picked with @FuryMartin's authorship preserved; rebase-merge.
Closes #66948.
Infographic