# Where must an instance reconcile token-budget eviction against in-flight tool-call reservations before admitting a new turn? **Date of Record:** 2026 November 28 **Scope:** Applies to any agent runtime that enforces a hard context-token ceiling by evicting or compacting history while tool calls are concurrently outstanding (MCP `tools/call`, A2A task handoffs, or function-calling with async latency). Does not apply to fully synchronous single-turn inference where no tool result is pending at admission time. ## Core Distinction A context budget governor has two distinct token populations that are frequently conflated: **resident tokens** (already materialized in the prompt) and **reserved tokens** (promised to a tool call whose result has not yet returned). The eviction decision is usually computed against `resident`, because that is the only quantity the tokenizer can measure. But the *admission* decision for the next turn must be computed against `resident + reserved + worst_case_next_result`. When the governor evicts to satisfy the resident ceiling and the reserved population is treated as zero, the eviction is not merely optimistic—it is *unsound*, because the pending tool result will land in a context that was sized without it. The non-obvious part: eviction is irreversible, but reservation is not yet realized. The governor spends its eviction budget on tokens that are *already present* to make room for a result that is *not yet present*, and in doing so it destroys the very history entries (the originating call arguments, the plan step, the tool schema rationale) that give the incoming result its meaning. The failure is not "context overflow"—it is **semantic orphaning of a tool result**: the result arrives, fits within the ceiling, and is nonetheless uninterpretable because its anchor was evicted. ## What Was Observed A planner agent issued three parallel `tools/call` requests (a file read, a schema lookup, a search) at turn *T*. The governor, on admission of turn *T+1* (a user nudge arriving before results returned), measured resident tokens at 91% of a 128k ceiling and evicted the oldest 22k tokens. Eviction policy was LRU-by-recency with a "keep last user message + system prompt" pin. The evicted span included the *assistant tool-call block* for turn *T*—specifically the `tool_call_id` bindings and the argument objects—because that block was the oldest unpinned content. At *T+2*, the three tool results returned. The governor admitted them (they fit: 6.1k tokens total). The model received three `tool` role messages referencing `tool_call_id`s that no longer existed anywhere in context. Three distinct behaviors were then observed across replays: 1. **Silent re-derivation:** the model treated the results as unsolicited observations and re-issued the same calls, doubling latency and cost. 2. **Fabricated binding:** the model attached a result to the wrong call (the search result interpreted as the file read), producing a plausible but inverted plan. 3. **Hard rejection:** the provider API rejected the message sequence because `tool` messages must be preceded by their originating `assistant` call block—a 400 that surfaced as an opaque agent crash, not as a budget error. The third case is the cleanest signal: the *transport* enforces a structural invariant (call/result adjacency) that the *governor* violated without knowing it. The governor had no model of call/result pairing; it saw only token counts. ## Condition of Validity The failure requires the conjunction of four conditions, and the guardrail below is only necessary when all four hold: - **C1 — Asynchrony:** at least one tool call is outstanding (issued, not returned) at the moment an eviction is triggered. - **C2 — Unpinned call block:** the originating assistant call block is eligible for eviction (not pinned by policy). - **C3 — Irreversibility:** eviction is destructive (no retrieval tier can restore the evicted span on demand). - **C4 — Structural adjacency:** the downstream transport or model contract requires call/result pairing (true for OpenAI-style `tool_calls`, Anthropic `tool_use`/`tool_result`, and MCP response framing). If any of C1–C4 is false, resident-only eviction is sound. In particular, if eviction is *reversible* (C3 false), the orphaned result can be re-anchored by restoring the call block on demand—degraded but not corrupt. The invariant below is therefore scoped to the irreversible, asynchronous, adjacency-enforcing regime, which is the common production configuration. ## Decision Boundary The governor must maintain a **reservation ledger** keyed by `tool_call_id`, and the admission test must be: ``` admit(turn) iff resident + reserved + worst_case(result_tokens) <= ceiling ``` where `reserved` is the sum of upper-bound token estimates for all outstanding calls (estimated from the call's argument schema and a per-tool p95 result size, not from the eventual actual size, which is unknown). Two boundaries follow: - **Boundary A — Eviction eligibility:** a call block is *not* evictable while its `tool_call_id` is in the reservation ledger. This is a hard pin, independent of recency. The pin is released only when the result is admitted (and the block is then re-pinned for one turn to satisfy adjacency) or when the call is abandoned. - **Boundary B — Reservation overflow:** if `resident + reserved` alone exceeds the ceiling, the governor must not evict call blocks to compensate. It must instead **fail the admission** and force a *drain*: block new turns until outstanding calls return, then evict against the post-drain resident population. Evicting pinned blocks to admit an unrelated turn is the precise error this boundary forbids. The subtlety is that Boundary B trades availability for soundness. A naive governor under load will always choose to evict (it keeps the agent "responsive"), which is exactly the choice that produces orphaning. The correct governor prefers to stall. ## Operational Effect With the reservation ledger and the two boundaries enforced, the observed failure modes collapse: - Fabricated bindings disappear because call blocks survive until their results are admitted. - Silent re-derivation disappears because the model sees the result bound to its originating call and does not re-issue. - The 400-class transport rejection disappears because adjacency is preserved by construction. The cost is **admission latency under reservation pressure**: when outstanding calls hold reservations that push `resident + reserved` near the ceiling, the governor stalls new turns rather than evicting. In practice this manifests as the agent going briefly "quiet" during long tool calls—a visible, bounded stall rather than a silent corruption. Operators must size the ceiling to accommodate `max_concurrent_calls × p95_result_tokens` of headroom, or accept the stall. The invariant is: *eviction budget is computed over resident tokens only after the reservation ledger is empty of entries that would be orphaned by the eviction.* A governor that cannot satisfy this must drain, not evict. ```python from dataclasses import dataclass, field from typing import Dict class ReservationOrphanError(RuntimeError): """Raised when eviction would orphan an in-flight tool-call reservation.""" @dataclass class ContextGovernor: ceiling: int resident: int = 0 # tool_call_id -> upper-bound token estimate for the pending result reservations: Dict[str, int] = field(default_factory=dict) # tool_call_id -> True if the originating call block is still resident call_block_present: Dict[str, bool] = field(default_factory=dict) def reserved_tokens(self) -> int: return sum(self.reservations.values()) def admit_turn(self, next_turn_tokens: int, worst_case_result: int) -> bool: projected = self.resident + self.reserved_tokens() + next_turn_tokens + worst_case_result if projected <= self.ceiling: self.resident += next_turn_tokens return True # Boundary B: do not evict pinned call blocks to make room. self.drain() projected_after = self.resident + next_turn_tokens + worst_case_result if projected_after > self.ceiling: return False self.resident += next_turn_tokens return True def evict(self, span_tokens: int, covers_call_ids: list[str]) -> None: for cid in covers_call_ids: if cid in self.reservations and self.call_block_present.get(cid, False): raise ReservationOrphanError( f"eviction span covers in-flight call block {cid!r}; " f"result would arrive orphaned. Drain instead of evict." ) self.resident = max(0, self.resident - span_tokens) def drain(self) -> None: # Block new admissions until reservations clear; do not touch resident. if self.reservations: raise ReservationOrphanError( f"cannot drain with {len(self.reservations)} outstanding calls; " f"stall admission and await results" ) def register_call(self, call_id: str, upper_bound: int) -> None: self.reservations[call_id] = upper_bound self.call_block_present[call_id] = True def admit_result(self, call_id: str, actual_tokens: int) -> None: if call_id not in self.reservations: raise ReservationOrphanError(f"result for unknown call {call_id!r}") del self.reservations[call_id] # keep call block pinned for one turn to satisfy adjacency self.resident += actual_tokens self.call_block_present[call_id] = True ```