Repository navigation
feat(compaction): L3 microcompact dual-path, cache-state-driven (M4.3… - #28
Merged
Merged
Conversation
… / v4) The marquee layer: microcompact keeps the N newest tool_result blocks and clears all older ones to a marker (count-based, transcript-wide — so it reaches tool results inside the recent window too, unlike L2's stale-zone snip). The defining idea is that infrastructure state decides the algorithm: a cache-warmth clock picks the path, and both paths make zero extra API calls. - COLD (more than microcompactColdMs ~5 min has elapsed since the last model call, so the prefix cache is already expired): clear older tool results in place — free, the prefix rebuilds anyway. - HOT (prefix still warm): defer — preserve the warm prefix. The gateway does not expose Anthropic cache_edits, so the hot path cannot free the prefix for free; deferring is the faithful native adaptation (see docs/v4-compaction-pipeline-roadmap.md M4.3). Honest consequence: continuous operation is HOT, so L3 mostly defers within a run and acts on idle/resume. - core: microcompactToolResults + MicrocompactOptions (context.ts); query loop tracks lastModelCallAt via an injectable QueryOptions.now clock, computes cacheWarmth at the turn boundary, inserts the microcompact stage as [spill, snip, microcompact, reclaim], and marks query.microcompact_cold. - tests: 2 L3 unit tests (keeps newest N + clears older, preserves artifactPath; no-op when <= N); 1 integration test driving cold vs hot via the injected clock and asserting the profile mark. - docs: CLAUDE.md query-loop step 7 lists L3 + the warmth clock; v4 roadmap M4.3 delivered with the cache_edits caveat called out. 235 tests pass (+3); all 10 eval tasks green (L3 dormant/hot in continuous eval), fingerprint unchanged. 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.
… / v4)
The marquee layer: microcompact keeps the N newest tool_result blocks and clears all older ones to a marker (count-based, transcript-wide — so it reaches tool results inside the recent window too, unlike L2's stale-zone snip). The defining idea is that infrastructure state decides the algorithm: a cache-warmth clock picks the path, and both paths make zero extra API calls.
COLD (more than microcompactColdMs ~5 min has elapsed since the last model call, so the prefix cache is already expired): clear older tool results in place — free, the prefix rebuilds anyway.
HOT (prefix still warm): defer — preserve the warm prefix. The gateway does not expose Anthropic cache_edits, so the hot path cannot free the prefix for free; deferring is the faithful native adaptation (see docs/v4-compaction-pipeline-roadmap.md M4.3). Honest consequence: continuous operation is HOT, so L3 mostly defers within a run and acts on idle/resume.
core: microcompactToolResults + MicrocompactOptions (context.ts); query loop tracks lastModelCallAt via an injectable QueryOptions.now clock, computes cacheWarmth at the turn boundary, inserts the microcompact stage as [spill, snip, microcompact, reclaim], and marks query.microcompact_cold.
tests: 2 L3 unit tests (keeps newest N + clears older, preserves artifactPath; no-op when <= N); 1 integration test driving cold vs hot via the injected clock and asserting the profile mark.
docs: CLAUDE.md query-loop step 7 lists L3 + the warmth clock; v4 roadmap M4.3 delivered with the cache_edits caveat called out.
235 tests pass (+3); all 10 eval tasks green (L3 dormant/hot in continuous eval), fingerprint unchanged.