Fix the context meter's blind spots and stale compaction arming - #339
Merged
TheGreatAxios merged 4 commits intoAug 7, 2026
Conversation
TheGreatAxios
force-pushed
the
cl-5564-context-window-fills-far-faster-than-the-meter-reports
branch
from
August 7, 2026 04:48
f38586d to
b12b4a4
Compare
The system prompt and active tool schemas ride on every request the same way turns do, but the local context estimate only ever summed turn content, so it undercounted by whatever the harness's own framing cost.
Compaction arming read only reported input tokens, so a provider that omits or zeroes usage pinned the estimate at 0 and never armed, even as real occupancy grew. Cache reads and writes ride on the context window the same way input does, so both now route through one shared token-counting function instead of being hand-picked per call site. A tool result produced by a turn's own tool batch also arrives after that turn's arming decision was made; when the decision came from the local estimate (usage was missing), the governor now re-derives it against the live estimate on the next tool.done instead of waiting for the following inference.done. The arming rule itself is unchanged: it still requires more turns than createPruningCompactor's own no-op floor, since arming below that floor cannot compact anything.
The status bar previously read only the last turn's reported input and cache tokens, with no fallback, so a provider that omits usage pinned the meter at a stale or 0% reading. It now trusts the same estimate the compaction governor already computed, including the governor's own decision on whether that number is estimated, rather than re-deriving that decision from a second usage read. The tilde prefix that marks an estimated percentage is written once and reused by both the status bar and the prompt border. Cost accounting's own input-plus-cache sum is replaced with the same shared function so all three consumers agree on what "context size" means.
MIN_TURNS_TO_COMPACT was an independent literal that happened to match createPruningCompactor's keepRecentTurns, itself duplicated as a third literal in the session and sub-agent compactor registrations. The independent copy was also off by one: the compactor's own no-op condition is keepRecentTurns + 1, not keepRecentTurns, so the governor could arm a compaction at the exact turn count the compactor was guaranteed to no-op on. All three call sites now share one exported constant, and the governor computes its floor with the same function the compactor uses internally.
TheGreatAxios
force-pushed
the
cl-5564-context-window-fills-far-faster-than-the-meter-reports
branch
from
August 7, 2026 05:19
b12b4a4 to
fc57acc
Compare
TheGreatAxios
deleted the
cl-5564-context-window-fills-far-faster-than-the-meter-reports
branch
August 7, 2026 06:36
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
compactorNoOpFloorhelper) instead of an independent literal, which had also been off by one and could arm a compaction the compactor was guaranteed to no-op oncontextTokensFromUsagefunction, and mark the meter with a tilde when it is showing an estimate rather than provider-reported usageVerification
bun run typecheck,bun run build, andbun testpass on this branch after rebasing ontoorigin/release/tui-bugfixes; observed 4362/4362 across two consecutive full-suite runssrc/agent/compaction.test.ts,src/agent/context-estimate.test.ts,src/context-compactor.test.ts,src/cost/cost-summary.test.ts,src/director.test.ts,src/tui-opentui/prompt-border.test.ts, andtests/unit/context-window.test.ts, including a test that exercises the exact turn count at the compactor's no-op floor and one past itcompaction.test.ts, "does not catch a huge tool result mid-cycle when the provider reported real usage") — only the usage-omitted path gets the live re-checkCloses CL-5564