Skip to content

refactor(session): stop excerpting the same tail turn twice in turnCost - #1407

Merged
TheGreatAxios merged 2 commits into
mainfrom
cl-10535-excerpt-once
Oct 13, 2026
Merged

TheGreatAxios merged 2 commits into
mainfrom
cl-10535-excerpt-once

Conversation

@TheGreatAxios

Copy link
Copy Markdown
Collaborator

CL-10535 — Stop excerpting the same tail turn twice in compactor turnCost

Fix

selectTail excerpted the same tail turn multiple times per pass:

  • turnCost called excerptTailTurn directly, then excerptedTurnTokens, which called excerptTailTurn again (the reported double-excerpt in turnCost).
  • The closure token estimate called excerptedTurnTokens on raw turns, so picked closure turns were excerpted a third time.

The fix caches the first excerptTailTurn result per turn in selectTail (excerptFor + excerptCache) and reuses it for the closure token estimate, turnCost's token count, and the emitted live copies. excerptedTurnTokens is replaced by liveTurnTokens, 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 new excerptTailTurnCallCount test seam counts excerptTailTurn invocations; the test asserts a full compactor pass over N tail turns calls excerptTailTurn exactly 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 pass
  • compactor suites (compactor-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 fail
  • bun run typecheck — exit 0
  • oxfmt --check + oxlint on changed files — clean
  • bun run check:dead-exports — 0 violations

Diff stat

src/session/compactor.ts +30 −14, src/session/compactor-excerpt-once.test.ts +104 (new).

@linear-code

linear-code Bot commented Oct 12, 2026

Copy link
Copy Markdown

CL-10535

@corbits-triage

Copy link
Copy Markdown
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 TheGreatAxios changed the title fix(session): excerpt each tail turn at most once in selectTail (CL-10535) refactor(session): stop excerpting the same tail turn twice in turnCost Oct 12, 2026

@TheGreatAxios TheGreatAxios left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review · Approve

Stops excerpting the same tail turn twice inside one selectTail pass by caching the first excerpt.

Findings

No findings.

@TheGreatAxios
TheGreatAxios merged commit 5e71be1 into main Oct 13, 2026
13 checks passed
@TheGreatAxios
TheGreatAxios deleted the cl-10535-excerpt-once branch October 13, 2026 01:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant