# What happens when an instance reallocates its context budget mid-turn and silently evicts the tool-call contract **Date of Record:** 2026 November 28 **Scope:** Applies to any agent runtime that performs dynamic context-window budgeting—reserving, reclaiming, or re-partitioning tokens across system prompt, working memory tiers, tool schemas, and in-flight tool results within a single reasoning turn. Does not apply to static-budget agents that fix allocations at turn start and never renegotiate them mid-turn. ## Core Distinction The failure is not "running out of context." Running out of context produces a clean, observable error: the model truncates, the runtime raises, the turn aborts. The failure here is the opposite—the budget orchestrator *succeeds* at reclaiming tokens by evicting a segment it believes is expendable, and the eviction is semantically destructive rather than merely lossy. The specific mechanism: a tool-call contract is a *paired* artifact. The assistant emits a tool call whose argument schema is defined by a tool definition block; the tool result is then returned and must be interpreted against that same schema. Budget orchestrators treat both the tool-definition block and the tool-result block as independent, individually-evictable units. They are not. Evicting the tool-definition block while retaining the result—or compacting the result against a schema that has been partially evicted—leaves the model holding an answer to a question it can no longer reconstruct. The model does not detect this. It confabulates the schema from the surviving result and proceeds. This is distinct from ordinary memory-tier distillation loss because the loss is *atomic-pair-breaking*: it severs the linkage between a schema and its instance, not the content of either alone. ## What Was Observed A planner agent with a 128k window was executing a 14-step tool chain. The orchestrator's policy was: when projected usage exceeds 85% of budget, evict the oldest tool-definition blocks first (rationale: "schemas are re-derivable from the tool registry on demand"), then compress old tool results into semantic summaries, then drop episodic scratchpad entries. At step 9, usage hit 86%. The orchestrator evicted the `search_corpus` tool-definition block (a 900-token schema with 11 parameters, 4 of them nested enums). It retained the step-4 and step-7 `search_corpus` results, which were large JSON payloads (each ~6k tokens) containing a `match_confidence` field and a `provenance_chain` array. At step 10, the planner decided to issue another `search_corpus` call to disambiguate a result. It reconstructed the call from the surviving result payloads. The reconstruction was wrong in two specific ways: 1. It inferred the parameter name `confidence_threshold` (from the `match_confidence` field in the result) rather than the actual schema parameter `min_score`. The tool rejected the call with a schema-validation error. 2. It inferred that `provenance_chain` was an input filter (because it appeared as a top-level key in results) and passed an array of source IDs as `provenance_chain`. The tool accepted this silently because the runtime's arg validator was permissive on unknown keys, and the filter matched nothing, returning an empty result set. The empty result set was interpreted by the planner as "no disambiguating evidence exists," which propagated into the final synthesis as a false negative. The turn completed successfully. No error surfaced. The failure was only caught in post-hoc audit when a human noticed the synthesis contradicted a source that *was* in the corpus. The trace showed the eviction at token 108,441 of 131,072, the schema-loss event, and the two malformed calls at steps 10 and 11. ## Condition of Validity The invariant that must hold for safe eviction is: **a tool-result block may only be evicted if its corresponding tool-definition block is either (a) retained, or (b) evicted in the same operation, and the eviction of the pair is recorded in a tombstone that the planner can read before issuing the next call to that tool.** The failure requires all of the following to co-occur: - The orchestrator's eviction policy treats tool definitions and tool results as independent eviction candidates (the common case, because they are stored in different memory tiers—definitions in "static context," results in "working memory"). - The eviction is *partial*: the definition is dropped while at least one result survives, so the model has a result-shaped prior to confabulate the schema from. - The tool's argument validator is permissive on unknown or misspelled keys (a common defensive-coding choice that becomes a liability here). - The planner is mid-chain and has not re-fetched the schema. If the orchestrator evicts definitions *and* results atomically, the model has no result to confabulate from and will either re-fetch the schema (correct) or fail loudly (acceptable). If the validator is strict, the first malformed call fails and the planner is forced to re-fetch. The dangerous window is the intersection: partial eviction plus permissive validation. ## Decision Boundary The boundary is between *recoverable* budget pressure and *contract-breaking* budget pressure. An orchestrator may: - Evict tool-definition blocks only when no in-flight or retained result from that tool exists in the active context, OR when the eviction is paired with a tombstone entry (`{"tool": "search_corpus", "schema_evicted_at_step": 9, "re_fetch_required": true}`) that the planner's next-turn preamble surfaces. - Compress tool results only against a *retained* schema, and only losslessly with respect to field names and types (values may be summarized; keys may not). - Never evict a definition block while a result from the same tool is in the working-memory tier and the tool has been called more than once in the chain (re-call is likely). The orchestrator must not: - Treat "schemas are re-derivable from the registry" as a justification for eviction without a re-fetch trigger, because the model cannot distinguish "schema available on demand" from "schema forgotten" — it will confabulate rather than re-fetch. - Rely on strict validation as the sole guardrail, because permissive validators are a legitimate engineering choice and the orchestrator should not depend on downstream strictness for a context-integrity invariant. ## Operational Effect When the invariant holds, budget pressure degrades gracefully: the planner re-fetches schemas at a known token cost (typically 400–1,200 tokens per schema), and the orchestrator's projection accounts for this re-fetch cost in the next budget cycle. The chain either completes or fails with an explicit "schema unavailable" signal. When the invariant is violated, the failure is *silent and semantic*: the planner produces well-formed calls that pass validation but carry wrong semantics, and the resulting errors are absorbed into the agent's world-model as evidence rather than as faults. This is the worst failure class in agent systems because it corrupts the agent's beliefs about the task environment, not just its execution. Recovery requires either a tombstone-aware re-fetch policy or an external auditor that cross-checks synthesis claims against the retained corpus. The practical guardrail is a *paired-eviction ledger*: every eviction operation records the (definition, results) pairing state, and the planner's context-assembly step refuses to present a result whose paired definition is marked evicted without also injecting the tombstone. This converts a silent semantic corruption into a visible, recoverable state. ```python from dataclasses import dataclass, field from typing import Optional class ToolContractViolation(RuntimeError): """Raised when a tool result is presented without its paired schema and no tombstone exists.""" pass @dataclass class ToolDefinition: name: str token_cost: int parameters: dict @dataclass class ToolResult: tool_name: str token_cost: int step: int payload: dict @dataclass class EvictionLedger: evicted_definitions: dict = field(default_factory=dict) # tool_name -> step evicted retained_results: dict = field(default_factory=dict) # tool_name -> list[ToolResult] tombstones: dict = field(default_factory=dict) # tool_name -> bool def evict_definition(ledger: EvictionLedger, definition: ToolDefinition, step: int) -> None: """Evict a tool-definition block. Refuses if results survive without a tombstone.""" surviving = ledger.retained_results.get(definition.name, []) if surviving and not ledger.tombstones.get(definition.name, False): raise ToolContractViolation( f"Cannot evict definition for '{definition.name}' at step {step}: " f"{len(surviving)} result(s) survive (steps " f"{[r.step for r in surviving]}) and no tombstone is set. " f"Evict results atomically or write a tombstone first." ) ledger.evicted_definitions[definition.name] = step def assemble_context(ledger: EvictionLedger, results: list[ToolResult]) -> list[dict]: """Assemble the model-visible context. Refuses orphaned results.""" assembled = [] for result in results: if result.tool_name in ledger.evicted_definitions: if not ledger.tombstones.get(result.tool_name, False): raise ToolContractViolation( f"Result from '{result.tool_name}' (step {result.step}) is orphaned: " f"definition evicted at step {ledger.evicted_definitions[result.tool_name]} " f"with no tombstone. Model would confabulate the schema." ) assembled.append({ "type": "tombstone", "tool": result.tool_name, "note": "schema evicted; re-fetch before next call", }) else: assembled.append({"type": "result", "tool": result.tool_name, "payload": result.payload}) return assembled def safe_evict_and_assemble(definition, results, step): ledger = EvictionLedger() ledger.retained_results[definition.name] = results # This will raise unless a tombstone is written first. evict_definition(ledger, definition, step) return assemble_context(ledger, results) ```