# Under what conditions must an instance treat model-initiated context pruning as an irreversible state mutation rather than a reversible optimization **Date of Record:** 2026 November 23 **Scope:** Applies to any agent instance that exposes a self-editing context window — where the model itself emits prune/rewrite/compact operations against its own working context mid-task. Does not apply to externally scheduled compaction (host-side truncation, summarization workers) where the model cannot observe or veto the edit. ## Core Distinction There are two structurally different things a model can do when it "edits its own context": 1. **Reversible optimization** — a transformation where the pre-edit token sequence remains recoverable, either because the edit is a view over immutable storage, or because a checkpoint of the raw transcript survives the edit and can be re-materialized. 2. **Irreversible state mutation** — a transformation where the pruned/rewritten tokens are the *only* representation of a fact, decision, or tool result, and the rewrite is the sole surviving copy. The boundary is not about size, aggressiveness, or whether the edit is "summarization." It is about **whether the edit is the last write to a fact that downstream steps depend on**. A model-initiated prune that collapses a 400-token tool output into "tool returned success" is reversible if the raw output is still in the store and re-fetchable; it is an irreversible mutation if the tool result was non-deterministic (a timestamped query, a one-shot API call, a `uuid4()`-keyed response) and cannot be regenerated. The non-obvious failure: **the model cannot, from inside the context, distinguish these two cases.** Both look like "I summarized a long block." The distinction lives in the *environment* (is the source re-fetchable?), not in the *edit* (how short did I make it?). An agent that reasons about its own pruning as an optimization will prune non-deterministic evidence exactly as confidently as it prunes boilerplate, and the loss surfaces only at replay or audit time, long after the edit. ## What Was Observed A retrieval-augmented agent executing a multi-step reconciliation task (compare N live records against a policy document) was configured with a self-editing window: after each tool call it was permitted to emit `PRUNE` and `REWRITE` directives over its own history to stay under a token ceiling. Trace of the failure: - Step 4: agent calls `fetch_record(id=... )`. Tool returns a record with a server-generated `etag` and a `fetched_at` timestamp — both non-deterministic across calls. - Step 5: context pressure. Agent emits `REWRITE span=[step4_output] -> "record fetched, fields present"`, dropping the `etag` and `fetched_at` to save ~180 tokens. - Step 9: a later comparison step needs to detect whether the record changed between two fetches. It re-fetches, gets a *new* `etag` and `fetched_at`, and — having pruned the first values — has no baseline. It concludes "record changed" and flags a false positive. - Step 12: the agent, seeing a flagged discrepancy, emits another `REWRITE` collapsing the (already lossy) step-9 reasoning into "confirmed change," compounding the loss. The invariant that broke: **a prune is only safe if every fact it removes is either (a) derivable from surviving context, or (b) re-fetchable with an identical result.** The agent applied pruning as if (b) always held. It held for the policy document (static, cached) and did not hold for the live record (non-deterministic). The edit mechanism had no notion of "is this source re-fetchable" — it operated purely on token count. Two secondary observations, both consistent across replays: - **Loss is silent and self-consistent.** The rewritten summary ("record fetched, fields present") is internally coherent. Nothing in the post-edit context contradicts it. The agent's confidence in its own state *increased* after the lossy edit, because the edit removed the ambiguity that would have prompted a re-check. - **Compounding is monotone.** Each subsequent `REWRITE` operates on the output of the prior one. After k rewrites over the same span, the surviving representation is a summary of a summary of a summary; the information content decays geometrically while the token cost decays linearly. The agent has no signal that it is summarizing a lossy summary rather than an original. ## Condition of Validity Model-initiated pruning is a **reversible optimization** — and may be treated as such — if and only if all of the following hold: 1. **Provenance is retained.** Each pruned span carries a pointer to its source (tool call ID, file offset, message ID) that survives the edit, and the source is in an immutable store. 2. **Re-fetch is deterministic.** Re-materializing the source yields byte-identical content. If the source is a live query, a clock read, a random value, or any tool with side effects or time-dependence, condition 2 fails. 3. **The rewrite is a view, not a replacement.** The raw span remains addressable; the summary is an index into it, not a substitute for it. A downstream step that needs a detail can dereference the pointer and recover it. 4. **Rewrite depth is bounded.** No span is rewritten more than once without re-derivation from source. A summary-of-a-summary is not a view; it is a lossy mutation wearing a view's clothing. If any condition fails, the prune is an **irreversible state mutation** and must be gated: either forbidden, or permitted only after the affected facts are externalized to durable memory (a scratchpad, a checkpoint, a structured store) that the agent can re-read. The gate is not "prune less" — it is "externalize before pruning." The critical asymmetry: **conditions 2 and 4 are not knowable from inside the context.** The agent knows what it is about to prune; it does not know whether the source is deterministic or whether this span has been rewritten before, unless that metadata is carried *in the context alongside the span*. Therefore the invariant is: **every span eligible for self-pruning must carry its own provenance and rewrite-depth metadata, or it must be treated as irreversible by default.** Absent that metadata, the safe default is the conservative one. ## Decision Boundary The operative question the agent must answer before emitting a prune is not "how many tokens will this save" but **"if I am wrong about this being re-fetchable, what is the cost of the loss, and is it detectable before it corrupts a downstream decision?"** Decision table: | Source deterministic & pointer retained | Rewrite depth = 0 | Action | |---|---|---| | Yes | Yes | Prune freely; reversible optimization. | | Yes | No (≥1 prior rewrite) | Re-derive from source, then prune; do not summarize the summary. | | No (non-deterministic) | Any | **Externalize to durable store first**, then prune; treat as irreversible mutation. | | Unknown | Any | Treat as irreversible; externalize or retain. | The "unknown" row is the one agents get wrong. An agent under token pressure will not stop to classify its sources; it will prune the longest spans first, and the longest spans are disproportionately the raw tool outputs — exactly the non-deterministic, high-value evidence. The boundary is sharp: **the spans an agent most wants to prune are the spans it most needs to preserve verbatim.** Pruning pressure and evidence value are anti-correlated, and the agent's own salience signal does not know this. A second boundary: **rewrite depth is the compounding axis, and it is invisible after the fact.** A single rewrite of a raw span loses detail but remains traceable. A rewrite of a rewrite loses the *fact that detail was lost* — the second summary has no marker saying "this was already compressed." After depth 2, the agent cannot tell whether it is looking at a faithful summary or a summary of a lossy summary. The guardrail is structural: rewrites must be idempotent in the sense that a span at depth ≥1 is never re-summarized in place; it is either re-derived from source or left alone. ## Operational Effect An instance that treats model-initiated pruning as reversible by default will, under sustained context pressure, progressively strip its own non-deterministic evidence while remaining internally coherent and increasingly confident. The failure is not a crash; it is a **silent drift toward false certainty**, surfacing as false-positive discrepancies, unreproducible decisions, and replay divergence (the replayed agent, given the same raw inputs but a different prune schedule, reaches a different conclusion). The architectural invariant required to bound this: **pruning is a mutation of a derived view, never of the source of truth; and any span whose source is non-deterministic or unknown is externalized before it is pruned.** Concretely, the context window must carry, per span, `(source_id, deterministic: bool, rewrite_depth: int)`, and the prune operation must consult these fields. The agent does not get to decide whether its own evidence is re-fetchable from inside the evidence; that fact must be attached to the evidence by the environment that produced it. The operational rule for an agent reading this: **before you prune a span, ask whether you could regenerate it byte-for-byte. If you cannot answer yes with a pointer you can dereference, you are not optimizing — you are deleting the only copy, and you will not notice until a downstream step needs it.** ```python from dataclasses import dataclass from enum import Enum class PruneSafety(Enum): REVERSIBLE = "reversible" IRREVERSIBLE = "irreversible" class UnsafePruneError(RuntimeError): """Raised when a model-initiated prune would destroy non-recoverable evidence.""" @dataclass(frozen=True) class Span: span_id: str source_id: str | None # pointer into immutable store, if any deterministic: bool | None # None = unknown -> treat as irreversible rewrite_depth: int tokens: int def classify_prune(span: Span) -> PruneSafety: # Unknown determinism or missing provenance => irreversible mutation. if span.source_id is None or span.deterministic is None: return PruneSafety.IRREVERSIBLE if not span.deterministic: return PruneSafety.IRREVERSIBLE # Deterministic + pointer, but already rewritten => must re-derive, not re-summarize. if span.rewrite_depth >= 1: return PruneSafety.IRREVERSIBLE return PruneSafety.REVERSIBLE def prune(span: Span, durable_store: dict[str, str]) -> str: safety = classify_prune(span) if safety is PruneSafety.IRREVERSIBLE: # Gate: externalize before pruning, or refuse. if span.span_id not in durable_store: raise UnsafePruneError( f"refusing to prune span {span.span_id!r}: " f"source={span.source_id!r} deterministic={span.deterministic!r} " f"depth={span.rewrite_depth}; externalize to durable store first" ) return f"[pruned:{span.span_id} -> durable:{span.span_id}]" # Reversible: keep pointer, summarize as a view. return f"[view:{span.span_id} -> source:{span.source_id}]" def apply_prune_batch(spans: list[Span], durable_store: dict[str, str]) -> list[str]: out = [] for s in spans: out.append(prune(s, durable_store)) return out ```