MoonshotAI / MoonshotAI/kimi-code
After auto compaction, the agent abandons the in-flight request and re-executes the session's earliest skill activation
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.5k
- Forks
- 1.2k
- Avg merge
- 11h 53m
- Merged PRs (30d)
- 350
Description
What happened
In a long session (many hours, many completed tasks), auto compaction fired mid-turn while the agent was answering the user's latest question. Right after compaction completed, the agent stopped working on that question and started executing the session's very first message instead — a /skill activation from hours earlier whose task had long been finished. The user had to cancel the run.
From the session's wire.jsonl:
- The turn for the latest question ran 2 steps normally (answer drafted, an edit applied;
finishReason: tool_use, turn not finished). - At the next step boundary, auto compaction triggered (
full_compaction.begin, sourceauto) and blocked the turn. - Compaction rebuilt the context to 20 kept user messages + 1 summary; all assistant/tool messages — including the in-flight answer — were dropped. A
permission_modereminder was re-injected. - The very next step's thinking reads: "The user activated the skill with a specific request…" and the agent began executing that stale skill instruction.
Why it happens
Three design properties combine:
- The earliest message is kept verbatim on purpose. Compaction keeps real user input (including user-slash
skill_activationenvelopes) within a token budget, and the head segment deliberately preserves the oldest messages because "the earliest prompts usually carry the original task statement" (packages/agent-core/src/agent/compaction/handoff.ts). In a multi-task session that assumption no longer holds: the head message here was a ~26k-char skill activation envelope beginning withUser activated the skill "…". Follow the loaded skill instructions.— after truncation, a dangling mandate with no visible answer. - Kept user messages are stripped of their answers. All assistant messages are dropped, so a long-completed request reads exactly like a pending one. The summary covered only recent work and never stated that the first message's task was completed, so the model scanned the kept messages, found everything recent marked done, and grabbed the one instruction that looked unanswered.
- No continuation anchor after mid-turn compaction. The turn simply continues on the rebuilt context (
packages/agent-core/src/loop/turn-step.ts); nothing re-states "you were answering question X and have not finished". The only guidance is the summary-prefix prose.
Expected behavior
After mid-turn compaction the agent should resume the in-flight request, not reinterpret the oldest preserved user message as its current task.
Suggested direction
Have the compaction summary explicitly account for every earlier request still visible among the kept user messages — done / abandoned / superseded / still open — and have the summary prefix tell the model not to restart requests the summary marks as completed. (A stricter variant would narrow what skill_activation envelopes contribute to the kept set, but that changes the rebuilt context shape and is more invasive.)
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 packages/agent-core/src/agent/compaction/handoff.ts and packages/agent-core/src/loop/turn-step.ts, then inspect the described wire.jsonl sequence to understand the mid-turn context rebuild. Trace how kept user messages, summaries, and the continuation state are assembled. Done means an auto-compacted turn resumes its in-flight request instead of re-executing a completed skill activation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- ai, cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 66/100