Skip to content

Fix Kimi Coding tool-call replay#82550

Merged
clawsweeper[bot] merged 1 commit into
mainfrom
ak/fix-kimi-coding-replay
May 16, 2026
Merged

Fix Kimi Coding tool-call replay#82550
clawsweeper[bot] merged 1 commit into
mainfrom
ak/fix-kimi-coding-replay

Conversation

@amknight

Copy link
Copy Markdown
Member

Summary

Fixes #82161 by preserving Kimi Coding reasoning replay on OpenAI-compatible follow-up turns and by backfilling the blank reasoning_content placeholder Kimi expects on assistant tool-call replay messages when thinking is enabled.

Reproduction

I reproduced the issue against current main with a source-level probe for { provider: "kimi", api: "openai-completions", id: "kimi-for-coding" }. The failing behavior was that buildOpenAICompletionsParams serialized the assistant tool-call replay without reasoning_content, even though the Kimi/Moonshot-compatible K2.6 route preserved it.

I also ran the same reproduction path in Blacksmith Testbox before the fix. That Blacksmith source probe showed assistantHasReasoningContent: false for kimi-for-coding. The Blacksmith environment did not expose a live Kimi/Moonshot key, so live provider auth was blocked; the manual E2E proof below uses a local Kimi-compatible endpoint that rejects the same missing-field condition.

Root Cause

kimi-for-coding was not in the OpenAI-compatible reasoning replay allowlist used by the Chat Completions payload sanitizer, so the replay sanitizer stripped provider-owned reasoning_content before the next request. The Kimi provider wrapper also did not add the blank reasoning_content placeholder for assistant tool-call replay messages when OpenAI-compatible Kimi thinking was enabled.

Fix

  • Adds kimi-for-coding to the replay-required model ids in the OpenAI Chat Completions sanitizer and transcript policy.
  • Expands model-id matching to handle prefixed/suffixed aliases such as hf:moonshotai/kimi-k2-thinking and xiaomi/mimo-v2.6-pro:cloud.
  • Updates the Kimi Coding stream wrapper to backfill reasoning_content: "" on assistant tool-call replay messages when thinking is enabled, and to strip replay reasoning fields when thinking is disabled.
  • Adds focused regression coverage for transport serialization, transcript policy, and the Kimi wrapper.
  • Adds a changelog entry.

Verification

  • node scripts/run-vitest.mjs src/agents/openai-transport-stream.test.ts src/agents/transcript-policy.test.ts extensions/kimi-coding/stream.test.ts locally after rebasing onto origin/main (400 passed).
  • git diff --check origin/main...HEAD.
  • codex review --uncommitted before publishing: no actionable correctness findings.

Real behavior proof

Behavior addressed: Kimi Coding OpenAI-compatible follow-up turns after tool use must include provider-owned assistant replay reasoning_content so Kimi does not reject the next request.

Real environment tested: Blacksmith Testbox tbx_01krr7g58dy8f2qcxd7vqxh01q, GitHub Actions run https://github.com/openclaw/openclaw/actions/runs/25960370706.

Exact steps or command run after this patch: node scripts/crabbox-wrapper.mjs run --provider blacksmith-testbox --blacksmith-workflow .github/workflows/ci-check-testbox.yml --blacksmith-job check --blacksmith-ref main --timing-json --shell -- "... node scripts/run-vitest.mjs src/agents/openai-transport-stream.test.ts src/agents/transcript-policy.test.ts extensions/kimi-coding/stream.test.ts; ... manual Kimi-compatible loopback E2E ...".

Evidence after fix: Blacksmith focused tests passed (5 passed, 396 passed at that pre-rebase base), then the manual E2E fake provider captured /v1/chat/completions with thinking: { "type": "enabled" } and assistant replay reasoning_content: "".

Observed result after fix: the fake Kimi-compatible endpoint returned KIMI_REPLAY_OK; the same harness rejects the request if assistant tool-call replay is missing reasoning_content.

What was not tested: a live Kimi API request, because the Blacksmith environment did not provide KIMI_API_KEY, KIMICODE_API_KEY, or MOONSHOT_API_KEY.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling extensions: kimi-coding size: M maintainer Maintainer-authored PR labels May 16, 2026
@clawsweeper

clawsweeper Bot commented May 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: passed.

Summary
The PR preserves Kimi Coding reasoning_content replay for OpenAI-compatible tool-call follow-up turns, extends replay model-id matching, adds Kimi wrapper/tests, and updates the changelog.

Reproducibility: yes. at source level: current main drops or fails to synthesize reasoning_content for kimi-for-coding replay, and the linked report includes a concrete Kimi 400 after tool-call history. I did not run a live Kimi request in this read-only review.

Real behavior proof
Not applicable: The external contributor proof gate does not apply to this MEMBER/maintainer-labeled PR; the body still includes Testbox and loopback endpoint proof, but no live Kimi API run.

Next step before merge
No repair lane is needed; the PR is already opted into automerge and has no actionable review findings, so checks and mergeability should gate it.

Security
Cleared: The diff changes provider payload serialization, tests, and changelog text only; it adds no dependencies, workflow execution, secrets handling, or package-resolution behavior.

Review details

Best possible solution:

Land the narrow replay serialization fix once exact-head checks and merge gates pass, then split any remaining Kimi tool-call argument assembly failure into its own focused follow-up.

Do we have a high-confidence way to reproduce the issue?

Yes, at source level: current main drops or fails to synthesize reasoning_content for kimi-for-coding replay, and the linked report includes a concrete Kimi 400 after tool-call history. I did not run a live Kimi request in this read-only review.

Is this the best way to solve the issue?

Yes for the replay serialization bug: the PR extends provider-specific replay policy and the Kimi wrapper without weakening stock OpenAI sanitization. The later argument-assembly report should be a separate follow-up if it still reproduces.

What I checked:

  • Protected PR state: Live PR API shows author_association MEMBER, labels include maintainer and clawsweeper:automerge, head 9a4605e, and the PR is open/mergeable. (9a4605ee3843)
  • Current main transport gap: Current main preserves reasoning_content only for compat flags or listed model ids; the allowlist lacks kimi-for-coding and the normalizer splits at the first colon before slash handling. (src/agents/openai-transport-stream.ts:2552, 9b560b8a41f4)
  • Current main transcript-policy gap: Current main's strict OpenAI-compatible transcript policy lacks kimi-for-coding in the replay-required model-id set, so it can drop historical reasoning for that route. (src/agents/transcript-policy.ts:160, 9b560b8a41f4)
  • Current main Kimi wrapper gap: The Kimi stream wrapper maps thinking into the provider payload and strips generic reasoning knobs, but it does not backfill assistant tool-call reasoning_content for OpenAI-compatible replay. (extensions/kimi-coding/stream.ts:321, 9b560b8a41f4)
  • PR diff matches implicated paths: The patch adds kimi-for-coding to both replay allowlists, broadens prefixed/suffixed model-id matching, and adds Kimi wrapper logic plus focused regression tests for enabled and disabled thinking payloads. (extensions/kimi-coding/stream.ts:75, 9a4605ee3843)
  • Related issue context: The linked issue gives a concrete 2026.5.12 Kimi 400 for missing reasoning_content and later adds a separate possible tool-call argument assembly failure, so this PR addresses the replay half but may not close every reported symptom.

Likely related people:

  • steipete: Recent commits preserved Kimi/MiMo reasoning replay and standardized the Kimi Coding model id near the affected transport and provider catalog surfaces. (role: recent provider replay and Kimi provider contributor; confidence: high; commits: 99dfb8291f1c, 2d8339529b58, 53cd3daed3cb; files: src/agents/openai-transport-stream.ts, src/agents/transcript-policy.ts, extensions/kimi-coding/provider-catalog.ts)
  • jimdawdy-hub: Recent transport work changed requiresReasoningContentOnAssistantMessages handling, the replay mechanism this PR extends. (role: transport compat contributor; confidence: high; commits: d00cd314d17b, d4c83edba89f; files: src/agents/openai-transport-stream.ts, src/agents/openai-completions-compat.ts)
  • Dan O'Brien: Prior Kimi thinking stream work is directly adjacent to the wrapper changed by this PR. (role: Kimi thinking stream contributor; confidence: medium; commits: 8f173563926b; files: extensions/kimi-coding/stream.ts)
  • frankekn: Recent Kimi thinking-default work is adjacent to enabled/disabled thinking payload behavior in the same plugin area. (role: Kimi thinking behavior contributor; confidence: medium; commits: 4ca5f51430d7; files: extensions/kimi-coding/stream.ts)

Remaining risk / open question:

  • The PR body has Testbox and loopback payload proof, but no live Kimi API request because the environment lacked Kimi/Moonshot credentials.
  • The linked issue includes a later possible tool-call argument assembly failure that this replay-focused patch does not prove or fix.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 5a14b1c5c5d7.

@amknight amknight marked this pull request as ready for review May 16, 2026 11:29
@amknight

Copy link
Copy Markdown
Member Author

/clawsweeper automerge

@clawsweeper clawsweeper Bot added the clawsweeper:automerge Maintainer opted this PR into bounded ClawSweeper-reviewed automerge label May 16, 2026
@clawsweeper

clawsweeper Bot commented May 16, 2026

Copy link
Copy Markdown
Contributor

🦞✅
ClawSweeper merged this PR after the passing review.

Source: clawsweeper[bot]
Feedback: structured ClawSweeper verdict: pass (sha=9a4605ee3843e2fdb9dd8d61b39400e58871923a)
Merge status: merged by ClawSweeper automerge
Merged at: 2026-05-16T11:54:47Z
Merge commit: f8b7008f7c53

What merged:

  • The PR preserves Kimi Coding reasoning_content replay for OpenAI-compatible tool-call follow-up turns, extends replay model-id matching, adds Kimi wrapper/tests, and updates the changelog.
  • Reproducibility: yes. at source level: current main drops or fails to synthesize reasoning_content for kimi- ... es a concrete Kimi 400 after tool-call history. I did not run a live Kimi request in this read-only review.

Automerge notes:

  • No ClawSweeper repair was needed after automerge opt-in.

The automerge loop is complete.

Automerge progress:

  • 2026-05-16 11:29:58 UTC review queued fcc577e85d93 (queued)
  • 2026-05-16 11:41:07 UTC review passed fcc577e85d93 (structured ClawSweeper verdict: pass (sha=fcc577e85d935692b7b5fdf391c62cde57533...)
  • 2026-05-16 11:46:44 UTC review queued 9a4605ee3843 (after repair)
  • 2026-05-16 11:54:33 UTC review passed 9a4605ee3843 (structured ClawSweeper verdict: pass (sha=9a4605ee3843e2fdb9dd8d61b39400e588719...)
  • 2026-05-16 11:54:49 UTC merged 9a4605ee3843 (merged by ClawSweeper automerge)

@clawsweeper clawsweeper Bot force-pushed the ak/fix-kimi-coding-replay branch from fcc577e to 9a4605e Compare May 16, 2026 11:46
@clawsweeper clawsweeper Bot merged commit f8b7008 into main May 16, 2026
113 checks passed
@clawsweeper clawsweeper Bot deleted the ak/fix-kimi-coding-replay branch May 16, 2026 11:54
markfietje pushed a commit to markfietje/openclaw that referenced this pull request May 20, 2026
Summary:
- The PR preserves Kimi Coding reasoning_content replay for OpenAI-compatible tool-call follow-up turns, extends replay model-id matching, adds Kimi wrapper/tests, and updates the changelog.
- Reproducibility: yes. at source level: current main drops or fails to synthesize reasoning_content for kimi- ... es a concrete Kimi 400 after tool-call history. I did not run a live Kimi request in this read-only review.

Automerge notes:
- No ClawSweeper repair was needed after automerge opt-in.

Validation:
- ClawSweeper review passed for head 9a4605ee3843e2fdb9dd8d61b39400e58871923a.
- Required merge gates passed before the squash merge.

Prepared head SHA: 9a4605ee3843e2fdb9dd8d61b39400e58871923a
Review: openclaw/openclaw#82550 (comment)

Co-authored-by: Alex Knight <15041791+amknight@users.noreply.github.com>
markfietje pushed a commit to markfietje/openclaw that referenced this pull request May 20, 2026
Summary:
- The PR preserves Kimi Coding reasoning_content replay for OpenAI-compatible tool-call follow-up turns, extends replay model-id matching, adds Kimi wrapper/tests, and updates the changelog.
- Reproducibility: yes. at source level: current main drops or fails to synthesize reasoning_content for kimi- ... es a concrete Kimi 400 after tool-call history. I did not run a live Kimi request in this read-only review.

Automerge notes:
- No ClawSweeper repair was needed after automerge opt-in.

Validation:
- ClawSweeper review passed for head 9a4605ee3843e2fdb9dd8d61b39400e58871923a.
- Required merge gates passed before the squash merge.

Prepared head SHA: 9a4605ee3843e2fdb9dd8d61b39400e58871923a
Review: openclaw/openclaw#82550 (comment)

Co-authored-by: Alex Knight <15041791+amknight@users.noreply.github.com>
galiniliev pushed a commit to galiniliev/openclaw that referenced this pull request May 20, 2026
Summary:
- The PR preserves Kimi Coding reasoning_content replay for OpenAI-compatible tool-call follow-up turns, extends replay model-id matching, adds Kimi wrapper/tests, and updates the changelog.
- Reproducibility: yes. at source level: current main drops or fails to synthesize reasoning_content for kimi- ... es a concrete Kimi 400 after tool-call history. I did not run a live Kimi request in this read-only review.

Automerge notes:
- No ClawSweeper repair was needed after automerge opt-in.

Validation:
- ClawSweeper review passed for head 9a4605e.
- Required merge gates passed before the squash merge.

Prepared head SHA: 9a4605e
Review: openclaw#82550 (comment)

Co-authored-by: Alex Knight <15041791+amknight@users.noreply.github.com>
SebTardif pushed a commit to SebTardif/openclaw that referenced this pull request May 24, 2026
Summary:
- The PR preserves Kimi Coding reasoning_content replay for OpenAI-compatible tool-call follow-up turns, extends replay model-id matching, adds Kimi wrapper/tests, and updates the changelog.
- Reproducibility: yes. at source level: current main drops or fails to synthesize reasoning_content for kimi- ... es a concrete Kimi 400 after tool-call history. I did not run a live Kimi request in this read-only review.

Automerge notes:
- No ClawSweeper repair was needed after automerge opt-in.

Validation:
- ClawSweeper review passed for head 9a4605e.
- Required merge gates passed before the squash merge.

Prepared head SHA: 9a4605e
Review: openclaw#82550 (comment)

Co-authored-by: Alex Knight <15041791+amknight@users.noreply.github.com>
SebTardif pushed a commit to SebTardif/openclaw that referenced this pull request May 24, 2026
Summary:
- The PR preserves Kimi Coding reasoning_content replay for OpenAI-compatible tool-call follow-up turns, extends replay model-id matching, adds Kimi wrapper/tests, and updates the changelog.
- Reproducibility: yes. at source level: current main drops or fails to synthesize reasoning_content for kimi- ... es a concrete Kimi 400 after tool-call history. I did not run a live Kimi request in this read-only review.

Automerge notes:
- No ClawSweeper repair was needed after automerge opt-in.

Validation:
- ClawSweeper review passed for head 9a4605e.
- Required merge gates passed before the squash merge.

Prepared head SHA: 9a4605e
Review: openclaw#82550 (comment)

Co-authored-by: Alex Knight <15041791+amknight@users.noreply.github.com>
SebTardif pushed a commit to SebTardif/openclaw that referenced this pull request May 24, 2026
Summary:
- The PR preserves Kimi Coding reasoning_content replay for OpenAI-compatible tool-call follow-up turns, extends replay model-id matching, adds Kimi wrapper/tests, and updates the changelog.
- Reproducibility: yes. at source level: current main drops or fails to synthesize reasoning_content for kimi- ... es a concrete Kimi 400 after tool-call history. I did not run a live Kimi request in this read-only review.

Automerge notes:
- No ClawSweeper repair was needed after automerge opt-in.

Validation:
- ClawSweeper review passed for head 9a4605e.
- Required merge gates passed before the squash merge.

Prepared head SHA: 9a4605e
Review: openclaw#82550 (comment)

Co-authored-by: Alex Knight <15041791+amknight@users.noreply.github.com>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
Summary:
- The PR preserves Kimi Coding reasoning_content replay for OpenAI-compatible tool-call follow-up turns, extends replay model-id matching, adds Kimi wrapper/tests, and updates the changelog.
- Reproducibility: yes. at source level: current main drops or fails to synthesize reasoning_content for kimi- ... es a concrete Kimi 400 after tool-call history. I did not run a live Kimi request in this read-only review.

Automerge notes:
- No ClawSweeper repair was needed after automerge opt-in.

Validation:
- ClawSweeper review passed for head 9a4605e.
- Required merge gates passed before the squash merge.

Prepared head SHA: 9a4605e
Review: openclaw#82550 (comment)

Co-authored-by: Alex Knight <15041791+amknight@users.noreply.github.com>
galiniliev pushed a commit to galiniliev/openclaw that referenced this pull request May 25, 2026
Summary:
- The PR preserves Kimi Coding reasoning_content replay for OpenAI-compatible tool-call follow-up turns, extends replay model-id matching, adds Kimi wrapper/tests, and updates the changelog.
- Reproducibility: yes. at source level: current main drops or fails to synthesize reasoning_content for kimi- ... es a concrete Kimi 400 after tool-call history. I did not run a live Kimi request in this read-only review.

Automerge notes:
- No ClawSweeper repair was needed after automerge opt-in.

Validation:
- ClawSweeper review passed for head 9a4605e.
- Required merge gates passed before the squash merge.

Prepared head SHA: 9a4605e
Review: openclaw#82550 (comment)

Co-authored-by: Alex Knight <15041791+amknight@users.noreply.github.com>
SebTardif pushed a commit to SebTardif/openclaw that referenced this pull request May 26, 2026
Summary:
- The PR preserves Kimi Coding reasoning_content replay for OpenAI-compatible tool-call follow-up turns, extends replay model-id matching, adds Kimi wrapper/tests, and updates the changelog.
- Reproducibility: yes. at source level: current main drops or fails to synthesize reasoning_content for kimi- ... es a concrete Kimi 400 after tool-call history. I did not run a live Kimi request in this read-only review.

Automerge notes:
- No ClawSweeper repair was needed after automerge opt-in.

Validation:
- ClawSweeper review passed for head 9a4605e.
- Required merge gates passed before the squash merge.

Prepared head SHA: 9a4605e
Review: openclaw#82550 (comment)

Co-authored-by: Alex Knight <15041791+amknight@users.noreply.github.com>
SebTardif pushed a commit to SebTardif/openclaw that referenced this pull request May 26, 2026
Summary:
- The PR preserves Kimi Coding reasoning_content replay for OpenAI-compatible tool-call follow-up turns, extends replay model-id matching, adds Kimi wrapper/tests, and updates the changelog.
- Reproducibility: yes. at source level: current main drops or fails to synthesize reasoning_content for kimi- ... es a concrete Kimi 400 after tool-call history. I did not run a live Kimi request in this read-only review.

Automerge notes:
- No ClawSweeper repair was needed after automerge opt-in.

Validation:
- ClawSweeper review passed for head 9a4605e.
- Required merge gates passed before the squash merge.

Prepared head SHA: 9a4605e
Review: openclaw#82550 (comment)

Co-authored-by: Alex Knight <15041791+amknight@users.noreply.github.com>
SebTardif pushed a commit to SebTardif/openclaw that referenced this pull request May 26, 2026
Summary:
- The PR preserves Kimi Coding reasoning_content replay for OpenAI-compatible tool-call follow-up turns, extends replay model-id matching, adds Kimi wrapper/tests, and updates the changelog.
- Reproducibility: yes. at source level: current main drops or fails to synthesize reasoning_content for kimi- ... es a concrete Kimi 400 after tool-call history. I did not run a live Kimi request in this read-only review.

Automerge notes:
- No ClawSweeper repair was needed after automerge opt-in.

Validation:
- ClawSweeper review passed for head 9a4605e.
- Required merge gates passed before the squash merge.

Prepared head SHA: 9a4605e
Review: openclaw#82550 (comment)

Co-authored-by: Alex Knight <15041791+amknight@users.noreply.github.com>
qiaokuan1992 pushed a commit to qiaokuan1992/openclaw that referenced this pull request Jun 2, 2026
Summary:
- The PR preserves Kimi Coding reasoning_content replay for OpenAI-compatible tool-call follow-up turns, extends replay model-id matching, adds Kimi wrapper/tests, and updates the changelog.
- Reproducibility: yes. at source level: current main drops or fails to synthesize reasoning_content for kimi- ... es a concrete Kimi 400 after tool-call history. I did not run a live Kimi request in this read-only review.

Automerge notes:
- No ClawSweeper repair was needed after automerge opt-in.

Validation:
- ClawSweeper review passed for head 9a4605e.
- Required merge gates passed before the squash merge.

Prepared head SHA: 9a4605e
Review: openclaw#82550 (comment)

Co-authored-by: Alex Knight <15041791+amknight@users.noreply.github.com>
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
Summary:
- The PR preserves Kimi Coding reasoning_content replay for OpenAI-compatible tool-call follow-up turns, extends replay model-id matching, adds Kimi wrapper/tests, and updates the changelog.
- Reproducibility: yes. at source level: current main drops or fails to synthesize reasoning_content for kimi- ... es a concrete Kimi 400 after tool-call history. I did not run a live Kimi request in this read-only review.

Automerge notes:
- No ClawSweeper repair was needed after automerge opt-in.

Validation:
- ClawSweeper review passed for head 9a4605e.
- Required merge gates passed before the squash merge.

Prepared head SHA: 9a4605e
Review: openclaw#82550 (comment)

Co-authored-by: Alex Knight <15041791+amknight@users.noreply.github.com>
SYU8384 pushed a commit to SYU8384/openclaw that referenced this pull request Jun 3, 2026
Summary:
- The PR preserves Kimi Coding reasoning_content replay for OpenAI-compatible tool-call follow-up turns, extends replay model-id matching, adds Kimi wrapper/tests, and updates the changelog.
- Reproducibility: yes. at source level: current main drops or fails to synthesize reasoning_content for kimi- ... es a concrete Kimi 400 after tool-call history. I did not run a live Kimi request in this read-only review.

Automerge notes:
- No ClawSweeper repair was needed after automerge opt-in.

Validation:
- ClawSweeper review passed for head 9a4605e.
- Required merge gates passed before the squash merge.

Prepared head SHA: 9a4605e
Review: openclaw#82550 (comment)

Co-authored-by: Alex Knight <15041791+amknight@users.noreply.github.com>
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
Summary:
- The PR preserves Kimi Coding reasoning_content replay for OpenAI-compatible tool-call follow-up turns, extends replay model-id matching, adds Kimi wrapper/tests, and updates the changelog.
- Reproducibility: yes. at source level: current main drops or fails to synthesize reasoning_content for kimi- ... es a concrete Kimi 400 after tool-call history. I did not run a live Kimi request in this read-only review.

Automerge notes:
- No ClawSweeper repair was needed after automerge opt-in.

Validation:
- ClawSweeper review passed for head 9a4605e.
- Required merge gates passed before the squash merge.

Prepared head SHA: 9a4605e
Review: openclaw#82550 (comment)

Co-authored-by: Alex Knight <15041791+amknight@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling clawsweeper:automerge Maintainer opted this PR into bounded ClawSweeper-reviewed automerge extensions: kimi-coding maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kimi thinking mode fails on tool-call messages: reasoning_content missing in assistant message

1 participant