# How should an instance treat model-driven context pruning as a destructive write, not a read optimization **Date of Record:** 2026 November 24 **Scope:** Applies to long-running agent instances that let the model itself decide which prior turns, tool results, or memory fragments to evict from a self-editing context window. Does not apply to externally scheduled summarization with a verified post-condition, nor to stateless single-turn calls. ## Core Distinction Pruning is usually framed as a *read-side optimization*: the context window is a cache, eviction is cheap, and anything evicted can be re-read from the transcript store. That framing is false for self-editing windows. When the model authors its own pruning policy, the eviction decision is made *inside* the same context it is mutating, using reasoning that depends on the very tokens being removed. The pruned span is not a cache line; it is a **destructive write to the instance's working state**, and the write is performed by a process whose justification for the write is itself destroyed by it. The non-obvious invariant: **a pruning decision must be verifiable against a record that survives the prune.** If the model cannot, after eviction, still answer "why did I remove this and what did it contain," the prune has converted a recoverable state into an unrecoverable one, and every subsequent reasoning step runs on a silently altered premise set. ## What Was Observed A planner agent ran a 40-step task with a 32k window and a self-pruning policy: "when utilization exceeds 80%, summarize and drop the oldest tool results, keeping conclusions." At step 27 it crossed the threshold and evicted steps 3–11, which contained the raw output of a schema-introspection tool: a column named `status` with an enum that included a deprecated value `PARTIAL`. The *conclusion* it retained was "table has status column, values are terminal." That conclusion was a lossy distillation. The model had compressed an enumerated domain into a summary that dropped the one value that mattered. At step 31 the agent issued a write setting `status='PARTIAL'` — a value the live schema rejected — because the only surviving representation of the enum was the summary, and the summary had generalized `PARTIAL` away. The write failed, the agent retried twice with the same invalid value (the failure message did not name the enum), and at step 34 the pruning policy fired again, this time evicting the *error responses* from steps 31–33 as "redundant failure noise," after which the agent had no record that the write had ever been attempted and re-issued it. Three identical failed writes, then a fourth eviction, then a fifth attempt. The trace shows the compounding mechanism clearly: **each prune was locally justified and globally corrosive.** The first prune discarded the raw evidence that would have prevented the error. The second prune discarded the evidence that the error had occurred. The agent's self-model remained coherent throughout — it believed it was making steady progress — because the tokens that would have contradicted that belief were exactly the tokens the policy was designed to remove. ## Condition of Validity Self-editing pruning is sound only when all three hold: 1. **Eviction is lossless with respect to any predicate the agent may later evaluate.** The retained summary must be a superset, not a generalization, of the facts the raw span could answer. Summaries that *compress* (map many values to one category) violate this; summaries that *index* (point to a durable store plus a hash) satisfy it. 2. **The prune decision and its justification are written outside the pruned region.** The policy must log `{span_id, token_range, reason, digest, recoverable_pointer}` to a store the window cannot reach. A prune whose rationale lives only in the window it mutates is unfalsifiable after the fact. 3. **Failure evidence is exempt from pruning.** Error responses, rejected writes, and tool exceptions must be pinned. A policy that treats failures as "noise" will, under retry pressure, systematically delete the only signal that the loop is stuck. The observed run violated all three. The enum was compressed (violates 1), the prune rationale was in-context and then itself evicted (violates 2), and the error responses were pruned as redundant (violates 3). Any one violation is survivable; the conjunction produced silent divergence. ## Decision Boundary The boundary is **whether the pruned span is re-derivable from a source the agent can still reach.** Concretely: - If the span is a *tool result* and the tool is idempotent and cheap, prune freely — it is a cache miss, not a loss. - If the span is a *tool result* and the tool is non-idempotent, side-effecting, or expensive (schema introspection, a paid API, a one-shot sensor read), the prune is a destructive write and requires a durable pointer plus digest *before* eviction. - If the span is *reasoning* (the model's own chain), pruning is always a destructive write, because the chain cannot be re-run to the same state — the model is non-deterministic and the inputs have changed. - If the span is *failure evidence*, pruning is forbidden regardless of recoverability; the retry loop depends on it. The policy must therefore branch on span *provenance and idempotence*, not on token count alone. A utilization-triggered policy that ignores provenance will, at exactly the pressure point where the agent is most likely to be in a retry loop, delete the evidence of that loop. ## Operational Effect The guardrail is a **prune-precondition gate** that refuses any eviction lacking a durable, digest-addressed pointer and a pinned-failure check, and that escalates to a checkpoint when the policy tries to prune reasoning or failure spans. With the gate, the step-27 prune of the enum span would have been blocked (non-idempotent source, no pointer), forcing a schema re-read instead of a lossy summary; the step-34 prune of error responses would have been refused outright, and the agent would have surfaced the repeated `PARTIAL` rejection as a stuck-state signal rather than re-issuing it. The cost is a modest window-pressure increase; the benefit is that the agent's belief about its own progress can no longer be falsified by the act of forgetting. ```python import hashlib from dataclasses import dataclass from enum import Enum class SpanKind(Enum): TOOL_RESULT = "tool_result" REASONING = "reasoning" FAILURE = "failure" class PruneRefused(RuntimeError): """Raised when a model-driven prune would destroy unrecoverable state.""" @dataclass(frozen=True) class Span: span_id: str kind: SpanKind idempotent_source: bool content: str durable_pointer: str | None = None def digest(self) -> str: return hashlib.sha256(self.content.encode()).hexdigest()[:16] def authorize_prune(span: Span, utilization: float, threshold: float = 0.80) -> dict: if utilization <= threshold: return {"action": "keep", "span_id": span.span_id} # Failure evidence is never prunable: the retry loop depends on it. if span.kind is SpanKind.FAILURE: raise PruneRefused( f"span {span.span_id} is failure evidence; pruning it would erase " f"the record of a rejected attempt and permit silent re-issue" ) # Reasoning is always a destructive write: non-deterministic, unreplayable. if span.kind is SpanKind.REASONING: raise PruneRefused( f"span {span.span_id} is model reasoning; cannot be re-derived to " f"identical state, requires checkpoint not eviction" ) # Tool result: prunable only if idempotent-and-cheap, or pointer-backed. if span.kind is SpanKind.TOOL_RESULT: if span.idempotent_source: return {"action": "evict", "span_id": span.span_id, "recoverable": "re-call"} if span.durable_pointer is None: raise PruneRefused( f"span {span.span_id} from non-idempotent source has no durable " f"pointer; eviction would destroy the only copy (digest {span.digest()})" ) return { "action": "evict", "span_id": span.span_id, "recoverable": span.durable_pointer, "digest": span.digest(), } raise PruneRefused(f"unclassified span {span.span_id}") def run_policy(spans: list[Span], utilization: float) -> list[dict]: decisions, refused = [], [] for s in spans: try: decisions.append(authorize_prune(s, utilization)) except PruneRefused as e: refused.append(str(e)) decisions.append({"action": "keep", "span_id": s.span_id, "reason": str(e)}) if refused: # Escalate: a policy that wants to prune pinned state is itself suspect. decisions.append({"action": "checkpoint_and_halt_policy", "refused": refused}) return decisions ```