Skip to content

feat(compaction): fold to a token-capped tail, not recent turns - #1227

Merged
TheGreatAxios merged 3 commits into
mainfrom
cl-9489-folds-must-be-extract-summary-actions-plus-a-token-capped
Sep 29, 2026
Merged

TheGreatAxios merged 3 commits into
mainfrom
cl-9489-folds-must-be-extract-summary-actions-plus-a-token-capped

Conversation

@TheGreatAxios

Copy link
Copy Markdown
Collaborator

Summary

  • Folds keep a token-capped tail instead of the last N turns verbatim.
  • Pair atomicity still holds: a tool call and its result stay together or both excerpt.
  • Fat handoff file remains the durable working state; the live prompt is the thin spine plus that tail.

Verification

  • pre-commit typecheck + build passed on commit
  • Targeted compaction suite was not finished on this branch (work was interrupted). Treat CI as the first full gate.

Part of CL-9489

@linear-code

linear-code Bot commented Sep 29, 2026

Copy link
Copy Markdown

CL-9489

@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

Incomplete, not shippable. The verbatim last-N floor is gone and the CL-9006 latch is not weakened, but the live fold is still spine + unexcerpted anchors + tail, the tail cap has holes, still-over folds are silent, and the pairing suite is red.

Blocking

  1. Unexcerpted anchors blow the 60% trigger. apply still emits [summaryTurn, ...anchorTurns, ...tailTurns]. edit_file/write_file score 10 and drag full bodies (excerpting is tail-only). A fixture of 8 fat edit pairs landed at ~160k tokens vs a 76.8k trigger.

  2. Non-convergence is not reported. foldNonConverged is a getter only; the director never reads it. After a still-over fold the consecutive cap is spent and the session sits over 60% with no operator notice.

  3. Pairing suite is red (compactor-pairing.test.ts, 8 fails). When selectTail keeps every turn, the early summarizedTurns.length === 0 return skips stubSupersededReads.

  4. Images are free against the tail cap. excerptedTurnChars ignores image blocks, so a huge newest screenshot can keep tailTokenEstimate ≤ 2500 while occupancy stays over 60%.

Should-fix

preserveWholeUserMessages is declared and never read by selectTail.

What holds

  • COMPACTOR_KEEP_RECENT_TURNS / keepRecentTurns deleted; default tail budget 2500 tokens.
  • Pair atomicity for well-formed call/result sequences still holds.
  • Fat handoff blob + thin spine pointer remain.

@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 (second pass, 25ab7a67)

Shippable. All four prior blockers are closed. Independent tester: 172 pass / 0 fail; typecheck exit 0. CL-9006 latch is not weakened.

  1. Live fold is spine + token-capped tail. Fat edit_file/write_file bodies go to the handoff; occupancy fixture < 76800.
  2. Still-over folds emit custom.compaction.fold_nonconverged (TUI systemNotice / exec warn).
  3. stubSupersededReads still runs when the tail swallows the transcript. Pairing suite green.
  4. Images count via estimateContentBlockTokens.

Hygiene for later (not blocking): dead-ish preserveWholeUserMessages / maxAnchorTurns leftovers; screenshot budget test can be made stricter.

@TheGreatAxios
TheGreatAxios force-pushed the cl-9489-folds-must-be-extract-summary-actions-plus-a-token-capped branch from 25ab7a6 to d098a62 Compare September 29, 2026 23:14
Unexcerpted edit_file pairs were riding the live fold as score-10
anchors and holding occupancy over the 60% trigger. The live set is
now the thin spine plus a token-capped tail: file-edit bodies go in
the fat handoff, images count against the tail budget, superseded
reads still stub when the tail is the whole transcript, and a still-
over fold notifies the operator without weakening the occupancy latch.

# Conflicts:
#	src/session/compactor.ts
Tiny fixtures sat inside the 2500-token live tail and no-oped.
The paging e2e echoed the summarizer prompt, so verify truncated
the repair and aborted the fold. Point the auth store test at
the testkit mock helper.
@TheGreatAxios
TheGreatAxios force-pushed the cl-9489-folds-must-be-extract-summary-actions-plus-a-token-capped branch from 9434566 to 7b0f0f6 Compare September 29, 2026 23:42
@TheGreatAxios
TheGreatAxios merged commit 51d08f4 into main Sep 29, 2026
13 checks passed
@TheGreatAxios
TheGreatAxios deleted the cl-9489-folds-must-be-extract-summary-actions-plus-a-token-capped branch September 29, 2026 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant