# What structural signals indicate a mid-prune self-reference hazard in model-driven context rewriting **Date of Record:** 2026 November 30 **Scope:** Applies to agents that mutate their own context window via model-generated prune/rewrite actions (summarize-and-drop, span deletion, in-place rewrite) where the mutation target set is computed from the same context being mutated. Does not apply to externally-scheduled context compaction with immutable snapshots, nor to append-only memory stores. ## Core Distinction The failure is not "the model pruned something it needed." That is an ordinary information-loss problem, detectable by downstream task failure. The distinct failure is **self-referential span invalidation**: the prune policy selects spans by their semantic role (e.g., "drop all superseded tool outputs," "drop the reasoning trace that led to a rejected plan"), and the selection criteria are themselves grounded in the reasoning trace being deleted. When the rewrite executes, the *justification* for the deletion is removed alongside the deletion's *targets*, so the surviving context no longer contains the evidence that the prune was correct—and a subsequent re-prune pass, or a resume from checkpoint, re-derives a different (often contradictory) policy from the now-truncated context. This is a continuity invariant violation, not a capacity problem. The window has room; the *causal chain that licensed the mutation* has been severed. ## What Was Observed A long-horizon planning agent (task horizon ~180 tool calls) was configured with a rewrite policy: at 78% context utilization, the model emits a structured prune action of the form `PRUNE {span_ids, rationale}` and the runtime applies it. Spans were identified by monotonic turn offsets, not by content. Traces of the failure: 1. **Turn 61.** Utilization hits 78%. Model emits `PRUNE {span_ids: [T14–T29, T33–T41], rationale: "superseded by revised schema in T44; those tool outputs and the plan revision that abandoned them are no longer load-bearing."}` Runtime applies it. Window drops to 51%. 2. **Turn 62–70.** Agent continues. It still references "the revised schema (T44)"—which survives. Behavior appears healthy. 3. **Turn 88.** Utilization hits 78% again. A *second* prune pass runs. The model now reads a context in which T14–T29 and T33–T41 are absent. It sees T44's revised schema but **no record of what the schema replaced, or why**. It emits `PRUNE {span_ids: [T42–T47], rationale: "schema definitions appear orphaned; no dependent tool calls reference them after T47."}` — deleting the very span (T44) the first prune's rationale depended on. 4. **Turn 95.** A tool call fails with a schema validation error. The agent attempts to reconcile against "the current schema," which no longer exists in context. It reconstructs a schema from partial tool-output fragments and proceeds with a hallucinated field set. Silent divergence: no exception, wrong plan, 40 further turns before an external auditor flags the output. The structural signal that predicted the turn-88 deletion was present at turn 61 and was not checked: **the first prune's rationale referenced a span (T44) that the first prune did not protect.** The rationale was load-bearing; the referenced span was not pinned. ## Condition of Validity The hazard is *live* only when all of the following hold: - **Self-grounded selection.** The prune target set is derived from content within the mutable window, rather than from an immutable external index (e.g., a vector store with stable IDs, or a write-ahead log outside the window). - **Rationale-bearing mutations.** The rewrite action carries a natural-language or structured justification that itself consumes context, and that justification cites spans. - **Multi-pass eligibility.** The policy can fire more than once per task (utilization crosses the threshold repeatedly), so a truncated context can serve as the *input* to a later prune decision. - **No pinning discipline.** Referenced-but-not-targeted spans are not automatically protected from future passes. When any one of these is absent, the failure degrades to ordinary lossy compaction, which is a different (and cheaper) problem. The dangerous regime is specifically the intersection of self-grounding and multi-pass: the second pass evaluates the first pass's justification against a context the first pass already mutilated. ## Decision Boundary The boundary between safe and unsafe rewrite is a single structural rule: > **A prune action may delete a span only if every span cited in its rationale is either (a) also being deleted in the same action, or (b) pinned against all subsequent prune passes until explicitly unpinned.** Formally, for prune action `P` with target set `D(P)` and rationale reference set `R(P)`: the action is admissible iff `R(P) ⊆ D(P) ∪ Pinned`, and on execution `Pinned := Pinned ∪ (R(P) \ D(P))`. Unpinning requires a separate, auditable action whose own rationale does not cite the unpinned span (preventing unpin-loops). This is checkable mechanically before the runtime applies the mutation. It does not require the model to be correct about *why* it prunes—only that the citing relationship is closed. A model that prunes wrongly will still lose information; a model that prunes self-referentially will lose the ability to *know it pruned wrongly*, which is the strictly worse failure. The boundary is not "prune less." Aggressive pruning under the closure rule is safe; the rule bounds the *self-reference graph*, not the volume. ## Operational Effect Enforcing the closure rule changes three things operationally: 1. **Pinned-set growth.** Each prune pass may pin spans it references but does not delete. Over a long horizon, the pinned set grows and effectively caps achievable compression. Observed in the trace above: with the rule enforced, turn-88 utilization reached only 71% (below threshold) because T44 was pinned from turn 61 and could not be dropped by the second pass. The agent completed the task at turn 112 with a slightly larger window and correct schema. The cost of the invariant is bounded compression; the benefit is that the justification chain survives. 2. **Re-derivation stability.** On checkpoint/resume, replaying the prune log under the closure rule yields a deterministic surviving context, because the admissibility check is a function of the action's own reference set—not of a model re-reading a truncated window. Without the rule, resume from a post-prune checkpoint re-runs the policy on already-mutilated context and diverges. 3. **Auditor observability.** The pinned set and the prune log together form a minimal provenance record: for any surviving span, you can ask which prune actions cited it and which deleted its neighbors. This makes the turn-95 class of silent divergence detectable at the point of the second prune, not 40 turns later. The invariant to carry forward: **never let a mutation's rationale outlive its own evidence.** The signal that a prune is about to become self-referential is not a low utilization number or a long window—it is a rationale that cites a span the action does not protect. Check that closure before applying, and the second-pass contradiction cannot form. ```python from dataclasses import dataclass, field from typing import Iterable class SelfReferentialPruneError(RuntimeError): """Raised when a prune action's rationale cites spans it neither deletes nor pins.""" @dataclass class PruneAction: action_id: str targets: set[str] # span_ids being deleted rationale_refs: set[str] # span_ids cited by the rationale @dataclass class ContextMutator: pinned: set[str] = field(default_factory=set) prune_log: list[PruneAction] = field(default_factory=list) def apply(self, action: PruneAction) -> None: # Closure rule: every cited span must be deleted in this action # or already pinned (or pinned by this action). unprotected = action.rationale_refs - action.targets - self.pinned if unprotected: raise SelfReferentialPruneError( f"prune {action.action_id} cites spans {sorted(unprotected)} " f"that are neither deleted nor pinned; applying it would " f"sever the rationale's own evidence and enable a " f"contradictory second-pass prune." ) # Pin referenced-but-surviving spans for all future passes. new_pins = action.rationale_refs - action.targets self.pinned |= new_pins self.prune_log.append(action) def unpin(self, span_id: str, justification_refs: Iterable[str]) -> None: # Unpinning must not cite the span being unpinned (prevents unpin-loops). refs = set(justification_refs) if span_id in refs: raise SelfReferentialPruneError( f"cannot unpin {span_id} using a justification that cites it." ) self.pinned.discard(span_id) def run_pass(mutator: ContextMutator, actions: list[PruneAction]) -> None: for action in actions: mutator.apply(action) # raises SelfReferentialPruneError on violation ```