[Bug] Compaction forgets dynamically loaded (select_tools) MCP tools
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 57/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- typescript
- Área
- backend-api-design
Línea de trabajo
Read packages/agent-core-v2/src/agent/contextMemory/compactionHandoff.ts and the dynamic tool tracking in packages/agent-core-v2/src/agent/toolSelect/dynamicTools.ts. Start with the buildContextCompactionShape behavior and the reproduction described in the issue. Add or locate a regression test that checks collectLoadedDynamicTools after compaction; done means previously loaded tools and their announcement remain available in the rebuilt context.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
What version of Kimi Code is running?
2.6.3 (source main snapshot, 2026-11-18). Confirmed by reading the compaction and tool-selection code.
Which open platform/subscription were you using?
None involved (code-level audit).
Which model were you using?
A model with dynamically_loaded_tools capability, with at least one deferred MCP server configured.
What platform is your computer?
Windows 11 x64.
What issue are you seeing?
After a full compaction, tools that were loaded through select_tools are forgotten, even though they were active before the compaction.
How the two sides work:
- Loading a deferred tool writes a system message with origin
{ kind: 'injection', variant: 'dynamic_tool_schema' }(packages/agent-core-v2/src/agent/toolSelect/dynamicTools.ts:9). - The tool-selection service derives the currently loaded tools only from history:
requestTools()(packages/agent-core-v2/src/agent/toolSelect/toolSelectService.ts:153-172) andshapeToolsForDisclosure()(:470-491) both callcollectLoadedDynamicTools(messages)(dynamicTools.ts:109-127), which scans for those system messages. - The compaction rebuild (
packages/agent-core-v2/src/agent/contextMemory/compactionHandoff.ts:126-131) keeps only: user messages selected by the head/tail policy, the summary, the continuation anchor, and injections appended aftercompactedCount. System messages are not kept, andappendedInjectionsonly covers messages after the compaction snapshot, so everydynamic_tool_schemamessage is dropped.
After compaction, collectLoadedDynamicTools(history) returns an empty map. For deferred tools this means:
requestTools()no longer adds the previously loaded tools to the request.shapeToolsForDisclosure()no longer marks them as loaded.- The model has to call
select_toolsagain to re-load tools it already loaded, and may make tool calls that were valid moments earlier.
The loadable-tools announcement (isLoadableToolsAnnouncement) lives in the same history-based path and is dropped too.
What steps can reproduce the bug?
- Configure an MCP server with deferred tools and use a model with the
dynamically_loaded_toolscapability. - Load one of those tools via
select_toolsand verify it can be called. - Run
/compact(or let auto-compaction run). - Inspect the next request: the loaded tool is gone from
tools[], and the model must re-runselect_tools. - In a unit test: build a context containing a
role: 'system'message withorigin: { kind: 'injection', variant: 'dynamic_tool_schema' }, applybuildContextCompactionShape, and assert thatcollectLoadedDynamicTools(compacted.messages)is non-empty (it currently returns an empty map).
What is the expected behavior?
Tools that were loaded before compaction should remain loaded after compaction. Either the dynamic_tool_schema messages (and the announcement) should be carried into the rebuilt history, or the loaded-tool set should live in a state that compaction does not reset.
Additional information
Suggested fix: in buildContextCompactionShape, carry forward the tool-selection system/injection messages that describe loaded dynamic tools (they are small compared with the summary and are behavior, not history), or teach createCompactionSummaryMessage/the continuation message to re-emit them from tool-selection state. A regression test would pin collectLoadedDynamicTools across a compaction round trip.
Related but distinct: #4389 described the compaction request losing the prompt cache because it strips the announcement; this issue is about the rebuilt context losing loaded tools.
Contribution
- I am willing to submit a PR for this bug fix myself (please wait for maintainer approval in this issue first)
- Lenguaje dominante
- TypeScript
- Estrellas
- 8.3k
- Forks
- 1.4k
- Merge medio
- 12 h 6 min
- PR fusionados (30 d)
- 596
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de MoonshotAI/kimi-code
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
MoonshotAI/kimi-code#5539 ·
Los mantenedores suelen responder en 1 día
-
[Bug] Kimi RC workspace folder picker does not display symbolic link directoriesPosiblemente ocupada @markankamaransheogarat-sys la tomó hace 2 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
MoonshotAI/kimi-code#5296 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
MoonshotAI/kimi-code#5256 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
MoonshotAI/kimi-code#5062 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
MoonshotAI/kimi-code#5057 ·
Los mantenedores suelen responder en 1 día
Todos los issues de MoonshotAI/kimi-code
Issues similares
-
Add Alice&BotAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
slavakurilyak/awesome-ai-agents#1048 ·
-
bot:ai-assisted component:faucet github_actions security status:untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
midnightntwrk/midnight-faucet-api#215 ·
Los mantenedores suelen responder en 1 día
-
[功能] 手机端命令执行显示 AI 动作描述Abiertoenhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
NanmiCoder/cc-haha#2034 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
mobile prio:low
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
digitalfabrik/entitlementcard#3324 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Los mantenedores suelen responder en 1 día