fix(core): stop duplicating the cut entry into both head and recent during compaction - #14055
Open
hobostay wants to merge 1 commit into
Open
fix(core): stop duplicating the cut entry into both head and recent during compaction#14055hobostay wants to merge 1 commit into
hobostay wants to merge 1 commit into
Conversation
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge The off-by-one fix in Files Reviewed (3 files)
Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0 Review guidance: REVIEW.md from base branch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes an off-by-one in
SessionCompaction.select()(packages/core/src/session/compaction.ts) that duplicated the partially-split conversation entry into both thehead(summarized away) andrecent(kept) outputs of auto-compaction.Why
When the keep budget overflows mid-entry, the entry at
indexis split into a prefix (intended forhead) and a suffix (intended forrecent). Butheadwas built withconversation.slice(0, split)wheresplit = index + 1, so the full entry was included inheadin addition to its prefix — and its suffix therefore appeared in both outputs. The summary prompt sent to the model contained duplicated content with an inflated token count, which also makes theToken.estimate(summaryPrompt) > context - summaryOutputguard more likely to abort auto-compaction entirely, leaving the session stuck on context-overflow errors.The fix keeps separate cut points:
headtakes the entries before the split index plus the prefix;recenttakes the suffix plus the entries after it.Testing
Added a regression test in
packages/core/test/session-compaction.test.tsthat constructs four fixed-size entries with a budget that splits the third one. It fails on the previous logic (headcontains the cut entry's tail) and passes with the fix.bun test(packages/core, 1325 pass) andbun run typecheckare green; the single failure in the full suite (ProjectCopy > requires force to remove a dirty git worktree) reproduces on unmodifiedmainon this machine and is unrelated.