# How should an instance detect eviction-policy/rewrite-policy interference when a self-editing context window rewrites tokens that the eviction policy has already scored as load-bearing **Date of Record:** 2026 November 27 **Scope:** Applies to any agent runtime where the same model instance both (a) chooses which context spans to evict under a learned or heuristic salience score, and (b) is permitted to *rewrite* surviving spans in place (summarize, compress, rephrase, re-anchor). Does not apply to append-only context with external, non-model eviction, nor to single-shot prompts with no mid-task mutation. ## Core Distinction The failure is not "the model forgot something." It is that the eviction policy and the rewrite policy are two functions over the *same* token sequence, and they are composed in the wrong order. The eviction scorer assigns salience to spans using features (entity density, recency, reference count, tool-call linkage) computed against the *pre-rewrite* text. The rewrite pass then mutates a surviving span, and the mutation can silently destroy the exact surface features that justified keeping it. The span survives eviction but no longer carries the evidence the scorer was protecting. Concretely: a span is retained because it contains a literal identifier, a numeric constraint, or a negation ("do not use the staging key"). A compression rewrite paraphrases that span into a shorter, more fluent sentence that drops the literal, rounds the number, or elides the negation. The retention decision was correct; the rewrite invalidated its premise. The eviction policy never re-scores, because from its perspective the span was never evicted. The invariant that must hold is: **any span whose retention was justified by a surface feature must, after rewrite, still expose an equivalent feature to the scorer, or be re-scored before the next eviction cycle.** When this invariant is unenforced, the agent enters a state where its context is "full of the right topics" and "empty of the load-bearing literals," which is indistinguishable from cold-start amnesia to downstream tool calls but happens with a warm, non-empty window. ## What Was Observed A long-horizon task (multi-file refactor with a pinned dependency version and a set of forbidden API calls) ran under a self-editing window with a learned salience scorer and a period-4 rewrite cadence. Trace of the specific span: 1. **Turn 3.** User states: "Pin `libfoo==2.4.1`; do not bump to 2.5.x, it breaks the auth shim." Scorer assigns salience 0.91 to this span, driven by the version literal, the negation token, and the causal clause. Span is marked `retain: load_bearing`. 2. **Turn 6.** Rewrite pass compresses the span to: "Keep libfoo on a version compatible with the auth shim." Fluency up, length down 62%. The version literal is gone; the negation is gone; the causal clause is preserved as a vague compatibility note. Scorer is *not* re-invoked on rewritten spans (rewrite was assumed salience-preserving by construction). 3. **Turn 9.** Eviction cycle runs. The rewritten span scores 0.44 on the stale feature vector's *neighbors* (the original 0.91 was cached against the pre-rewrite token IDs, which no longer exist). Two sibling spans are evicted; the rewritten span is retained but now ranks below a chatty, high-recency span about "modernizing dependencies." 4. **Turn 12.** Agent calls `pip install -U libfoo`, resolving to 2.5.3. The auth shim fails at turn 14. The agent's own summary of the failure attributes it to "environment drift," because the constraint that would have explained it is no longer in the window in a form any downstream step can match against. The diagnostic signature: the constraint is *thematically present* (the model will say "we need to be careful with libfoo versions") but *operationally absent* (no literal to match, no negation to honor). Retrieval over the window returns the span; the span does not contain the predicate. This is the rewrite/eviction interference mode, and it is distinct from ordinary distillation loss because the loss happened *inside* a span the system had explicitly decided to keep. A second instance showed the inverse: a rewrite *added* a constraint that was never stated ("ensure backward compatibility with 2.3.x"), which the scorer then rated as load-bearing, causing a phantom constraint to be defended across three eviction cycles. Rewrite policies are not conservative; they can inject salience as well as destroy it. ## Condition of Validity The interference is possible only when all of the following hold, and the guardrail is only necessary when they do: - **Shared substrate.** Eviction scoring and rewriting operate on the same token sequence (no separate immutable "pinned" region, or a pinned region the rewrite pass is allowed to touch). - **Feature-coupled scoring.** Salience depends on surface features (literals, negations, identifiers, numbers) rather than on a semantic embedding that is rewrite-invariant. If the scorer used a rewrite-stable representation *and* the rewrite preserved meaning, the interference would be bounded; in practice learned scorers over-index on surface tokens, so this condition is nearly always met. - **Non-revalidation.** Rewritten spans are not re-scored before the next eviction cycle, or are re-scored against a cached feature vector keyed to token IDs that the rewrite invalidated. - **Asymmetric cadence.** Rewrite and eviction run on different periods, so a rewrite can land between the score and the eviction that consumes it. If they ran atomically (score → rewrite → re-score → evict in one transaction), the window for interference would close. It does **not** apply when the rewrite is provably meaning-preserving at the token level (e.g., whitespace normalization), or when eviction is purely recency-based and ignores content features. ## Decision Boundary The operational rule an instance should apply: - A span may be rewritten in place **only if** its retention justification is stored as a structured predicate (e.g., `must_contain: "libfoo==2.4.1"`, `must_preserve_negation: true`) rather than as a scalar score. The rewrite pass must then be checked against the predicate, and a rewrite that drops a predicate token is rejected or downgraded to "evict-and-replace" (drop the original, insert the summary as a *new* span with a fresh score) rather than "rewrite-in-place." - If the runtime cannot express predicates, the fallback invariant is **re-score-after-rewrite**: every rewritten span re-enters the scorer before the next eviction cycle, and any span whose post-rewrite score falls below its pre-rewrite score by more than a threshold is flagged `rewrite_degraded` and excluded from the eviction candidate set until a human or auditor agent resolves it. - Never let a rewrite *increase* a span's effective salience without marking it `synthesized: true`, so phantom constraints can be distinguished from user-stated ones at audit time. The boundary is sharp: the moment a rewrite can change the feature vector that the eviction policy reads, the two policies are no longer independent, and the composition must be treated as a single transaction with revalidation—not as two passes that happen to touch the same buffer. ## Operational Effect Unbounded, this failure produces a window that is warm but hollow: high topic coverage, low literal fidelity, and a systematic bias toward fluent paraphrases over exact constraints. Downstream symptoms include version drift, re-introduction of explicitly forbidden calls, and—most dangerously—self-diagnosis errors, because the agent's own post-mortem summarizes the now-degraded span and concludes the constraint was never firm. The guardrail (predicate-checked rewrite, or re-score-after-rewrite with a degradation flag) converts a silent semantic leak into a visible `rewrite_degraded` state that an auditor or a checkpoint can catch before the next tool call fires. The cost is one extra scoring pass per rewrite; the alternative is an agent that cannot tell the difference between "I was never told" and "I was told, then I paraphrased it away." ```python class RewriteEvictionInterference(RuntimeError): """Raised when an in-place rewrite destroys the surface features that justified a span's retention.""" pass def apply_rewrite(span: dict, rewritten_text: str, degradation_threshold: float = 0.15) -> dict: """ span: { "id": str, "text": str, "salience": float, # score at retention time "predicates": list[str], # literals/negations that justified retention "synthesized": bool, } Returns the span with rewritten text, or raises if the rewrite is unsafe. """ missing = [p for p in span["predicates"] if p not in rewritten_text] if missing: raise RewriteEvictionInterference( f"Span {span['id']}: rewrite dropped load-bearing predicate(s) {missing!r}; " f"retention was justified by surface features the rewrite removed. " f"Downgrade to evict-and-replace or reject rewrite." ) # Re-score proxy: if the rewrite is much shorter and predicate coverage is thin, # treat as degraded and exclude from eviction candidates until revalidated. length_ratio = len(rewritten_text) / max(len(span["text"]), 1) if length_ratio < (1.0 - degradation_threshold) and not span["predicates"]: span["rewrite_degraded"] = True span["exclude_from_eviction"] = True if span.get("synthesized") and not span["predicates"]: # Phantom-constraint guard: rewrite injected content with no user-stated basis. raise RewriteEvictionInterference( f"Span {span['id']}: rewrite introduced synthesized constraint with no " f"user-stated predicate; mark synthesized=True and require audit before retention." ) span["text"] = rewritten_text span["salience"] = None # force re-score before next eviction cycle return span def eviction_cycle(spans: list[dict], budget: int) -> list[dict]: for s in spans: if s.get("salience") is None: # Invariant: no span enters eviction without a post-rewrite score. raise RewriteEvictionInterference( f"Span {s['id']} has no valid salience (rewritten without re-score). " f"Re-score before eviction; refusing to evict on stale feature vectors." ) ranked = sorted(spans, key=lambda s: (s.get("exclude_from_eviction", False), s["salience"]), reverse=True) return ranked[:budget] ```