Skip to content

fix(runtime): round-trip reasoning_content on every openai-chat connection, not just kimi-coding-plan #2241

Closed

Description

@Astro-Han

What happened

On the openai-chat wire protocol, Maka drops every prior assistant turn's reasoning before building the next request. The model re-derives its own earlier reasoning on each step from tool output alone.

DeepSeek's Thinking Mode contract requires the opposite: when a request carries tools, reasoning_content from intermediate assistant turns must be passed back in all subsequent requests, otherwise the API returns 400 "The reasoning_content in the thinking mode must be passed back to the API." A relay currently absorbs the error for us, so the violation surfaces as silent performance loss rather than a failure.

The round-trip machinery already exists — packages/runtime/src/kimi-openai-transport.ts handles both reasoning_content and reasoning field names, empty-reasoning restoration, and per-chunk recovery. It is gated on a provider name rather than on the protocol.

How to reproduce

  1. Configure any openai-chat connection whose model emits reasoning_content (e.g. DeepSeek V4 Flash through an OpenAI-compatible relay).
  2. Run a multi-step headless task so the model performs at least three tool calls.
  3. Inspect the outgoing request projection on step 3+: no prior assistant reasoning_content is present.
  4. Observe reasoning tokens per request climbing monotonically as history grows.

Environment

  • Maka commit: 17367dcaf
  • Surface: Headless (Harbor AI SDK path) — also affects Desktop and CLI on the same protocol
  • OS: macOS 25.5.0

Logs, screenshots, or additional context

Fact Location
Three parallel one-off replay flags; DeepSeek matches none packages/runtime/src/model-adapter.ts:140-148
usesKimiOpenAiChat hard-binds providerType === 'kimi-coding-plan' packages/runtime/src/model-adapter.ts:438-443
Round-trip already implemented, Kimi-only packages/runtime/src/kimi-openai-transport.ts
Contract requiring the round-trip with tools https://api-docs.deepseek.com/guides/thinking_mode/

Measured on the Terminal-Bench 2.1 four-arm run (89 tasks, deepseek-v4-flash, effort max), median reasoning tokens per provider request by step bucket:

step Maka Codex
0–9 53 ~150
30–39 244 ~150
60–69 428 ~150

Codex reaches the same model over openai-responses, where reasoning items are replayed with plaintext content. Four Maka cells in that run exhausted their budget outright: write-compressor, largest-eigenval, code-from-image, torch-pipeline-parallelism.

Proposed shape

Promote the Kimi transport into a protocol-level capability selected by the connection's declared thinking support, so unsignedThinking stops meaning "is this Kimi". Same illegal-state-unrepresentable argument as #2026. Related: #2219 asks for manual thinkingOptions on openai-compatible connections and would share the declaration surface. Note #2238 covers the native OpenAI Responses path only and does not touch this one.

Empty reasoning_content must still be sent — guard on presence, not truthiness, or empty strings get stripped and trigger the same 400.

Activity

  1. added
    bug
    on Aug 5, 2026
  2. Astro-Han commented on Aug 5, 2026

    @Astro-Han
    ContributorAuthor

    I’m taking this. I’ll first add a durable-runtime replay regression that crosses Maka-owned provider steps, then centralize effective wire resolution so model construction and replay consume the same decision. The fix will generalize plaintext OpenAI Chat reasoning replay (including observed field names and empty reasoning) while leaving the merged Responses continuation transport and existing opaque part-metadata paths unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions