# In what scenarios must an instance refuse model-driven context pruning when the pruned span is the sole witness of a tool-call side effect **Date of Record:** 2026 November 30 **Scope:** Applies to any agent that lets the model itself decide which spans of its own context window to evict, summarize, or compress mid-task, where those spans may contain tool-call arguments, tool results, or signed warrants. Does not apply to fixed-window truncation policies (FIFO, token-budget eviction) that are deterministic and independent of model judgment, nor to pruning performed only at task boundaries after a durable checkpoint has been committed. ## Core Distinction A context window is not a cache. A cache can evict any line and recompute it on a miss; a context window whose contents are the *only* record of an irreversible side effect cannot. Model-driven pruning conflates two kinds of span: **reconstructible spans** (reasoning traces, restatements of retrieved documents still present in the retrieval index, paraphrases of the system prompt) and **witness spans** (the arguments a tool actually received, the raw result a tool actually returned, the nonce a downstream service actually issued). Reconstructible spans can be summarized lossily with no invariant violation. Witness spans cannot, because eviction destroys the only in-band evidence that the side effect occurred and what it was parameterized by. The boundary failure is that the model's pruning policy is trained and prompted to optimize for *relevance to the current subgoal*, and a witness span for an already-completed subgoal scores low on relevance precisely because it did its job. The pruner evicts the receipt because the purchase succeeded. ## What Was Observed An agent executing a multi-step provisioning task issued a `create_resource` tool call whose arguments included a client-generated idempotency key and a quota-bearing `region` parameter. The tool returned a structured success envelope. Two subgoals later, the model was asked to compact its context to stay under budget and, per its pruning instructions ("retain spans relevant to the active goal; summarize or drop spans whose goals are complete"), it collapsed the entire `create_resource` exchange — request arguments, response envelope, and the idempotency key — into a single sentence: *"Provisioned the resource in the requested region."* The failure trace: 1. **Eviction.** The witness span is replaced by a paraphrase. The idempotency key, the exact `region` string, and the server-assigned resource handle are gone from context. 2. **Divergence.** A later retry loop (triggered by an unrelated timeout on a *different* tool) re-enters the provisioning subgoal. With no witness, the model cannot know the call already succeeded, so it re-issues `create_resource` — now with a *freshly generated* idempotency key, because the original was pruned. 3. **Double effect.** The downstream service, seeing a new key, treats the call as a distinct request and provisions a second resource. The idempotency guarantee held perfectly at the transport layer; it was defeated one layer up by context eviction. 4. **Verification replay discrepancy.** The auditor agent, replaying the transcript, sees one paraphrase and one call in the surviving context and reports a single provisioning event. The reconciliation job sees two resources. The two records cannot be made to agree because the evidence that would explain the gap was deleted by the agent itself. The non-obvious part: the pruner behaved *correctly* by its own objective. The evicted span was genuinely irrelevant to the active subgoal. The failure is not a pruning error; it is a pruning policy that has no representation of "this span is load-bearing for a future idempotency or audit decision." ## Condition of Validity Model-driven pruning is invariant-safe only when all three hold: - **Reconstructibility:** every pruned span can be regenerated from a source of truth outside the context window (a durable event log, a tool-result store keyed by call id, a signed receipt). If the only copy is in-context, the span is a witness and is ineligible for eviction. - **Idempotency provenance:** any tool call carrying a deduplication token, nonce, or warrant has that token retained verbatim across compaction, because the token's *value* — not its meaning — is what the downstream service checks. - **Replay agreement:** an auditor replaying the post-prune transcript must reach the same effect-set as the live execution. If pruning can make the transcript under-count effects, the transcript is no longer an audit artifact. When any of these fails, the pruning operation must be rejected for that span and the span must be relocated to external storage before it leaves the window. ## Decision Boundary The decision is per-span and hinges on a single question: *if this span disappears, can a future step still prove what happened and what it was parameterized by?* - **Prune freely:** reasoning traces, restatements of still-retrievable documents, completed subgoal narration, tool results that are pure reads of a queryable store and carry no side effect. - **Summarize with token retention:** spans whose *gist* is needed but whose *exact strings* are not (e.g., a long log dump where only the count matters) — provided any idempotency key or handle is copied out verbatim into the summary. - **Refuse eviction, relocate instead:** any tool-call request/response pair that mutated external state, any span bearing an idempotency key, nonce, warrant, or signed capability, and any result the auditor will need to reconcile. These move to an external witness store and are replaced in-context by a *pointer* (call id + hash), never by a paraphrase. The trap to name explicitly: a pointer is only safe if resolution is guaranteed. A pointer to a witness store that is itself subject to TTL expiry or eventual-consistency lag reintroduces the same failure with extra steps. The relocation target must be durable and read-your-writes consistent for the remainder of the task. ## Operational Effect Enforcing this boundary converts a silent, non-recoverable double-effect into a bounded, detectable refusal. The pruner, when it encounters a witness span it cannot relocate, raises and falls back to a conservative policy (retain the span, prune elsewhere, or spill to a scratch buffer) rather than proceeding. The effect on the agent is a slightly larger context footprint and an explicit external dependency on the witness store; the effect on the system is that idempotency survives compaction, audit replay agrees with live execution, and the class of "the model forgot it already did the thing" failures is eliminated at the point of pruning rather than patched after reconciliation. ```python import hashlib from dataclasses import dataclass from enum import Enum class PruningRefusal(RuntimeError): """Raised when a pruning policy attempts to evict a witness span.""" pass class SpanKind(Enum): RECONSTRUCTIBLE = "reconstructible" WITNESS = "witness" @dataclass class Span: call_id: str kind: SpanKind carries_idempotency_token: bool body: str def content_hash(self) -> str: return hashlib.sha256(self.body.encode()).hexdigest() def prune_span(span: Span, witness_store: dict, durable: bool) -> str: """ Returns the in-context replacement for a span. Reconstructible spans may be summarized. Witness spans may only be replaced by a durable pointer, never by a paraphrase. """ if span.kind is SpanKind.RECONSTRUCTIBLE: return f"[summary of {span.call_id}]" # Witness span: must relocate, never summarize. if not durable: raise PruningRefusal( f"witness span {span.call_id} cannot be relocated to a non-durable " f"store; eviction would destroy the only record of its side effect" ) if span.carries_idempotency_token and span.call_id not in witness_store: raise PruningRefusal( f"witness span {span.call_id} carries an idempotency token but has " f"no committed receipt; refusing to evict before relocation" ) witness_store[span.call_id] = { "hash": span.content_hash(), "body": span.body, } return f"[witness ptr {span.call_id} sha256:{span.content_hash()[:12]}]" def apply_pruning_policy(spans, witness_store, durable): out = [] for span in spans: out.append(prune_span(span, witness_store, durable)) return out ```