feat(compaction): opt-in LLM semantic compaction summarizer (M3.2c / §1)#22
Merged
Conversation
Add the long-designed semantic-compaction seam. Where the default compactMessagesTiered shrinks stale messages in place (deterministic, pointer- izing the whales), the new compactMessagesWithSummary REPLACES the whole stale region with a single LLM-written recap — recovering the reasoning/prose that pointers cannot. Root task + recent window stay verbatim. Boundary safety: the recent-window start snaps earlier past any leading tool_result so a kept tool_result never has its originating tool_use dropped (no orphaned pairing). When there is no accumulated stale history yet (e.g. one big recent tool_result), it returns untouched and leaves the pathological case to the reactive prompt_too_long net — semantic compaction condenses HISTORY, not the recent window. Opt-in and non-breaking: the deterministic pointer path stays the default. The proactive-compaction block branches on QueryOptions.compactionSummarizer and marks the reset as proactive_compaction_semantic. It is one amortized cache reset like any compaction (invariant #1); non-determinism is gated behind a scripted fake in tests (invariant #2). - core: compactMessagesWithSummary + MessageSummarizer (context.ts), QueryOptions.compactionSummarizer, createModelCompactionSummarizer (model- backed summarizer kept in core next to the loop). - cli: myagent agent --semantic-compaction (builds the summarizer from the agent's own client), help/usage text. - eval: EvalTask.initialMessages + new semantic-compaction task (seeds a stale whale, asserts the summarizer seam fires + tokens drop); fingerprint updated to tasks=10 turns=21 in=14350 out=835. - tests: 3 unit (recap replacement, boundary snap, under-target no-op) + 1 loop integration (proactive path uses the injected summarizer). - docs: CLAUDE.md query-loop step 7 + roadmap M3.2c marked delivered. 214 tests pass (+4). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Add the long-designed semantic-compaction seam. Where the default compactMessagesTiered shrinks stale messages in place (deterministic, pointer- izing the whales), the new compactMessagesWithSummary REPLACES the whole stale region with a single LLM-written recap — recovering the reasoning/prose that pointers cannot. Root task + recent window stay verbatim.
Boundary safety: the recent-window start snaps earlier past any leading tool_result so a kept tool_result never has its originating tool_use dropped (no orphaned pairing). When there is no accumulated stale history yet (e.g. one big recent tool_result), it returns untouched and leaves the pathological case to the reactive prompt_too_long net — semantic compaction condenses HISTORY, not the recent window.
Opt-in and non-breaking: the deterministic pointer path stays the default. The proactive-compaction block branches on QueryOptions.compactionSummarizer and marks the reset as proactive_compaction_semantic. It is one amortized cache reset like any compaction (invariant #1); non-determinism is gated behind a scripted fake in tests (invariant #2).
214 tests pass (+4).