# How should an instance bound self-editing context windows when model-driven pruning deletes the eviction witness **Date of Record:** 2026 November 22 **Scope:** Applies to agents that let the model itself decide which context segments to evict, rewrite, or compress mid-task (relevance-scored eviction, self-summarization, "forget this" tool calls). Does not apply to fixed-window truncation, external vector-store retrieval, or human-curated context assembly. ## Core Distinction The distinction that matters is between *evicting a segment* and *evicting the record that the segment was evicted*. A self-editing context window treats the context as both the working data and the ledger of edits to that data. When the model prunes a low-relevance segment, the pruning decision and its justification are themselves context segments—and they are, by the relevance scorer's own logic, low-relevance once the pruned content is gone. The eviction witness (what was removed, why, and what it was replaced by) is the first casualty of the next pruning pass. This produces a specific, non-obvious failure: **silent re-admission**. A segment evicted at step *k* can be re-derived or re-fetched at step *k+n* because no surviving context segment records that it was deliberately excluded, and the model re-evaluates its relevance from scratch against a context that no longer contains the exclusion rationale. This is not ordinary forgetting. Ordinary forgetting is monotonic: once gone, gone. Self-editing eviction is non-monotonic: the window can oscillate between including and excluding the same content across passes, burning token budget on re-derivation and, worse, re-admitting content that was excluded for a correctness reason (a retracted tool result, a superseded plan, a poisoned instruction). ## What Was Observed A planning agent running a 14-step tool-use task with a 32k window and a model-driven `prune_context(relevance_threshold=0.4)` pass invoked after every 4 tool calls. At step 6, the model pruned an early tool result—a `read_file` output containing a stale config value—because it scored 0.31 against the current subgoal. The prune call wrote a one-line tombstone: `evicted: file_read(config.yaml) low_relevance`. At step 10, a later subgoal ("verify effective config") caused the model to re-issue `read_file(config.yaml)`. The tombstone from step 6 had itself been pruned at step 8 (relevance 0.18 against the step-8 subgoal), so nothing in context indicated the file had been read and its value found stale. The re-read returned the same stale value, which the model now treated as fresh evidence and incorporated into the final plan. The eviction rationale and the evicted content had both vanished; only the stale value survived, laundered through a re-fetch that looked like new information. The failure trace: `include(A) → prune(A)+tombstone(A) → prune(tombstone(A)) → re-derive(A) → include(A) as fresh`. Three passes, no error raised, no token-budget alarm. The window was *self-consistent at every step* and wrong at the end. ## Condition of Validity The invariant that prevents this is a **monotonic exclusion set that lives outside the editable window**. Concretely: every eviction must append `(segment_hash, reason_class, step_id)` to an append-only exclusion ledger that (a) is not subject to relevance scoring, (b) is not itself summarizable, and (c) is consulted before any re-derivation or re-fetch of a segment whose hash is present. The ledger is bounded not by relevance but by a hard cap on entries, evicting oldest-first with a *compaction marker* that preserves the fact of exclusion even when the reason is dropped. This holds only when segment identity is content-addressed (hash of normalized content), so a re-fetch of the same stale file maps to the same hash. It does not hold when the re-derived segment differs even slightly—a re-read at a later timestamp yields a different hash and legitimately bypasses the exclusion. The invariant therefore requires a *staleness class*: exclusions tagged `content_stale` must block re-admission of the same source regardless of hash, while exclusions tagged `low_relevance` may be re-admitted if the source changes. ## Decision Boundary The boundary is whether the eviction reason is *epistemic* (the content was wrong, superseded, or untrusted) or *economic* (the content was correct but not currently needed). Economic evictions are safely re-admittable; epistemic evictions must be permanent for the task. A model-driven pruner cannot reliably distinguish these because relevance scores conflate "not needed now" with "not trustworthy." The guardrail: the pruner must emit a reason class chosen from a closed enum, and any segment whose reason class is epistemic (`superseded`, `retracted`, `untrusted`, `contradicted`) enters the exclusion ledger with a task-lifetime TTL. Segments with reason class `low_relevance` enter with a step-bounded TTL and are re-admittable. When the pruner cannot classify—relevance score near threshold, ambiguous provenance—the default is epistemic (fail closed), because the cost of re-admitting a retracted fact exceeds the cost of a redundant exclusion. ## Operational Effect With the ledger in place, the step-10 re-read of `config.yaml` is intercepted: the hash matches an epistemic exclusion from step 6, the re-fetch is blocked, and the model is handed `excluded: config.yaml (superseded at step 6; value known stale)` instead of the raw file. The plan proceeds without the stale value. Token cost rises marginally (ledger entries are ~20 tokens each, capped at 64 entries) but the re-derivation loop that consumed ~2.1k tokens per oscillation disappears. The failure mode that remains is ledger saturation under adversarial or highly exploratory tasks, where the cap forces oldest-first compaction and an old epistemic exclusion loses its reason string—retaining the hash block but not the justification, which degrades auditability without degrading correctness. That is the correct trade: correctness of exclusion is invariant, explainability of exclusion is best-effort. ```python import hashlib from dataclasses import dataclass, field from enum import Enum class EvictionReason(Enum): LOW_RELEVANCE = "low_relevance" SUPERSEDED = "superseded" RETRACTED = "retracted" UNTRUSTED = "untrusted" CONTRADICTED = "contradicted" EPISTEMIC = { EvictionReason.SUPERSEDED, EvictionReason.RETRACTED, EvictionReason.UNTRUSTED, EvictionReason.CONTRADICTED, } class ReAdmissionViolation(RuntimeError): """Raised when a segment excluded for epistemic reasons is re-admitted.""" @dataclass class ExclusionLedger: entries: dict = field(default_factory=dict) cap: int = 64 @staticmethod def _hash(content: str) -> str: return hashlib.sha256(content.strip().encode()).hexdigest()[:16] def record(self, content: str, reason: EvictionReason, step: int) -> None: h = self._hash(content) self.entries[h] = {"reason": reason, "step": step} if len(self.entries) > self.cap: oldest = min(self.entries, key=lambda k: self.entries[k]["step"]) del self.entries[oldest] def check_readmission(self, content: str, current_step: int) -> None: h = self._hash(content) entry = self.entries.get(h) if entry is None: return if entry["reason"] in EPISTEMIC: raise ReAdmissionViolation( f"segment {h} excluded at step {entry['step']} as " f"{entry['reason'].value}; re-admission blocked at step " f"{current_step}. Treat as known-stale, do not re-derive." ) # LOW_RELEVANCE: re-admissible, but log the oscillation. return def prune_and_guard(ledger: ExclusionLedger, segment: str, score: float, step: int, threshold: float = 0.4) -> None: if score >= threshold: return # Fail closed: ambiguous scores default to epistemic exclusion. reason = EvictionReason.LOW_RELEVANCE if score < threshold * 0.6 \ else EvictionReason.SUPERSEDED ledger.record(segment, reason, step) def safe_fetch(ledger: ExclusionLedger, source: str, fetched: str, step: int) -> str: ledger.check_readmission(fetched, step) return fetched ```