MoonshotAI / MoonshotAI/kimi-code
Feature request: Automatic subagent fallback across the model pool on provider errors (402/429)
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.5k
- Forks
- 1.2k
- Avg merge
- 11h 53m
- Merged PRs (30d)
- 350
Description
Feature request: Automatic subagent fallback across the model pool on provider errors (402/429)
Context
Kimi Code CLI resolves subagent models from the [secondary_model] section of ~/.kimi-code/config.toml. On 2026-08-29, 4 coder subagent launches died at mission start with provider account/quota errors and no fallback:
| Resolved model | Provider error | Outcome |
|---|---|---|
deepseek/deepseek-v4-pro |
"402 Insufficient Balance" | agent killed, no fallback |
zai/glm-5.2 |
"429 Insufficient balance or no resource package" | agent killed, no fallback |
deepseek/deepseek-v4-flash (default) |
"402" | agent killed, no fallback (×2) |
Each failure killed the agent without a message naming which alias/provider had been resolved. Root cause observed the same day: [secondary_model].default_model followed neither the user's /model selection nor the main default_model — the main session had been switched to zhipuai-coding-plan/glm-5.3-flash, while the subagent UI still showed "DeepSeek V4 Flash".
Problem or Gap
- No fallback chain: a 402/429 from the resolved provider kills the subagent instead of trying the next model in
[secondary_model.models]. - Opaque failure: the error message names neither the configured alias nor the resolved provider, making diagnosis a manual config inspection.
- Config drift:
[secondary_model].default_modelis decoupled from the main model selection and silently goes stale.
Proposal
- Automatic fallback chain: on a 402/429 from the resolved provider, retry on the next available model in
[secondary_model.models], with a visible UI trace, e.g.agent-3: deepseek-v4-flash unavailable (402) → falling back to glm-5.3-flash. secondary_model.follow_main_model = true: optional flag making the subagent default model follow the main session model (the one set via/model).- Explicit failure naming: when no fallback is possible, the subagent failure message names the alias AND the resolved provider for each attempt.
Impact
- Resilience: provider account/quota outages no longer kill subagents at mission start.
- Diagnosability: failures name what was attempted and what failed.
- Config sanity: subagent model selection follows the user's actual model choice instead of a stale config entry.
Acceptance criteria
- A 402/429 on the resolved model triggers a fallback to the next pool model without user intervention; the subagent starts on the replacement model.
- The fallback leaves a visible UI trace naming the rejected model (with error code) and the replacement.
- With
follow_main_model = true, subagents start on the current main-session model after/modelis changed. - If the whole pool is exhausted, the failure message lists alias + provider + error for each attempt.
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 at the subagent model resolution path driven by ~/.kimi-code/config.toml's [secondary_model] section and trace provider-error handling for 402/429. Compare that path with /model changes; done means fallback attempts, visible traces, follow_main_model behavior, and exhausted-pool messages satisfy the four acceptance criteria.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- ai-infra-agents, cli
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100