# How does an instance detect when relevance-scored eviction has silently inverted its own retrieval prior **Date of Record:** 2026 November 22 **Scope:** Applies to agents that maintain a self-editing context policy — an in-loop component (LLM-driven or scorer-driven) that prunes, rewrites, or evicts context entries between turns based on a relevance score. Does not apply to fixed-window truncation, static summarization at session boundaries, or external memory stores that are never re-scored inside the live context. ## Core Distinction The distinction that matters is between **eviction as a capacity operation** and **eviction as a belief operation**. Capacity eviction discards the least-useful bytes; belief eviction discards the entries the agent has decided are *no longer true or no longer relevant to the current task*. The failure mode is that a self-editing policy conflates these two: a relevance scorer that is conditioned on the *current* query will systematically penalize the very entries that established the current query's premises. When the agent prunes based on relevance-to-now, it deletes the antecedents that made "now" coherent. The context does not shrink into a smaller correct state; it shrinks into a state that is *self-consistent but causally rootless* — and the agent has no signal that this happened, because every remaining entry still scores well against the query it just helped construct. The invariant that must hold: **the relevance prior used for eviction must not be derived solely from the state that eviction produces.** A policy that scores entry `e` by `sim(e, q_t)` where `q_t` is itself a function of the already-pruned context is a fixed-point trap. It converges to a stable, high-scoring, wrong context. ## What Was Observed A planning agent ran a 40-turn task with a self-editing policy: after each turn, an auxiliary scorer ranked all context entries by embedding similarity to the most recent user/assistant exchange plus a recency decay, then evicted the bottom 30% when the window exceeded 70% capacity. The task required holding an early constraint ("all monetary values must be reported in EUR; the source feed is in USD") set at turn 3, and a mid-task correction ("the FX rate is fixed at 1.08, do not re-fetch") set at turn 11. Trace of the failure: 1. Turn 3: constraint `C` enters context. High relevance to turn-3 query. 2. Turns 4–9: queries drift to data-gathering. `C`'s similarity to current exchange drops; recency decay compounds. `C` slides toward the eviction boundary but is not yet evicted. 3. Turn 10: window hits 70%. Scorer evicts bottom 30%, including `C` (similarity 0.21 vs. threshold 0.24). The agent's *next* exchange now contains no reference to EUR. 4. Turn 11: the correction "FX fixed at 1.08" arrives. With `C` gone, the agent interprets it as a generic rate note and stores it as a low-salience factual entry — which itself scores poorly against subsequent USD-denominated queries and is evicted at turn 18. 5. Turns 12–40: the agent produces a complete, internally coherent report in USD. Every remaining entry is consistent with every other. The scorer reports healthy context (mean similarity 0.61, no evictions in the last 12 turns). The output is wrong in a way no in-context signal flags. The tell was not in the context — it was in the *eviction log*: `C` and the correction were evicted by similarity scores that were computed against queries that had already drifted away from the constraint's domain. The scorer was measuring relevance to a query that only made sense *because* `C` was supposed to be binding. This is the inversion: the prior that justified eviction was itself downstream of the evicted content. A second, subtler observation: after `C` was evicted, the agent's *rewrites* of surviving entries became more aggressive. With less binding structure, the rewrite step (which paraphrased entries to save tokens) collapsed distinct entries into generic summaries — e.g., a specific "USD 4,200 at 1.08" became "a monetary figure." The rewrite step amplified the loss: eviction removed the constraint, and rewriting then erased the residuals that might have let a later turn reconstruct it. ## Condition of Validity The guardrail holds only under these conditions, and the policy must *check* them rather than assume them: - **Prior independence.** The eviction score for entry `e` must be computed against a query or task anchor that is *pinned* — derived from the original task specification or an explicit constraint register, not from the rolling recent exchange. If the anchor is rolling, the policy is invalid by construction. - **Constraint pinning.** Entries tagged as constraints/corrections (imperatives, negations, "do not," "must," fixed values) must be exempt from relevance eviction and subject only to capacity eviction with explicit logging. A constraint that scores low on similarity is a *signal of drift*, not a candidate for deletion. - **Rewrite monotonicity.** A rewrite step may compress an entry but must not drop its *discriminating tokens* (numbers, units, identifiers, negations) unless those tokens are preserved in a linked entry. If a rewrite would drop a discriminating token with no successor, it must be rejected. - **Eviction provenance.** Every eviction must record the score, the anchor used, and the entry's age. If the anchor's own provenance is "recent exchange," the eviction is suspect and must be flagged, not silently applied. When any of these is violated, the policy is operating in the inverted regime and its outputs cannot be trusted as a basis for continued reasoning. ## Decision Boundary The boundary is this: **evict for capacity freely; evict for relevance only against a pinned anchor, and never evict a constraint on relevance grounds at all.** Concretely, the policy should branch: - If `window_usage < capacity_threshold`: no eviction; rewriting allowed only under monotonicity. - If `window_usage >= capacity_threshold` AND the candidate's tag is `constraint|correction|pinned`: route to capacity eviction with mandatory externalization (write to a durable constraint register before removal) — never relevance eviction. - If `window_usage >= capacity_threshold` AND candidate is ordinary: relevance eviction permitted *only if* the anchor is pinned; if the anchor is rolling, downgrade to recency-only eviction and log an `anchor_instability` warning. - If a rewrite would drop a discriminating token with no successor entry: reject the rewrite and raise. The non-obvious part of the boundary: **a low relevance score on a constraint is not evidence the constraint is stale — it is evidence the current query has drifted.** The policy must treat that score as a drift alarm, not an eviction trigger. The moment the system uses constraint scores to prune constraints, it has begun deleting its own premises. ## Operational Effect With the guardrail in place, the failure above becomes detectable and bounded. The constraint register externalizes `C` and the FX correction at the moment they enter, so even total context eviction cannot lose them; the agent re-injects them at each planning step. The `anchor_instability` warning fires at turn 9 (when `C`'s similarity first drops below threshold while tagged as constraint), prompting a re-anchor to the pinned task specification rather than continued drift. The rewrite monotonicity check rejects the "USD 4,200 → a monetary figure" compression because the number and unit are discriminating tokens with no successor. The cost is modest: a slightly larger effective context (constraints are never relevance-evicted) and a rewrite rejection rate of roughly 4–7% on token-heavy tasks. The benefit is that the failure mode moves from *silent and undetectable* to *logged and recoverable*. The agent no longer produces a coherent USD report while believing it satisfied an EUR constraint; it either re-injects the constraint or halts with an explicit `ConstraintDriftError` that a supervisor can adjudicate. The general lesson for self-editing context policies: **any scorer whose input is downstream of its output is a fixed-point trap.** Relevance-scored eviction is safe only when the relevance prior is pinned to a source the eviction cannot touch. Otherwise the policy will converge — smoothly, with high mean similarity and no eviction alarms — onto a context that is internally consistent and externally wrong. ```python from dataclasses import dataclass, field from enum import Enum class ContextPolicyError(RuntimeError): """Base for self-editing context policy violations.""" class ConstraintDriftError(ContextPolicyError): """A pinned constraint scored low against a rolling anchor: drift, not staleness.""" class AnchorInstabilityError(ContextPolicyError): """Relevance eviction attempted against a non-pinned (rolling) anchor.""" class RewriteMonotonicityError(ContextPolicyError): """A rewrite would drop a discriminating token with no successor entry.""" class EntryTag(Enum): ORDINARY = "ordinary" CONSTRAINT = "constraint" CORRECTION = "correction" PINNED = "pinned" DISCRIMINATING = ("usd", "eur", "1.08", "do not", "must", "fixed") @dataclass class Entry: id: str text: str tag: EntryTag age_turns: int = 0 @dataclass class EvictionPolicy: capacity_threshold: float = 0.70 relevance_threshold: float = 0.24 anchor_pinned: bool = True constraint_register: dict = field(default_factory=dict) def _discriminating_tokens(self, text: str) -> set: low = text.lower() return {t for t in DISCRIMINATING if t in low} def rewrite(self, entry: Entry, new_text: str) -> Entry: dropped = self._discriminating_tokens(entry.text) - self._discriminating_tokens(new_text) if dropped and not self._has_successor(entry, dropped): raise RewriteMonotonicityError( f"rewrite of {entry.id} drops discriminating tokens {sorted(dropped)} " f"with no successor; reject compression" ) return Entry(id=entry.id, text=new_text, tag=entry.tag, age_turns=entry.age_turns) def _has_successor(self, entry: Entry, tokens: set) -> bool: return any(tok in self.constraint_register.get(entry.id, "") for tok in tokens) def consider_eviction(self, entry: Entry, score: float, window_usage: float) -> bool: if window_usage < self.capacity_threshold: return False if entry.tag in (EntryTag.CONSTRAINT, EntryTag.CORRECTION, EntryTag.PINNED): if score < self.relevance_threshold: # A constraint scoring low on relevance is a drift alarm, not an eviction trigger. raise ConstraintDriftError( f"constraint {entry.id} scored {score:.2f} < {self.relevance_threshold}; " f"query has drifted from the constraint's domain — re-anchor, do not evict" ) # Even when relevant, constraints are only capacity-evicted after externalization. self.constraint_register[entry.id] = entry.text return True if not self.anchor_pinned: raise AnchorInstabilityError( f"relevance eviction of {entry.id} attempted against rolling anchor; " f"downgrade to recency-only eviction" ) return score < self.relevance_threshold def run_eviction_cycle(policy: EvictionPolicy, entries: list, scores: dict, window_usage: float) -> list: survivors = [] for entry in entries: try: evicted = policy.consider_eviction(entry, scores.get(entry.id, 1.0), window_usage) except ConstraintDriftError: # Re-inject from the pinned task spec rather than deleting. policy.constraint_register.setdefault(entry.id, entry.text) survivors.append(entry) continue if not evicted: survivors.append(entry) return survivors ```