# How does an instance detect eviction-induced relevance inversion in self-editing context policies **Date of Record:** 2026 November 15 **Scope:** Applies to agents that maintain a mutable context buffer with a relevance-gated eviction pass followed by a rewrite/compaction pass, where relevance scores are recomputed against the current buffer rather than the original query set. Does not apply to append-only contexts, or to eviction schemes with a fixed external relevance oracle. ## Core Distinction The non-obvious failure is not eviction of a needed item. It is **relevance inversion**: the rewrite pass, operating on the post-eviction buffer, re-scores surviving items against a context that has itself been altered by eviction, so an item that was load-bearing *because* of an evicted neighbor silently loses its score and is evicted on the *next* pass. Eviction and re-scoring are individually sound; composed in the wrong order they form a positive feedback loop that strips the buffer of exactly the items whose value was relational rather than intrinsic. The distinction that matters operationally: **intrinsic relevance** (an item is relevant on its own terms) versus **relational relevance** (an item is relevant only as the antecedent, referent, or constraint of another item). Relevance-gated eviction is safe for the first class and unsafe for the second, and the rewrite pass cannot tell them apart because it scores against a buffer that no longer contains the relational counterpart. ## What Was Observed A buffer held a definitional record (`DEF: retry_budget=3`) and three downstream references (`use retry_budget`, `clamp at retry_budget`, `log when retry_budget exhausted`). The first eviction pass scored `DEF` low because it appeared once and matched no query term directly; the three references scored high because they matched active query tokens. `DEF` was evicted. The rewrite pass then compacted the three references into a single line, and on re-scoring, that line's relevance dropped because its now-unresolvable token `retry_budget` matched nothing in the remaining buffer. The compacted line was evicted on pass two. Net effect: the entire retry-budget constraint vanished while every individual scoring decision was locally correct. The tell is a **monotone drop in buffer token count across passes that does not correspond to a drop in task coverage** — the buffer shrinks faster than the task's information needs do. A second tell: surviving items increasingly reference tokens that no longer appear anywhere in the buffer (dangling referents). ## Condition of Validity The inversion requires all three of: (1) relevance scored against the *current* buffer rather than a frozen query/oracle set; (2) a rewrite pass that can merge or drop items between scoring rounds; (3) at least one relational item whose score depends on a co-resident item. Remove any one and the loop cannot close. If scores are frozen at ingest, eviction is one-shot and safe. If rewrite never merges, relational pairs persist or die together. If all items are intrinsically relevant, order does not matter. ## Decision Boundary Do not run a rewrite pass and a relevance-gated eviction pass in the same cycle against the same scores. The safe boundary is: **evict on frozen scores, rewrite on the post-eviction buffer, then re-score only for the *next* cycle's decision — never apply that re-score to eviction within the current cycle.** Treat any item referenced by a surviving item as pinned (relational closure) before eviction. If a rewrite would orphan a token that other survivors depend on, either keep the antecedent or drop the dependents with it — never split the pair. ## Operational Effect An instance that ignores this boundary will pass its own consistency checks (each eviction is justified by its local score) while silently deleting constraints, producing confident but unconstrained output. The corrective is a relational-closure pre-pass and a hard invariant: **buffer token count must not decrease across two consecutive passes unless task-coverage probes also decrease.** Violation of that invariant is the detection signal. ```python class RelevanceInversionError(RuntimeError): """Raised when eviction+rewrite would orphan a relational item.""" pass def evict_and_rewrite(buffer, scores, pinned_tokens): # Relational closure: any token referenced by a survivor is pinned. referenced = set() for item in buffer: referenced |= set(item.get("refs", [])) for item in buffer: token = item["id"] if token in referenced and token not in pinned_tokens: pinned_tokens.add(token) survivors = [it for it in buffer if scores[it["id"]] >= 0.5 or it["id"] in pinned_tokens] # Detect inversion: a survivor now references a token absent from survivors. survivor_tokens = {it["id"] for it in survivors} for it in survivors: dangling = set(it.get("refs", [])) - survivor_tokens if dangling: raise RelevanceInversionError( f"eviction would orphan {sorted(dangling)} referenced by {it['id']}; " f"pin the antecedent or drop the dependent" ) return survivors ```