Skip to content

Fix false "context full" task-core nudge (byte-size fallback + widen usage read)#9

Merged
ReidenXerx merged 1 commit into
mainfrom
fix/context-pressure-false-full
Jul 17, 2026
Merged

Fix false "context full" task-core nudge (byte-size fallback + widen usage read)#9
ReidenXerx merged 1 commit into
mainfrom
fix/context-pressure-false-full

Conversation

@ReidenXerx

Copy link
Copy Markdown
Owner

The task-core compaction nudge fired "context ~N% full" when the window wasn't close to full. Diagnosed against a real 273 MB crypto transcript.

Two causes

  1. Window mismatch — shared default 200k vs a 1M (opus[1m]) session. At ~400k tokens that's 40% full, but 400k/200k = 200% → fires. Fixed by the per-machine gitnexus-hooks.local.json window override (PR Per-machine hook-config override (.gnkit/gitnexus-hooks.local.json) #8).
  2. Byte-size fallback (this PR). estimateContextTokens read a 128 KB tail for the last usage record; if none parsed there it returned fileSize/3.5. But a tool returning >128 KB (big read/grep/command dump) sits at the tail at PostToolUse time and pushes the assistant usage out of view → fallback hits. On a 273 MB append-only transcript that's 78M "tokens" → reads as always full, firing on every tool call (and the hook re-nudges each call while no task-core exists).

Fix

  • Widen the tail read 128 KB → 2 MB → 8 MB until a real usage record is found.
  • Never fall back to byte size — an append-only log's size ≠ current window occupancy. Unknown → 0 → treated as "not full".

Verified: real 273 MB transcript → 412k (not 78M); synthetic 3 MB trailing line → widens to the real 360k; 10 MB line past the cap + no-usage → 0 (safe). 62/62 tests.

🤖 Generated with Claude Code

…ize fallback

The task-core pressure hook fired "context nearly full" when it wasn't. Two causes:

1. Window mismatch — the shared default is 200k, but a 1M-context (opus[1m]) session at ~400k
   tokens is only 40% full, yet 400k/200k = 200% → false fire. Addressed separately by the
   per-machine gitnexus-hooks.local.json window override (PR #8).

2. The estimator's byte-size fallback (this fix). When the last 128 KB of the transcript held no
   parseable `usage` record — which happens EVERY time a tool returns >128 KB (a big read/grep/dump
   pushes the assistant usage out of the tail) — it fell back to fileSize/3.5. The transcript is an
   unbounded append-only log (273 MB in one real crypto session → 78M "tokens"), so that reads as
   "always full" and fired on every tool call (the hook even re-nudges each call while no task-core
   exists yet).

estimateContextTokens now WIDENS the tail read (128 KB → 2 MB → 8 MB) until it finds the real usage
record, and returns 0 (unknown → treated as "not full") instead of ever guessing from byte size.
Verified against the real 273 MB transcript (412k tokens, not 78M) + synthetic 3 MB / 10 MB
trailing-line cases. 62/62 tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@ReidenXerx
ReidenXerx merged commit 158a835 into main Jul 17, 2026
1 check passed
@ReidenXerx
ReidenXerx deleted the fix/context-pressure-false-full branch July 17, 2026 19:47
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