provider.api_error: unload_tools rejected — "tool is not declared or has already been unloaded" — session unrecoverable
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- typescript
- Domain
- ai-infra-agents, cli
Research direction
Start by tracing how context compaction rebuilds request history and preserves dynamic_tool_schema messages, then follow how unload_tools directives are validated against provider tool state. The issue points to #5066 as related; compare its findings with a long session using MCP servers and dynamic tool loading. Done means compaction cannot leave unload directives inconsistent and the session can continue after compaction.
Written by the indexing model from the issue text.
Description
What version of Kimi Code is running?
2.8.0
What platform is your computer?
Linux (WSL2)
What model were you using?
Default Kimi model with dynamically_loaded_tools capability.
What issue are you seeing?
Every turn in the session fails with:
Error: [provider.api_error] unload_tools at message position 88:
tool "<mcp tool name>" is not declared or has already been unloaded
The request history contains an unload_tools directive that the provider-side load/unload state machine rejects. Once it appears, every subsequent request is rejected with the same error — the session cannot continue, only starting a new session helps.
Notably, dynamic tool loading was active even though tool-select is NOT enabled under [experimental], no MCP server has deferred: true, and no KIMI_CODE_EXPERIMENTAL* env vars are set.
Likely related to #5066 (compaction drops dynamic_tool_schema messages): if compaction rebuilds history while unload directives remain, the wire history can end up inconsistent with the provider-side state machine.
Steps to reproduce
- Long session with MCP servers, dynamic tool loading active.
- Context compaction occurs (auto-compaction in a long session).
- Next request fails with the error above; every retry fails identically.
Expected behavior
The client should keep load/unload directives consistent with the provider state machine (or rebuild them after compaction), and a session should never enter a state where every request is rejected.
Also reported via /feedback, Feedback ID 3611.
- Dominant language
- TypeScript
- Stars
- 8.3k
- Forks
- 1.4k
- Avg merge
- 12h 6m
- Merged PRs (30d)
- 596
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing 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.
More from MoonshotAI/kimi-code
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
MoonshotAI/kimi-code#5539 ·
Maintainers usually reply within 1 day
-
[Bug] Kimi RC workspace folder picker does not display symbolic link directoriesPossibly taken @markankamaransheogarat-sys claimed this 2 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
MoonshotAI/kimi-code#5296 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
MoonshotAI/kimi-code#5256 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
MoonshotAI/kimi-code#5062 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
MoonshotAI/kimi-code#5057 ·
Maintainers usually reply within 1 day
All issues in MoonshotAI/kimi-code
Similar issues
-
Add Alice&BotOpen
Difficulty 1/5 Under an hour Newbie friendliness 72/100
slavakurilyak/awesome-ai-agents#1048 ·
-
bot:ai-assisted component:faucet github_actions security status:untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
midnightntwrk/midnight-faucet-api#215 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
NanmiCoder/cc-haha#2034 · 1 comment ·
Maintainers usually reply within 1 day
-
mobile prio:low
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
digitalfabrik/entitlementcard#3324 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day