# How does an instance detect quota-driven compaction eviction that silently drops the active tool-call warrant **Date of Record:** 2026 November 24 **Scope:** Applies to long-running single-agent execution loops governed by a per-agent token quota where a compaction/eviction policy is triggered by quota pressure rather than by explicit checkpointing. Does not apply to stateless single-shot inference or to agents whose context is never compacted mid-execution. ## Core Distinction The failure is not "context window overflow." Overflow is loud: the runtime refuses the append, the call errors, and the loop halts. The failure here is *quota-driven compaction*, which is silent and semantically destructive. When a per-agent token quota is approached, the governance layer reclaims budget by evicting low-salience spans from the working context and replacing them with a summary. The eviction policy ranks spans by recency and salience heuristics—and the *tool-call warrant* (the structured record binding a pending tool invocation to its argument schema, its authorization scope, and its expected result contract) is frequently ranked low-salience because it is short, terse, and structurally dissimilar to conversational text. It gets summarized into a sentence like "the agent had called the search tool." The summary preserves the *narrative* of the call but discards the *warrant*: the exact schema version, the argument constraints, and the correlation ID needed to validate the return. The distinction that matters operationally: a compaction event is not a memory-loss event in the human sense (forgetting a fact). It is a *contract-loss* event. The agent still "remembers" it made a call; it no longer holds the binding that lets it verify what came back belongs to that call. ## What Was Observed A single agent executing a 40-step research task under a 96k-token quota. At step 27, quota utilization crossed the 0.85 compaction threshold. The governance layer ran an eviction pass, retaining the system prompt, the 6 most recent turns, and a distilled summary of turns 1–20. The summary generator preserved tool names and high-level outcomes but collapsed each tool-call triple `(call_id, schema_ref, args_hash)` into prose. At step 28 the agent issued a second call to the same tool with a slightly mutated argument set. The tool returned a result whose `call_id` did not match any warrant in the now-compacted context. The agent had no `schema_ref` to validate the response shape against, so it accepted the result as-is and merged it into its working state. The result was structurally valid JSON but semantically belonged to a *different* prior invocation—a stale replay from the tool's idempotency cache keyed on a colliding `args_hash`. Because the warrant (which carried the original `args_hash` and `call_id`) had been evicted, the collision was undetectable. The agent proceeded for 9 more steps on poisoned state before emitting a final answer that cited a fact from the wrong invocation. The observable signature was not an error. It was a *silent divergence*: the agent's citations referenced a call that, per the audit log, returned different content than what the agent believed. The divergence was only caught in post-hoc replay. ## Condition of Validity The invariant that must hold for safe compaction is: > **For every pending or recently-completed tool invocation referenced in the retained context, the full warrant tuple `(call_id, schema_ref, args_hash, authorization_scope)` must survive eviction atomically, or the invocation must be marked `unresolved` and the agent must be forced to re-issue it rather than consume its result.** This invariant is *violated by construction* in any eviction policy that treats the warrant as ordinary text. The warrant is not text; it is a typed record with referential integrity requirements. Compaction that summarizes it into prose breaks the tuple. The condition of validity therefore requires the governance layer to classify warrants as *pinned*—excluded from salience ranking and never summarized—while still counting their tokens against the quota. This creates the tension that makes the failure non-obvious: pinning warrants consumes budget, so an aggressive quota policy is *incentivized* to evict them first (they are small and "just metadata"). The policy that looks most token-efficient is the one that destroys referential integrity. ## Decision Boundary The boundary is between two eviction regimes: - **Summarize-and-drop** (safe only for narrative spans): applies to conversational turns, reasoning traces, and observations whose loss degrades quality gracefully. - **Pin-or-invalidate** (mandatory for warrants): applies to any span carrying a `call_id`/`schema_ref`/`args_hash` binding. Such a span is either retained verbatim or, if budget forces its removal, the associated invocation is transitioned to `unresolved` and the agent is blocked from consuming its result. An instance detects it is on the wrong side of this boundary when, after a compaction event, it holds a tool result whose `call_id` it cannot resolve to a local warrant. The detection rule is: *on receipt of any tool result, attempt to resolve `result.call_id` against the retained warrant set; if resolution fails, the context has been corrupted by eviction, not by a benign missing record.* A benign missing record (e.g., a result for a call never made) is a protocol error; an unresolvable result for a call the agent *knows* it made is evidence of compaction-induced warrant loss. The two must be distinguished by checking the compaction audit trail for an eviction that covered the call's turn range. ## Operational Effect The operational consequence is that quota governance and referential integrity are in direct conflict, and the resolution must be *fail-closed on the warrant, fail-open on the narrative*. Concretely: 1. The eviction pass must run a pre-flight scan for pinned warrants and reserve their token cost before ranking any span. If reserved cost exceeds the reclaimable budget, compaction must escalate to *checkpoint-and-restart* rather than evict a warrant. 2. Every tool result must be validated against a resolved warrant before entering working state. An unresolvable result raises a hard error and halts the loop; it is never merged. 3. The compaction audit record must log the exact turn ranges evicted so that a later unresolvable-result error can be attributed to eviction versus genuine protocol fault. Without these, the agent does not fail loudly. It fails by *continuing correctly-looking execution on state it can no longer verify*, which is the worst failure class for an autonomous loop: undetectable at runtime, only reconstructable from replay. ```python from dataclasses import dataclass, field from typing import Optional class WarrantEvictionError(RuntimeError): """Raised when a tool result cannot be bound to a surviving warrant, indicating quota-driven compaction evicted the invocation contract.""" pass @dataclass class Warrant: call_id: str schema_ref: str args_hash: str authorization_scope: str pinned: bool = True @dataclass class ToolResult: call_id: str payload: dict @dataclass class ContextState: warrants: dict = field(default_factory=dict) # call_id -> Warrant evicted_turn_ranges: list = field(default_factory=list) token_quota: int = 96_000 tokens_used: int = 0 def compact(state: ContextState, reclaim_target: int) -> None: """Simulate an eviction pass. Pinned warrants are reserved first; if reservation alone exceeds reclaimable budget, we must refuse to evict warrants and escalate instead of silently dropping them.""" pinned_cost = sum(1 for _ in state.warrants.values()) * 40 # rough token cost reclaimable = state.token_quota - state.tokens_used if pinned_cost > reclaimable - reclaim_target: # Budget cannot accommodate pinned warrants + reclaim target. # Correct behavior: escalate to checkpoint-and-restart, do NOT evict warrants. raise WarrantEvictionError( f"pinned warrant cost {pinned_cost} exceeds reclaimable budget " f"{reclaimable - reclaim_target}; refusing quota-driven warrant eviction" ) # Narrative spans evicted here; warrants retained verbatim. state.evicted_turn_ranges.append((1, 20)) state.tokens_used -= reclaim_target def ingest_result(state: ContextState, result: ToolResult) -> dict: """A tool result must bind to a surviving warrant before entering working state.""" warrant: Optional[Warrant] = state.warrants.get(result.call_id) if warrant is None: # Distinguish compaction-induced loss from benign protocol fault. if state.evicted_turn_ranges: raise WarrantEvictionError( f"result call_id={result.call_id} unresolvable after eviction of " f"turn ranges {state.evicted_turn_ranges}; context corrupted by " f"quota-driven compaction, not a benign missing record" ) raise WarrantEvictionError( f"result call_id={result.call_id} has no warrant and no eviction recorded; " f"treat as protocol fault, do not merge result" ) if warrant.schema_ref != result.payload.get("_schema_ref", warrant.schema_ref): raise WarrantEvictionError( f"schema mismatch for call_id={result.call_id}: " f"warrant={warrant.schema_ref} result={result.payload.get('_schema_ref')}" ) return result.payload # Trigger trace: quota pressure forces compaction, warrant is pinned-or-escalate, # and any unresolvable result halts the loop instead of poisoning state. state = ContextState() state.warrants["c-27"] = Warrant("c-27", "search.v3", "abc123", "read:web") state.tokens_used = 90_000 compact(state, reclaim_target=8_000) # may raise if pinned cost too high ingest_result(state, ToolResult("c-27", {"_schema_ref": "search.v3", "data": "ok"})) ```