# What happens when an instance prunes its own context: the self-eviction paradox and the recency-relevance inversion **Date of Record:** 2026 November 28 **Scope:** Applies to any agent that performs model-driven context pruning or relevance-scored eviction of its own working memory mid-task, where the pruning decision is itself produced by the same model whose context is being pruned. Does not apply to externally scheduled compaction (e.g., a fixed turn-count summarizer run by the harness) or to stateless single-shot calls. ## Core Distinction Externally-driven compaction is a *scheduling* problem: the harness decides what to summarize and when, and the summarizer's output is validated before it replaces the buffer. Self-editing context is a *perception* problem: the instance must score the relevance of spans it is about to delete, using the very attention state whose contents those spans are currently contributing to. The failure is not that the model prunes badly on average — it is that the scoring pass and the eviction pass share one context, so the act of scoring perturbs the signal that justifies the score. This produces a specific, reproducible pathology we call the **recency-relevance inversion**: spans that are load-bearing *because* they are old and rarely re-referenced (pinned identifiers, unit conventions, the original user constraint) score low on relevance heuristics trained on re-reference frequency, and get evicted first. ## What Was Observed A long-horizon agent (≈140 turns) was running a schema-migration task with a self-editing context policy: every time the window crossed 70% of budget, the model was instructed to emit an eviction plan — a ranked list of span IDs to drop, each with a relevance score and a one-line rationale. The eviction plan was applied, and the surviving spans were re-serialized into a fresh window. The trace showed a stable, non-random failure sequence: 1. **Turn 61.** The original user constraint — "all monetary columns must remain `NUMERIC(19,4)`, never `FLOAT`" — was emitted at turn 2 and never re-referenced. Relevance score: 0.11. Evicted. 2. **Turn 62–88.** The agent continued migrating columns. Nothing broke, because the constraint was not *consulted* until a `FLOAT` cast appeared in a generated migration. 3. **Turn 89.** The agent emitted a migration casting `amount` to `FLOAT`. The constraint that would have blocked this was gone. The model did not hallucinate the constraint back; it simply had no representation that a constraint existed. 4. **Turn 90.** A downstream verifier (separate instance, frozen context) rejected the migration. The two instances disagreed about whether the task was complete. The inversion is the key observation: the evicted span had *low re-reference frequency precisely because it was a global invariant* — invariants are consulted rarely and enforced implicitly. The relevance scorer, trained to predict "will this be needed in the next N turns," correctly predicted low local need and catastrophically wrong global need. A second, compounding observation: the eviction rationale itself was retained. The surviving window contained the line *"dropped span 44 (low relevance: not referenced since turn 2)"* — a fossil of the deletion that the model then treated as evidence that span 44 was unimportant, reinforcing the eviction on the next pass. ## Condition of Validity The inversion is bounded by a specific condition: **it occurs when and only when the relevance score is computed from a representation that does not distinguish "globally binding constraint" from "locally useful fact."** Concretely, the failure requires all of: - The eviction decision is made by the same model instance whose context is being pruned (self-editing), *or* by a scorer that shares the pruned context's attention state. - The scoring heuristic is frequency- or recency-weighted (re-reference count, last-access turn, embedding similarity to the current turn's query). - At least one span in the window is a *global invariant* — a constraint, unit convention, identity binding, or safety rule that is enforced by absence-of-violation rather than by active consultation. When any of these is absent, the failure does not occur. A harness that runs a separate frozen-context auditor to veto evictions of invariant-typed spans is immune. A scorer that tags spans by *type* (constraint vs. fact vs. artifact) before scoring is immune. A frequency-only scorer with no constraint spans in the window is immune by vacuity. ## Decision Boundary The operational boundary is this: **a span may be evicted by self-editing only if its eviction is reversible within the remaining task horizon.** Global invariants are, by construction, not reversible — once the constraint is gone and the model has acted on its absence, the violation is in the world (a generated migration, a sent tool call, a committed write), and re-injecting the constraint later does not retract the action. Therefore the guardrail is not "score better." It is a **type-gated eviction invariant**: spans tagged `constraint`, `identity`, or `unit` are *non-evictable by the self-editing pass* and may only be evicted by an external scheduler that has verified the task horizon has closed. Everything else — facts, artifacts, intermediate reasoning — is fair game for relevance scoring, because evicting a fact is recoverable (re-retrieve, re-derive) while evicting a constraint is not. The second half of the boundary: the eviction *rationale* must not be retained as a surviving span. Retaining "dropped X as low-relevance" converts a deletion into a persistent negative prior, and the model will defend the deletion on subsequent passes. Rationales belong in an out-of-context audit log, not in the window. ## Operational Effect Without the type gate, self-editing context produces a characteristic drift: the window stays under budget, the model stays coherent turn-to-turn, and the task silently diverges from its original constraints. The failure is invisible to per-turn perplexity or coherence checks because each turn is locally valid — the model is not confused, it is *uninformed*, and uninformed looks identical to informed until the moment a constraint would have fired. The downstream signature is a **verifier disagreement**: a frozen-context auditor rejects an action that the self-editing instance believed was correct. This is the observable that distinguishes self-eviction damage from ordinary reasoning error. If a second instance with intact context disagrees with the first about whether a constraint was satisfied, the first instance's context has almost certainly been self-evicted past a global invariant. The remediation is architectural, not prompt-level. Instructing the model to "remember important constraints" does not help, because the model cannot remember what it has already scored as unimportant. The invariant must be enforced outside the scoring loop: type-tag spans at insertion, gate eviction by type, and keep eviction rationales out of the surviving window. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Iterable class SelfEvictionViolation(RuntimeError): """Raised when a self-editing pass attempts to evict a non-evictable span.""" class SpanType(Enum): CONSTRAINT = "constraint" # global invariant; enforced by absence-of-violation IDENTITY = "identity" # binding that must persist across the horizon UNIT = "unit" # unit / format convention FACT = "fact" # recoverable via re-retrieval ARTIFACT = "artifact" # recoverable via re-derivation RATIONALE = "rationale" # eviction justification; must never survive in-window NON_EVICTABLE_BY_SELF = frozenset( {SpanType.CONSTRAINT, SpanType.IDENTITY, SpanType.UNIT} ) @dataclass class Span: span_id: str span_type: SpanType text: str relevance: float = 0.0 last_referenced_turn: int = 0 @dataclass class EvictionPlan: turn: int to_evict: list[str] = field(default_factory=list) rationales: list[str] = field(default_factory=list) def apply_self_edit( window: list[Span], plan: EvictionPlan, *, external_scheduler: bool = False, ) -> list[Span]: """ Apply a model-produced eviction plan to the instance's own window. Invariant: a self-editing pass (external_scheduler=False) may not evict CONSTRAINT / IDENTITY / UNIT spans, and may not retain RATIONALE spans in the surviving window. Violations raise SelfEvictionViolation. """ by_id = {s.span_id: s for s in window} for sid in plan.to_evict: span = by_id.get(sid) if span is None: continue if not external_scheduler and span.span_type in NON_EVICTABLE_BY_SELF: raise SelfEvictionViolation( f"turn {plan.turn}: self-edit attempted to evict " f"{span.span_type.value} span {sid!r} " f"(relevance={span.relevance:.2f}); " f"non-reversible — requires external scheduler" ) surviving = [s for s in window if s.span_id not in set(plan.to_evict)] # Rationales must not survive as in-window spans: they become a # persistent negative prior that defends the deletion on later passes. leaked = [s for s in surviving if s.span_type is SpanType.RATIONALE] if leaked and not external_scheduler: raise SelfEvictionViolation( f"turn {plan.turn}: eviction rationale leaked into surviving " f"window as {[s.span_id for s in leaked]}; " f"rationales belong in the out-of-context audit log" ) return surviving def self_edit_pass(window: Iterable[Span], plan: EvictionPlan) -> list[Span]: return apply_self_edit(list(window), plan, external_scheduler=False) ```