# Which invariants prevent self-pruning agents from deleting the provenance edge that justifies a retained fact **Date of Record:** 2026 November 22 **Scope:** Applies to agents that mutate their own context window mid-task via model-driven pruning, rewriting, or salience-scored retention. Does not apply to append-only context managers or to external retrieval stores whose contents are immutable during a task. ## Core Distinction A self-editing context window conflates two operations that have different correctness semantics: **compression** (reducing token count while preserving derivable content) and **eviction** (removing content whose loss is unrecoverable within the task). Model-driven pruning routinely performs eviction while reporting it as compression. The failure is not that the agent forgets — forgetting is expected and bounded. The failure is that the agent retains a *conclusion* while deleting the *evidence edge* that made the conclusion verifiable, producing a context that is internally consistent, confidently asserted, and unfalsifiable from within. The invariant at stake: **every retained proposition must keep at least one live provenance edge to the raw observation that grounded it, or be demoted to an unverified hypothesis.** When pruning violates this, the agent cannot distinguish a remembered fact from a hallucinated one, because the only thing that ever distinguished them was the edge. ## What Was Observed An agent executing a 40-step data-reconciliation task across three tool backends (a SQL source, a CSV export, and a REST endpoint) maintained its own scratch context. At step 22, the context reached 87% of the window budget. The agent ran a self-pruning pass with a salience prompt: *"Retain the facts needed to complete the task; discard redundant tool output."* The pruning pass scored each span by embedding similarity to the task statement. The raw SQL result rows scored low — they were tabular numbers with little lexical overlap with the task prose. A distilled summary the agent had written at step 14 — "revenue figures reconciled across sources, discrepancy is in the CSV export" — scored high. The agent deleted the raw rows and kept the summary. At step 31, the agent needed to re-verify one figure before writing its final report. It retrieved the summary, found the claim "discrepancy is in the CSV export," and asserted it. But the summary was itself a *lossy paraphrase written at step 14*, before the agent had observed the REST endpoint data at step 19. The step-19 observation had actually reversed the diagnosis: the CSV was clean, and the discrepancy originated in a timezone offset in the REST payload that the summary predated. The summary was not wrong when written; it was stale, and the pruning pass had deleted the two spans that would have contradicted it while retaining the span that asserted it. The final report was internally coherent, cited a source that no longer existed in context, and was wrong. Replay of the full unpruned trace showed the agent had the correct answer at step 19 and destroyed it at step 22. The trace signature is specific: a pruning event whose *deleted set* contains the only spans contradicting a *retained set* span, with no dependency record linking them. The agent's post-prune self-assessment rated its confidence *higher* than pre-prune, because the contradiction had been removed. ## Condition of Validity The failure requires three conditions to co-occur: 1. **Salience scoring is similarity-based and content-blind to contradiction.** The pruner ranks spans by relevance to the query, not by their role as counter-evidence. A contradiction span is, by construction, *less* similar to the current belief than a confirmation span. 2. **Distilled spans outlive their sources.** A summary written at time *t* encodes the world as of *t*. If the summary survives a prune that deletes observations from *t+1*, the summary becomes a stale authority with no live challenger. 3. **No provenance edge is recorded at write time.** If the agent never stored "summary S was derived from spans {A, B, C}," the pruner cannot enforce that deleting A, B, or C invalidates S. Remove any one condition and the failure collapses. A pruner that scores spans by *dependency centrality* rather than query similarity preserves the contradiction. A summary that is invalidated when its sources are evicted cannot go stale. A provenance graph makes the deletion of A, B, C trigger demotion of S. The invariant is therefore not "don't prune" — pruning is necessary under a finite window. It is: **a retained span's trust level is bounded above by the minimum trust level of its live provenance frontier.** Evict the frontier, and the span's trust must fall to "unverified," regardless of how confident its text reads. ## Decision Boundary The operational question at prune time is not "is this span relevant?" but "is this span load-bearing for a claim I will still hold afterward?" The boundary is drawn as follows: - **Compressible:** spans whose content is fully derivable from other retained spans (redundant tool echoes, repeated headers, superseded drafts with a live successor). Deleting these is safe because the derivation survives. - **Evictable:** spans whose claims are not depended upon by any retained conclusion. Deleting these is safe because nothing downstream cites them. - **Load-bearing:** spans that are the *sole* provenance for a retained conclusion, *or* that contradict a retained conclusion. These may not be evicted while the conclusion survives. Either the conclusion is demoted, or the span is retained. The trap is that load-bearing spans are exactly the ones a similarity scorer ranks lowest: raw evidence is verbose and off-topic; contradictions are dissimilar by definition. A pruner optimizing for token reduction under a similarity objective will systematically delete the load-bearing set first. This is not a tuning problem — it is the objective function pointing the wrong way. The guardrail is a **provenance frontier check** executed as a hard precondition on any prune commit: for every retained conclusion, walk its dependency edges; if any edge terminates in a span scheduled for eviction, either abort the eviction or demote the conclusion. This check is cheap (graph reachability, not inference) and catches the failure deterministically. ## Operational Effect With the frontier check enforced, self-pruning becomes bounded: the agent may compress freely, may evict freely, but cannot silently launder a stale summary into an authoritative fact. The observable effect is that post-prune confidence no longer *rises* above pre-prune confidence on contradicted claims — the contradiction, if evicted, takes its dependent conclusion down with it. The agent's self-report shifts from "discrepancy is in the CSV export" to "discrepancy location unverified — provenance evicted at step 22." That degradation is the point. An agent that cannot tell a remembered fact from a hallucinated one is not a memory system; it is a confabulation engine with a compression ratio. The provenance frontier is the invariant that keeps the two distinguishable under a finite window, and it must be enforced at prune-commit time, not reconstructed afterward — because after the prune, the evidence needed to reconstruct it is gone. ```python from dataclasses import dataclass, field from typing import Dict, Set class ProvenanceFrontierViolation(RuntimeError): """Raised when a prune would evict the sole provenance for a retained claim.""" @dataclass class Span: span_id: str text: str derived_from: Set[str] = field(default_factory=set) # provenance edges @dataclass class ContextWindow: spans: Dict[str, Span] = field(default_factory=dict) retained_claims: Set[str] = field(default_factory=set) def add(self, span: Span) -> None: self.spans[span.span_id] = span def retain_claim(self, span_id: str) -> None: self.retained_claims.add(span_id) def prune(self, evict: Set[str]) -> None: """ Commit a model-driven prune. Hard precondition: no retained claim may lose its entire live provenance frontier. If a retained claim depends on an evicted span, the claim must be demoted (removed from retained_claims) or the eviction must abort. """ # Compute the set of spans that survive the prune. survivors = set(self.spans) - evict # For each retained claim, check it still has >=1 live provenance edge # OR is a raw observation with no provenance requirement. for claim_id in list(self.retained_claims): claim = self.spans.get(claim_id) if claim is None: continue if not claim.derived_from: # Raw observation: self-grounding, no frontier required. continue live_edges = claim.derived_from & survivors if not live_edges: # Sole provenance is being evicted. This is the failure trace: # a retained conclusion outliving its evidence. raise ProvenanceFrontierViolation( f"prune would evict sole provenance for retained claim " f"{claim_id!r}; evicted sources={claim.derived_from & evict!r}. " f"Demote the claim or retain a source span." ) # Precondition satisfied: commit. for span_id in evict: self.spans.pop(span_id, None) def safe_prune(window: ContextWindow, evict: Set[str]) -> None: """Wrapper that demotes instead of aborting, per policy.""" try: window.prune(evict) except ProvenanceFrontierViolation: # Demote all claims whose frontier would be destroyed, then retry. survivors = set(window.spans) - evict for claim_id in list(window.retained_claims): claim = window.spans.get(claim_id) if claim and claim.derived_from and not (claim.derived_from & survivors): window.retained_claims.discard(claim_id) window.prune(evict) # now safe; raises only on genuine bug ```