fix(moonshot): backfill reasoning_content on assistant tool-call replay messages#92396
fix(moonshot): backfill reasoning_content on assistant tool-call replay messages#92396xialonglee wants to merge 1 commit into
Conversation
…ay messages Moonshot/Kimi requires reasoning_content on all assistant tool-call messages when thinking is enabled. After LCM compaction, cross-model fallback, or session repair, the replayed history may be missing this field, causing a 400 error from the Moonshot API. Backfill an empty string to satisfy the API schema contract without fabricating semantic reasoning content. Follows the same provider-owned backfill pattern already used by Kimi Coding (extensions/kimi-coding/stream.ts) and DeepSeek V4 (provider-stream-shared.ts). Fixes openclaw#71491 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Codex review: needs real behavior proof before merge. Reviewed June 12, 2026, 5:29 AM ET / 09:29 UTC. Summary PR surface: Source +31, Tests +86. Total +117 across 2 files. Reproducibility: unclear. The review failed before ClawSweeper could establish a reproduction path. Review metrics: none identified. Stored data model Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Risk before merge
Maintainer options:
Next step before merge
Review detailsBest possible solution: Retry the Codex review after fixing the execution failure. Do we have a high-confidence way to reproduce the issue? Unclear. The review failed before ClawSweeper could establish a reproduction path. Is this the best way to solve the issue? Unclear. Retry the review first so ClawSweeper can evaluate the actual issue and fix direction. AGENTS.md: unclear because the file could not be read completely. Codex review notes: model internal, reasoning high; reviewed against d4819948f37d. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +31, Tests +86. Total +117 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Summary
Fixes the
reasoning_content is missing in assistant tool call message400 error when using Moonshot/Kimi models with thinking enabled in long sessions, after LCM compaction, cross-model fallback, or/compact.Problem
When thinking mode is enabled for Moonshot models, the API requires
reasoning_contenton all replayed assistant tool-call messages. After LCM compaction, cross-model fallback, or session compression—the replayed history loses this field, causing:This is a provider-agnostic regression affecting Moonshot/Kimi and any OpenAI-compatible upstream requiring
reasoning_contentreplay preservation.Solution
In
createMoonshotThinkingWrapper, when thinking is enabled: walkpayloadObj.messagesand backfillreasoning_content: ""on assistant messages containingtool_callsthat are missing the field.Follows the same provider-owned backfill pattern already used by:
extensions/kimi-coding/stream.ts:90-106)src/plugin-sdk/provider-stream-shared.ts:401-425)Changes
src/llm/providers/stream-wrappers/moonshot-thinking.ts— AddedensureMoonshotToolCallReasoningContent()helper, called wheneffectiveThinkingType === 'enabled'src/agents/embedded-agent-runner-extraparams-moonshot.test.ts— Added 4 test cases: backfill, preserve existing, skip when thinking disabled, skip non-tool-call messagesReal behavior proof
Behavior addressed: Moonshot/Kimi models return 400 when thinking is enabled and replayed assistant tool-call messages are missing
reasoning_content. TheensureMoonshotToolCallReasoningContenthelper backfillsreasoning_content: ""on assistant tool-call messages before the outbound API request is dispatched.Real environment tested: Local dev workstation, Linux x86_64, Node 22.19.0, pnpm, branch
fix/moonshot-reasoning-content-backfillat commit 0596077. The payload mutation runs synchronously before any network call, so a live Moonshot API key is not needed to observe the corrected payload shape.Exact steps or command run after this patch:
Evidence after fix:
Observed result after fix: The 4 new Moonshot reasoning_content test cases all pass. The existing 8 Moonshot extraparams tests remain green (no regression). The adjacent OpenAI transport stream suite (250 tests) also remains green, confirming the provider-owned stream wrapper change does not leak into the shared transport path.
What was not tested: Live Moonshot API end-to-end with a real multi-turn session that triggers LCM compaction. The payload mutation is a synchronous pre-dispatch transform verified entirely through the 12 unit tests above. A live API integration test is not practical for this fix because it requires Moonshot credentials and a long-running session to trigger compaction, and the fix itself runs before any network I/O — the test assertions check the exact payload shape the API would receive.
Related
Fixes #71491
AI-Assisted
This PR was prepared with assistance from Claude Code.