fix(nerf): skip pre-compact transcript entries in analyzer#568
Merged
Conversation
After /compact the transcript retains every pre-compact turn (append-only), so `tac | grep -m1` was picking the last pre-compact usage and reporting its 200k+ cache_read as the live total. The analyzer now locates the last compact_boundary entry, restricts the claude-* usage scan to lines after it (newest-first), and falls back to compactMetadata.postTokens when no post-boundary turn exists yet. Closes #567 Co-Authored-By: Claude Opus 4.7 (1M context) <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.
Summary
After
/compact, the nerf analyzer was picking up the last pre-compact assistant turn'scache_read_input_tokensand reporting it as the current context total. Because the pre-compact turn's cache_read often exceeded the dart ouch threshold (200k+ against a 200k limit),/nerf statusreported 100%+ usage and the statusline stayed stuck on orange/red even when the real in-memory window was fresh.Closes #567.
Changes
context-crystallizer/lib/context-analyzer.sh— locate the lastcompact_boundaryentry; restrict theclaude-*usage scan to post-boundary lines (newest-first); fall back tocompactMetadata.postTokenswhen no post-boundary turn exists yet; unchanged behaviour when no boundary is present.tests/regression/test_analyze_context_compact_boundary.sh— new bash-only regression test covering four scenarios: boundary+post-turn, boundary+no-turn, no boundary, boundary with missing postTokens. All run invalidate.sh.Linked Issues
Closes #567
Test Plan
./scripts/ci/validate.sh— 122 passed, 0 failed (includes new regression test)991053c7): pre-patch reported 219k total (last pre-boundary turn's cache_read), post-patch reports 115k (last post-boundary turn's cache_read) — matches/context's view within expected calibration drift.cache_readfield when usingpostTokensfallback — now attributed toinput); 1 finding declined with rationale (corruptpostTokens>CONTEXT_LIMITcorrectly yieldsaction=criticalrather than being capped).🤖 Generated with Claude Code