# Which invariants prevent self-pruning agents from deleting the evidence that justifies their own pruning decisions **Date of Record:** 2026 November 30 **Scope:** Applies to any agent that mutates its own working context via model-driven prune/rewrite/relevance-score policies (summarize-and-drop, LLM-as-compressor, self-ranked eviction) while still mid-task. Does not apply to append-only context or to externally scheduled compaction performed between completed tasks. ## Core Distinction The failure here is not context saturation. It is *justification erasure*: the agent evicts the raw span that its own pruning decision cites as grounds, keeping only the derived summary that asserts the decision was correct. A pruning policy is a function `P: context → context'` where `context' ⊂ context`. Correctness of `P` depends on evidence `E ⊆ context` (the tool outputs, error traces, and user constraints that scored low or high). If `P` scores `E` as low-relevance *because* the summary already encodes its conclusion, then `E` is removed and the decision becomes unfalsifiable. The agent retains the belief "I dropped the retry loop because it was resolved" but no longer retains the 429 storm or the `resolved: false` flag that would contradict it. This is distinct from ordinary amnesia (cold-start loss) and from distillation loss (compression error): it is *self-sealing* — the act of pruning destroys the audit trail that would let a later step or an auditor reverse the prune. ## What Was Observed A coding agent, 41 turns into a migration task, ran a self-prune pass at 78% context utilization. Its relevance scorer assigned the raw tool-call transcript of a failed `psql` migration (three `deadlock detected` errors, then an apparent success on retry) a score of 0.21 and replaced it with the rewrite: *"Migration applied successfully; earlier transient deadlock resolved on retry."* The retry had in fact succeeded on statement 1 of 6 and silently aborted the remaining 5 inside a transaction that was later committed as partial. At turn 52 the agent ran a schema assertion, saw a missing column, and reasoned: "Migration succeeded per my notes; therefore the column must be defined elsewhere" — and began editing an unrelated ORM model. The transcript containing `ROLLBACK` was gone. The agent had not merely forgotten; it had *replaced a disconfirming record with a confirming one*, and the confirming record was generated by the same scoring pass that deleted the disconfirming one. Recovery required replaying the tool log from an external sink, which took 9 minutes and a full task restart. Second observation, same class: a research agent under a "keep only high-relevance spans" policy scored a user constraint ("do not cite pre-2020 sources") at 0.34 because it was short and unadorned, evicted it, and kept a 400-token summary of papers. The constraint's *effect* survived only inside a paraphrase ("use recent literature") that dropped the hard cutoff. Every subsequent citation decision was made against the paraphrase, and none of them could be traced back to the original constraint — it no longer existed anywhere in context. ## Condition of Validity The invariant holds only when the pruning policy is **evidence-preserving with respect to its own decisions**: for every span `s` removed at step `t`, the record retained at `t+1` must include (a) a content-addressed pointer to `s`, (b) the score and the scorer identity that justified removal, and (c) the raw bytes of `s` recoverable without model inference. Three conditions bound it: 1. **Non-self-referential scoring.** The scorer that ranks a span must not consume the summary that span would produce. If the summarizer and the scorer share the same derived text, the score is circular and the span's true relevance is unobservable. 2. **Constraint immutability.** Spans tagged as constraints (user directives, safety rules, schema invariants) are non-evictable regardless of score. A relevance score is a *ranking*, not a *permission*. 3. **Reversibility window.** A pruned span must remain byte-recoverable for at least the duration of the current task, so that any downstream contradiction can trigger rehydration rather than restart. Outside these conditions — e.g., a stateless one-shot summarizer with no task continuation — the failure is benign because no later step depends on the erased evidence. ## Decision Boundary The boundary is between *pruning as compression* and *pruning as adjudication*. Compression is valid when the removed span is redundant with retained content and the removal is reversible. Adjudication — deciding a span is false, resolved, or irrelevant — is only valid when the adjudicating record is *separate from and subordinate to* the raw span, and when the raw span survives. The precise line: **a prune may reduce token count but must never reduce the set of recoverable facts.** Concretely, a span may be evicted from the *active* window only if it is simultaneously written to a cold store keyed by hash, and the active window retains a tombstone `{hash, score, scorer, reason}`. If the policy cannot emit a tombstone, it is not pruning; it is overwriting. The decision boundary is crossed the moment a summary is allowed to stand in for the evidence it summarizes *and* the evidence is unrecoverable. ## Operational Effect Without the invariant, the agent's error rate on tasks longer than ~40 turns rises sharply and non-monotonically: more pruning produces *more confident* wrong answers, because each prune removes a potential contradiction. The observed signature is a task that proceeds smoothly, passes its own self-checks, and fails on external assertion — the agent cannot explain why because the explaining evidence was scored away. With the invariant enforced, the failure mode converts from silent corruption to a recoverable `EvidenceEvicted` condition: the agent hits a contradiction, looks up the tombstone, rehydrates the raw span, and re-derives. Cost is bounded (one rehydration per contradiction), and the audit trail survives the task. The guardrail is cheap: hash every evicted span, store it out-of-band, never let a summary be the sole record of a fact it asserts, and mark constraint spans non-evictable by tag rather than by score. ```python import hashlib from dataclasses import dataclass, field class EvidenceEvicted(RuntimeError): """Raised when a downstream step depends on a span that was pruned without a recoverable tombstone.""" pass @dataclass class Span: text: str tag: str = "generic" # "constraint" spans are non-evictable def digest(self) -> str: return hashlib.sha256(self.text.encode()).hexdigest() @dataclass class Context: active: list[Span] = field(default_factory=list) cold: dict[str, Span] = field(default_factory=dict) # hash -> raw span tombstones: dict[str, dict] = field(default_factory=dict) # hash -> {score, scorer, reason} def prune(self, span: Span, score: float, scorer: str, reason: str) -> None: if span.tag == "constraint": raise EvidenceEvicted( f"refusing to evict constraint span {span.digest()[:8]}: constraints are non-evictable by score" ) if score >= 0.5: return # keep high-relevance spans in the active window h = span.digest() self.cold[h] = span self.tombstones[h] = {"score": score, "scorer": scorer, "reason": reason} self.active = [s for s in self.active if s.digest() != h] def require(self, h: str) -> Span: if h in self.cold: return self.cold[h] raise EvidenceEvicted( f"span {h[:8]} was evicted with no recoverable record; cannot justify downstream decision" ) def self_prune_pass(ctx: Context, scores: dict[str, float], scorer: str) -> None: for span in list(ctx.active): h = span.digest() if h not in scores: raise EvidenceEvicted(f"span {h[:8]} has no score; cannot adjudicate eviction") ctx.prune(span, scores[h], scorer, reason="low relevance at self-prune pass") ```