MoonshotAI / MoonshotAI/kimi-cli
Issue: Foreground subagents exhaust single API key rate limit, causing 429 errors and hangs
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 11.4k
- Forks
- 1.3k
- Avg merge
- 9h 47m
- Merged PRs (30d)
- 2
Description
What feature would you like to see?
Problem Description
When running multiple foreground subagents concurrently (e.g., 3–4 coder or explore subagents working on independent tasks), all subagents share the same API key as the root runtime. This leads to severe rate-limit contention:
- Rate limit exhaustion: A single
KIMI_API_KEYhas finite TPM/RPM quotas. With 3–4 subagents each making multi-step LLM calls, the quota is consumed almost instantly. - 429 errors and retries: Subsequent requests hit
429 Too Many Requests. Subagents either retry (wasting tokens) or hang waiting for quota recovery. - Poor user experience: From the user's perspective, subagents that should complete in seconds instead take minutes or fail silently. The shell UI shows subagents as "running" with no visible progress.
- No backend attribution: All requests appear in the Kimi console as
KimiCLI/1.44.0with no way to distinguish root agent calls from subagent calls, making it impossible to diagnose which subagent is consuming quota.
Reproduction Steps
- Configure a single API key via
/loginorKIMI_API_KEY. - Launch 3+ foreground subagents concurrently:
/coder "Analyze app.py" /coder "Review key pool design" /coder "Check test coverage" - Observe that:
- Subagent response latency increases dramatically after the first few LLM calls
429errors appear in logs (if debug mode is enabled)- Subagents may exceed the default timeout and get killed
Expected Behavior
- Each concurrent subagent should use a distinct API key when multiple keys are available
- The system should enforce a concurrency limit based on available key count to avoid exhausting all keys
- Subagent requests should carry a discernible User-Agent so backend monitoring can attribute quota consumption correctly
Environment
- Kimi CLI version: 1.44.0
- OS: macOS / Linux
- Python: 3.14
- Provider: kimi (Kimi Code platform)
Additional Context
- The root agent itself also consumes the same key for compaction, user replies, etc. With subagents added, the contention becomes even worse.
- There is currently no concurrency limit for foreground subagents beyond the hardcoded background task limit, meaning a user can accidentally spawn unlimited subagents and DDoS their own API key.
- The timeout description in the Agent tool schema claims "Foreground: no default timeout (runs until completion)", which means a hung subagent (due to rate-limit backoff) will never be killed.
Additional information
No response
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 tracing foreground subagent scheduling, API-key handling, and the Agent tool timeout schema; inspect how the existing background task limit is applied. Done means concurrent subagents use distinct available keys, respect a key-based concurrency limit, expose a discernible User-Agent, and do not hang indefinitely under rate limiting.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend-api-design, cli
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100