openclaw - 💡(How to fix) Fix `wrapStreamRepairMalformedToolCallArguments` clears valid tool call arguments for Moonshot/Kimi provider

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Root Cause

Extensive testing confirms the issue is NOT in Kimi's API. Direct API calls (both streaming and non-streaming) return correct tool calls with valid arguments and tool names.

The issue is in OpenClaw's streaming pipeline:

  1. pi-ai transport layer correctly parses Kimi's SSE chunks and assembles valid tool_calls with correct function.name and function.arguments
  2. wrapStreamRepairMalformedToolCallArguments (a repair middleware) incorrectly determines that the tool calls need "repair"
  3. This repair calls clearToolCallArgumentsInMessage, which wipes the already-correct arguments to {}
  4. Subsequently, normalizeToolCallNameForDispatch fails to infer the tool name from empty arguments, producing unknown

Fix Action

Workaround

None currently available without modifying OpenClaw source code. A monkey-patch script that excludes the Moonshot provider from the repair layer has been tested and confirmed to work.

RAW_BUFFERClick to expand / collapse

Bug Description

When using the Moonshot (Kimi K2.6) provider with streaming enabled, tool call arguments are systematically cleared to {} by the internal wrapStreamRepairMalformedToolCallArguments repair layer, despite Kimi's API returning correctly formatted tool calls at the transport level.

Additionally, normalizeToolCallNameForDispatch produces unknown tool names when the repair layer has already cleared the arguments.

Environment

  • OpenClaw version: 2026.5.20 (e510042)
  • Provider: Moonshot (Kimi K2.6, via kimi/kimi-code)
  • Mode: Streaming (SSE) + reasoning enabled
  • Node.js: v22.22.0
  • OS: Linux (WSL2)

Root Cause Analysis

Extensive testing confirms the issue is NOT in Kimi's API. Direct API calls (both streaming and non-streaming) return correct tool calls with valid arguments and tool names.

The issue is in OpenClaw's streaming pipeline:

  1. pi-ai transport layer correctly parses Kimi's SSE chunks and assembles valid tool_calls with correct function.name and function.arguments
  2. wrapStreamRepairMalformedToolCallArguments (a repair middleware) incorrectly determines that the tool calls need "repair"
  3. This repair calls clearToolCallArgumentsInMessage, which wipes the already-correct arguments to {}
  4. Subsequently, normalizeToolCallNameForDispatch fails to infer the tool name from empty arguments, producing unknown

Test Results

TestMethodStreamReasoningResult
1Direct Kimi API❌ No❌ No✅ Correct args
2Direct Kimi API❌ No✅ Yes✅ Correct args
3Direct Kimi API✅ Yes❌ No✅ Correct args
4Direct Kimi API✅ Yes✅ Yes✅ Correct args
5Via OpenClaw✅ Yes✅ Yes❌ args={}, name=unknown

All 4 direct API tests pass. Only when routed through OpenClaw's streaming pipeline do arguments get cleared.

Test Script

Available at: /tmp/kimi_tool_final_test.py

Impact

  • Kimi K2.6 is unusable for tool-calling tasks through OpenClaw
  • Fallback to other models works, but Kimi has unique capabilities (e.g., S1 scoring in quantitative trading strategies) that other models cannot replicate
  • 118/118 tool calls failed in production over the past 24 hours

Suggested Fix

Two options (either would work):

Option A (Minimal): In wrapStreamRepairMalformedToolCallArguments, skip the repair logic for Moonshot/Kimi provider (since their tool calls are already valid at the transport level).

Option B (Fundamental): In clearToolCallArgumentsInMessage, check whether arguments are already valid non-empty JSON before clearing them. Only clear truly malformed arguments.

Workaround

None currently available without modifying OpenClaw source code. A monkey-patch script that excludes the Moonshot provider from the repair layer has been tested and confirmed to work.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix `wrapStreamRepairMalformedToolCallArguments` clears valid tool call arguments for Moonshot/Kimi provider