Fix false "context full" task-core nudge (byte-size fallback + widen usage read)#9
Merged
Merged
Conversation
…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>
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.
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
opus[1m]) session. At ~400k tokens that's 40% full, but400k/200k = 200%→ fires. Fixed by the per-machinegitnexus-hooks.local.jsonwindow override (PR Per-machine hook-config override (.gnkit/gitnexus-hooks.local.json) #8).estimateContextTokensread a 128 KB tail for the lastusagerecord; if none parsed there it returnedfileSize/3.5. But a tool returning >128 KB (big read/grep/command dump) sits at the tail at PostToolUse time and pushes the assistantusageout 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
128 KB → 2 MB → 8 MBuntil a realusagerecord is found.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