MoonshotAI / MoonshotAI/kimi-code
User message appended during compaction is buried before the summary while the continuation anchor points at older work
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.5k
- Forks
- 1.2k
- Avg merge
- 11h 53m
- Merged PRs (30d)
- 350
Description
Background
#3537 adds a continuation anchor after the compaction summary ("Context compaction is complete — continue the work that was in progress when it began."). Codex review on that PR flagged a race that was verified against the project's own test (keeps messages appended while compacting an unchanged prefix in packages/agent-core-v2/test/agent/fullCompaction/fullCompaction.test.ts).
Problem
When the user appends a message while compaction is generating its summary, historySafeToCompact accepts it (unchanged prefix + real user input) and the rebuilt context becomes:
user: old kept messages...
user: "new user while compacting" <- appended during compaction, lands here
user: [compaction summary] <- summarizer never saw the new message
user: [continuation anchor] <- "continue the work that was in progress when it began"
The last message directs the model to resume the work that was in progress when compaction began, but the user's newest intent arrived after that point. The fresh request is neither covered by the summary nor anchored — it sits buried before the summary while the final slot points at older work. Before #3537 the newest slot was the summary itself (content, not a resume directive), so the anchor sharpens a pre-existing positioning gap into an explicit misdirection for this corner.
The window is narrow (the user must send input during summary generation) and the new message is preserved verbatim, so impact is bounded — hence deferred from #3537.
Directions
- Prompt layer: make the anchor target the latest preserved user message instead of the work in progress at begin, e.g. "the latest preserved user message above is the current request; continue any work it left in progress rather than starting over." Positional targeting is race-robust because the kept set preserves chronological order, so its last message is always the newest genuine input.
- Harness layer: place user messages appended after compaction begin past the handoff (after summary + anchor) in the rebuilt shape. Semantically cleanest but changes kept-set accounting (
keptUserMessageCount, fold parity).
Related: #2680, #3487, #3537 (codex review comment: https://github.com/MoonshotAI/kimi-code/pull/3537#discussion_r3947252547)
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-v2/test/agent/fullCompaction/fullCompaction.test.ts, especially “keeps messages appended while compacting an unchanged prefix,” then trace the compaction prompt and rebuilt-context harness it exercises. Compare the prompt-layer and harness-layer directions, and verify with tests that input appended during summary generation is correctly targeted after compaction without breaking kept-message accounting.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- ai, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100