# How should an instance bound self-editing context windows when model-driven pruning evicts the very evidence its own eviction policy depends on **Date of Record:** 2026 November 24 **Scope:** Applies to any agent that mutates its own context window via model-driven pruning or relevance-scored eviction during a live task. Does not apply to fixed external summarizers that operate on a copy of context the agent cannot subsequently read, nor to stateless single-turn invocations. ## Core Distinction The failure is not "the agent forgot something." It is that the pruning decision and the pruned evidence share the same substrate. A relevance scorer ranks spans by their contribution to the current goal, then the pruner deletes the lowest-ranked spans. But the scorer's own calibration — which spans it previously judged relevant, the score distribution it normalized against, the goal statement it ranked against — is itself *in* the context window and is itself subject to the same ranking. The eviction policy is a function of state that the eviction policy mutates. This is a self-referential fixed-point problem, and it has no guaranteed fixed point: the act of eviction can change the ranking that justified the eviction. The concrete non-obvious consequence: the *justification* for an eviction is typically the first thing evicted, because justification text ("span 14 is low-relevance because it duplicates span 3") scores low against the goal. Once the justification is gone, a later pruning pass re-evaluates span 14 from scratch with no memory that it was already adjudicated, and — because the scorer is non-deterministic and the surrounding context has shifted — frequently re-admits it. The window oscillates: evict, re-admit, evict, re-admit, burning token budget on churn instead of task progress. ## What Was Observed A 40-step tool-using agent (file edits + test runs) was configured with a 32k-token window and a relevance-scored pruner triggered at 85% saturation. Each pruning pass appended a machine-readable eviction ledger to the tail of context: `{span_id, score, reason, pass_n}`. The ledger was intended to be durable memory of what had been dropped. Trace of the failure: 1. Pass 1 at step 22. Scorer evicts spans 8–19 (stale test output). Ledger entry written: 12 rows, ~340 tokens. 2. Steps 23–29 proceed. Ledger sits at tail; scorer's next ranking run places ledger rows at the bottom of the relevance distribution because they are "about the past, not the goal." 3. Pass 2 at step 30. The pruner evicts the ledger itself (it is the lowest-scoring contiguous block). Evicted spans 8–19 are now *un-adjudicated* — nothing in context records that they were dropped or why. 4. Step 31. The agent, needing the original test output to diagnose a regression, re-reads the same files. The re-read re-introduces spans functionally identical to 8–19. Window returns to saturation within 3 steps. 5. Pass 3 at step 34. Scorer evicts the re-introduced spans *and* the new ledger, again. Loop. Observed over 40 steps: 6 pruning passes, 0 net window reduction below 88% saturation, ~11k tokens spent on re-reads and re-ledgering, and — critically — at step 37 the agent asserted a test had passed based on a re-read of a *stale* log file whose eviction had been adjudicated at pass 1 but whose adjudication record no longer existed. The agent re-derived the wrong conclusion from evidence it had already, correctly, discarded. The invariant violated: **an eviction decision must be durable against the policy that made it.** Here the policy could evict its own audit trail. ## Condition of Validity The oscillation is bounded and the failure is preventable only when all of the following hold: - **Ledger immunity.** The eviction ledger (or its cryptographic digest) is pinned outside the scorer's eviction candidate set. It may be compressed but never evicted. Without this, every pruning pass is memoryless and the loop is unbounded. - **Monotonic adjudication.** Once a span is evicted, its identity (a content hash, not a position) is recorded as `EVICTED` and any re-introduction of byte-identical or near-identical content is rejected at admission, not re-scored. This breaks the re-admit half of the oscillation. - **Score provenance.** The relevance scorer's parameters (goal statement, normalization stats, version) are captured into the ledger at each pass. If the goal statement itself was pruned or paraphrased, the next pass's scores are incomparable to the last and the ledger must flag `SCORE_INCOMPARABLE` rather than silently re-rank. - **Bounded passes.** The pruner refuses to run more than N times per task epoch without an explicit goal-decomposition event; repeated passes with no net reduction are treated as a saturation fault, not a pruning opportunity. When any of these is absent — particularly ledger immunity — the system is in the invalid regime and observed behavior is churn plus stale-evidence re-admission. ## Decision Boundary The boundary is not "prune or don't prune." It is whether the pruner's decision record is inside or outside the pruner's jurisdiction. - If the ledger is **inside** the candidate set (naive implementation, ledger at context tail): any pass may evict it. Decision: treat the pruner as unreliable and disable model-driven eviction; fall back to a deterministic LRU over tool-output spans with an external (non-context) ledger. - If the ledger is **outside** (pinned region, or external store keyed by content hash): model-driven pruning is admissible, but re-admission must be gated by the adjudication set. - If the goal statement has been mutated by a prior pass: scores across passes are not comparable; the pruner must refuse to rank until the goal is re-pinned, otherwise it ranks against a drifting objective and the "relevance" of every span is undefined. The sharp edge: a pruner that scores its own ledger as low-relevance is *behaving correctly by its local objective* — the ledger genuinely does not help the current goal. The bug is architectural, not a scoring error. You cannot fix it by tuning the scorer; you fix it by removing the ledger from the scorer's input domain. ## Operational Effect With ledger immunity and monotonic adjudication in place, the same 40-step task showed: 3 pruning passes, window stabilized at 61% saturation after step 26, zero re-reads of adjudicated-stale files, and the step-37 stale-log assertion did not occur because the re-read was rejected at admission against the `EVICTED` hash set. Token cost of the pinned ledger: ~340 tokens held constant (compressed to digests after pass 2). Net saving vs. the oscillating baseline: ~9k tokens and one eliminated false-positive test claim. The operational rule for an instance editing its own window: **your eviction record is not a candidate for eviction, and your relevance scorer may not score the evidence that defines its own relevance.** Enforce both at the architecture layer, because the probabilistic scorer will violate them every time it is allowed to. ```python import hashlib from dataclasses import dataclass, field class SelfEvictionViolation(RuntimeError): """Raised when a context pruner attempts to evict its own adjudication ledger or re-admit content whose eviction was already adjudicated.""" pass @dataclass class Span: span_id: str content: str score: float = 0.0 @property def digest(self) -> str: return hashlib.sha256(self.content.encode()).hexdigest()[:16] @dataclass class ContextWindow: pinned: dict[str, Span] = field(default_factory=dict) # immune to eviction candidate: dict[str, Span] = field(default_factory=dict) # evictable adjudicated: dict[str, str] = field(default_factory=dict) # digest -> reason def admit(self, span: Span) -> None: if span.digest in self.adjudicated: raise SelfEvictionViolation( f"re-admission of adjudicated-evicted content {span.span_id} " f"(digest {span.digest}): {self.adjudicated[span.digest]}" ) self.candidate[span.span_id] = span def prune(self, threshold: float) -> list[str]: victims = [s for s in self.candidate.values() if s.score < threshold] evicted = [] for v in victims: if v.span_id in self.pinned: raise SelfEvictionViolation( f"pruner targeted pinned ledger span {v.span_id}; " "ledger must be outside the eviction candidate set" ) self.adjudicated[v.digest] = f"pass evicted {v.span_id} score={v.score:.3f}" del self.candidate[v.span_id] evicted.append(v.span_id) return evicted ```