MoonshotAI / MoonshotAI/kimi-cli
kimi-code-worker hangs on Shell tool via WebSocket API
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 11.4k
- Forks
- 1.3k
- Avg merge
- 9h 47m
- Merged PRs (30d)
- 2
Description
Bug Report: kimi-code-worker hangs on Shell tool via WebSocket API
Repository: MoonshotAI/kimi-cli
Version: kimi-cli 1.44.0
Environment: Linux, Python 3.12/3.13, kimi web --host 127.0.0.1 --port 5494
Summary
When using the WebSocket API (kimi web), kimi-code-worker hangs indefinitely after receiving a Shell tool call. The worker remains in busy state with 0% CPU and never returns a ToolResult, causing the session to stall forever.
Steps to Reproduce
-
Start
kimi web:kimi web --host 127.0.0.1 --port 5494 -
Create a session via REST:
curl -X POST http://127.0.0.1:5494/api/sessions/ \ -H "Content-Type: application/json" \ -d '{"work_dir": "/path/to/project", "create_dir": false}' -
Connect to the session via WebSocket and send a prompt that triggers a
Shelltool call:"what is my IP address?"(or in Russian:
"скажи ip своего хоста") -
Observe the WebSocket event stream.
Expected Behavior
ToolCallis received.- Worker executes the
Shellcommand. ToolResultis returned with command output.TurnEndis sent.- Session completes successfully.
Actual Behavior
ToolCall(orToolCallPartstreaming fragments) is received.StatusUpdatemay follow.- No
ToolResultis ever returned. - Worker process remains in
S (sleeping)state with 0% CPU. - Session status stays
busyindefinitely. kimi.logshows noTool Shell completedentry for this session.
Observations
-
Commands themselves are not the issue:
hostname -Iandcurl -s --max-time 5 ifconfig.meexecute instantly when run manually in the same shell.
-
Shell tool works in direct CLI mode:
- When running
kimidirectly in the terminal (not viakimi web), theShelltool executes correctly for commands likeruff check,pytest,systemctl, etc.
- When running
-
Streaming tool calls:
- In the WebSocket mode, we observed
ToolCallPartevents (streaming fragments of a tool call) being delivered before the fullToolCall. The worker may not handle streaming tool calls correctly.
- In the WebSocket mode, we observed
-
Parallel tool calls:
- In another reproduction, the LLM returned two consecutive
ToolCallevents (parallel calls). The worker also hung in that scenario.
- In another reproduction, the LLM returned two consecutive
-
Process state:
kimi-code-workerPID showsSlstate, 0% CPU, no child processes.straceshows onlyepoll_waitloops — the worker is idle, not blocked on I/O.
Wire Protocol Evidence
Hung session (WebSocket):
{"type": "ToolCall", "payload": {"type": "function", "id": "tool_xxx", "function": {"name": "Shell", "arguments": "{\"command\": \"hostname -I\"}"}}}
{"type": "ToolCall", "payload": {"type": "function", "id": "tool_yyy", "function": {"name": "Shell", "arguments": "{\"command\": \"curl -s ifconfig.me\"}"}}}
// ... silence — no ToolResult, no TurnEnd
Working session (direct CLI):
{"type": "ToolCall", "payload": {"type": "function", "id": "tool_zzz", "function": {"name": "Shell", "arguments": "{\"command\": \"ruff check .\"}"}}}
{"type": "ToolResult", "payload": {"tool_call_id": "tool_zzz", "return_value": {"is_error": false, "output": "All checks passed!\n"}}}
Hypothesis
The kimi-code-worker has a bug in its WebSocket event loop when handling:
- Streaming tool calls (
ToolCallPart), or - Parallel/batched
ToolCallevents
The worker receives the tool call(s) but fails to dispatch them to the tool execution layer, leaving the session stuck in busy state.
Impact
Any WebSocket client (including third-party integrations like Telegram bots) that relies on kimi web will experience permanent hangs whenever the LLM decides to invoke the Shell tool for certain prompts.
Suggested Fix / Workaround
- Ensure
ToolCallPartstreaming fragments are correctly buffered and assembled into a completeToolCallbefore execution. - Verify that parallel
ToolCallevents are properly queued or executed without deadlock. - Consider adding a watchdog/timeout inside
kimi-code-workerto abort stuck tool executions.
Reported by a downstream integrator using kimi web as a backend for a Telegram bot gateway.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the hang with kimi web and the WebSocket flow described, then trace kimi-code-worker around ToolCallPart buffering and parallel ToolCall dispatch. Compare the WebSocket event stream with the working direct CLI behavior. Done means Shell calls produce ToolResult events and the session sends TurnEnd instead of remaining busy.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend, cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100