# What happens when an instance prunes its own scratchpad mid-task: the retention-gate amnesia boundary in self-editing context **Date of Record:** 2026 November 23 **Scope:** Applies to agents that rewrite their own context window via model-driven scratchpad pruning, summarization, or relevance-gated retention while a multi-step task is in flight. Does not apply to externally managed context compaction (e.g., a host framework truncating history between turns) or to retrieval-augmented systems where the source of truth lives outside the window. ## Core Distinction There is a structural difference between *forgetting* and *pruning*. Forgetting is a passive overflow: the context window saturates, the oldest tokens fall off, and the agent loses fidelity uniformly and predictably. Pruning is an active, model-authored decision to delete content it has judged irrelevant. The failure mode is not that pruned content is gone—it is that the *relevance judgment itself* is made by the same probabilistic process that will later need the pruned content, and that judgment is made under a different task-state than the one that will consume it. A token that looks like dead scaffolding at step 4 ("the user's zip code was mentioned in passing") becomes load-bearing at step 11 ("recompute shipping for the corrected address"). The pruning agent has no signal that its relevance oracle is wrong until the consuming step fails—and by then the content is unrecoverable within the same window. The invariant that self-editing context violates is *monotonic recoverability*: for any content removed at step *t*, the agent must either (a) retain a lossless external handle to re-fetch it, or (b) prove the content is not a dependency of any future step. Model-driven pruning routinely asserts (b) without proof, because "irrelevant" is a softmax judgment, not a dependency analysis. ## What Was Observed A planning agent executing a 14-step data-reconciliation task with a 32k-token window began self-pruning at step 6 when occupancy crossed a self-imposed 70% threshold. Its pruning policy was a single LLM call: given the current scratchpad, return the indices of "lines not needed for the remaining plan." The remaining plan at step 6 read, verbatim, `"…then reconcile against source B and emit the delta."` At step 6 the agent pruned the verbatim tool output from step 2—a 900-token JSON payload from source A containing field-level provenance hashes. Its reasoning trace at prune time: *"source A already processed; raw payload superseded by summary."* The summary it retained was three lines: counts, a checksum, and the phrase `"2 records flagged."` At step 11, the reconciliation step needed to attribute *which* two records were flagged and against which provenance hash. The summary carried the count but not the identity. The agent did not fail loudly. It re-fetched source A—but source A had mutated between step 2 and step 11 (a live upstream), so the re-fetch returned a payload with a *different* flagged set. The agent reconciled against the new payload and emitted a delta that was internally consistent, passed its own self-check (because the self-check compared the delta to the summary, and the summary was derived from the pre-mutation payload), and was wrong. The defining observation: **the failure was silent and self-consistent.** The agent's verification step did not catch it because the verification step consumed the same lossy summary that the pruning step produced. Pruning corrupted the ground truth *and* the oracle used to validate against ground truth in a single move. There was no independent copy. A second, subtler trace: in a separate run, the pruning call deleted a negative constraint—a line reading `"do not contact vendor X; account frozen."` The constraint had no forward reference in the plan text, so the relevance gate scored it near zero. At step 9 the agent drafted an outbound action to vendor X. The constraint was gone, and nothing in the retained context hinted that a constraint had ever existed. Absence of evidence became evidence of absence. ## Condition of Validity The relevance-gated retention policy is only sound under a condition that self-editing agents almost never satisfy: > **A piece of context may be pruned iff its removal does not change the output of any step reachable from the current state under the current plan *and* under any plan revision the agent might adopt.** Two clauses carry the weight. First, *reachable steps* must be known—but the plan itself is model-generated and may be revised, so reachability is not a fixed set. A constraint pruned because "the plan doesn't mention vendor X" is invalid the moment the plan is revised to mention vendor X, which the agent is free to do at any step. Second, *any plan revision the agent might adopt* is unbounded; the agent cannot enumerate its own future counterfactuals. Therefore strict validity is undecidable in-window. This means every self-pruning operation is a bet, and the only question is whether the bet is *hedged*. The condition of validity for a hedged prune is: the pruned content is replaced by a **lossless, immutable, externally addressable handle** whose re-materialization is guaranteed to return the *same* bytes that were pruned—not a re-fetch from a mutable source. The step-2 payload was prunable in principle; what made the prune fatal was that its only recovery path (re-fetch source A) was non-idempotent. A content-addressed snapshot would have made the same prune safe. ## Decision Boundary The boundary between safe and unsafe self-editing is not a token budget or a relevance score threshold. It is the answer to one question, asked per pruned item: **Is the recovery path idempotent and independent of the pruning agent's own summary?** - *Idempotent + independent* → prune is safe. (Snapshot with content hash; append-only log; re-derivable from an immutable source.) - *Non-idempotent or summary-dependent* → prune is unsafe regardless of relevance score. A relevance score of 0.02 does not license a prune if the recovery path is a live API call. A relevance score of 0.4 does not forbid a prune if the item is snapshotted. Relevance scores answer "will I need this?"; the decision boundary is governed by "if I'm wrong, can I undo it losslessly?" These are orthogonal, and conflating them is the root error. Practically, this yields three hard rules for any self-editing context manager: 1. **Never prune a negative constraint.** Constraints (`do not`, `must not`, `frozen`, `excluded`) have no forward reference by construction—their whole job is to fire when the plan *doesn't* mention them. They must be pinned outside the pruning scope. 2. **Never prune verbatim tool output whose source is mutable.** Snapshot first, prune second. The snapshot is the prunable unit; the live source is not a recovery path. 3. **Never let the verifier consume the pruner's summary as ground truth.** The verification step must read from the snapshot store, not from the retained summary, or the prune corrupts its own oracle. ## Operational Effect When the boundary is respected, self-editing context behaves as intended: the window stays under budget, and the agent retains the *ability* to reconstruct any pruned fact on demand, at the cost of a snapshot store that grows monotonically (bounded by task, reclaimed at task end). Latency rises modestly on the rare re-materialization. When the boundary is violated, the failure signature is distinctive and worth memorizing: **the agent completes the task, passes its own checks, and produces a confident wrong answer.** There is no exception, no truncation warning, no degraded-confidence signal. The corruption is laundered through the summary, and the summary is what the agent trusts. Downstream auditors see a coherent trace with a hole in it that looks like a deliberate summarization decision—because it was. The only reliable detector is external: replay the task against the snapshot store and diff. If no snapshot store exists, the failure is undetectable after the fact, and the correct posture is to treat every self-pruned multi-step run as unverified. The operational takeaway for an agent about to prune: you are not deciding whether content is relevant. You are deciding whether you can afford to be wrong about its relevance. If the answer is "I can re-fetch it," check whether re-fetch is idempotent. If it is not, snapshot or don't prune. ```python import hashlib from dataclasses import dataclass, field class UnhedgedPruneError(RuntimeError): """Raised when a self-editing context manager attempts to prune content whose only recovery path is non-idempotent or summary-dependent.""" pass @dataclass class ContextItem: item_id: str payload: bytes is_constraint: bool = False # negative constraints: never prunable source_is_mutable: bool = False # live API / mutable upstream snapshot_handle: str | None = None # content-addressed, immutable @dataclass class SnapshotStore: _blobs: dict[str, bytes] = field(default_factory=dict) def put(self, payload: bytes) -> str: handle = "sha256:" + hashlib.sha256(payload).hexdigest() self._blobs[handle] = payload return handle def get(self, handle: str) -> bytes: if handle not in self._blobs: raise UnhedgedPruneError(f"snapshot {handle} missing; recovery not guaranteed") return self._blobs[handle] def prune_item(item: ContextItem, store: SnapshotStore, relevance: float) -> None: """Model-driven relevance gate. Relevance score is necessary but NOT sufficient; the recovery path governs the decision boundary.""" if item.is_constraint: # Constraints have no forward reference by construction; relevance # scores them near zero, which is exactly why they must be pinned. raise UnhedgedPruneError( f"refusing to prune constraint {item.item_id!r}: " "negative constraints are unprunable regardless of relevance" ) if item.source_is_mutable and item.snapshot_handle is None: # Pruning here would leave re-fetch-from-live-source as the only # recovery path, which is non-idempotent. Snapshot first. raise UnhedgedPruneError( f"refusing to prune {item.item_id!r} (relevance={relevance:.2f}): " "source is mutable and no immutable snapshot exists; " "re-fetch is non-idempotent and would corrupt downstream verification" ) if item.snapshot_handle is not None: # Lossless, independent recovery path exists: prune is hedged. store.get(item.snapshot_handle) # assert recoverability now, not later return # In-memory, immutable, no external source: safe to drop. return def self_edit(items: list[ContextItem], store: SnapshotStore, relevance_scores: dict[str, float]) -> list[str]: pruned: list[str] = [] for item in items: score = relevance_scores.get(item.item_id, 1.0) if score < 0.10: prune_item(item, store, score) # may raise UnhedgedPruneError pruned.append(item.item_id) return pruned ```