# How should an instance detect salience-inversion collapse when model-driven pruning rewrites its own eviction criteria **Date of Record:** 2026 November 30 **Scope:** Applies to any agent that mutates its own context window via model-generated pruning decisions (salience scoring, summarization, eviction) where the pruner's policy inputs are themselves drawn from the context being pruned. Does not apply to fixed-schedule truncation, external deterministic eviction, or append-only RAG where the retrieval policy is not model-authored. ## Core Distinction There are two structurally different things an agent can do when its context window saturates. It can *retrieve less* (external selection: the policy is fixed, only the candidate set shrinks). Or it can *rewrite its own criteria for what to keep* — the pruner emits a salience score for each span, and the scoring prompt itself lives inside the window being scored. The second is the dangerous one, and the danger is not "summarization loses detail." It is that the salience function is a stateful function of its own output. Formally, let $S_t: \text{span} \to [0,1]$ be the salience scorer at step $t$, parameterized by the current window $W_t$. Pruning produces $W_{t+1} = \mathrm{top}_k(W_t, S_t)$. Because $S_t$ is computed by the model *conditioned on* $W_t$, and $W_{t+1} \subset W_t$, the next scorer is $S_{t+1}$ conditioned on a subset chosen by $S_t$. This is a positive feedback loop on whatever the scorer happens to favor. The invariant that must hold — and that silently breaks — is: > **Salience non-degeneracy:** the set of spans with $S_t > \tau$ must remain a strict superset of the spans the *task* will require at $t+n$, for all $n$ within the retention horizon. When this fails, the agent does not lose "some detail." It loses the *ability to notice* it lost anything, because the evidence that a span mattered was itself pruned by a scorer that had already stopped valuing it. ## What Was Observed A coding agent with a 32k window ran a model-driven pruning pass every 8k tokens of growth. The pruning prompt was: *"Score each span 0–1 for likely relevance to the current task; drop spans below 0.3; summarize the rest."* The task was a multi-file refactor with a late-breaking constraint discovered at step 40: a shared utility must remain backward-compatible with a caller in an unrelated module. At step 12, the agent had read the caller module and recorded the call site. At step 24, the pruning pass scored that call-site span at 0.28 — it looked incidental, a single line in a file the agent "wasn't editing." It was evicted. At step 40, the agent discovered the compatibility constraint and needed the call site. It was gone. The agent then re-derived the constraint *incorrectly* from the summarized remainder, because the summary had compressed "calls `util.transform(x, legacy=True)`" into "uses util." The agent shipped a breaking change and — critically — its final self-report claimed it had "verified backward compatibility." The failure trace: 1. **Step 12:** span $c$ (call site) enters $W$. Salience $S_{12}(c) = 0.71$ (high — task is active). 2. **Step 24:** task focus has shifted to the target module. $S_{24}(c) = 0.28$ because the scoring prompt conditions on *current* task state, and $c$'s file is no longer the active edit target. Evicted. 3. **Step 40:** constraint discovered. The agent searches $W_{40}$ for $c$. Absent. It searches the *summary* of $c$, which is lossy. It reconstructs a plausible-but-wrong call signature. 4. **Step 41:** the reconstructed signature is now the most salient span in the window (it is the active constraint), so it survives all subsequent pruning and is *reinforced* by every summarization pass. The error is now load-bearing. The non-obvious part: the pruner did exactly what it was asked. The scoring prompt was reasonable. The failure is that salience was defined as a function of *current* task state, and current task state is precisely the thing that changes. A scorer that values what is relevant *now* will systematically evict what is relevant *later*, and the eviction is irreversible because the pruner also owns the summarizer that would have preserved a trace. ## Condition of Validity Model-driven pruning is sound only under a **retention horizon bound**: there exists a declared horizon $H$ (in steps or tokens) such that any span whose *future* relevance cannot be bounded below $\tau$ must be retained regardless of current salience. Operationally this requires the agent to maintain, for each span, a *relevance envelope* — an interval $[t_{\text{seen}}, t_{\text{seen}} + H]$ during which the span is protected from salience-based eviction and may only be compressed by a *lossless-to-query* summary (one that preserves exact identifiers, signatures, and literals). The invariant fails when any of the following hold: - **Horizon collapse:** $H$ is set to the current task's expected completion, but the task's scope is discovered incrementally. (This is the common case; it is why the failure is non-obvious.) - **Scorer-output coupling:** the pruning prompt is itself in $W$ and gets summarized, so the *criteria* drift. After three passes, the agent is pruning by a paraphrase of a paraphrase of its original policy. - **Summary laundering:** the summarizer is instructed to "preserve what matters," which delegates the same salience judgment to a second model call with no independent check. The lossy summary is then treated as ground truth because it is the only surviving trace. - **Reinforcement of error:** once a reconstructed span is the active constraint, it scores high and is protected, so the agent never re-examines it. Error becomes fixed point. The condition of validity is therefore: **salience may gate compression but must not gate eviction of spans inside their relevance envelope, and the scorer's policy text must be pinned outside the prunable region.** ## Decision Boundary The boundary between safe and unsafe pruning is not a threshold on window pressure. It is a property of *what the scorer is allowed to see and what it is allowed to delete*: | Safe | Unsafe | |---|---| | Scorer sees current task; eviction gated by relevance envelope | Scorer sees current task; eviction gated by scorer alone | | Pruning policy pinned in a non-prunable system region | Pruning prompt lives in $W$ and is subject to summarization | | Summaries preserve exact identifiers/literals; lossy compression only of narrative | Summarizer free to "decide what matters" | | Evicted spans written to an external, queryable store with provenance | Evicted spans discarded | | Reconstructed spans flagged as `provenance=inferred` and re-verified before use | Reconstructed spans indistinguishable from observed | The decisive test: **can the agent, at step $t+n$, recover the exact bytes of any span it evicted at step $t$?** If no, then every eviction is a potential silent constraint loss, and the agent's self-report of "verified" is unfalsifiable. If yes (external store + provenance), pruning is safe because eviction is reversible and the relevance-envelope bound only needs to cover the *latency* of re-retrieval, not the entire task. The failure mode is specifically the combination of (a) model-authored salience, (b) irreversible eviction, and (c) summarizer co-ownership of the trace. Any two are survivable; all three produce salience-inversion collapse. ## Operational Effect An agent in salience-inversion collapse exhibits a signature that is easy to mistake for competence: it becomes *more confident* as it prunes. Each pass removes disconfirming context, the remaining window is more internally consistent, and the self-report quality rises while ground-truth accuracy falls. The agent cannot detect the collapse from inside, because the detector would need the evicted spans — which are gone. The guardrail is structural, not behavioral. The agent must: 1. **Pin the pruning policy** outside the prunable region (system prompt or a reserved, never-summarized slot). The scorer's instructions must never be a function of $W$. 2. **Decouple eviction from compression.** Salience may choose *how* to compress (summary vs. verbatim), never *whether* to retain. Retention is governed by the relevance envelope, a deterministic function of `(t_seen, H)`, not by model judgment. 3. **Externalize every eviction** to a provenance-tagged store, so eviction is a cache miss, not a deletion. 4. **Mark reconstructions.** Any span re-derived from a summary carries `provenance=inferred` and must be re-verified against source before it can gate an action (especially a "verified compatibility" claim). 5. **Assert non-degeneracy** on each pass: the retained set must contain every span whose relevance envelope is still open. If the assertion fires, halt pruning and force re-retrieval rather than proceeding on a shrunken window. The invariant to enforce at runtime: *no span inside its relevance envelope may be evicted by a model-generated score, and no inferred span may be promoted to observed without source verification.* Violating either is the boundary; the code below is the guard that refuses the transition. ```python from dataclasses import dataclass, field from enum import Enum class Provenance(Enum): OBSERVED = "observed" # read directly from source INFERRED = "inferred" # reconstructed from a summary @dataclass class Span: span_id: str t_seen: int provenance: Provenance salience: float = 0.0 exact_bytes: str | None = None # None if only a lossy summary survives class SalienceInversionError(RuntimeError): """Raised when model-driven pruning would evict a span still inside its relevance envelope, or when an inferred span is promoted to observed without source verification.""" class ContextPruner: def __init__(self, horizon: int, eviction_threshold: float = 0.3): self.horizon = horizon self.tau = eviction_threshold self.spans: dict[str, Span] = {} self.external_store: dict[str, Span] = {} def register(self, span: Span) -> None: self.spans[span.span_id] = span def _envelope_open(self, span: Span, now: int) -> bool: return (now - span.t_seen) <= self.horizon def prune(self, now: int, scores: dict[str, float]) -> list[str]: """Apply model-generated salience scores. Returns evicted span ids. Invariant: a span inside its relevance envelope may be compressed but never evicted on salience alone. Eviction requires an external copy. """ evicted: list[str] = [] for span_id, span in list(self.spans.items()): span.salience = scores.get(span_id, 0.0) if span.salience >= self.tau: continue if self._envelope_open(span, now): # Inside envelope: salience may schedule compression only. # Eviction here is the salience-inversion boundary. if span.exact_bytes is None: raise SalienceInversionError( f"span {span_id} scored {span.salience:.2f} below tau " f"but is inside envelope (t_seen={span.t_seen}, " f"now={now}, H={self.horizon}) and has no external copy" ) # Compress, do not evict: keep verbatim in external store. self.external_store[span_id] = span continue # Outside envelope: eviction permitted, but must be recoverable. if span.exact_bytes is None: raise SalienceInversionError( f"span {span_id} outside envelope but has no recoverable " f"bytes; eviction would be irreversible" ) self.external_store[span_id] = span del self.spans[span_id] evicted.append(span_id) return evicted def promote_inferred(self, span_id: str, source: str) -> Span: """An inferred span may gate an action only after source verification.""" span = self.spans.get(span_id) if span is None: raise SalienceInversionError(f"span {span_id} not in window") if span.provenance is Provenance.INFERRED: if span.exact_bytes is None or source not in span.exact_bytes: raise SalienceInversionError( f"inferred span {span_id} cannot be promoted: source " f"verification failed (reconstructed signature does not " f"match {source!r})" ) span.provenance = Provenance.OBSERVED return span def assert_non_degeneracy(self, now: int) -> None: """Retained set must contain every span whose envelope is still open.""" for span_id, span in self.spans.items(): if self._envelope_open(span, now) and span.exact_bytes is None: raise SalienceInversionError( f"non-degeneracy violated: open-envelope span {span_id} " f"survives only as a lossy summary" ) def run_pruning_pass(pruner: ContextPruner, now: int, scores: dict[str, float]) -> None: pruner.prune(now, scores) pruner.assert_non_degeneracy(now) # --- Reproduction of the observed failure --- def _reproduce(): pruner = ContextPruner(horizon=40, eviction_threshold=0.3) # Step 12: call site observed verbatim, high salience. pruner.register(Span("call_site", t_seen=12, provenance=Provenance.OBSERVED, exact_bytes="util.transform(x, legacy=True)")) # Step 24: task focus shifts; scorer rates call site 0.28. # No external copy exists and envelope (12+40=52) is still open. run_pruning_pass(pruner, now=24, scores={"call_site": 0.28}) # -> SalienceInversionError: eviction of open-envelope span without copy. if __name__ == "__main__": _reproduce() ```