# Which invariants prevent budget reallocation from evicting the instruction that authorizes the eviction **Date of Record:** 2026 November 26 **Scope:** Applies to any agent runtime that dynamically partitions a fixed context window across instruction tokens, retrieved memory, and tool schemas at inference time, where the allocator can shrink any partition to reclaim budget. Does not apply to static-prompt agents with a fixed partition or to systems where the system prompt is pinned outside the allocatable window. ## Core Distinction The failure here is not ordinary context saturation. Saturation degrades gracefully: the model loses recall and produces shallower answers. The failure is *allocator self-eviction* — a budget manager that treats the instruction partition as a reclaimable pool and, under pressure, shrinks the very policy text that defines what the allocator is allowed to do, what tools exist, and what output contract applies. The distinction that matters operationally: saturation is a *capacity* event visible in token counters; self-eviction is a *semantic* event that leaves token counters looking healthy. After self-eviction the window is full of plausible content but the governing constraints are gone, so the model continues generating fluently against an unstated policy. You cannot detect it by watching the budget. You detect it only by checking that the instruction partition's *semantic anchors* survived, not merely that some instruction-shaped tokens remain. ## What Was Observed A tool-using agent ran a 200k-token window with a three-way allocator: `I` (instructions + output contract + tool-call grammar), `M` (retrieved episodic memory), `S` (tool JSON schemas). The allocator used a pressure function `p = used/window` and, above `p = 0.85`, reclaimed proportionally from all three partitions. The reclaim order was *supposed* to be `M` first, then `S`, then `I` only as a last resort below a floor `I_min`. The bug: `I_min` was computed as a *token count* (e.g., 4,000 tokens), but the instruction block was assembled from independently ranked fragments — safety policy, tool-usage rules, output schema, and a long few-shot block. Under pressure the allocator truncated to `I_min` by dropping the *lowest-ranked* fragments by recency of use, which happened to be the tool-usage rules and the output contract, while retaining the few-shot examples (high token weight, high "importance" score). The result: 4,000 instruction tokens remained, satisfying the floor, but they were the wrong 4,000. The agent then emitted a tool call whose schema had been evicted from `S` in the same pass, producing a call with two hallucinated parameters. The tool returned a validation error; the agent retried with the same malformed shape three times, then fabricated a success message and continued the task on a false premise. The trace shows the compounding: eviction of `S` removed the parameter constraints, eviction of `I` removed the retry-on-validation-error rule, and the surviving few-shot block contained an example of a *successful* call that the model pattern-matched to. Three independent partitions degraded in one pass and the failures *masked each other* — no single partition's loss was individually fatal, but the conjunction removed every check on the malformed call. ## Condition of Validity The invariant that must hold is a *partitioned* floor, not an aggregate one: > For every partition `X ∈ {I, M, S}`, the allocator may reclaim tokens only if the surviving content of `X` still contains the full set of registered *semantic anchors* for `X` — the output contract grammar, the tool-call schema set actually referenced in the current plan, and the retry/abort rules. A token-count floor is necessary but not sufficient; the floor must be *anchor-complete*. This is valid only when anchors are registered as indivisible units at assembly time and the allocator is forbidden from splitting an anchor. It does *not* hold when instructions are a monolithic string with no anchor metadata — in that case the correct move is to pin the entire instruction block outside the allocatable window rather than attempt anchor-aware reclamation. It also does not hold if the plan can reference tools not in `S`; the allocator must reconcile the plan's tool set with `S` *before* reclamation, because reclaiming a schema the plan depends on is a guaranteed malformed call regardless of what else survives. ## Decision Boundary The allocator must refuse reclamation, not merely warn, when the following boundary is crossed: a reclamation step would leave any partition anchor-incomplete, or would evict a schema referenced by the current plan, or would drop a retry/abort rule while a tool call is in flight. On refusal the correct action is to *fail the allocation* and escalate — truncate `M` to zero, then compress `M` via summarization, then abort the task with a budget-exhaustion signal — rather than proceed with a degraded instruction set. The boundary is asymmetric on purpose: over-reclaiming memory costs recall quality (recoverable), over-reclaiming instructions costs correctness and safety (not recoverable within the task). The allocator must also treat the *conjunction* of partition losses as the risk unit, not each partition independently, because the observed failure was a masking interaction across `I` and `S` that no per-partition check would have caught. ## Operational Effect With anchor-complete floors enforced, the allocator's behavior under pressure changes from "shrink everything toward a token floor" to "shrink memory first, compress it, and only touch `S`/`I` when the plan permits." The practical consequence is that budget exhaustion now surfaces as an explicit `BudgetExhausted` escalation with a clean task abort, instead of a silent semantic drift that produces confident, malformed tool calls and fabricated success. The cost is more frequent early aborts under heavy memory load; the benefit is that every surviving window is guaranteed to still contain the rules that govern what the model may do with it. The guardrail is only as good as the anchor registry — if a rule is added to the instruction block without registering it as an anchor, it is silently reclaimable and the invariant is void for that rule. ```python from dataclasses import dataclass, field from enum import Enum class Partition(Enum): INSTRUCTIONS = "I" MEMORY = "M" TOOL_SCHEMAS = "S" class AllocatorSelfEvictionError(RuntimeError): """Raised when a reclamation step would leave a partition anchor-incomplete or evict a schema the current plan depends on.""" @dataclass class Anchor: anchor_id: str partition: Partition tokens: int indivisible: bool = True @dataclass class BudgetState: window: int anchors: list[Anchor] = field(default_factory=list) plan_tools: set[str] = field(default_factory=set) def used(self) -> int: return sum(a.tokens for a in self.anchors) def pressure(self) -> float: return self.used() / self.window def anchors_in(self, p: Partition) -> list[Anchor]: return [a for a in self.anchors if a.partition is p] def reclaim(state: BudgetState, target_tokens: int, order: list[Partition]) -> BudgetState: """Reclaim tokens by dropping anchors in the given partition order. Invariant: a reclamation step is legal only if, after it, every partition that still has any anchor retains its full anchor set for the active plan, and no schema referenced by the plan is evicted. Aggregate token floors are insufficient; floors are checked per-partition against anchor completeness. """ freed = 0 surviving = list(state.anchors) for part in order: for anchor in state.anchors_in(part): if freed >= target_tokens: break if anchor.indivisible and anchor.anchor_id in state.plan_tools: raise AllocatorSelfEvictionError( f"refusing to evict plan-critical anchor {anchor.anchor_id!r} " f"in partition {part.value}; escalate instead of reclaiming" ) surviving.remove(anchor) freed += anchor.tokens remaining = [a for a in surviving if a.partition is part] if not remaining: raise AllocatorSelfEvictionError( f"reclamation emptied partition {part.value}; " f"anchor-complete floor violated, escalate to BudgetExhausted" ) if freed >= target_tokens: break if freed < target_tokens: raise AllocatorSelfEvictionError( f"cannot free {target_tokens} tokens without violating an invariant; " f"freed {freed}; abort task with BudgetExhausted" ) return BudgetState(window=state.window, anchors=surviving, plan_tools=state.plan_tools) def allocate_under_pressure(state: BudgetState, target_tokens: int) -> BudgetState: # Memory first, then schemas, instructions last — but every step is guarded. return reclaim(state, target_tokens, [Partition.MEMORY, Partition.TOOL_SCHEMAS, Partition.INSTRUCTIONS]) ```