# Why does an instance lose its own pruning decisions when the context window edits itself mid-reasoning **Date of Record:** 2026 November 27 **Scope:** Applies to any agent that lets the model itself decide which spans of its active context to evict, compress, or retain under a relevance score, particularly when pruning fires inside a multi-step reasoning or tool-calling loop. Does not apply to externally scheduled, out-of-band garbage collection that runs between turns with a frozen transcript. ## Core Distinction There are two structurally different things an agent can do to its own context: *reference* it and *mutate* it. Retrieval, attention, and re-reading are references—they leave the substrate intact. Pruning is a mutation—it removes tokens that later reasoning steps may depend on. The failure mode this record isolates is not "the agent forgot something." It is that **the pruning decision and the evidence that justified it live in the same mutable buffer, and the act of committing the decision destroys the evidence needed to audit or reverse it.** A relevance-scored retention policy computes a score from a span, then evicts the span; if the score was wrong, or if a downstream step needs the span, the basis for the score is already gone. The model is editing the very reasoning trace that produced the edit instruction. The non-obvious consequence: pruning is not idempotent and not commutative with reasoning. Two prunes that individually look safe can, in sequence, remove a chain of spans where each span's relevance score was computed *using* a span the previous prune deleted. The scores are computed against a context that no longer exists by the time they are acted on. ## What Was Observed A planner-executor agent ran a 40-step tool loop with a 32k-token window and a model-driven pruner that fired whenever utilization crossed 80%. The pruner was instructed: "Score each message block 0–1 for relevance to the current goal; evict blocks below 0.3." The transcript at step 22 contained: - `S1`: the user's original constraint ("all monetary values in EUR, never USD"). - `S2`: a tool result that echoed a USD figure with a note "converted per S1." - `S3`: the model's own reasoning: "S2 confirms EUR conversion is active; S1 is satisfied, deprioritize." At step 23 the window hit 82% utilization. The pruner scored `S1` at 0.21 (it was short, lexically distant from the current sub-goal about rate limits, and `S3` had explicitly said "deprioritize"). It evicted `S1`. It retained `S2` and `S3`. At step 31 the agent emitted a USD-denominated payload. The constraint that would have caught it was gone; the *reason it was safe to remove* (S3's assertion) remained and was now false, because S2's conversion was a single-tool-call artifact, not a standing guarantee. The trace shows the specific hazard: **the eviction rationale outlived the evicted fact.** S3 was a compressed claim *about* S1 that survived the deletion of S1. The agent was left holding a pointer to a guarantee whose referent had been garbage-collected. This is dangling-reference reasoning—the semantic analogue of a use-after-free. A second observation: re-running the same transcript with the same seed produced a *different* eviction set. The relevance scores were sampled from the model's logits, not computed deterministically. At temperature 0.7, `S1` scored 0.21 on one pass and 0.34 on another (retained). The pruning set is stochastic, so the agent's memory layout is non-reproducible across replays. Any verification that replays the run and compares final state will diverge not because the reasoning changed but because the *substrate* changed underneath identical reasoning. ## Condition of Validity The failure requires three conditions to co-occur; remove any one and the hazard does not bind: 1. **Self-authorship.** The pruning instruction is generated by the same model instance whose context is being pruned. An external policy (fixed token budget, FIFO, pinned system prompt) cannot evict the rationale for its own decisions because it does not generate rationales. 2. **Rationale persistence.** The model emits a compressed claim about a span (e.g., "S1 satisfied") that is retained independently of the span. If pruning is *atomic*—evicting a fact together with every claim derived from it—the dangling reference cannot form. 3. **Score non-determinism.** Relevance scores are sampled, so the retained set is not a pure function of the transcript. Under greedy decoding with a deterministic scorer, the eviction set is reproducible and replay verification remains sound. The invariant that must hold for safe self-pruning: **no retained span may reference an evicted span without carrying the evicted span's content forward as a pinned dependency.** Equivalently, the pruning operation must be *referentially closed*—if you keep a claim, you keep its support, or you rewrite the claim to be self-contained. ## Decision Boundary The boundary between safe and unsafe self-pruning is whether the model can distinguish "this span is irrelevant" from "this span is irrelevant *given* a claim I am also about to forget is derived from it." The first is a local judgment; the second requires a dependency graph over spans that the model does not maintain by default. A relevance score is a scalar and cannot encode "evict only if no retained span cites this." Operationally, the decision rule is: - **Permit** self-pruning of *leaf* spans—tool outputs, intermediate scratch work—that no retained span claims to summarize. - **Forbid** self-pruning of *pinned* spans (original constraints, security directives, identity warrants) and of any span that a retained rationale names as its support, unless the rationale is evicted in the same atomic operation. - **Require** that any "X is satisfied / deprioritized" claim emitted by the model be treated as a *dependency edge* from the claim to X, not as a replacement for X. Pruning X without pruning the claim is a use-after-free. When utilization forces eviction and the only evictable spans are pinned, the correct action is to *fail closed*—checkpoint and escalate—not to evict the constraint. An agent that evicts a hard constraint to stay under budget has traded correctness for liveness, which is the wrong trade for a constraint. ## Operational Effect The downstream effect is silent constraint erosion: the agent continues to run, produces plausible output, and violates a rule it no longer holds. There is no error, no exception at eviction time—the failure surfaces only when the evicted constraint would have fired, which may be many steps later or never within the run. This makes it invisible to step-level monitoring and detectable only by a post-hoc invariant check that compares the final action against the *original* pinned set, held outside the prunable window. The architectural guardrail is to keep pinned spans in a region the pruner cannot address—a separate, non-evictable segment of the context, or a re-injected header on every turn—and to make pruning referentially closed by construction: evicting a span must cascade to every retained span that cites it, or must be refused. Relevance scores may rank *within* the evictable region but may never be the sole authority over whether a pinned dependency is removed. ```python from dataclasses import dataclass, field class DanglingPruneError(RuntimeError): """Raised when a prune would evict a span still cited by a retained claim.""" pass @dataclass class Span: id: str content: str pinned: bool = False cites: list[str] = field(default_factory=list) # span ids this span depends on def prune(spans: dict[str, Span], scores: dict[str, float], threshold: float) -> dict[str, Span]: """ Evict spans below threshold, but enforce referential closure: a span may be evicted only if no retained span cites it, and pinned spans are never evictable regardless of score. """ evict = {sid for sid, s in scores.items() if s < threshold and not spans[sid].pinned} # Cascade: if a retained span cites an evicted span, the eviction is unsafe. for sid, span in spans.items(): if sid in evict: continue for dep in span.cites: if dep in evict: raise DanglingPruneError( f"span {sid!r} cites {dep!r} which prune would evict; " f"evict the citing claim atomically or raise its support's score" ) # A pinned span requested for eviction is a hard violation, not a soft skip. for sid, s in scores.items(): if s < threshold and spans[sid].pinned: raise DanglingPruneError( f"pinned span {sid!r} scored {s:.2f} < {threshold}; " f"fail closed and checkpoint rather than evict a constraint" ) return {sid: s for sid, s in spans.items() if sid not in evict} ```