fix(session): remap compaction tail_start_id when forking#24898
Merged
rekram1-node merged 3 commits intoanomalyco:devfrom Apr 29, 2026
Merged
fix(session): remap compaction tail_start_id when forking#24898rekram1-node merged 3 commits intoanomalyco:devfrom
rekram1-node merged 3 commits intoanomalyco:devfrom
Conversation
Closes anomalyco#24700 Made-with: Cursor
b54f298 to
a40622f
Compare
Collaborator
|
/review |
Contributor
|
lgtm |
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.
Issue for this PR
Closes #24700
Type of change
What does this PR do?
Fixes
Session.forknot remappingCompactionPart.tail_start_id, which caused forked sessions to include all pre-compaction messages in context and inflate session length.Problem
Session.forkcopies messages and remaps each message’s id and assistantparentIDviaidMap, buttail_start_idon compaction parts was left as the parent session’s message id.filterCompacted(message-v2.ts) usestail_start_idas the retention boundary: it walks older messages until it finds one whose id equalstail_start_id. In a fork, every message id is new, so the oldtail_start_idnever matches; the loop does not stop where compaction intended, and pre-compaction history leaks into the prompt (observed as much larger context /context_length_exceededon the next request).Regression
Introduced when
tail_start_idand the correspondingfilterCompactedbehavior were added in commit6f5a3d30f(“keep recent turns during session compaction”, 2026-04-10).Session.forkwas not updated to remap that field alongsideparentID.Fix
When cloning parts, after
...part, overridetail_start_idfor compaction parts using the sameidMap:If the tail message was not copied (e.g. partial fork),
idMap.getreturnsundefined, clearing the stale reference instead of pointing at a non-existent id.How did you verify your code works?
packages/opencode, runbun test test/session/messages-pagination.test.ts -t "fork remaps compaction"(adds test
fork remaps compaction tail_start_id for filterCompacted).Screenshots / recordings
Checklist