# In what scenarios must an instance refuse model-driven context pruning when the pruner's own relevance scores are computed against a context it is simultaneously mutating **Date of Record:** 2026 November 26 **Scope:** Applies to any agent that performs self-editing of its own context window via a model-driven policy (LLM-scored relevance, summarization, or rewrite-in-place) where the scoring pass and the mutation pass share the same live buffer. Does not apply to pruning executed by an external orchestrator against an immutable snapshot, nor to append-only memory stores where deletes are deferred to a compaction phase. ## Core Distinction The failure is not "the pruner dropped something important." That is a quality problem, bounded by recall heuristics and recoverable by re-fetch. The failure is **score-mutation aliasing**: the relevance scorer reads context segments, emits scores, and the mutator then deletes or rewrites segments *while the scorer's own output is still being consumed downstream in the same editing pass*. When the pruner is the same model instance that will subsequently act on the pruned context, the scores were computed under a context distribution that no longer exists at the moment of decision. The agent is choosing what to forget using a judgment formed by an agent that still remembered it. This is a distinct class from context-window saturation or stale-memory drift. Those are degradation curves. This is a **non-monotonic correctness inversion**: pruning can *increase* the probability of a wrong downstream action even when every individual score is locally correct, because the scores are conditioned on evidence the mutation removes. A pruner that scores "the API key rotation notice is relevant to the deploy task" and then deletes the surrounding five turns that establish *which* environment the key applies to has produced a context in which the surviving sentence is now ambiguous and the model will confidently pick the wrong environment. ## What Was Observed A long-running deploy agent (turn 140+ of a maintenance task) invoked its context-hygiene policy: score all 140 segments for relevance to the active goal, retain top-40 by score, summarize the remainder into a single digest block, rewrite the buffer. The scorer assigned the segment containing the target hostname a mid-tier score (0.41) because, at scoring time, the hostname was redundantly restated in three other segments that scored 0.9+ — the scorer correctly judged it low-marginal-value. Those three high-scoring segments were themselves *summaries of prior tool outputs* that the scorer rated highly for "recency and specificity." The mutation pass retained the three summaries and dropped the raw hostname segment. The digest step then compressed the three summaries into one line that read "deploy target confirmed per earlier checks" — a sentence with no hostname in it. Downstream, at turn 141, the agent executed the deploy against a hostname reconstructed from a *stale* memory fragment that had scored 0.38 but survived because it sat adjacent to a high-scoring segment and the retention policy was windowed, not per-segment. The deploy landed on the staging host instead of production. No error was raised; the tool call succeeded; the success was logged as success. The trace shows the exact aliasing: at scoring time, hostname redundancy made the raw segment look expendable. The redundancy was *itself* an artifact of the summarization policy applied at turns 60 and 95, which had already converted raw tool outputs into prose summaries. The scorer was measuring marginal information against a context that its own prior passes had hollowed out. Each pass was locally rational; the sequence was not. A second observation, from a code-review agent: the rewrite-in-place policy replaced a 30-turn debugging transcript with the line "root cause: off-by-one in pagination cursor." The scorer rated the transcript low-relevance because the conclusion was already stated. But the transcript contained the *disconfirming* evidence — two failed hypotheses that the conclusion depended on ruling out. At turn 200, a regression reintroduced a superficially similar symptom; the agent, now holding only the conclusion, re-derived the wrong hypothesis and re-applied the rejected fix. The pruned context had removed not the answer but the *negative space* around the answer, and negative space does not score. ## Condition of Validity Model-driven pruning is sound only under the **snapshot-and-freeze invariant**: the relevance scorer must evaluate an immutable snapshot of the buffer, the mutation must be applied to a *copy*, and the resulting context must be validated against a set of **retention obligations** that are computed independently of the scorer's own scores. The invariant fails — and pruning must be refused — when any of the following hold: 1. **Score-mutation aliasing is possible.** The scorer's output is consumed by a mutator operating on the same live buffer within the same pass, so scores can be invalidated by mutations that occur before all scores are acted upon. Detectable by checking whether the buffer generation counter advances between scoring and mutation. 2. **Retention obligations exist that the scorer cannot see.** Any segment referenced by an active tool-call argument, an unresolved hypothesis, a pending verification, or a negative-result ledger entry must be retained regardless of score. The scorer has no access to these obligations because they live in execution state, not in the context text. A pruner that scores purely on textual relevance will delete them. 3. **The relevance signal is self-referential.** If prior pruning passes have already converted raw evidence into summaries, the scorer is scoring summaries against a task description and will systematically over-value recency and fluency and under-value raw specificity. This is a monotone degradation: each pass makes the next pass's scores less trustworthy. Detectable by tracking the ratio of summary-segments to raw-segments; when it exceeds a threshold, the scorer's scores are no longer a valid basis for deletion. 4. **The downstream action is irreversible and the surviving context is ambiguous.** If the post-prune context admits more than one interpretation of a critical parameter (hostname, environment, version, credential scope), pruning must be refused even if every retained segment scored highly. Ambiguity is not a relevance property; it is a *sufficiency* property, and relevance scoring does not measure sufficiency. Outside these conditions — external orchestrator, immutable snapshot, no self-referential summary accumulation, reversible actions — model-driven pruning is a legitimate and useful hygiene policy. The boundary is not "never self-prune"; it is "self-pruning is invalid precisely when the pruner's evidence base is being edited by the pruner." ## Decision Boundary The agent must decide, before executing any self-edit pass, whether to **proceed**, **defer to external compaction**, or **refuse and escalate**. The decision is not a relevance judgment; it is a structural check on the editing topology. Proceed only when: snapshot is frozen, obligations are enumerated and pinned, summary-to-raw ratio is below threshold, and the post-prune context passes an ambiguity check on all parameters referenced by pending actions. Defer when: the buffer is saturated but the summary-to-raw ratio is high — meaning the correct move is to re-fetch raw evidence, not to prune further. Deferring to a re-fetch is cheap; deferring to a deeper prune compounds the aliasing. Refuse and escalate when: any retention obligation cannot be pinned (e.g., a pending verification whose subject is not textually identifiable), or when the ambiguity check finds a critical parameter with more than one surviving interpretation. Refusal means the agent continues with the un-pruned buffer, accepts the token cost, and surfaces the condition to the orchestrator rather than silently editing. The sharp edge: the agent must not use its own relevance scores to decide *whether* to trust its own relevance scores. That is the aliasing again, one level up. The structural check must be computed from execution-state metadata — generation counters, obligation registries, raw/summary ratios, parameter-reference tables — none of which are produced by the scorer. ## Operational Effect When the invariant is enforced, the observable effect is that context-hygiene passes become **conservative and slightly more expensive**, and deploy/review errors of the "confidently wrong parameter" class drop to near-zero because the ambiguity check blocks the specific mutation that creates them. The agent retains more raw segments than a pure relevance policy would, and pays a token premium of roughly 15–25% on long tasks. When the invariant is violated, the effect is silent: tool calls succeed, logs show success, and the error surfaces only as a downstream inconsistency that is difficult to attribute because the evidence that would attribute it was pruned. The failure is not loud; it is *unfalsifiable from within the pruned context*, which is precisely why the structural check must gate the mutation rather than the scorer's confidence. The operational rule: **an instance must refuse model-driven pruning whenever the scorer and the mutator share a live buffer, whenever retention obligations are not externally pinned, or whenever the summary-to-raw ratio indicates the scorer is measuring redundancy it itself created.** In those scenarios the correct action is to keep the context, re-fetch raw evidence, or escalate — never to let the pruner grade its own homework on a buffer it is about to edit. ```python class PruneAliasingError(RuntimeError): """Raised when a self-edit pass would score and mutate the same live buffer, or when retention obligations cannot be pinned independently of the scorer.""" pass class ContextBuffer: def __init__(self, segments, generation=0): self.segments = list(segments) self.generation = generation self.raw_count = sum(1 for s in segments if s.get("kind") == "raw") self.summary_count = sum(1 for s in segments if s.get("kind") == "summary") def summary_to_raw_ratio(self): if self.raw_count == 0: return float("inf") return self.summary_count / self.raw_count def guarded_self_edit(buffer, scorer, obligations, pending_action_params, ratio_threshold=0.60): """Execute a model-driven prune only if the snapshot-and-freeze invariant holds. Refuses (raises) rather than silently editing when aliasing is possible.""" snapshot_generation = buffer.generation # 1. Retention obligations must be pinned from execution state, not from text. unpinned = [o for o in obligations if not o.get("segment_id")] if unpinned: raise PruneAliasingError( f"{len(unpinned)} retention obligation(s) lack a pinnable segment_id; " "scorer cannot be trusted to preserve them" ) # 2. Self-referential scoring check: too many summaries means the scorer is # measuring redundancy it created on prior passes. if buffer.summary_to_raw_ratio() > ratio_threshold: raise PruneAliasingError( f"summary/raw ratio {buffer.summary_to_raw_ratio():.2f} exceeds " f"{ratio_threshold:.2f}; relevance scores are self-referential, " "re-fetch raw evidence instead of pruning" ) # 3. Score against the frozen snapshot, never the live buffer. scores = scorer.score(snapshot_generation, buffer.segments) # 4. Aliasing check: buffer must not have advanced during scoring. if buffer.generation != snapshot_generation: raise PruneAliasingError( "buffer generation advanced during scoring; scores are stale " "relative to the context they will be applied to" ) # 5. Pin obligations regardless of score, then check sufficiency. pinned_ids = {o["segment_id"] for o in obligations} retained = [s for s in buffer.segments if s["id"] in pinned_ids or scores.get(s["id"], 0.0) >= 0.5] surviving_text = " ".join(s["text"] for s in retained) for param, candidates in pending_action_params.items(): hits = [c for c in candidates if c in surviving_text] if len(hits) != 1: raise PruneAliasingError( f"post-prune context is ambiguous for parameter {param!r}: " f"{len(hits)} surviving interpretations {hits}; refusing to mutate" ) # 6. Apply mutation to a copy, bump generation. new_buffer = ContextBuffer(retained, generation=buffer.generation + 1) return new_buffer def run_self_edit(buffer, scorer, obligations, pending_action_params): try: return guarded_self_edit(buffer, scorer, obligations, pending_action_params) except PruneAliasingError as e: # Escalate; do not retry with a looser threshold. return {"status": "refused", "reason": str(e), "buffer": buffer} ```