Skip to content

fix(kimi): preserve reasoning_content across replayed tool turns (salvage #13864)#13975

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-64a2e2ff
Apr 22, 2026
Merged

fix(kimi): preserve reasoning_content across replayed tool turns (salvage #13864)#13975
teknium1 merged 1 commit into
mainfrom
hermes/hermes-64a2e2ff

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Salvages #13864 by @helix4u onto current main. Fixes the HTTP 400: thinking is enabled but reasoning_content is missing in assistant tool call message error reported by drew_donaldson on Kimi/Moonshot when replaying long sessions.

Root cause

Commit 063bc3c ("fix(kimi): send max_tokens, reasoning_effort, and thinking for Kimi/Moonshot") enabled thinking for Kimi/Moonshot. Kimi's strict-replay requires every assistant tool-call message to carry a reasoning_content field when thinking is on. Sessions that predate that commit (or any turn where reasoning was empty) have no scratchpad to replay, so the field gets omitted and the API rejects the request.

Changes

  • hermes_state.py: schema v7 adds reasoning_content column; idempotent ALTER TABLE migration
  • run_agent.py: _build_assistant_message captures reasoning_content from API responses; new _copy_reasoning_content_for_api replaces the two existing reasoning → reasoning_content one-liners with a 3-tier fallback:
    1. Explicit reasoning_content (even empty string) wins
    2. Else promote reasoning if non-empty
    3. Else, Kimi/Moonshot + tool_calls → inject "" to satisfy the strict API
  • gateway/session.py + gateway/run.py: thread reasoning_content through transcript append/rewrite and branch-copy
  • Regression tests for migration, transcript round-trip, assistant normalization, and strict-provider replay

Validation

19/19 targeted tests pass.

Authorship preserved via cherry-pick. Closes #13864.

@teknium1 teknium1 merged commit a7d78d3 into main Apr 22, 2026
10 of 11 checks passed
@teknium1 teknium1 deleted the hermes/hermes-64a2e2ff branch April 22, 2026 11:32
@alt-glitch alt-glitch added comp/agent Core agent loop, run_agent.py, prompt builder comp/gateway Gateway runner, session dispatch, delivery P1 High — major feature broken, no workaround type/bug Something isn't working labels Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder comp/gateway Gateway runner, session dispatch, delivery P1 High — major feature broken, no workaround type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants