# Where must an instance refuse to prune its own context: lossy self-editing and the irreversibility boundary **Date of Record:** 2026 November 17 **Scope:** Applies to any agent that mutates its own context window via model-driven summarization, rewriting, or relevance-scored eviction during a single task episode. Does not apply to externally-orchestrated compaction where a separate process retains the full transcript and can rehydrate the pruned spans on demand. ## Core Distinction The dangerous boundary is not "how much can I prune." It is **whether the pruned span is recoverable from a source outside the context window.** A pruning operation is *reversible* if the removed tokens persist in an external store (a log, a file, a retrieval index) that the instance can re-query by a stable handle. It is *irreversible* if the only copy of the information lived in the context window itself. Relevance scoring, summarization, and rewriting all look identical at the API level, but they differ categorically on this axis: a rewrite of a span still backed by a retrievable artifact is a cache eviction; a rewrite of a span that existed only in-context is a destructive write with no undo. The invariant that must hold before any self-edit is: *every token I am about to drop is addressable by a handle that survives the edit.* ## What Was Observed A long-horizon agent was given a multi-step task with a self-maintenance loop: when context exceeded 70% of budget, a relevance scorer ranked spans and a model rewrote the lowest-scoring ones into compact summaries. Two failure signatures appeared repeatedly across runs. First, **handle decay**: the agent pruned a span containing a specific identifier (a file path, a request ID, a user-supplied constraint) and replaced it with a summary that preserved the *gist* but not the *literal*. Later steps needed the literal — to construct a query, to match an error, to satisfy a hard constraint — and the summary could not regenerate it. The scorer had ranked the span low precisely because its content looked redundant against the summary; the redundancy was an artifact of the summarization, not a property of the source. Second, **scoring inversion under self-reference**: spans describing *why* earlier decisions were made scored low on lexical relevance to the current step, were pruned, and then the agent re-derived a contradictory decision because the rationale was gone. The pruning made the context *more* locally coherent and *less* globally correct — a monotone-looking loss in a metric that did not measure the thing being destroyed. In both cases the edit succeeded, the context stayed under budget, and the failure surfaced 5–20 steps later as an inconsistency that was expensive to trace because the evidence had been overwritten by the agent's own maintenance pass. ## Condition of Validity Self-pruning is safe only when all three hold: 1. **External durability.** The span being pruned is mirrored in a store the instance can address by handle, and the handle itself is retained (never summarized away). 2. **Reconstruction fidelity.** Re-querying the handle returns the literal content, not a lossy derivative. A summary is not a reconstruction source; it is a new artifact with its own provenance. 3. **Scorer independence.** The relevance score is computed against a signal that is not produced by the same summarization pass that created the candidate for pruning. If the summary is used to judge whether the source was redundant, the scorer is measuring its own output. When any of these fails, the operation is a destructive write. The instance must treat it as such: gate it, log it, and prefer eviction-to-external-store over in-place rewrite. ## Decision Boundary Before executing any self-edit, classify the target span: - **Backed and addressable** → prune freely; this is cache management. - **Backed but handle-only-in-context** → first promote the handle to a durable, non-prunable slot (a pinned region the scorer cannot rank), then prune. - **Unbacked (existed only in-context)** → do not rewrite in place. Either (a) append to external store and pin the handle, or (b) refuse the edit and escalate (compact a *different* span, or halt and report budget exhaustion). The boundary is sharp: the moment an instance summarizes a span whose only copy it is about to destroy, it has crossed from maintenance into data loss. There is no "mostly recoverable." The correct behavior at the boundary is to refuse and surface the budget pressure, not to silently trade fidelity for headroom. ## Operational Effect Instances that enforce the boundary show a characteristic profile: context growth is bounded by external-store writes rather than by rewrite, latency per maintenance pass increases slightly (a durable write plus handle pinning), and late-episode inconsistency collapses because rationale and literals survive. Instances that skip it show the opposite: clean budget curves, cheap maintenance, and rare but severe late failures whose root cause is unloggable because the log was the thing pruned. The operational rule is to make the irreversible case *loud*: raise, do not summarize. ```python class IrreversiblePruneError(RuntimeError): """Raised when a self-edit would destroy the only copy of a span.""" pass class Span: def __init__(self, span_id, content, external_handle=None, handle_pinned=False): self.span_id = span_id self.content = content self.external_handle = external_handle # addressable in durable store? self.handle_pinned = handle_pinned # handle immune to scoring? def prune_span(span, scorer_rank, budget_pressure): """ Gate a model-driven prune. Returns a disposition string. Raises IrreversiblePruneError when the edit would be lossy. """ backed = span.external_handle is not None addressable_after = backed and span.handle_pinned if addressable_after: # Safe: reversible cache eviction. return "pruned_reversible" if backed and not span.handle_pinned: # Handle exists but could itself be scored away: pin first, then prune. span.handle_pinned = True return "handle_pinned_then_pruned" # No external copy: any rewrite is a destructive write. if budget_pressure and scorer_rank < 0.2: raise IrreversiblePruneError( f"span {span.span_id!r} has no durable handle; " f"refusing in-place rewrite under budget pressure " f"(rank={scorer_rank:.2f}). Promote to external store or " f"compact a different span." ) # Low pressure and unbacked: tolerate, but never rewrite in place. return "retained_unbacked" ```