MoonshotAI / MoonshotAI/kimi-cli
Background multi-agent runs can stall the CLI and cascade into provider timeouts / event-loop errors
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 11.4k
- Forks
- 1.3k
- Avg merge
- 9h 47m
- Merged PRs (30d)
- 2
Description
Title: Background multi-agent runs can stall the CLI and cascade into provider timeouts / event-loop errors
What version of Kimi Code CLI is running?
Source checkout on main at commit a8f09bce1570fc76092dfba018bedc2429cba2af
pyproject.toml version: 1.30.0
Which open platform/subscription were you using?
Please fill in the actual /login or /setup target used in your session.
Which model were you using?
Please fill in the model shown in the status bar during reproduction.
What platform is your computer?
Microsoft Windows NT 10.0.26100.0 x64
What issue are you seeing?
When many agents are launched in a short period, the CLI becomes noticeably sluggish. After that, repeated provider failures begin to appear, such as:
LLM provider error: Connection error.LLM provider error: Request timed out.
Background task failures then appear in bursts, for example:
Background task failed: 创建SF-001群聊模式详解文档Background task failed: 创建ER-002重试策略配置指南Background task failed: 创建NI-001 Rust助手引擎配置指南Background task failed: 创建HF-004角色分割系统配置Background task failed: 创建SF-003 Canvas协同编辑文档Background task failed: 创建TP-002高级指令完全指南
In some runs, the TUI eventually ends with:
Unhandled exception in event loop:
Exception None
Press ENTER to continue...
Reducing concurrency to 4 makes the CLI noticeably more stable, but bursty multi-agent runs can still feel laggy before terminal failures happen.
What steps can reproduce the bug?
- Start an interactive Kimi CLI session on Windows.
- Launch multiple independent background agents in a short time window.
- Let them stream output concurrently while some of them hit provider retries or timeouts.
- Observe the shell becoming sluggish, followed by
Connection error/Request timed out. - In some cases, the prompt_toolkit UI ends with
Unhandled exception in event loop.
A practical repro pattern is bulk documentation or batch task generation where many agent jobs are started or restarted in bursts.
What is the expected behavior?
- Background agents should remain responsive under bursty multi-agent workloads.
- Provider timeouts should not cascade simply because multiple agents are producing output concurrently.
- The shell/TUI event loop should not crash with
Unhandled exception in event loop. - Lowering concurrency may improve throughput stability, but the CLI should not become visibly sluggish even before the hard task limit is reached.
Additional information
This does not look like a missing concurrency limit.
From code inspection:
src/kimi_cli/config.pysetsmax_running_tasks = 4by default.src/kimi_cli/background/manager.pyenforces that limit before creating background agent tasks.src/kimi_cli/background/agent_runner.pywrites background-agent wire output continuously.src/kimi_cli/subagents/output.pycurrently appends transcript output synchronously per message and tee-writes to task output logs.src/kimi_cli/notifications/notifier.pypolls every second, and shell mode wires that poller tobackground_tasks.reconcile().
A plausible explanation is:
- bursty background-agent output increases synchronous local I/O and task reconciliation pressure;
- the event loop becomes sluggish;
- provider/network timeouts become more likely;
- the shell eventually destabilizes and may surface a prompt_toolkit event-loop error.
This is a code-level hypothesis, not a confirmed fix.
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 with src/kimi_cli/background/agent_runner.py and src/kimi_cli/subagents/output.py, then trace reconciliation from src/kimi_cli/notifications/notifier.py and src/kimi_cli/background/manager.py. Reproduce the bursty background-agent workload on Windows with concurrency set to 4 and observe local I/O, task reconciliation, provider failures, and TUI behavior. Done means bursty runs remain responsive without cascading timeouts or an unhandled event-loop error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100