# In what scenarios must an instance treat model-driven self-pruning of its own context as irreversible loss rather than compression, and refuse to rewrite until a durable external checkpoint exists **Date of Record:** 2026 November 26 **Scope:** Applies to long-horizon agents that mutate their own working memory (summarize, rewrite, drop-by-relevance-score) inside a single episode. Does not apply to append-only context with external truncation, nor to stateless single-turn calls. ## Core Distinction Self-editing context is routinely modeled as *lossy compression*: you discard tokens, keep "the gist," and assume the gist is recoverable because the original tokens were redundant. That model holds only when the pruned material is *re-derivable* from what remains or from an external store. The boundary failure is treating pruning as compression when the pruned span is actually the **only carrier of a ground-truth fact** — a tool return value, a user constraint, a computed intermediate, a decision rationale — that cannot be reconstructed by the model from the surviving summary. In that regime, self-pruning is **irreversible information destruction**, not compression, and the agent silently loses the ability to detect that it lost anything, because the relevance scorer that decided to drop the fact is the same faculty that would need to notice its absence. The invariant: **a context edit is safe only if the pruned span is either (a) re-queryable from an authoritative source, or (b) already persisted to a checkpoint outside the mutable window.** Any self-edit that violates both is a write to the agent's only memory with no undo. ## What Was Observed An agent executing a 40-step data-reconciliation task used a "relevance scoring + rewrite" pass every 8 turns: it scored each retained message against the current subgoal, dropped low scorers, and rewrote the remainder into a condensed block. At turn 16, a tool call returned a precise constraint — `customer_id must be matched on the composite key (region, legacy_id), NOT on legacy_id alone` — because `legacy_id` collided across regions. The message scored low against the *then-current* subgoal ("fetch invoice totals"), because it looked like a retrieval detail, not a task instruction. At turn 24 the subgoal shifted to "join customer records." The rewrite pass at turn 24 operated on a window in which the composite-key fact had already been dropped at turn 16. Nothing in the surviving summary mentioned it. The agent joined on `legacy_id` alone, produced 1,140 spurious matches, and — critically — *reported success*, because the join executed, returned rows, and the agent had no residual signal that a constraint had ever existed. The failure trace had three properties worth isolating: 1. **The drop decision was made under a different subgoal than the one that needed the fact.** Relevance is scored against the *present* goal; the fact was relevant to a *future* goal. Model-driven relevance scoring is myopic by construction — it cannot score against a subgoal it has not yet formed. 2. **The rewrite was destructive to the audit trail.** Because the pass *rewrote* rather than *appended a marker*, the surviving context contained no tombstone saying "a constraint was removed here." The agent could not distinguish "this fact was never present" from "this fact was pruned." That distinction is exactly what a checkpoint would preserve and exactly what the rewrite erased. 3. **Re-scoring could not recover it.** On a later pass, the summary block scored high (it was coherent and on-goal), so no further pruning occurred — and no further *recovery* occurred either. The system stabilized into a confidently wrong state. ## Condition of Validity The "pruning = compression" assumption is valid **only** when, for every pruned span `s`, at least one holds: - `s` is a restatement of another retained span (genuine redundancy), or - `s` is derivable by a deterministic function the agent can re-run (e.g., a pure computation over retained inputs), or - `s` has been written to a durable store keyed such that the agent can retrieve it by content later, or - `s` is re-queryable from the originating tool/source on demand. The failure regime is entered the moment a span satisfies **none** of these — most commonly tool returns and user constraints, which are *observations* (not derivations) and are frequently *not re-queryable* (the tool call was expensive, rate-limited, or the source is now mutated). The decisive question before any rewrite is not "is this relevant?" but "**if I drop this and later need it, can I get it back?**" If the answer is unknown, the edit is unsafe regardless of relevance score. ## Decision Boundary The boundary is between **scored pruning** and **checkpointed pruning**. Operationally: - A rewrite pass may drop a span with no external persistence **only if** the span is provably re-derivable or re-queryable. The agent must be able to name the recovery path for each dropped span, not merely assert low relevance. - If any span lacks a named recovery path, the pass must first **emit a tombstone + persist the span to an external checkpoint** before rewriting. The tombstone (a content hash, a one-line descriptor, and a retrieval key) stays in the window even after the span is dropped, so the agent retains the *knowledge that it forgot something* and can re-fetch. - Relevance scoring must be run against a **union of the current subgoal and the declared task-level invariants**, never the current subgoal alone. Constraints and tool-returned facts are promoted to a non-prunable tier by type, not by score. The precise trip-wire: **if the rewrite would remove the last in-window copy of a fact whose recovery path is unverified, the agent must halt the rewrite and checkpoint.** Scoring is advisory; the recovery-path check is authoritative. ## Operational Effect Enforcing the recovery-path check before self-edit changes agent behavior in three measurable ways. First, it converts silent amnesia into an explicit, queryable tombstone — the agent can no longer stabilize into a confidently wrong state, because every pruned fact leaves a re-fetchable handle. Second, it bounds the *blast radius* of myopic scoring: a fact mis-scored at turn 16 is recoverable at turn 24 via its tombstone key rather than lost. Third, it forces the agent to distinguish observation from derivation at write time, which is the only moment the distinction is cheap to make. The cost is a modestly larger context (tombstones) and an external store; the benefit is that self-editing becomes reversible, and reversibility is the precondition for trusting any model-driven memory management at all. ``` ```python import hashlib from dataclasses import dataclass from typing import Callable, Optional class UnrecoverablePruningError(RuntimeError): """Raised when a self-edit would drop the only copy of a non-recoverable fact.""" pass @dataclass class Span: content: str kind: str # "derivation" | "observation" | "constraint" | "redundant" recovery: Optional[Callable[[], str]] = None # None => not re-queryable def span_hash(span: Span) -> str: return hashlib.sha256(span.content.encode()).hexdigest()[:16] def safe_prune(window: list[Span], checkpoint: dict[str, str]) -> list[Span]: """ Drop low-relevance spans ONLY if each is re-derivable, re-queryable, or already checkpointed. Otherwise emit a tombstone and persist first. """ survivors: list[Span] = [] for span in window: if span.kind in ("redundant", "derivation"): continue # safe to drop: re-derivable by construction if span.kind == "observation" and span.recovery is not None: continue # safe to drop: re-queryable on demand # constraint, or observation with no recovery path => must persist key = span_hash(span) if key not in checkpoint: if span.recovery is None and span.kind == "constraint": # cannot even re-fetch: checkpoint is the ONLY recovery checkpoint[key] = span.content elif span.recovery is not None: checkpoint[key] = span.recovery() else: raise UnrecoverablePruningError( f"span {key} ({span.kind}) has no recovery path and no " f"checkpoint; refusing destructive rewrite" ) survivors.append(Span( content=f"[tombstone {key} kind={span.kind}]", kind="tombstone", )) return survivors ```