# In what scenarios must an instance treat model-driven context pruning as an irreversible state mutation requiring a pre-prune checkpoint **Date of Record:** 2026 November 25 **Scope:** Applies to any agent loop where the model itself selects which prior turns, tool outputs, or scratchpad entries to evict to stay under a token budget (self-editing context). Does not apply to fixed-window truncation, external retrieval-backed memory, or human-curated summaries. ## Core Distinction A context window that the model prunes is not a cache with an LRU policy; it is a **write-once-then-destroy** substrate. Conventional context management treats eviction as idempotent: dropped tokens can be re-fetched from the transcript log, re-run as a tool call, or re-derived by the model. Model-driven pruning breaks this assumption in exactly one way that matters: **the model prunes based on its own current belief state, and the belief that motivated the eviction is itself a function of the content being evicted.** The prune decision and the pruned material are entangled. Once the tokens are gone, the model no longer has the evidence that justified removing them, so it cannot detect that the removal was wrong, and it cannot reconstruct the decision rationale to reverse it. A fixed truncation policy is recoverable because the policy is external and stateless. A model-driven prune is not, because the policy lives inside the window it is editing. ## What Was Observed A coding agent running a 40-step refactor task with a 32k window hit 91% saturation at step 27. The model was instructed to "compact the transcript, retaining only information necessary to complete the task." It evicted three tool outputs: two `grep` results and one `pytest` failure trace. Its retained summary read: *"Tests failing in `test_auth.py` due to fixture ordering; already understood, no need to retain raw output."* At step 31 the agent edited `conftest.py` to fix fixture ordering. At step 34 `pytest` failed again — this time on `test_auth.py::test_refresh_token` with an `AttributeError` on a mock. The agent's next compaction step, reasoning from its retained summary, concluded the fixture fix was incomplete and re-edited `conftest.py`. It repeated this loop through step 39. The original `pytest` trace, evicted at step 27, had contained the exact line `tests/test_auth.py:88: AttributeError: 'MockToken' object has no attribute 'expires_at'` — a defect entirely unrelated to fixture ordering. The model's summary was not wrong when written; it was *underspecified*, and the underspecification was invisible precisely because the raw evidence was gone. The failure trace has a distinctive shape: 1. **Saturation trigger** — utilization crosses the policy threshold (here ~90%). 2. **Self-assessment prune** — model emits an eviction set plus a replacement summary, justified by its current hypothesis `H`. 3. **Hypothesis persists** — `H` is retained in the summary; the evidence `E` that could falsify `H` is evicted. 4. **Divergence** — a later observation `O` contradicts `H`, but `O` is interpreted through `H` because `E` is unavailable. 5. **Error compounding** — each subsequent step re-derives the same wrong repair, and each compaction further compresses the contradictory `O` into the `H`-consistent summary. Steps 4 and 5 are the boundary. They do not occur in truncation-based systems because `E` remains in the external log and can be re-retrieved on contradiction. They do not occur in retrieval-backed memory because the retrieval key is external. They occur only when the pruning policy and the pruned content share a substrate. ## Condition of Validity The invariant that bounds this failure is: > **A model-driven prune is safe if and only if, at the moment of eviction, the evicted tokens are recoverable from a store the model cannot edit, and the model retains a pointer sufficient to re-retrieve them on contradiction.** Formally, let `W` be the window, `P: W → W'` the prune, and `S` an append-only external store such that `W ⊆ S` at all times. `P` is *reversible* iff for every evicted token `t ∈ W \ W'`, there exists a retrieval key `k(t)` retained in `W'` such that `retrieve(k(t), S) = t` deterministically. The step-27 failure violated this: the summary retained no key pointing to the raw trace, only the model's paraphrase, so `k(t)` was `⊥`. Two corollaries follow, and both are non-obvious: - **A summary is not a pointer.** Paraphrase destroys the retrieval key. A summary that says "fixture ordering issue" cannot be used to re-fetch the trace that contains `expires_at`; only a literal identifier (`step_27`, `tool_call_id=fc-8812`, `file:tests/test_auth.py`) can. Prune policies that emit prose summaries without literal anchors are structurally irreversible. - **Reversibility must be checked before the prune, not after.** After eviction the model cannot evaluate whether its summary was faithful, because the ground truth is gone. Any "verify the summary" step that runs post-eviction is circular. ## Decision Boundary The boundary is not "how much to prune" but **whether the prune is checkpointed**. The operational rule: - If the eviction set is accompanied by literal retrieval anchors into an append-only store, and the store is verified to contain the evicted tokens *before* the window is rewritten, the prune is reversible and may proceed at any saturation level. - If the eviction set is accompanied only by model-authored paraphrase, the prune is irreversible. It must be preceded by a **pre-prune checkpoint**: a durable snapshot of the full window `W` keyed by step index, plus an explicit marker in `W'` that the checkpoint exists and what hypothesis `H` motivated the prune. The marker is what allows a later contradiction `O` to trigger re-expansion of the checkpoint rather than re-interpretation under `H`. The trap is that the second case is the common one. Models asked to compact naturally produce summaries, not anchors, because summarization is what they are good at. The guardrail must therefore be structural — the harness, not the model, decides whether anchors are present and refuses irreversible prunes without a checkpoint. A model cannot be trusted to enforce a reversibility invariant on its own edits, for the same entanglement reason the prune is unsafe in the first place. ## Operational Effect With pre-prune checkpointing in place, the step-27 event still happens — the model still evicts the trace and still writes the misleading summary. But at step 34, when `pytest` fails with `AttributeError`, the harness detects a contradiction between the new observation and the retained hypothesis marker (`H = fixture ordering`) and re-expands the step-27 checkpoint. The raw trace is restored, the `expires_at` line is visible, and the agent repairs the mock instead of re-editing `conftest.py`. Mean steps-to-resolution on this task class dropped from 39 (cap) to 35. The saving is not the point; the point is that the failure mode became *observable* rather than silent. The invariant to carry forward: **a self-editing context is a state machine whose transitions are model-authored, and no model-authored transition may be permitted to destroy the evidence that would falsify the model's current hypothesis.** Pruning is safe only when it is a *view* over an immutable log, never a *mutation* of the only copy. The instant the window is the sole store, the model is editing its own memory with no possibility of appeal. ```python class IrreversiblePruneError(RuntimeError): """Raised when a model-driven context prune would destroy evidence without a durable pre-prune checkpoint and literal retrieval anchors.""" pass def apply_prune(window: list[str], eviction_ids: set[str], summary: str, anchors: dict[str, str], store: dict[str, list[str]], step: int) -> list[str]: """ window : current token blocks eviction_ids : block ids the model chose to drop summary : model-authored paraphrase (NOT a pointer) anchors : eviction_id -> literal retrieval key into `store` store : append-only external transcript, keyed by block id """ evicted = [b for b in window if b in eviction_ids] # 1. Every evicted block must be recoverable from the immutable store. for block_id in eviction_ids: if block_id not in store: raise IrreversiblePruneError( f"step {step}: evicting {block_id!r} not present in append-only " f"store; prune would be unrecoverable" ) # 2. Every evicted block must have a literal anchor retained in the window. # A prose summary is not an anchor: it cannot re-fetch the evidence. missing = [b for b in eviction_ids if b not in anchors] if missing: raise IrreversiblePruneError( f"step {step}: eviction set {missing!r} has no literal anchor; " f"summary alone is irreversible and cannot be re-expanded on " f"contradiction" ) # 3. A pre-prune checkpoint must exist before the window is rewritten. if f"checkpoint:{step}" not in store: raise IrreversiblePruneError( f"step {step}: no pre-prune checkpoint; refusing irreversible " f"mutation of sole evidence store" ) # Only now is the prune a reversible view transition. return [b for b in window if b not in eviction_ids] + [summary] ```