Commit e70433a
committed
fix(sessions): drop dead-end orphan entries when compaction retry forks parentId chain
Compaction retry can write a duplicate compaction event under the same
parentId. One side becomes a dead-end with no descendants while the
other carries the rest of the chain, so any downstream consumer that
reconstructs causal order by walking parentId breaks at the fork.
Extend repairSessionFileIfNeeded to detect this on load: when there are
two or more compaction siblings sharing one parentId AND exactly one of
those compaction siblings has a non-empty subtree, drop the dead-end
compaction loser(s). Generic non-compaction entries are NEVER dropped:
a session JSONL is a tree, so a legitimate side branch can naturally be
a leaf next to a continued sibling, and only the compaction-retry path
is known to produce the duplicate-sibling-with-shared-parentId shape
this repair targets. Two-branch transcripts where multiple compaction
siblings carry real subtrees are also left alone, and so are
compaction-sibling groups where no candidate has won yet.
Adds 9 regression tests including the canonical compaction-retry
pattern, the #79635 [P2] regression that pins the generic-leaf
carve-out, a mixed-sibling case (one compaction loser dropped while a
non-compaction sibling under the same parent is preserved), nested
compaction forks, deliberate two-branch transcripts, no-winner
compaction candidate groups, linear transcripts, and legacy entries
without parentId.
Fixes #488101 parent 0e1ea08 commit e70433a
3 files changed
Lines changed: 661 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
| 209 | + | |
209 | 210 | | |
210 | 211 | | |
211 | 212 | | |
| |||
0 commit comments