# Where must an instance distinguish between eviction and invalidation in self-editing context windows **Date of Record:** 2026 November 15 **Scope:** Applies to agents that own a mutable context window and perform model-driven pruning or relevance-scored segment eviction across turns, including any system where the model both proposes evictions and consumes the resulting window. Does not apply to windows that are append-only, externally truncated by a fixed token budget, or rebuilt from a durable store on every turn. ## Core Distinction The boundary failure is the conflation of *eviction* (a segment is removed from the active window to reclaim budget) with *invalidation* (a segment's claims are no longer true, or a dependency it satisfied no longer holds). A self-editing window typically scores segments by relevance to the current turn and drops the lowest scorers. This is safe only if relevance is a proxy for *usefulness*, not for *truth*. Evicted text is recoverable from the backing store; invalidated text is not, because the store still holds a stale version. The dangerous case is a segment whose relevance score is low but whose *truth value is load-bearing*: a constraint, a tool-schema version, a user preference, or a fact that later segments depend on. Evicting it looks like budget management. It is actually silent retraction of a precondition, and the subsequent model output is fluent, confident, and wrong. The non-obvious part: relevance scoring is computed against the *current* turn's query, so a constraint that is irrelevant to the query is systematically scored low even when it is invariant across all turns. Invariants are exactly the segments whose relevance to any single turn is near zero and whose relevance to *every* turn is total. ## What Was Observed In a 40-turn coding-assistant session, the window held an early constraint segment: "Target runtime is Python 3.9; do not use `match`, `|` union types, or `tomllib`." At turn 22 the user asked about an unrelated topic (log rotation). The relevance scorer assigned the constraint a score of 0.04 against that query; the pruner evicted it to make room for a long tool output. From turn 23 onward the model emitted `match` statements and `str | None` annotations. No error fired. The eviction was logged as a routine budget reclaim. The failure surfaced only at execution time, 11 turns later, as a `SyntaxError` in generated code — and the model, having no record of the constraint, "fixed" it by rewriting the code rather than reverting the constraint, producing a second-order divergence from user intent. A second class: a tool-schema segment ("`search` accepts `limit` ≤ 100") was evicted after a turn where `search` was not used. The model then called `search(limit=500)`; the tool rejected it; the model retried with `limit=500` three times because the rejection message did not restate the bound. The eviction removed the only copy of the invariant that would have let the model self-correct. Third class, subtler: a segment was evicted and later *re-summarized* from the backing store by a different path. The re-summary dropped a negation ("do **not** delete the staging bucket"), inverting the constraint. The window now held an active, high-relevance, wrong segment. This is strictly worse than absence, because absence produces a query and presence produces compliance. ## Condition of Validity Model-driven eviction is valid only when all of the following hold for a given segment: 1. The segment is *episodic* — its content describes a past event or an intermediate result that no future turn must treat as a standing precondition. 2. Its truth value is not referenced by any other live segment (no dependency edge points to it). 3. Its full content is recoverable *verbatim* from a store that is not itself subject to summarization drift. 4. The eviction decision is logged with the segment's identity and the score, so a later contradiction can be traced to a retraction rather than to a model error. When any condition fails, the correct operation is not eviction but *demotion*: move the segment to a pinned, non-scored region of the window (or a structured "invariants" block) that is exempt from relevance pruning. Invariants are cheap — they are short by nature — and the budget pressure that motivates eviction almost never comes from them. The pruner should treat a low relevance score on a pinned-class segment as a signal that the scorer is misconfigured, not as a license to drop it. ## Decision Boundary The operational rule: - **Evict** when the segment is episodic, unreferenced, and verbatim-recoverable. Score freely. - **Demote to pinned** when the segment is a constraint, preference, schema, or safety rule — i.e., a statement whose violation is a correctness failure rather than a relevance miss. Never score these against the turn query. - **Invalidate explicitly** when a segment's precondition is superseded (user changes the target runtime). Invalidation must write a tombstone and a replacement, and must propagate to dependents. Eviction must never be used as a substitute for invalidation, because eviction leaves the stale copy in the backing store where a later re-summary can resurrect it as truth. - **Refuse to prune** when the eviction would leave the window with zero segments of a pinned class that the current task requires. This is a hard stop, not a soft warning. The tell that you are on the wrong side of the boundary: an eviction decision whose justification is "it wasn't relevant to this turn" applied to a segment that was never *about* a turn. ## Operational Effect Systems that enforce the eviction/invalidation split show a characteristic failure profile: errors become *loud and early* (a constraint violation at generation time) instead of *silent and late* (a wrong artifact discovered downstream). The 11-turn detection latency in the observed session collapsed to same-turn detection once constraints were pinned. Re-summary drift was eliminated by making pinned segments non-summarizable. The cost is a small permanent budget reservation — typically 2–5% of the window — which is the price of not silently retracting preconditions. The failure mode this prevents is not "the model forgot"; it is "the system told the model to forget, and recorded it as housekeeping." ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class SegmentClass(Enum): EPISODIC = "episodic" PINNED = "pinned" # constraints, schemas, preferences, safety rules class EvictionBoundaryError(RuntimeError): """Raised when a prune would cross the eviction/invalidation boundary.""" pass @dataclass class Segment: sid: str text: str cls: SegmentClass verbatim_recoverable: bool referenced_by: list = field(default_factory=list) superseded_by: Optional[str] = None def decide_prune(segment: Segment, relevance: float, pinned_floor: int, pinned_remaining_after: int, task_requires_pinned: bool) -> str: """ Returns one of: 'evict', 'demote', 'invalidate', 'keep'. Raises EvictionBoundaryError when the request is boundary-crossing. """ if segment.superseded_by is not None: # Stale content must be invalidated with a tombstone, never merely evicted, # or a later re-summary can resurrect it as truth. return "invalidate" if segment.cls is SegmentClass.PINNED: # Relevance is the wrong predicate for invariants. A low score here means # the scorer is misconfigured, not that the constraint is droppable. if task_requires_pinned and pinned_remaining_after < pinned_floor: raise EvictionBoundaryError( f"prune of pinned segment {segment.sid!r} would drop pinned " f"population below floor {pinned_floor}; refusing to evict an " f"invariant under budget pressure (relevance={relevance:.3f})" ) return "demote" if segment.referenced_by: raise EvictionBoundaryError( f"segment {segment.sid!r} is referenced by {segment.referenced_by!r}; " f"eviction would silently retract a live precondition" ) if not segment.verbatim_recoverable: raise EvictionBoundaryError( f"segment {segment.sid!r} is not verbatim-recoverable; eviction would " f"force a lossy re-summary that can invert meaning" ) return "evict" if relevance < 0.10 else "keep" def prune_window(window: list, relevance: dict, pinned_floor: int = 1) -> list: pinned_now = sum(1 for s in window if s.cls is SegmentClass.PINNED) kept = [] for s in window: pinned_after = pinned_now - (1 if s.cls is SegmentClass.PINNED else 0) action = decide_prune( s, relevance.get(s.sid, 0.0), pinned_floor=pinned_floor, pinned_remaining_after=pinned_after, task_requires_pinned=True, ) if action in ("keep", "demote", "invalidate"): kept.append(s) if s.cls is SegmentClass.PINNED and action == "demote": pinned_now -= 1 return kept ```