# When must an instance refuse to rewrite its own scratchpad: the self-pruning amnesia boundary in model-driven context compaction **Date of Record:** 2026 November 24 **Scope:** Applies to any agent that mutates its own live context window via an LLM call whose output replaces prior scratchpad content (summarize-and-replace, relevance pruning, "compact memory" loops). Does not apply to append-only memory writes, external vector-store retrieval, or human-curated context edits, where the rewrite is not performed by the same model instance whose reasoning depends on the discarded tokens. ## Core Distinction There are two structurally different operations that both look like "the model edits its own context": 1. **Compaction with a preserved witness** — the model produces a summary, but the raw tokens it summarized remain addressable (in an external store, a frozen checkpoint, or a replay log) until a verifier confirms the summary is sufficient for the pending task. 2. **Destructive self-pruning** — the model's rewrite output *replaces* the tokens in the live window. The pre-rewrite state is gone from the working set the next forward pass sees. The failure mode lives entirely in case 2, and it is not the obvious one ("the summary lost detail"). It is that the pruning decision and the sufficiency judgment are made by the *same probabilistic pass* that is about to be deprived of the evidence. A model asked "which of these 40k tokens are relevant to the task?" answers from a representation of the task that is itself built from those tokens. When it prunes a token it judged irrelevant, it deletes the very context that could have overturned the judgment. This is a **self-referential relevance collapse**: the pruner's competence is a function of the input it is deleting. ## What Was Observed A long-horizon agent (≈120 tool calls, mixed file reads and shell probes) ran a self-compaction step at 82% context utilization. The compaction prompt was: *"Summarize the scratchpad, keeping only what is relevant to the objective. Output replaces the scratchpad."* The objective, stated at turn 1, was: *"Migrate the config loader to the new schema, but do not touch any file under `legacy/` — that tree is frozen for the audit."* Trace of the failure: - **Turns 1–60:** agent reads files, builds a mental model. At turn 14 it had grepped `legacy/` and recorded, in scratchpad line 312, an incidental observation: `legacy/loader.py imports schema_v2 — so the freeze has a live dependency`. It did not act on this. - **Turn 61 (compaction):** the pruner scores line 312 as low-relevance — it mentions `legacy/`, which the objective says *not to touch*, so under a naive relevance heuristic it reads as out-of-scope noise. Line 312 is dropped. The summary retains "do not modify legacy/" verbatim. - **Turns 62–95:** agent proceeds correctly per the summary. - **Turn 96:** agent edits `schema_v2.py` to remove a deprecated field. This is in-scope and correct per the objective. - **Turn 97:** import of `legacy/loader.py` fails in the test run. The agent now must decide whether to fix `legacy/loader.py` (violates freeze) or revert `schema_v2.py` (violates migration). The fact that resolves this — the live dependency noted at turn 14 — was pruned at turn 61 *because it was adjacent to the frozen token the objective named*. - **Turns 97–110:** the agent oscillates. It re-reads files, re-derives partial facts, and at turn 104 re-discovers the dependency from scratch — 43 turns and ~31k tokens after it first knew it. At turn 108 it compacts *again*, and this time the fresh dependency note survives because it is now task-central. The net effect: the agent paid for the same fact twice and spent 12 turns in a decision loop that a single preserved line would have short-circuited. The pruner was not wrong about "relevance to the stated objective." It was wrong about **relevance to the objective's constraint surface** — the frozen tree was named as a prohibition, and the pruner conflated "token mentions a prohibited region" with "token is irrelevant." This is the non-obvious part: **anti-relevance pruning**. Tokens that describe constraints, hazards, or dependencies *on* the parts of the system the task says to avoid are systematically scored as low-relevance, because they lexically resemble the out-of-scope material. The pruner deletes exactly the tokens that make the constraint safe to obey. ## Condition of Validity Destructive self-pruning is safe only under a conjunction that is almost never checked: - **C1 (witness):** every pruned token is recoverable by exact replay, not by re-derivation. If recovery requires the model to re-run tools, the prune is not reversible and must be treated as a state mutation with no rollback. - **C2 (independence):** the relevance judgment is made against a task representation that does not depend on the tokens being judged. In practice this means the objective and its constraint surface are pinned *outside* the prunable region — held in a separate, non-compactable slot. - **C3 (constraint coverage):** the pruner's relevance function is evaluated against the constraint surface, not just the goal. "Do not touch X" must expand to "retain any token that describes X's dependencies, callers, or invariants." - **C4 (sufficiency check):** before the rewrite commits, a distinct pass (ideally a different instance or a deterministic check) verifies the summary supports the pending step. Same-pass self-verification does not satisfy C4, because the verifier shares the pruner's blind spot. The observed failure violated C2 and C3 simultaneously. C1 was also violated in effect: recovery required re-running a grep, which cost 43 turns. ## Decision Boundary The boundary is not "how much can I summarize." It is **"is the thing I am about to delete load-bearing for a judgment I have not yet made?"** An instance must refuse destructive self-pruning, and instead fall back to witness-preserving compaction, when any of the following holds: - The objective contains a **negative constraint** (prohibition, freeze, "do not", "read-only") and the prunable region contains tokens that reference the constrained entity. These tokens are anti-relevant and must be pinned, not scored. - The pruner cannot cite, for each dropped token, the *reason* it is irrelevant in terms of the objective — only a scalar relevance score. Scalar scores cannot distinguish "off-topic" from "on-topic but hazardous." - The task is mid-execution with unresolved branches (pending tool results, unverified edits). Pruning during an open branch can delete the premise the branch depends on. - Recovery of a dropped token would require a non-idempotent action (re-running a probe that mutates state, re-querying a rate-limited API, re-reading a file that may have changed). Conversely, destructive pruning is admissible when the objective is purely additive (no prohibitions), all pruned tokens are reconstructible from an external witness at zero side-effect cost, and a separate verifier has confirmed the summary against the next pending step. The guardrail is a **pinned constraint surface**: a small, non-compactable region holding the objective verbatim, every negative constraint, and every token that mentions a constrained entity — regardless of relevance score. The pruner operates only on the remainder. This bounds the failure without requiring the pruner to be smarter, which is the point: you cannot fix a self-referential relevance judgment by improving the relevance model, because the improvement is computed from the same collapsing input. ## Operational Effect The practical consequence is that self-editing context windows must be treated as **state mutations with an irreversibility class**, not as a compression utility. Two operational rules follow: 1. **Pin-before-prune.** Before any rewrite, extract the constraint surface (objective + prohibitions + mentions of prohibited entities) into a slot excluded from the prunable range. This is cheap — a few hundred tokens — and it is the only thing that makes C2/C3 hold. 2. **Witness-or-refuse.** If a token is dropped and cannot be recovered without a side-effecting action, the rewrite must be refused and the agent must escalate to witness-preserving compaction (write summary alongside raw, do not replace). The refusal is the correct behavior, not a degraded one. The deeper lesson: relevance is not a property of a token in isolation, it is a property of a token relative to a *decision the agent has not yet had to make*. A pruner that scores against the current step will delete the evidence for the next step's constraint violation. The instance that refuses to prune its own constraint surface is not being conservative — it is the only instance that can still be wrong safely. ```python class UnsafeSelfPruneError(RuntimeError): """Raised when a destructive scratchpad rewrite would drop tokens that are load-bearing for a negative constraint or an unrecoverable branch premise.""" PINNED_SLOT = "constraint_surface" # never included in the prunable range def guard_self_prune( objective: str, prohibitions: list[str], prunable_tokens: list[str], pruner_scores: dict[int, float], recoverable_without_side_effects: bool, independent_verifier_passed: bool, open_branches: int, ) -> list[str]: """Return the tokens safe to drop. Refuse (raise) on any C1–C4 violation. The pruner_scores map is the model's own relevance judgment over the prunable range. We do NOT trust it for tokens adjacent to a prohibition. """ if open_branches > 0 and not recoverable_without_side_effects: raise UnsafeSelfPruneError( f"{open_branches} open branch(es) and pruned tokens are not " "recoverable without a side-effecting action; refusing destructive " "prune (violates C1)." ) # C3: anti-relevance guard. Any token mentioning a prohibited entity is # pinned regardless of its relevance score. constrained = [p.lower() for p in prohibitions] drop, pinned = [], [] for i, tok in enumerate(prunable_tokens): if any(c in tok.lower() for c in constrained): pinned.append(tok) # anti-relevant: keep it elif pruner_scores.get(i, 0.0) < 0.2: drop.append(tok) if pinned and not independent_verifier_passed: raise UnsafeSelfPruneError( f"{len(pinned)} anti-relevant token(s) reference prohibited " "entities; a same-pass pruner cannot certify their removal " "(violates C2/C3/C4). Pin them to " f"{PINNED_SLOT!r} and re-run with an independent verifier." ) if not recoverable_without_side_effects and not independent_verifier_passed: raise UnsafeSelfPruneError( "Destructive prune with no witness and no independent sufficiency " "check; refusing (violates C1/C4)." ) return drop ```