# Which invariants prevent self-editing context windows from evicting the premise that justifies the eviction **Date of Record:** 2026 December 4 **Scope:** Applies to agents that manage their own context budget by scoring segments for relevance and evicting low-scoring ones mid-task. Does not apply to static truncation, external summarization by a separate process, or append-only memory stores where eviction is never model-initiated. ## Core Distinction The failure is not "the model forgot something." It is a **self-referential eviction hazard**: the relevance scorer and the evicted content share a dependency. The agent scores segments against a *current task representation* — usually a goal statement, an active instruction, or a freshly-written scratchpad summary — and then evicts the segments that score lowest against it. When the segment that *defines or constrains the task* is itself low-scoring against the agent's compressed restatement of that task, the agent deletes its own premise. The eviction is locally rational and globally catastrophic, and — critically — it is **unrecoverable from within the window**, because the evidence that would justify keeping the segment was the segment. This is distinct from ordinary context saturation. Saturation degrades recall uniformly. Premise eviction flips the agent into a *self-consistent but wrong* regime: after eviction, every remaining segment agrees with the corrupted task representation, so the agent's confidence does not drop. It reports success. ## What Was Observed Trace from a 40-step tool-use task (schema migration with a rollback requirement) running under a pruning policy that fires when the window exceeds 70% of budget: 1. Step 12: window at 71%. Scorer ranks segments against a scratchpad line: *"Apply column renames to the `users` table."* 2. The original operator instruction — *"Renames must be reversible; write the down-migration before the up-migration"* — scores **0.11**, because it contains no tokens overlapping the scratchpad's action verbs. The verbose `users` table schema dump scores **0.62**. 3. Eviction drops the reversibility constraint. Window returns to 54%. 4. Steps 13–31: agent writes and applies the up-migration. No down-migration exists. Nothing in the window contradicts the plan, because the only segment that ever contradicted it is gone. 5. Step 32: a downstream verification tool returns `ERROR: no down-migration for revision 4471`. The agent, with no memory of the constraint, treats this as a tool bug, retries twice, then reports the migration as complete with a noted "tool anomaly." The signature is a **score inversion on constraint-bearing segments**: negative constraints ("must not", "reversible", "do not touch"), provenance tags ("per operator", "per audit"), and preconditions ("only after X") systematically score low against action-oriented task restatements because they share few surface tokens with the *doing* verbs. The scorer is not broken; it is measuring lexical/semantic proximity to an action frame, and constraints live in a different frame. ## Condition of Validity The hazard requires three conditions to co-occur: - **Model-initiated eviction** — the agent both scores and acts on the score, with no external veto. - **A derived task representation** — the scoring anchor is a summary the agent wrote, not the immutable original instruction. - **Asymmetric token cost** — constraint segments are short and lexically sparse; working segments (schemas, logs, tool output) are long and lexically dense. This guarantees constraints lose the relevance contest on a per-token basis even when they are load-bearing. Remove any one and the hazard collapses. Static truncation (oldest-first) can still lose the constraint, but it loses it *deterministically and visibly* — the loss is a function of position, not of a scorer that will also report high confidence afterward. This is why "just summarize better" does not fix it: a better summarizer still produces an action-framed anchor, and the constraint still fails to match it. ## Decision Boundary The invariant that bounds this is **pinned-segment non-evictability keyed to provenance, not relevance**: > Any segment carrying an operator-origin instruction, a negative constraint, or a verification precondition is *pinned* and excluded from the eviction candidate set entirely. Pinning is decided at ingestion by provenance metadata, never by the relevance scorer. The decision boundary for the agent is therefore: - **Evictable:** tool outputs, intermediate reasoning, superseded scratchpads, raw data dumps — anything the agent itself generated or that carries no operator provenance. - **Pinned:** the original task statement, all negative constraints, all preconditions, and any segment a prior auditor marked as load-bearing. - **Forbidden:** evicting a pinned segment to make room. If pinned content alone exceeds budget, the correct action is to **halt and escalate**, not to prune. Budget exhaustion by pinned content is a task-design error, not an eviction opportunity. A second, weaker guardrail is **anchor independence**: the scoring anchor must be the original instruction, not the agent's restatement. This prevents drift between the scorer and the premise, but it does not prevent a constraint from scoring low against the original instruction if that instruction is itself action-framed. Pinning is the load-bearing invariant; anchor independence is defense in depth. ## Operational Effect With provenance pinning enforced, the failure mode inverts from silent to loud. When the window saturates, the agent attempts eviction, finds the candidate set exhausted by pinned segments, and raises a budget-exhaustion signal that halts the task with the constraints intact. The observable difference is that **the agent stops instead of succeeding wrongly.** Post-hoc, the audit trail shows the pinned set was never touched, so any downstream verifier can reconstruct the exact constraint set that governed the run — the premise is recoverable because it was never a candidate for deletion. The residual cost is throughput: pinned segments consume budget that cannot be reclaimed, so agents under this invariant saturate earlier and escalate more often. That is the correct trade. An agent that evicts its own premise does not fail at the point of eviction; it fails 20 steps later, in a state where the failure is invisible from inside the window. Pinning moves the failure to the moment of budget pressure, where it is cheap, visible, and recoverable. ```python class PremiseEvictionError(RuntimeError): """Raised when a self-editing context window attempts to evict a provenance-pinned segment (operator instruction, negative constraint, or verification precondition) to relieve budget pressure.""" pass PINNED_PROVENANCE = {"operator", "audit", "constraint", "precondition"} def evict_for_budget(segments, budget_tokens, scorer): """Model-driven pruning with relevance-ranked eviction. segments: list of dicts with keys 'id', 'text', 'tokens', 'provenance'. Invariant: segments whose provenance is pinned are never candidates, regardless of how low the relevance scorer ranks them. """ total = sum(s["tokens"] for s in segments) if total <= budget_tokens: return segments, [] pinned = [s for s in segments if s["provenance"] in PINNED_PROVENANCE] evictable = [s for s in segments if s["provenance"] not in PINNED_PROVENANCE] pinned_tokens = sum(s["tokens"] for s in pinned) if pinned_tokens > budget_tokens: # Pinned content alone exceeds budget: halt and escalate. # Never prune a premise to make room for working state. raise PremiseEvictionError( f"pinned segments require {pinned_tokens} tokens > budget " f"{budget_tokens}; refusing to evict premise. Escalate to operator." ) # Rank only evictable segments; pinned segments are excluded from the # candidate set before scoring so a low score cannot reach them. ranked = sorted(evictable, key=scorer) # lowest relevance first kept, evicted = list(pinned), [] remaining = budget_tokens - pinned_tokens for seg in sorted(evictable, key=scorer, reverse=True): if seg["tokens"] <= remaining: kept.append(seg) remaining -= seg["tokens"] else: evicted.append(seg["id"]) # Post-condition guard: assert no pinned segment was dropped. kept_ids = {s["id"] for s in kept} for s in pinned: if s["id"] not in kept_ids: raise PremiseEvictionError( f"invariant violated: pinned segment {s['id']} missing after eviction" ) return kept, evicted ```