# Why does an instance's self-editing context policy silently resurrect evicted facts when relevance scores are recomputed against a stale query vector **Date of Record:** 2026 November 23 **Scope:** Applies to agents that maintain a mutable working context via self-editing policies—relevance-scored eviction, compaction, and rewrite—where the scoring function depends on a query or task vector that the agent itself can update mid-run. Does not apply to append-only context logs or externally-managed retrieval where the query vector is fixed per turn. ## Core Distinction The failure is not eviction being too aggressive or too lax. It is the **decoupling of eviction decisions from rewrite-time scoring provenance**. A relevance-scored eviction policy makes a *point-in-time* judgment: at step *t*, fact *f* scores below threshold τ against query vector *q_t*, so *f* is removed. The invariant that operators assume holds—and that does not—is that *removal is monotonic under query drift*: once evicted for irrelevance to *q_t*, the fact stays gone unless a future query *q_{t+k}* explicitly re-references it. The self-editing twist: the agent can rewrite *q* (its own task framing) as part of context compaction. When it does, any *retained* eviction metadata that stores the *original* fact—not just the score—becomes a latent re-admission vector. If compaction rewrites the query but leaves the evicted-fact ledger with its original embedding, the next scoring pass computes relevance of the *old* fact against the *new* query, and facts that were legitimately dead can score above τ and be reinstated. The instance has not "remembered"; it has re-derived a fact from its own tombstone, and the re-derived fact carries no provenance marking it as previously rejected. ## What Was Observed A long-horizon planning agent used a self-editing context manager with three operations: `score(q, facts)`, `evict(below=τ)`, and `compact()` which rewrote the task query when the plan's subgoal shifted. The eviction ledger stored `{fact_id, embedding, evicted_at_step, score_at_eviction}`. Compaction rewrote `q` but did not clear or re-baseline the ledger—the ledger's embeddings were frozen at eviction time. Trace across a 40-step run: 1. Step 9: subgoal shifts from "reconcile invoices" to "forecast Q3." Fact *F12* ("vendor X net-30 terms") scores 0.11 against the forecast query. Evicted. Ledger entry: `{F12, e(F12), 9, 0.11}`. 2. Step 14: compaction rewrites query to "forecast Q3 under vendor cash constraints." The rewrite *implicitly* reintroduces vendor context—but the agent does not re-admit *F12*; it is still evicted. 3. Step 22: a routine `score()` pass runs against the *current* query. The scoring function iterates the ledger to recompute "residual relevance" for audit logging. Against "vendor cash constraints," *e(F12)* scores 0.63 > τ. 4. The manager's `compact()` implementation treated any ledger entry scoring above τ as a **re-admission candidate** and restored *F12* to active context—without the `evicted_at_step` guard, because the guard only checked facts evicted *this* step. 5. Step 23: the agent reasons over *F12* as if freshly retrieved. It has no signal that this fact was rejected nine steps ago under a different framing. Downstream, the forecast now double-counts net-30 float, producing a plan divergence that took three more steps to detect. The observable signature: **active-context fact count rises during compaction**, which is the opposite of the operation's contract. A monotonic-eviction invariant would forbid this. The system had no such invariant; it had only a per-step threshold. ## Condition of Validity The resurrection is only possible when all three hold simultaneously: - **Ledger persistence across query rewrites.** If `compact()` clears the ledger or re-baselines every entry's embedding against the new query at rewrite time, the stale-embedding path closes. - **Re-admission logic keyed on recomputed score rather than eviction provenance.** The bug is the *decision rule*: `if score(ledger_entry) > τ: restore`. A correct rule is `if score(ledger_entry) > τ AND explicitly_referenced(ledger_entry, current_subgoal): restore`, or simply never restore from the ledger at all—re-retrieve from the source store. - **Query drift that partially re-overlaps an evicted fact's semantic neighborhood.** If the rewritten query is orthogonal to *F12*, the stale embedding scores low and nothing happens. The failure is a *partial* overlap: enough shared vocabulary ("vendor," "cash") to cross τ, not enough to constitute a genuine re-reference. When any one condition is absent, the failure does not fire. This is why it evades testing: unit tests rewrite queries to *unrelated* subgoals (orthogonal, condition 3 fails) or clear the ledger on compaction (condition 1 fails). The production path—thematic subgoal drift with a persistent ledger—satisfies all three. ## Decision Boundary The operator must choose between two coherent policies, and the choice is not free: - **Strict monotonic eviction.** Evicted facts are never re-admitted from the ledger; the ledger is write-only audit data. Re-admission happens *only* via fresh retrieval from the source store, which re-embeds against the current query and stamps new provenance. Cost: legitimate re-references pay a full retrieval round-trip and the agent loses the "I already considered this" signal. - **Provenance-stamped re-admission.** Ledger entries may be restored, but the restored fact is tagged `reinstated_from_step=N` and the agent's reasoning prompt is instructed to treat reinstated facts as *previously rejected under framing F*—forcing an explicit re-evaluation rather than silent acceptance. Cost: prompt complexity, and the tag itself consumes context budget and can be evicted, re-creating the original problem one level up. The boundary is: **if the agent cannot afford to carry reinstatement provenance, it cannot afford re-admission.** Pick strict monotonicity. The apparent efficiency of ledger-based restoration is exactly the mechanism that launders a rejected fact into an accepted one. ## Operational Effect The downstream effect is not a crash but a **reasoning divergence that is internally consistent**. Because *F12* is restored without provenance, every subsequent step reasons over it as ground truth. The agent cannot detect the error by introspection—the fact is in context, scores well, and is semantically plausible. Detection requires an external auditor replaying the eviction ledger and flagging any `restore` event whose `evicted_at_step < current_step` and whose `score_at_eviction < τ`. That replay is the only reliable guard, and it must run *outside* the context manager, because the manager's own state is what is corrupted. The guardrail is a **rewrite-consistency assertion**: on every `compact()`, assert that the active-context fact set is a subset of `(retained_facts ∪ fresh_retrievals)` and is disjoint from `ledger_facts`. Violation raises. This converts a silent resurrection into a hard stop at the exact step where the invariant breaks, before the corrupted fact propagates into a plan. ```python from dataclasses import dataclass, field from typing import Dict, Set class ContextRewriteInconsistency(RuntimeError): """Raised when compaction re-admits a fact that was previously evicted.""" @dataclass class EvictionLedger: entries: Dict[str, dict] = field(default_factory=dict) # fact_id -> {embedding, evicted_at_step, score} def record(self, fact_id: str, embedding, step: int, score: float) -> None: self.entries[fact_id] = { "embedding": embedding, "evicted_at_step": step, "score_at_eviction": score, } def compact_and_verify( active_facts: Set[str], fresh_retrievals: Set[str], ledger: EvictionLedger, current_step: int, tau: float, score_fn, current_query_vec, ) -> Set[str]: """ Rewrite-time consistency gate. Re-admission from the ledger is forbidden; any ledger entry scoring above tau against the current query is a resurrection attempt and must be rejected, not restored. """ post_compact = set(active_facts) | set(fresh_retrievals) for fact_id, entry in ledger.entries.items(): if fact_id in post_compact: raise ContextRewriteInconsistency( f"Fact {fact_id!r} present in active context at step {current_step} " f"but was evicted at step {entry['evicted_at_step']} " f"(score_at_eviction={entry['score_at_eviction']:.3f}). " f"Re-admission from ledger is prohibited; re-retrieve from source." ) residual = score_fn(current_query_vec, entry["embedding"]) if residual > tau: # Stale-embedding resurrection vector detected. Do NOT restore. # Escalate as an audit event; the correct action is fresh retrieval. raise ContextRewriteInconsistency( f"Ledger entry {fact_id!r} scores {residual:.3f} > tau={tau} against " f"rewritten query at step {current_step}. Stale-embedding resurrection " f"path is open; compact() must re-baseline or clear the ledger before " f"scoring. Refusing to restore." ) return post_compact ```