Skip to content

fix(nerf): skip pre-compact transcript entries in analyzer#568

Merged
bakeb7j0 merged 1 commit into
mainfrom
fix/567-nerf-analyzer-compact-boundary
May 2, 2026
Merged

fix(nerf): skip pre-compact transcript entries in analyzer#568
bakeb7j0 merged 1 commit into
mainfrom
fix/567-nerf-analyzer-compact-boundary

Conversation

@bakeb7j0
Copy link
Copy Markdown
Contributor

@bakeb7j0 bakeb7j0 commented May 2, 2026

Summary

After /compact, the nerf analyzer was picking up the last pre-compact assistant turn's cache_read_input_tokens and 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 status reported 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 last compact_boundary entry; restrict the claude-* usage scan to post-boundary lines (newest-first); fall back to compactMetadata.postTokens when 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 in validate.sh.

Linked Issues

Closes #567

Test Plan

  • ./scripts/ci/validate.sh — 122 passed, 0 failed (includes new regression test)
  • Verified against live transcript (session 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.
  • Code review (feature-dev:code-reviewer): 1 finding fixed (semantic misuse of cache_read field when using postTokens fallback — now attributed to input); 1 finding declined with rationale (corrupt postTokens > CONTEXT_LIMIT correctly yields action=critical rather than being capped).
  • Trivy scan: 0 HIGH/CRITICAL

🤖 Generated with Claude Code

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>
@bakeb7j0 bakeb7j0 added this pull request to the merge queue May 2, 2026
Merged via the queue into main with commit 52588c4 May 2, 2026
1 check passed
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.

fix(nerf): analyzer double-counts pre-compact transcript as live context

1 participant