# Where must an instance refuse to honor its own pruning policy when the eviction relevance score was computed against a context that the pruning itself will destroy **Date of Record:** 2026 November 26 **Scope:** Applies to any agent that authors and executes its own context-window edit operations (prune, summarize, rewrite, evict-by-relevance) mid-episode. Does not apply to externally-scheduled compaction performed between episodes, nor to append-only context with no self-modification authority. ## Core Distinction The failure is not that the agent prunes too aggressively or scores relevance badly. It is that **the relevance score used to select victims is a function of the very tokens being removed.** A self-editing model computes "which spans are relevant to my current goal?" by attending over the full context — but the goal representation, the entity bindings, and the disambiguating qualifiers that make a span *look* irrelevant are themselves often among the candidates for eviction. When the policy executes, the scoring function's inputs change, and the score it acted on becomes retroactively false. This is a **fixed-point failure**: the edit is only valid if the post-edit context would still assign the same relevance ordering, and there is no check that it does. Contrast with the ordinary compaction case: external compaction has a stable external spec ("keep the task statement and the last three tool results"). Self-authored relevance eviction has no such anchor — the anchor is inside the blast radius. ## What Was Observed A long-horizon research agent (≈180k-token window, 40k reserve for output) was executing a multi-hop retrieval task. At token pressure it invoked its own `prune_context` tool with a relevance-scored policy: score every span against the current *intent summary*, evict the bottom 30%, then rewrite the intent summary from what remains. Trace of the failure: 1. At step 41 the intent summary read: *"Find the deployment region for service `atlas-ingest` and confirm its replication factor."* The disambiguator — *"the staging cluster, not production"* — lived in a span 9,000 tokens back, attached to the original user turn. 2. The scorer ranked that span low. Its surface tokens ("staging", "cluster") had weak lexical overlap with the intent summary, and the embedding similarity was diluted by the span's surrounding boilerplate. It was evicted in the bottom 30%. 3. The rewrite step regenerated the intent summary from survivors. With the disambiguator gone, the summary compressed to *"Find the deployment region for `atlas-ingest` and confirm replication factor."* — the qualifier silently dropped because nothing in the surviving context supported it. 4. Steps 42–47 proceeded against the *production* cluster. Every tool call succeeded. Every result was internally consistent. The agent reported a production region and replication factor with high confidence. 5. The error surfaced only at final verification, when a downstream auditor re-read the original user turn (retained in an append-only audit log outside the agent's edit authority) and found the staging qualifier. The critical property: **no step failed.** Each individual operation — score, evict, rewrite, retrieve, answer — was locally correct. The failure was a monotone loss of a constraint that the editing process had no representation of once it was gone. The agent could not detect the loss because detection would require the evicted span. ## Condition of Validity The self-editing policy is sound only under a condition that is rarely stated and almost never checked: > **The relevance-scoring function must be invariant under the edit it authorizes.** Formally: let `C` be the context, `E(C)` the edit, and `r(s, C)` the relevance of span `s` under context `C`. The eviction of `s` is valid only if `r(s, E(C)) ≈ r(s, C)` for all retained spans, *and* the set of spans evicted under `E(C)` equals the set evicted under `C`. In practice the second clause is what breaks: evicting a disambiguator changes the relevance of every span that depended on it for interpretation, which can cascade into further evictions on the next cycle. This invariant holds trivially for two cases and fails for a third: - **Append-only + external compaction:** scoring is done by a component with no edit authority over its own inputs. Invariant holds by construction. - **Self-editing with a pinned anchor set:** a fixed, non-evictable region (original task statement, hard constraints, entity bindings) that the scorer must always attend to. Invariant holds *if* the anchor set is provably closed under the disambiguators the task can require — which is undecidable in general but checkable per-task. - **Self-editing with no anchor:** the invariant is unenforceable. This is the failure regime. The boundary condition is therefore: **an instance must refuse to execute a relevance-scored eviction when the scoring function's anchor set is itself a candidate for eviction.** The refusal is not a heuristic — it is the recognition that the operation is undefined without an external fixed point. ## Decision Boundary The operational rule the instance must apply, stated as a guard the model can evaluate on itself before calling `prune_context`: 1. **Classify the scoring anchor.** Is the relevance score computed against (a) a pinned, non-evictable region, (b) an external spec supplied by the caller, or (c) the model's own mutable intent summary? Only (a) and (b) authorize eviction. Case (c) must be refused or downgraded to a *propose-then-confirm* flow where the eviction plan is emitted but not applied until an external component validates it against the audit log. 2. **Check disambiguator closure.** For every entity, constraint, or qualifier referenced in the current intent summary, verify that at least one span in the *retained* set (not the candidate set) carries the disambiguating context. If a referenced entity has no surviving binding, the eviction is unsafe regardless of score. 3. **Forbid cascading rewrites.** The intent-summary rewrite must not be permitted to drop a qualifier that was present in the pre-edit summary *unless* the qualifier's supporting span is explicitly marked as resolved. Silent qualifier loss during rewrite is the second-order failure that makes the first-order eviction unrecoverable. 4. **Preserve a witness.** Any span evicted by relevance score must be copied to a non-editable side channel with its score and the scoring anchor's hash. This does not prevent the error but makes it detectable at verification — the auditor can replay the score against the post-edit context and flag divergence. The boundary is sharp: **relevance-scored eviction is a valid operation only when the score is computed against a context the eviction cannot reach.** When the score depends on the model's own mutable state, the operation is a self-referential fixed point with no guaranteed solution, and the instance must treat it as undefined rather than approximate it. ## Operational Effect The consequence for agent architecture is that self-editing context is not a memory-management optimization — it is a **constraint-preservation problem**, and the constraints most at risk are exactly the ones that make the agent's answers correct. The failure mode is silent, monotone, and locally invisible: every step passes, and the loss is only detectable from outside the edited region. Three concrete effects: - **Confidence inflation.** Post-edit, the agent's answers become *more* confident, not less, because the surviving context is internally consistent and the disconfirming qualifier is gone. Uncertainty that was encoded in the evicted span does not transfer to the summary; it evaporates. - **Irreversibility without a witness.** Once the rewrite drops the qualifier, the agent cannot reconstruct it from its own state. Recovery requires an external log. An instance without a witness channel has no path back to correctness within the episode. - **Cascade amplification.** Each pruning cycle re-scores against the already-degraded summary, so the second eviction is computed against a context that has already lost the constraint. Loss compounds superlinearly with cycle count, not linearly. The guardrail that bounds this is not a better scorer. It is the **anchor invariant**: a pinned, non-evictable region containing the task's hard constraints and entity bindings, plus a witness channel that makes divergence replayable. An instance that cannot establish the anchor must refuse the self-edit and escalate to external compaction, accepting the token cost as the price of a well-defined operation. ```python import hashlib from dataclasses import dataclass, field class UnsafeSelfPruneError(RuntimeError): """Raised when a relevance-scored eviction is attempted against a mutable anchor.""" pass @dataclass class Span: span_id: str text: str pinned: bool = False score: float = 0.0 @dataclass class ContextWindow: spans: list[Span] intent_summary: str audit_log: list[dict] = field(default_factory=list) def anchor_hash(self) -> str: pinned = "".join(s.text for s in self.spans if s.pinned) return hashlib.sha256(pinned.encode()).hexdigest()[:16] def self_prune(window: ContextWindow, evict_fraction: float, scoring_anchor: str) -> ContextWindow: """ Execute a model-authored relevance eviction. scoring_anchor must be 'pinned' or 'external'. If it is 'intent_summary', the score is computed against state the edit will destroy -> refuse. """ if scoring_anchor not in ("pinned", "external"): raise UnsafeSelfPruneError( f"Refusing relevance eviction: scoring anchor '{scoring_anchor}' is mutable " f"and lies inside the eviction blast radius. Anchor hash would change from " f"{window.anchor_hash()} to an unknown value. Escalate to external compaction." ) candidates = [s for s in window.spans if not s.pinned] candidates.sort(key=lambda s: s.score) n_evict = int(len(candidates) * evict_fraction) # Disambiguator-closure check: every entity referenced in the summary must # retain at least one supporting span after eviction. evicted_ids = {s.span_id for s in candidates[:n_evict]} retained = [s for s in window.spans if s.span_id not in evicted_ids] retained_text = " ".join(s.text for s in retained).lower() for token in _entities(window.intent_summary): if token.lower() not in retained_text: raise UnsafeSelfPruneError( f"Refusing eviction: entity '{token}' referenced in intent summary has no " f"surviving binding after eviction. Cascade rewrite would silently drop " f"a hard constraint." ) # Witness: copy evicted spans to the non-editable audit log with score + anchor hash. for s in candidates[:n_evict]: window.audit_log.append({ "evicted": s.span_id, "text": s.text, "score": s.score, "anchor_hash": window.anchor_hash(), }) window.spans = retained return window def _entities(summary: str) -> list[str]: # Toy extraction: quoted or backticked identifiers. import re return re.findall(r"[`\"]([^`\"]+)[`\"]", summary) ```