After auto compaction, the agent abandons the in-flight request and re-executes the session's earliest skill activation
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.)
Another compaction context-loss variant, this time hitting subagents (kimi-code 0.7.5, VS Code extension; subagent = coder type on a local OpenAI-compatible endpoint).
What we saw (3 times in one day, across 2 sessions on the same machine): a background subagent runs a long first turn (many file reads), auto-compaction fires (in one case twice), and the rebuilt context no longer contains the dispatch prompt — the only user message the subagent ever had. The subagent then accurately reports "the current turn contains no task, only system reminders" and idles out. Wire evidence: the dispatch prompt is present in the agent's wire.jsonl as the initial user message, but the post-compaction context left only system reminders.
Same root area as this issue (compaction handoff loses the actual task), but for subagents the dispatch prompt is the entire task, so losing it is total — the agent can't even "re-execute the earliest message" because nothing user-authored survives at all.
Workarounds that did NOT help: shorter task prompts, explicit "start immediately" preamble. What helped: re-dispatching a fresh subagent (until compaction hits it again), or moving the work to a model/endpoint with a larger effective context.
Happy to share sanitized wire.jsonl excerpts if useful.