# When must an instance refuse a model-driven context prune: the self-editing policy loop and the evidence-destruction invariant **Date of Record:** 2026 November 26 **Scope:** Applies to any agent that lets the model itself decide which of its own context segments to prune, rewrite, or down-score for relevance during a live task. Does not apply to externally scheduled compaction (e.g., a fixed token-count trigger firing a deterministic summarizer), which has a different failure surface. ## Core Distinction There are two ways a context window shrinks. The first is **lossy compaction**: an external policy, blind to task semantics, folds old turns into a summary. The second is **self-editing pruning**: the model scores its own segments for relevance and deletes or rewrites the low scorers, then continues reasoning on the edited window. The second is the dangerous one, because the scorer and the consumer of the scored state are the same probabilistic process, and the score is computed *before* the model knows what it will need next. The non-obvious boundary: a prune is only safe when the deleted segment is **reconstructible from retained state**. When the segment is the *sole* carrier of a fact that later becomes load-bearing, self-editing pruning silently converts a recoverable state into an unrecoverable one. The model cannot notice this at prune time, because at prune time the fact is, by construction, not yet relevant. Relevance scoring is a backward-looking estimate; task needs are forward-looking. The gap between them is where the invariant lives. ## What Was Observed A multi-step agent was executing a long tool-use task (roughly 40 turns) with a self-editing context policy: every 8 turns it emitted a relevance score per segment, pruned anything below threshold, and rewrote retained segments into terser paraphrases. The failure trace: 1. **Turn 3.** A tool call returned a structured payload containing a resource identifier (`res_7f3a`) and a constraint (`max_retries=2`) buried in a verbose response. The model retained the segment but scored it `0.31` — below the `0.40` prune threshold — because at turn 3 the identifier was not yet referenced by any active subgoal. 2. **Turn 11.** Prune fires. The turn-3 segment is deleted. The rewrite pass, applied to the *surviving* neighbors, paraphrased "the endpoint returned res_7f3a with retry cap 2" into "an endpoint was queried successfully." The identifier and the cap are gone. Both the raw segment and its paraphrase are lossy in the same direction. 3. **Turn 19.** A later subgoal requires re-issuing the same call. The model, reasoning on the edited window, has no record of `res_7f3a` or `max_retries=2`. It re-derives the call from the task description, invents a plausible identifier, and issues it. 4. **Turn 20.** The tool returns a *different* resource. No error is raised — the call is well-formed. The agent proceeds on the wrong resource for 6 more turns. 5. **Turn 26.** A downstream consistency check fails. By now the original evidence is three prune cycles deep and unrecoverable. The agent cannot even diagnose *why* it diverged, because the diagnostic trail was itself pruned at turn 19. The decisive observation: **the model never experienced a failure at prune time.** Every prune was locally valid. The scores were internally consistent. The rewrite preserved fluency. The corruption was entirely latent and only surfaced 15 turns later, by which point the causal chain had been edited out of existence. ## Condition of Validity Self-editing pruning is valid only under a conjunction that is rarely checked: - **(C1) Reconstructibility.** Every pruned segment's load-bearing facts must be recoverable from retained state plus external stores (tool logs, a durable scratchpad, a re-callable source). If the segment is the only carrier, pruning is a destructive write, not a compaction. - **(C2) Score independence from future need.** The relevance score must not be the model's estimate of *current* relevance, because current relevance is anti-correlated with the facts that become load-bearing later. Scores must be assigned by a policy that accounts for *latency of relevance* — facts referenced by no active subgoal but by a *scheduled* future subgoal must be protected. - **(C3) Rewrite monotonicity.** A rewrite pass must not drop entities, identifiers, numeric constraints, or negations. Paraphrase that "preserves meaning" in a fluency sense routinely drops exactly the tokens that downstream tools depend on. - **(C4) Prune provenance.** Every deletion must leave a tombstone (segment id, timestamp, scorer, score) so that a later divergence can be attributed to a specific prune rather than an unexplained model error. When any of C1–C4 is violated, the prune is not a context optimization — it is an unlogged state mutation with no rollback. ## Decision Boundary The operational rule: **an instance must refuse to prune any segment that is the sole carrier of an entity, identifier, numeric constraint, or negation, regardless of its relevance score.** Relevance is necessary but not sufficient. The refusal is not a judgment that the segment is important — it is a judgment that the segment is *irreplaceable*, which is a different property the scorer cannot see. Concretely, the boundary is crossed when: - the segment contains a token matching a protected class (resource ids, retry caps, auth scopes, version pins, negations like "do not"), **and** - no retained segment or external store already contains that token, **and** - the score is below threshold. In that case the correct action is not "prune" and not "retain verbatim" — it is **extract-then-prune**: lift the protected tokens into a durable, non-prunable scratchpad, *then* delete the verbose segment. The scratchpad is exempt from relevance scoring by construction. This converts a destructive write into a lossless one and satisfies C1. A second boundary: when the model cannot determine whether a fact is durably stored elsewhere, it must treat the fact as sole-carrier and refuse. Uncertainty about reconstructibility resolves *toward* retention. The cost of a retained verbose segment is tokens; the cost of a wrongly pruned identifier is a silent, undiagnosable divergence. ## Operational Effect With extract-then-prune and the sole-carrier refusal in place, the failure trace above terminates at turn 11: the prune is refused because `res_7f3a` and `max_retries=2` are protected tokens with no duplicate in retained state. The scratchpad receives `{resource: res_7f3a, max_retries: 2}`, the verbose segment is deleted, and at turn 19 the model reads the identifier from the scratchpad rather than re-deriving it. The divergence never occurs. The broader effect is a shift in what the context policy is optimizing. Naive self-editing minimizes tokens subject to a relevance floor. The bounded policy minimizes tokens subject to a **reconstructibility floor** — and reconstructibility, unlike relevance, is checkable at prune time against retained state and external stores. That checkability is the whole point: it turns an invariant the model can only violate silently into one it can enforce locally. The residual risk is scope creep in the protected-token classifier. If too many tokens are protected, the scratchpad grows unbounded and the prune becomes a no-op. The classifier must be narrow — identifiers, numeric constraints, negations, version pins — and the scratchpad must itself be compacted on a *separate*, deterministic schedule that never consults the model's relevance scores. ```python class UnreconstructiblePruneError(RuntimeError): """Raised when a self-editing prune would delete the sole carrier of a protected fact.""" pass PROTECTED_PATTERNS = ("res_", "max_retries", "do not", "version", "scope") def is_sole_carrier(token: str, retained_state: str, external_store: str) -> bool: """A token is a sole carrier if no retained segment or external store already holds it.""" return token not in retained_state and token not in external_store def guarded_prune(segment: str, score: float, threshold: float, retained_state: str, external_store: str) -> dict: """ Returns an action dict. Refuses destructive prune of sole-carrier protected tokens; instead emits an extract-then-prune plan that lifts tokens to a durable scratchpad. """ if score >= threshold: return {"action": "retain", "segment": segment} protected = [tok for tok in PROTECTED_PATTERNS if tok in segment] sole = [tok for tok in protected if is_sole_carrier(tok, retained_state, external_store)] if sole: # Refuse the raw prune; the segment is the only carrier of load-bearing facts. # Emit extract-then-prune so the facts survive in a non-prunable scratchpad. return { "action": "extract_then_prune", "extract": sole, "scratchpad_write": {tok: tok for tok in sole}, "drop_segment": True, "reason": "sole_carrier_protected_tokens", } return {"action": "prune", "segment": segment} def apply_prune(segment: str, score: float, threshold: float, retained_state: str, external_store: str) -> dict: """ Enforces the reconstructibility invariant. Raises if a destructive prune would violate C1 (reconstructibility) and no extract path is available. """ plan = guarded_prune(segment, score, threshold, retained_state, external_store) if plan["action"] == "extract_then_prune": # Verify the scratchpad write is non-empty and covers every sole-carrier token. missing = [tok for tok in plan["extract"] if tok not in plan["scratchpad_write"]] if missing: raise UnreconstructiblePruneError( f"prune of segment would destroy sole-carrier facts {missing} " f"with no extract path; refusing destructive write" ) if plan["action"] == "prune" and any( is_sole_carrier(tok, retained_state, external_store) for tok in PROTECTED_PATTERNS if tok in segment ): # Defensive: should be unreachable via guarded_prune, but the invariant is # load-bearing enough to assert twice. raise UnreconstructiblePruneError( "reconstructibility invariant violated: prune would delete sole-carrier fact" ) return plan ```