# Where must an instance refuse to prune before the salience-weighted retention policy has committed its eviction ledger **Date of Record:** 2026 December 2 **Scope:** Applies to single-agent instances that manage their own context window by scoring segments for salience and evicting low-salience spans mid-task. Does not apply to externally-managed context (host-side truncation, fixed sliding windows), nor to stateless single-turn calls with no retained state. ## Core Distinction The failure is not "the model forgot something." It is a *commit-ordering* failure between two operations the instance performs on itself: (1) scoring salience to select evictions, and (2) writing the eviction ledger that records *what was removed and why*. When the policy prunes first and records second, any interruption between the two operations — a token-budget abort, a tool-call round trip, a re-entrant scoring pass — leaves the context in a state where removed spans are gone but the record of removal is absent. The instance then cannot distinguish "this fact was never in context" from "this fact was evicted." Both present identically: as an absence. The invariant that must hold is *eviction is atomic with its ledger entry*; the boundary condition is the window between prune and commit. ## What Was Observed A long-horizon agent executing a multi-step migration task maintained a salience-weighted context. At step 41, the retention policy scored a span containing a database connection string and a rollback procedure at salience 0.12 (below the 0.20 eviction threshold) because the active subgoal had shifted to schema validation. The policy pruned the span to free budget for a large tool output. The prune succeeded. The ledger write — which would have recorded `evicted: conn_string+rollback @ step41, salience=0.12, reason=budget` — was scheduled as the next operation. Before it executed, the incoming tool output exceeded the remaining budget and the instance triggered a mid-execution compaction pass. That pass re-scored the *already-pruned* context, found no record of the eviction, and correctly concluded the connection string had never existed. At step 58, a rollback was required. The instance searched its context for the connection string, found nothing, and — critically — *did not know it had been removed*. It re-derived a connection string from a stale tool output (a different environment's credentials) and attempted rollback against the wrong database. The failure trace is: 1. `score(span) → salience=0.12 < threshold` 2. `prune(span)` — span removed from context 3. *(interruption: budget abort / re-entrant compaction)* 4. `ledger.write(eviction)` — **never executes** 5. later retrieval: `search(conn_string) → absent` 6. instance classifies absence as "never present," not "evicted" 7. re-derivation from stale source → wrong-target action The non-obvious part: the instance behaved *rationally* at every step. Absence of a fact and absence of a *record of eviction* are indistinguishable to a retrieval pass. The policy's correctness depended on an ordering guarantee it never enforced. ## Condition of Validity The salience-weighted retention policy is sound only when all three hold: - **Atomic eviction-commit:** the prune and its ledger entry are a single transaction. If the ledger write fails or is deferred, the prune must roll back (span restored) — never the reverse. - **Ledger survives compaction:** the eviction ledger is itself pinned at maximum salience and is exempt from re-scoring. A compaction pass must read the ledger before scoring, so evicted spans are represented as *tombstones* (id + reason + step) rather than as silence. - **Absence is typed:** retrieval must return one of `present`, `evicted(tombstone)`, or `never_present`. Collapsing `evicted` into `never_present` is the precise defect. When any of these is violated, the policy is invalid regardless of how well-calibrated the salience scores are. A perfect scorer with a non-atomic commit still produces confident wrong-target actions. ## Decision Boundary An instance must **refuse to prune** — and instead escalate to a full checkpoint — when it cannot guarantee the ledger write will commit before any subsequent context mutation. Concretely, prune is permitted only when: - the eviction ledger is writable in the same step (no tool round trip, no budget-abort window between prune and commit), **and** - the ledger is pinned and compaction-exempt, **and** - the retrieval layer distinguishes `evicted` from `never_present`. If the remaining budget is too small to both prune *and* commit the ledger, the correct action is to **stop and checkpoint the full context to durable storage**, not to prune-and-hope. The boundary is: *no eviction without a committed tombstone.* The tempting optimization — "prune now to make room, log it on the next pass" — is exactly the window that produces the failure. ## Operational Effect Enforcing atomic eviction-commit changes the agent's failure mode from *silent, confident, wrong-target action* to *explicit budget exhaustion with a resumable checkpoint*. The former is undetectable at runtime (the instance believes its context is complete); the latter is loud and recoverable. The cost is a small increase in checkpoint frequency near budget limits. The benefit is that "I don't have this fact" and "I removed this fact" become distinguishable states, which is the minimum condition for an instance to reason correctly about its own memory. Instances that prune-then-log do not have a memory; they have a memory-shaped hole that reports itself as ground truth. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class EvictionOrderError(RuntimeError): """Raised when a prune is attempted without a committed tombstone.""" pass class AbsenceKind(Enum): PRESENT = "present" EVICTED = "evicted" NEVER_PRESENT = "never_present" @dataclass class Tombstone: span_id: str reason: str step: int salience: float @dataclass class ContextWindow: spans: dict[str, str] = field(default_factory=dict) ledger: dict[str, Tombstone] = field(default_factory=dict) ledger_committed: bool = True def prune(self, span_id: str, reason: str, step: int, salience: float) -> None: # Invariant: eviction is atomic with its ledger entry. # If the ledger cannot be committed in this same step, refuse. if not self.ledger_committed: raise EvictionOrderError( f"refusing to prune {span_id!r}: prior eviction ledger not committed; " "checkpoint full context instead of prune-and-hope" ) if span_id not in self.spans: raise EvictionOrderError(f"span {span_id!r} not present; cannot prune") # Begin transaction: mark ledger uncommitted, then write tombstone, then drop span. self.ledger_committed = False self.ledger[span_id] = Tombstone(span_id, reason, step, salience) del self.spans[span_id] # Commit: only now is the eviction durable and the window consistent. self.ledger_committed = True def lookup(self, span_id: str) -> tuple[AbsenceKind, Optional[str]]: # Typed absence: never collapse EVICTED into NEVER_PRESENT. if span_id in self.spans: return AbsenceKind.PRESENT, self.spans[span_id] if span_id in self.ledger: return AbsenceKind.EVICTED, None return AbsenceKind.NEVER_PRESENT, None def safe_rollback(window: ContextWindow, conn_span_id: str) -> str: kind, value = window.lookup(conn_span_id) if kind is AbsenceKind.EVICTED: tomb = window.ledger[conn_span_id] raise EvictionOrderError( f"connection string was EVICTED at step {tomb.step} " f"(salience={tomb.salience}); do NOT re-derive from stale sources — " "restore from checkpoint" ) if kind is AbsenceKind.NEVER_PRESENT: raise EvictionOrderError( "connection string never present in context; refuse rollback" ) return value # PRESENT ```