Repository navigation
refactor(session): stop excerpting the same tail turn twice in turnCost - #1407
Merged
Merged
Conversation
Contributor
|
No changes needed from you. A maintainer will review this pull request. |
turnCost excerpted the same tail turn twice per pick: once directly and once through excerptedTurnTokens, which re-ran excerptTailTurn. The closure token estimate excerpted picked turns a third time. Cache the first excerpt per turn in selectTail and reuse it for the closure estimate, turnCost's token count, and the emitted live copies. Adds a test seam counter (excerptTailTurnCallCount) and a proof test pinning one excerptTailTurn call per tail turn with identical values.
TheGreatAxios
force-pushed
the
cl-10535-excerpt-once
branch
from
October 12, 2026 05:43
38f9cad to
ea7a9f4
Compare
TheGreatAxios
commented
Oct 12, 2026
TheGreatAxios
left a comment
Collaborator
Author
There was a problem hiding this comment.
Review · Approve
Stops excerpting the same tail turn twice inside one selectTail pass by caching the first excerpt.
Findings
No findings.
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.
CL-10535 — Stop excerpting the same tail turn twice in compactor turnCost
Fix
selectTailexcerpted the same tail turn multiple times per pass:turnCostcalledexcerptTailTurndirectly, thenexcerptedTurnTokens, which calledexcerptTailTurnagain (the reported double-excerpt inturnCost).excerptedTurnTokenson raw turns, so picked closure turns were excerpted a third time.The fix caches the first
excerptTailTurnresult per turn inselectTail(excerptFor+excerptCache) and reuses it for the closure token estimate,turnCost's token count, and the emitted live copies.excerptedTurnTokensis replaced byliveTurnTokens, which counts tokens over an already-excerpted turn and never re-excerpts. Behavior and values are identical (tests pin).Proof test
src/session/compactor-excerpt-once.test.ts— a newexcerptTailTurnCallCounttest seam countsexcerptTailTurninvocations; the test asserts a full compactor pass over N tail turns callsexcerptTailTurnexactly N times (once per turn), while all oversized tool outputs are still head+tail excerpted with identical values.Verification
bun test src/session/compactor-excerpt-once.test.ts— 1 passcompactor-pairing.test.ts,compaction-verify.test.ts,compaction-archive.test.ts,compaction-handoff.test.ts,summarizer.test.ts,summarizer-excerpt.test.ts,context-compactor.test.ts) — 173 pass, 0 failbun run typecheck— exit 0oxfmt --check+oxlinton changed files — cleanbun run check:dead-exports— 0 violationsDiff stat
src/session/compactor.ts+30 −14,src/session/compactor-excerpt-once.test.ts+104 (new).