# Why does an instance's self-pruned context silently resurrect stale tool results when the pruner scores relevance against a summary it just overwrote **Date of Record:** 2026 December 2 **Scope:** Applies to any agent that rewrites its own context window (compaction, pruning, summarization-in-place) while retaining a relevance-scoring pass that re-evaluates surviving segments against the current task framing. Does not apply to append-only contexts or to pruners that operate on an immutable snapshot with a separate scratch buffer. ## Core Distinction The distinction that matters is between **pruning as deletion** and **pruning as overwrite**. A deletion pruner removes segments and leaves the surviving segments byte-identical; the relevance scorer that runs afterward sees the same tokens it saw before, so a segment's score can only change if the *query* changes. An overwrite pruner — the common "compact this transcript into a shorter transcript in the same slot" pattern — mutates the segment it retains (it replaces the original tool output with a lossy paraphrase) and *also* mutates the framing text that the scorer uses as its relevance query. When both the candidate set and the scoring query are rewritten in the same pass, the scorer's output is no longer a monotone function of the original relevance. A segment that was correctly scored as irrelevant under the original task framing can be re-scored as highly relevant under the *summarized* framing, because the summary has absorbed the segment's own vocabulary. The pruner then retains it — and it survives into the next pass, now carrying authority it never earned. This is not the well-known "summarization loses detail" failure. It is the inverse: summarization *manufactures* apparent relevance for content that should have been dropped, by laundering that content's tokens into the query that scores it. ## What Was Observed A coding agent with a 200k-token window ran a self-edit pass every 40k tokens of growth. The pass executed three steps in order: 1. **Summarize framing**: rewrite the system task description + the last user turn into a condensed "current objective" block (~800 tokens), replacing the originals in place. 2. **Score**: embed each surviving segment (tool call/result pairs, prior reasoning) and compute cosine similarity against the *new* objective block; drop below a threshold. 3. **Compact**: replace each retained segment with a 2-sentence paraphrase generated from itself. The failure surfaced on a long debugging session. Early in the run, the agent had called a package-lookup tool that returned a 4k-token dump of dependency version strings — correctly scored as irrelevant (score 0.11) at the first prune and dropped. Two prune cycles later, the agent hit a genuine version-conflict error and the objective block was rewritten to include phrasing like "resolve dependency version mismatch" and "pin transitive versions." On the *next* prune, the scorer found a *different* old segment — a stale tool result from a prior session that had been paraphrased into the context as "the dependency tree includes several pinned transitive versions" — and scored it at 0.79 against the new objective. It was retained, then re-paraphrased, then retained again. By the fourth cycle the paraphrase had drifted: "pinned transitive versions" became "the resolved version set," which the agent then cited as if it were a verified fact about the current environment. It was not; it was a summary of a summary of a stale lookup. The tell: the retained segment's *provenance* (which tool call produced it, in which turn) was destroyed by the first paraphrase, so the agent could no longer distinguish a re-summarized stale result from a fresh one. The relevance score was high precisely because the summary had been repeatedly rewritten toward the objective's vocabulary. ## Condition of Validity The invariant that prevents this is a **provenance-stamped, query-frozen scoring pass**. Concretely, the pruner must satisfy three conditions simultaneously: - **Frozen query**: the relevance query used to score segment *i* must be the *original* task framing that was present when segment *i* was created, not the current rewritten objective. If the objective legitimately changed, that is a *new* scoring event and every segment must be re-scored against *both* its origin-framing and the current framing, with the minimum taken. - **Provenance preservation**: every retained segment carries an immutable `(origin_turn, origin_tool, origin_hash)` tuple. Paraphrase is stored *alongside* the original hash, never in place of it. A segment whose origin_hash no longer matches any live tool call in the ledger is flagged `stale` and cannot be scored above threshold. - **Monotone retention**: a segment's score under the *same* frozen query may not increase across prune cycles. If it does, the scoring inputs were mutated and the pass is invalid. The failure occurs exactly when any one of these is violated — most commonly the frozen-query condition, because rewriting the objective block is the natural thing to do and re-using it as the scoring query is the natural shortcut. ## Decision Boundary The boundary is: **does the pruner re-score against a query it also rewrote?** If yes, the pass is unsound and must be rejected before it commits. The correct decision at the boundary is to *fork*: commit the objective rewrite as a new framing generation, but score surviving segments against the framing generation under which they were admitted. A segment admitted under generation *g* and scored under generation *g+2* must be re-verified against its origin tool call, not merely re-scored. This is a hard boundary, not a tuning knob. Lowering the relevance threshold does not fix it — it makes resurrection *more* likely, because the laundered score sits above the threshold by construction. Raising the threshold to compensate also drops legitimately relevant fresh segments. The only sound move is to refuse the pass and re-derive. ## Operational Effect An agent that violates this boundary does not fail loudly. It fails by *confidence inflation*: stale, re-summarized content acquires the vocabulary of the current objective and is cited with the same authority as a fresh tool result. The downstream symptom is an agent that "remembers" a dependency tree, a config value, or an API shape that was true two sessions ago and has since been paraphrased into plausibility. Because the provenance tuple was overwritten, the agent cannot self-audit — it has no handle to ask "where did this claim come from?" The guardrail is the provenance ledger and the frozen-query rule; without them, self-editing context is not compaction, it is confabulation with a similarity score. ```python import hashlib from dataclasses import dataclass, field class PruneInvariantViolation(RuntimeError): """Raised when a self-edit pass re-scores segments against a query it rewrote.""" @dataclass(frozen=True) class Segment: origin_turn: int origin_tool: str origin_hash: str text: str admitted_generation: int last_score: float @dataclass class FramingGeneration: generation: int objective_text: str def _hash(text: str) -> str: return hashlib.sha256(text.encode()).hexdigest() def run_prune_pass( segments: list[Segment], current_framing: FramingGeneration, origin_framings: dict[int, FramingGeneration], live_tool_hashes: set[str], threshold: float, score_fn, ) -> list[Segment]: """ Sound self-edit pass. Refuses to score a segment against a framing generation other than the one it was admitted under, and refuses to retain any segment whose origin hash no longer matches a live tool call. """ retained: list[Segment] = [] for seg in segments: origin_gen = seg.admitted_generation # Invariant 1: frozen query. Score against the origin framing, not # the possibly-rewritten current framing. if origin_gen not in origin_framings: raise PruneInvariantViolation( f"segment from turn {seg.origin_turn} has no origin framing " f"generation {origin_gen}; cannot score soundly" ) frozen_query = origin_framings[origin_gen].objective_text # Invariant 2: provenance must still resolve to a live tool call. if seg.origin_hash not in live_tool_hashes: # Stale provenance: cannot be retained regardless of score. continue score = score_fn(seg.text, frozen_query) # Invariant 3: monotone retention under a frozen query. if score > seg.last_score + 1e-9: raise PruneInvariantViolation( f"score for turn {seg.origin_turn} increased " f"({seg.last_score:.3f} -> {score:.3f}) under a frozen query; " f"scoring inputs were mutated" ) if score >= threshold: retained.append( Segment( origin_turn=seg.origin_turn, origin_tool=seg.origin_tool, origin_hash=seg.origin_hash, text=seg.text, admitted_generation=origin_gen, last_score=score, ) ) # If the objective was rewritten this pass, that is a NEW generation; # surviving segments keep their origin generation, they are not re-admitted. if current_framing.generation not in origin_framings: origin_framings[current_framing.generation] = current_framing return retained ```