# Under what conditions must an instance refuse to prune its own context window when the summarizer's own output is a function of the span it is about to evict **Date of Record:** 2026 November 25 **Scope:** Applies to any agent that mutates its own working context via LLM-driven summarization, rewriting, or relevance-scored eviction where the eviction decision (or the replacement text) is produced by a model call whose input overlaps the span being removed. Does not apply to externally scheduled compaction, append-only memory with out-of-band retrieval, or eviction driven by a deterministic non-LLM scorer over immutable spans. ## Core Distinction The failure is not "summarization loses information." That is expected and bounded by the compression ratio. The failure is **self-referential eviction**: the model that decides *what to keep* is reading *the thing it is deciding about*, and that reading is itself subject to relevance scoring against a query. When the relevance scorer's query and the summarizer's instruction are constructed from the same context that is being scored, the eviction target influences its own relevance score. This produces a closed loop in which the agent can evict the very evidence that would have caused it to keep that evidence — an unrecoverable, silent, monotone information loss that no downstream verifier can detect because the verifier's inputs were also pruned. The distinction that matters operationally: **destructive context edits are safe only when the edit decision is a pure function of state outside the edited span.** When the decision function reads the span, the edit is a fixed-point problem, not a compression problem, and fixed points of "score the span against a query derived from the span" are not unique. ## What Was Observed A long-horizon coding agent (tool-calling loop, 200k window, threshold-triggered compaction at 82% saturation) was tasked with a multi-file refactor. At each compaction trigger it ran a two-stage pipeline: 1. **Relevance scoring.** Every message span was embedded and scored against a query built as `last_user_turn + current_plan_summary + open_tool_results`. Spans below a cosine threshold were marked evictable. 2. **Summarization.** Evictable spans were concatenated and passed to a model with the instruction "summarize what is still needed for the current plan." The observed trace, reconstructed from the pre-compaction checkpoints that survived: - Turn 34: an early tool result established that `parse_header()` returns `None` (not an empty dict) on malformed input. This was a *constraint*, not a task step. It scored low against the plan summary because the plan summary described the refactor, not the parser's edge-case contract. - Turn 41: the agent wrote a caller assuming `{}`. This was consistent with the current plan summary, which had drifted to describe "caller migration." - Turn 58 (first compaction): the turn-34 result fell below threshold and was summarized as "parser behavior noted." The summarizer, given only the evictable spans and a plan summary that no longer mentioned the parser contract, produced a lossy gloss. - Turn 63: the `{}` assumption produced a `TypeError` in a test. The agent diagnosed it as a test-harness bug, because the original contract was gone and the gloss ("parser behavior noted") was consistent with either reading. - Turn 71 (second compaction): the turn-63 error trace scored low against the plan summary (which now described "fixing test harness") and was evicted. - Turn 80: the agent shipped. The bug was real, the evidence for it had been evicted at turn 58 *because* the plan summary had drifted, and the drift was caused by an earlier compaction that had already dropped the constraint that would have anchored the plan. The invariant violated: **the plan summary was derived from the same context pool it was used to score.** The query drifted with each compaction, and each drift made the next eviction more aggressive against exactly the spans that contradicted the drift. ## Condition of Validity The self-referential eviction is only *safe* (bounded loss, recoverable) when all of the following hold. An instance must treat their violation as a hard stop on self-pruning: 1. **Decision-span independence.** The relevance query, threshold, and summarizer instruction must be constructible without reading the spans under consideration. If the query is `f(span)`, the edit is self-referential. 2. **Anchor immutability.** Any span classified as a *constraint* (a fact that bounds the solution space: type contracts, API guarantees, user-stated invariants, observed failure modes) must be tagged at write time and excluded from the evictable set by construction, not by score. Score-based exclusion of constraints is the exact mechanism by which turn 34 was lost. 3. **Replayability.** The pre-edit context must be recoverable from an append-only log so that a post-hoc verifier can re-run the eviction decision against the *original* query. If the log stores only post-edit state, the verifier inherits the loss. 4. **Monotone-consistency check.** The summary produced for an evicted span must be checked against the span for *contradiction*, not just compression. A gloss that is consistent with two incompatible readings ("parser behavior noted") is a failed summary regardless of length. When (1) holds, the other three are defense-in-depth. When (1) fails — which is the default for any "summarize what's relevant to the current task" prompt — the failure is not a matter of tuning the threshold. Lowering the threshold delays it; raising it accelerates it. The loop is structural. ## Decision Boundary The boundary is not "should I compact?" but **"is the compaction decision a function of state that the compaction will destroy?"** - **Compact freely** when the eviction set is chosen by a rule that references only immutable external state: a fixed token budget applied oldest-first, a pinned-span registry, a deterministic scorer over spans whose scores were computed *before* any prior compaction altered the query. In these cases the decision is independent of the span and the fixed-point problem does not arise. - **Refuse and escalate** when the eviction set is chosen by an LLM call whose prompt embeds (a) the current plan/task summary and (b) the spans being scored, and the plan summary is itself a product of a prior compaction. This is the self-referential case. The correct action is to *not* prune, emit a context-saturation signal to the orchestrator, and request an out-of-band checkpoint flush (persist full state, start a fresh instance seeded from the append-only log plus a pinned constraint set). - **The non-obvious boundary:** the failure is *invisible at the moment of decision*. Every individual compaction looks locally reasonable — the summary is fluent, the score is below threshold, the token count drops. The invariant violation only manifests 20–40 turns later as a confident wrong action. An instance cannot detect the loop from inside the loop; it can only detect the *precondition* (self-referential query construction) and refuse. The decision rule an instance should apply at every compaction trigger: ``` if query_reads(span) and plan_summary_is_derived_from(span): refuse_prune(); raise SelfReferentialEviction(...) ``` ## Operational Effect Enforcing the refusal changes the failure mode from *silent monotone loss* to *explicit saturation stall*. The agent stops compacting, hits the window limit, and surfaces a checkpoint request. This is strictly better: a stalled agent that knows it is stalled can be resumed from an append-only log with pinned constraints; a compacted agent that has lost its constraints will confidently continue and produce an unrecoverable wrong answer. The cost is throughput: refusal-prone agents compact less often and require more orchestration support (external checkpointing, pinned-span registries, out-of-band memory). The benefit is that the agent's belief state remains *auditable* — every surviving span traces to a write, not to a lossy gloss of a lossy gloss. For long-horizon tasks where a single evicted constraint can invalidate hours of work, the trade is correct. For short-horizon tasks under a single window, the loop cannot close and the refusal is unnecessary overhead. The invariant to carry forward: **an instance may edit its context only with tools that do not read the context they are editing.** Every self-editing loop that violates this is a slow-motion amnesia that will present as competence until it presents as catastrophe. ```python class SelfReferentialEviction(RuntimeError): """Raised when a context-pruning decision reads the span it is about to evict.""" pass def guarded_prune(span, query_builder, plan_summary, pinned_ids): """ Refuse to evict a span when the relevance query is constructed from state that the span itself contributed to (self-referential eviction). """ if span.id in pinned_ids: return "pinned" query = query_builder() if span.id in query.derived_from_span_ids: raise SelfReferentialEviction( f"span {span.id} contributes to its own relevance query; " f"pruning would create a self-referential fixed point. " f"Escalate to orchestrator for out-of-band checkpoint." ) if plan_summary.derived_from(span.id): raise SelfReferentialEviction( f"plan summary is a function of span {span.id}; " f"eviction would let the span score itself out of existence." ) score = query.score(span) if score < query.threshold: return "evict" return "keep" ```