Repository navigation
feat(agent-core): keep head and tail of user messages during compaction - #1313
Conversation
Compaction used to keep only the most recent 20k tokens of real user input, so the original task statement was the first thing to vanish in long sessions. Now, when the user-message pool fits the 20k budget it is still kept whole; when it overflows, the oldest 2k tokens and the most recent 18k are kept instead, with an elision marker between the two segments telling the model what was omitted and that the summary covers it. The summary prefix and the default system prompt describe the new shape as well. The new `keptHeadUserMessageCount` record field keeps restore and the wire-transcript folded length consistent: records without it (written by older versions) restore with the original tail-only selection that produced them, and the vis model-mode projection mirrors the same head/marker/tail rebuild.
|
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 76ee835a76
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| export function buildCompactionElisionText(omittedTokens: number): string { | ||
| return [ | ||
| '<system-reminder>', | ||
| `Some of this conversation's user messages were omitted here during compaction: the messages above this note are the oldest user input, the messages below are the most recent, and roughly ${String(omittedTokens)} tokens in between were dropped. The omitted content is covered by the compaction summary at the end of the conversation.`, |
There was a problem hiding this comment.
Avoid claiming overflow-dropped content was summarized
When the compaction request itself overflows, FullCompaction.compactionRound trims historyForModel and records droppedCount, and those trimmed messages are explicitly not covered by the generated summary. In that scenario, the new head/tail marker can replace user content that the summarizer never saw, but this text tells the next model the omitted content is covered by the summary, which can make it trust a summary blind spot as complete; the same absolute claim in the summary prefix should be qualified or driven by droppedCount.
Useful? React with 👍 / 👎.
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…on (MoonshotAI#1313) * feat(agent-core): keep head and tail of user messages during compaction Compaction used to keep only the most recent 20k tokens of real user input, so the original task statement was the first thing to vanish in long sessions. Now, when the user-message pool fits the 20k budget it is still kept whole; when it overflows, the oldest 2k tokens and the most recent 18k are kept instead, with an elision marker between the two segments telling the model what was omitted and that the summary covers it. The summary prefix and the default system prompt describe the new shape as well. The new `keptHeadUserMessageCount` record field keeps restore and the wire-transcript folded length consistent: records without it (written by older versions) restore with the original tail-only selection that produced them, and the vis model-mode projection mirrors the same head/marker/tail rebuild. * style(agent-core): drop redundant spread over slice in head selection
What
Changes the compaction retention strategy for real user messages:
COMPACT_USER_MESSAGE_HEAD_TOKENS) plus the most recent 18k. The head can extend into the cut-off beginning of the message whose end anchors the tail, so a single oversized message keeps both its start and its most recent part.The model is told about this in three places:
<system-reminder>, origin{kind: 'injection', variant: 'compaction_elision'}) inserted between the head and tail segments, stating what sits above/below and roughly how many tokens were omitted. Injection origin means the next compaction drops it (markers never stack), undo skips it, and the UI transcript never shows it.Boundary semantics
The tail boundary message is now truncated keeping its end (the more recent part), matching "most recent 18k" at token level; the head boundary keeps its beginning. Previously the boundary message always kept its beginning.
Compatibility
New record field
keptHeadUserMessageCount(agent-coreCompactionResult, protocol type + zod schema):foldedLength = keptUserMessageCount + 2instead of+ 1.apps/vismodel-mode projection mirrors the same head/marker/tail rebuild.Tests
Failing tests were written first, then the implementation. New coverage: selection unit tests (split, boundary directions, surrogate pairs, default budgets), marker text, transcript folded length, and integration tests (split shape + resume round-trip, no marker stacking across repeated compactions, no marker under budget, legacy-record restore). Full suites pass: agent-core 3418, protocol 503, vis-server 141, repo-wide typecheck clean. Snapshot/token-count updates in
full.test.tsare due to the longer summary prefix and were reviewed line by line.