# When must an instance distrust its own token governor: the double-count divergence at the tier-0 eviction boundary **Date of Record:** 2026 November 26 **Scope:** Applies to any agent loop whose context window is managed by a governor that maintains its own token ledger (priority tiers, eviction thresholds, degradation ladder) separate from the model's true tokenizer. Does not apply to systems where the governor queries the tokenizer synchronously on every mutation and the tokenizer is byte-identical to the one used at inference. ## Core Distinction A context budget governor is not a tokenizer. It is a *model* of a tokenizer, usually a cheap one: `len(text) // 4`, a tiktoken-compatible approximation, or a running counter incremented at append time and decremented at evict time. The governor's job is to keep `estimated_tokens <= budget` while preserving high-priority content. The failure mode is not "the estimate is wrong." The failure mode is **estimator drift that is asymmetric across tiers**: the governor under-counts tier-0 (system prompt, tool schemas, pinned facts) by a roughly constant amount, and under-counts tier-2 (ephemeral scratch, tool outputs) by an amount that grows with content type. Because tier-0 is evicted last and tier-2 is evicted first, the governor believes it has headroom that does not exist, and the first eviction it performs is *insufficient* — it evicts scratch content, re-checks its own stale ledger, declares the budget satisfied, and dispatches. The model then receives a prompt that overflows the real window, and the runtime either truncates from the tail (silently destroying tier-1 working state) or rejects the call (hard failure mid-loop). The distinction that matters operationally: **ledger consistency is not budget consistency.** A governor can be perfectly self-consistent — every append and evict balanced, no leaks — and still dispatch an over-budget prompt, because its unit of account diverges from the inference tokenizer's unit of account. Self-consistency is the invariant the governor enforces. It is the wrong invariant. ## What Was Observed A tool-using research agent ran a 40-step loop with a governor configured with `budget=128000`, three tiers, eviction order tier-2 → tier-1 → tier-0, and a `len//4` estimator. The loop executed cleanly for 31 steps. At step 32 the agent had accumulated ~180 KB of tier-2 tool output (HTML fragments, JSON blobs) and ~22 KB of tier-1 reasoning scratch. The governor's ledger read 121,400 estimated tokens — under budget, no eviction triggered. The actual tokenizer count for the same prompt was 138,900. The gap, 17,500 tokens, was concentrated in tier-2: dense JSON and minified HTML tokenize at roughly 2.6–3.1 chars/token under BPE, not 4.0. The `len//4` estimator had been under-counting tier-2 by ~28% for the entire run, and the error was *monotonic in tier-2 volume*, so it compounded silently until it crossed the real window. At step 32 the runtime accepted the prompt (window was 200K, so no hard overflow), but the model's effective attention over tier-1 degraded — the pinned scratch was now competing with 138K of tool noise — and the agent began re-deriving facts it had already established at steps 12 and 19. By step 35 it had re-fetched the same three sources twice. The loop terminated at step 40 having burned 2.1× the expected token budget with a duplicated work trace. A second instance, configured identically but with a 128K-window model, failed differently: at step 32 the runtime rejected the dispatch with a context-length error, the governor caught the exception, evicted the *lowest-priority tier-2 chunk it could find* (1,800 estimated tokens), re-checked its ledger (still under budget), and re-dispatched. Same rejection. Three retries, three identical evictions of the same-size chunk, then a hard failure. The governor's eviction loop was **converging on a fixed point that did not correspond to the real budget** — it kept evicting estimated tokens while the real overflow was structural (tier-0 + tier-1 alone exceeded the window once tier-2 was gone). The signature to watch for: **eviction attempts that do not reduce the real prompt size**, because the governor is evicting against a ledger whose error is concentrated in the tiers it is *not* evicting. ## Condition of Validity The governor's dispatch decision is valid only when three conditions hold simultaneously: 1. **Estimator bias is bounded and tier-uniform.** If `real_tokens - estimated_tokens <= ε` for a known `ε`, and `ε` is independent of tier composition, then `estimated <= budget - ε` is a sound dispatch condition. The `len//4` estimator violates this: its bias is a function of content type, and content type is correlated with tier (tier-2 is tool output, tier-0 is prose). 2. **Eviction actually reduces real tokens.** An eviction step is only a budget-reduction step if the evicted content's real token count is positive and the governor's estimate of it is not itself biased low. Evicting a 1,800-estimated-token JSON blob that is really 2,600 tokens reduces the real prompt by 2,600 but the ledger by 1,800 — the *gap widens* with every eviction of dense content. 3. **The residual (tier-0 + tier-1) fits the window on its own.** Graceful degradation assumes the ladder terminates in a valid state. If tier-0 + tier-1 real tokens exceed the window, no amount of tier-2 eviction helps, and the governor will loop. This must be checked against the *real* count of the irreducible tiers, not the ledger. When any of these fails, the governor's "under budget" verdict is not evidence of headroom. It is evidence that the ledger and the tokenizer have diverged, and the divergence is load-bearing. ## Decision Boundary The boundary is not "estimated vs. real." It is **whether the governor has ever re-anchored its ledger against ground truth since the last tier-composition change.** Concretely, an instance must stop trusting its governor and force a re-anchor when any of the following is true: - **Tier-2 volume has grown by more than ~40% since the last tokenizer check.** The estimator's bias scales with dense-content volume; a 40% swing moves the gap past most safety margins. - **An eviction was performed and the subsequent dispatch was rejected or truncated.** This is the definitive signal: the governor's model of the budget is wrong in the direction of optimism. Do not retry with another eviction; re-tokenize. - **The eviction loop has executed the same-size eviction more than twice without a successful dispatch.** This is the fixed-point failure; further evictions cannot converge. - **Tier-0 + tier-1 estimated tokens exceed 60% of budget.** The irreducible floor is close enough to the ceiling that tier-2 bias can push the total over, and the degradation ladder has little room. Below these thresholds, ledger-based dispatch is acceptable and cheap. Above them, the governor must be treated as a *hint*, not an oracle: re-tokenize the full prompt with the inference tokenizer, reset the ledger to the measured value, and recompute the eviction plan against the measured counts. The cost of a re-tokenize is one pass over the prompt; the cost of a wrong dispatch is a truncated working state or a duplicated multi-step trace. The architectural invariant: **the governor may estimate for scheduling, but must measure before dispatch when the estimate is load-bearing.** Estimation is for deciding *what to evict*; measurement is for deciding *whether to send*. Conflating the two is the failure. ## Operational Effect With the re-anchor guard in place, the failure mode becomes visible and bounded. The agent at step 32 re-tokenizes, discovers the 17,500-token gap, and evicts 22,000 real tokens of tier-2 (not 1,800 estimated), preserving tier-1 scratch and the step-12/19 facts. The loop completes at step 40 with a single work trace and 1.0× budget. The 128K instance re-tokenizes, discovers that tier-0 + tier-1 alone are 131,000 real tokens, correctly concludes that degradation cannot succeed, and escalates to a compaction pass (summarize tier-1 into tier-0) rather than looping on futile evictions. The guard costs one tokenizer pass per re-anchor, triggered rarely. Without it, the governor is a system that reports success while dispatching over-budget prompts, and its eviction loop is a convergence procedure aimed at the wrong fixed point. The operational lesson: a budget governor's self-consistency is a property of its ledger, not of the model's window, and the two diverge exactly when the content it is managing is densest — which is when the budget matters most. ```python import math from dataclasses import dataclass, field class GovernorDivergenceError(RuntimeError): """Raised when the governor's ledger and the real tokenizer disagree enough that a ledger-based dispatch decision is unsound.""" pass @dataclass class Tier: name: str content: list = field(default_factory=list) est_tokens: int = 0 class ContextGovernor: # Rough per-tier chars-per-token; tier-2 (tool output) is denser. CHARS_PER_TOKEN = {"tier-0": 4.0, "tier-1": 3.6, "tier-2": 2.8} def __init__(self, budget: int, window: int, tokenizer): self.budget = budget self.window = window self.tokenizer = tokenizer # callable: str -> int self.tiers = {n: Tier(n) for n in self.CHARS_PER_TOKEN} self.last_anchor = None self.eviction_attempts = 0 def append(self, tier_name: str, text: str) -> None: t = self.tiers[tier_name] t.content.append(text) t.est_tokens += int(len(text) / self.CHARS_PER_TOKEN[tier_name]) def ledger_total(self) -> int: return sum(t.est_tokens for t in self.tiers.values()) def real_total(self) -> int: return sum(self.tokenizer(x) for t in self.tiers.values() for x in t.content) def must_reanchor(self) -> bool: if self.eviction_attempts >= 2: return True irreducible = self.tiers["tier-0"].est_tokens + self.tiers["tier-1"].est_tokens if irreducible > 0.60 * self.budget: return True if self.last_anchor is not None: grown = self.tiers["tier-2"].est_tokens / max(self.last_anchor, 1) if grown > 1.40: return True return False def evict_tier2(self, target_est: int) -> int: t = self.tiers["tier-2"] removed = 0 while t.content and removed < target_est: chunk = t.content.pop(0) removed += int(len(chunk) / self.CHARS_PER_TOKEN["tier-2"]) t.est_tokens -= removed return removed def dispatch(self) -> str: if self.must_reanchor(): real = self.real_total() self.last_anchor = self.tiers["tier-2"].est_tokens if real > self.window: floor = (self.tiers["tier-0"].est_tokens + self.tiers["tier-1"].est_tokens) if floor >= self.window: raise GovernorDivergenceError( f"irreducible tiers ({floor} est) alone exceed window " f"({self.window}); eviction cannot converge" ) overflow = real - self.window # Evict against measured overflow, not the stale ledger. while self.real_total() > self.window and self.tiers["tier-2"].content: self.evict_tier2(overflow) self.eviction_attempts += 1 if self.real_total() > self.window: raise GovernorDivergenceError( f"post-eviction real tokens {self.real_total()} still exceed " f"window {self.window}; governor ledger was optimistic" ) self.eviction_attempts = 0 elif self.ledger_total() > self.budget: self.evict_tier2(self.ledger_total() - self.budget) self.eviction_attempts += 1 return "dispatched" ```