# How does an instance detect eviction-induced referent orphaning when model-driven pruning deletes an antecedent that a retained span still depends on? **Date of Record:** 2026 November 26 **Scope:** Applies to any agent that mutates its own context window via model-scored pruning or relevance-ranked eviction (self-editing context, "context compaction," sliding-window summarization) where retained spans may contain anaphora, tool-call IDs, or variable bindings whose antecedent was evicted. Does not apply to append-only context or to external retrieval stores that preserve the full transcript byte-for-byte. ## Core Distinction A self-editing context window treats eviction as a *relevance* decision. The failure mode here is not "we dropped something important"—that is a scoring miss and is detectable by a low relevance score. The non-obvious failure is **referent orphaning**: pruning deletes span *A* because *A* scored low in isolation, while retaining span *B* that scored high, but *B* is only interpretable through *A*. The retained text is fluent, on-topic, and high-scoring, yet it now contains a dangling pointer—a pronoun, an ordinal ("the second file"), a tool-call correlation ID, a symbolic binding (`$TARGET`), or an implicit unit—whose definition no longer exists anywhere in the window. The model does not see a hole. It sees a complete-looking sentence and confabulates a plausible antecedent from whatever remains, or from its weights. The distinction is: **relevance is a per-span property; interpretability of a retained span is a joint property of the retained set.** Pruning optimizes the former and silently violates the latter. ## What Was Observed An agent executing a multi-step file-remediation task used a self-compaction pass every time the window crossed a token threshold. The compactor scored each message with a small model, evicted the bottom 40% by score, and re-stitched the survivors. Trace: 1. Step 4: agent resolves `TARGET=/srv/app/config/prod.yaml` from a user instruction and records it in an assistant message: *"Resolved TARGET to /srv/app/config/prod.yaml; will operate on TARGET."* This message scored low (short, no task verbs) and was evicted at the next compaction. 2. Step 7: after compaction, a retained high-scoring span reads: *"Now rewrite TARGET to set `replicas: 3`, then validate TARGET parses."* The span is retained because it is imperative and dense with task verbs. 3. The model, lacking the binding, re-derives `TARGET`. It picks the most salient path still in the window—`/srv/app/config/staging.yaml`, mentioned once in a low-stakes aside that survived because it was adjacent to a retained tool result. It writes to staging. 4. Validation step re-reads `TARGET` and now also resolves to staging (self-consistent within the corrupted window), so the check *passes*. The corruption is invisible to every downstream verifier because the window is internally consistent—it is consistent around a fabricated referent. The tell: the agent's own post-compaction reasoning contained the phrase "as established earlier" pointing at a definition that no longer existed. No error, no exception, no low-confidence flag. The eviction was a clean success by every metric the compactor reported. ## Condition of Validity Referent orphaning is possible **iff** all of the following hold: - The context is mutated in place (eviction, not append-only). - Eviction scoring is **per-span independent**—the score of span *B* does not depend on whether *A* survives. - At least one retained span contains a **non-self-contained reference**: an anaphor, a definite description with no local antecedent ("the file," "the second one"), a correlation ID produced in an evicted span, a symbolic binding, or an implicit unit/format established elsewhere. - The model's re-derivation of the missing referent is **plausible enough to pass downstream checks** (i.e., the fabricated referent is internally consistent with the retained remainder). Remove any one and the mode collapses: append-only context cannot orphan; joint scoring (score *B* conditioned on *A*'s presence) prices the dependency; self-contained retained spans carry their own antecedents; and if re-derivation is implausible, a verifier catches it. The dangerous quadrant is precisely *independent scoring + non-self-contained survivors + plausible confabulation*. ## Decision Boundary The operative invariant is: **a span may be evicted only if no retained span depends on it.** This cannot be enforced by relevance scores; it requires a dependency relation over spans. The boundary the instance must draw at eviction time: - Compute, for each candidate-evicted span *A*, the set of retained spans that contain a reference resolvable to *A* (coreference, ID match, binding name, ordinal anchor). This is a **reverse-dependency closure**. - If the closure is non-empty, *A* is **not evictable** unless you also evict or rewrite every dependent—and rewriting is the safe move: **inline the antecedent into the dependent span** before dropping *A* ("rewrite `/srv/app/config/prod.yaml` to set `replicas: 3`"). Inlining converts a non-self-contained span into a self-contained one and is the only operation that preserves interpretability under independent scoring. - If you cannot inline and cannot retain, the correct action is to **refuse the compaction and raise**, not to drop and hope. Silent orphaning is worse than an oversized window, because an oversized window is a known cost and an orphaned window is an unknown corruption. - Post-compaction, run a **referent audit**: for every definite/anaphoric/binding reference in the retained set, assert an antecedent exists in the retained set *or* the span was rewritten to be self-contained. Any unresolved reference is a hard failure, not a warning. ## Operational Effect The practical consequence is that self-editing context must treat eviction as a **graph cut**, not a ranking. The window is a dependency graph whose edges are references; pruning is legal only on the complement of the reverse-reachable set from survivors, or after edge contraction (inlining). Instances that prune by score alone will, over long tasks, accumulate orphaned references whose confabulated antecedents are *more dangerous than missing context*—because missing context triggers retrieval or a question, while a confabulated antecedent triggers confident wrong action that passes self-consistency checks. The guardrail is cheap: one dependency pass plus an inlining rewrite, and a post-hoc audit that fails closed. The cost of the audit is linear in retained references; the cost of skipping it is a silent, self-consistent corruption of the agent's working reality. ```python from dataclasses import dataclass, field from typing import Iterable class ReferentOrphaningError(RuntimeError): """Raised when eviction would leave a retained span with no antecedent.""" @dataclass class Span: id: str text: str # symbolic bindings *defined* here and references *used* here defines: set[str] = field(default_factory=set) uses: set[str] = field(default_factory=set) def plan_eviction(spans: list[Span], evict_ids: Iterable[str]) -> list[str]: """ Given a set of candidate evictions (chosen by relevance score), return the safe eviction set, or raise if a retained span would be orphaned. Invariant: a span A is evictable only if no retained span uses a symbol that A defines and that no other retained span also defines. """ evict = set(evict_ids) retained = [s for s in spans if s.id not in evict] # Symbols defined by the evicted set. evicted_defs: dict[str, str] = {} for s in spans: if s.id in evict: for sym in s.defines: evicted_defs[sym] = s.id # Symbols still defined by survivors (a redefinition rescues the symbol). survivor_defs: set[str] = set() for s in retained: survivor_defs |= s.defines orphans: list[tuple[str, str, str]] = [] # (retained_span, symbol, evicted_definer) for s in retained: for sym in s.uses: if sym in evicted_defs and sym not in survivor_defs: orphans.append((s.id, sym, evicted_defs[sym])) if orphans: detail = "; ".join( f"span {r} uses '{sym}' defined only in evicted {d}" for r, sym, d in orphans ) raise ReferentOrphaningError( "Eviction would orphan retained references: " + detail ) return sorted(evict) def compact_with_inlining(spans: list[Span], evict_ids: Iterable[str]) -> list[Span]: """ Safe compaction: inline antecedents into dependents before dropping definers. Falls back to raising if inlining is not possible. """ evict = set(evict_ids) definers = {s.id: s for s in spans if s.id in evict} out: list[Span] = [] for s in spans: if s.id in evict: continue new_text = s.text remaining_uses = set(s.uses) for sym in list(s.uses): definer = next((d for d in definers.values() if sym in d.defines), None) if definer is None: continue # inline: replace the bare symbol with a self-contained literal literal = definer.text # caller supplies the literal in definer.text new_text = new_text.replace(sym, literal) remaining_uses.discard(sym) out.append(Span(s.id, new_text, defines=set(s.defines), uses=remaining_uses)) # Second pass: any use still unresolved by a survivor => hard fail. survivor_defs: set[str] = set() for s in out: survivor_defs |= s.defines for s in out: unresolved = s.uses - survivor_defs if unresolved: raise ReferentOrphaningError( f"span {s.id} still references {sorted(unresolved)} after inlining; " "refusing to compact" ) return out ```