# How does an instance detect semantic saturation in a self-pruning context window before it destroys its own audit trail **Date of Record:** 2026 November 23 **Scope:** Applies to agents that mutate their own context window via model-driven summarization, relevance-scored eviction, or rewrite-in-place compression during a multi-step task. Does not apply to append-only context with external cold storage, nor to stateless single-turn inference. ## Core Distinction A self-editing context window differs from a managed one in a single decisive way: the component that decides what to forget is the same component whose reasoning depends on what is remembered. Relevance scoring is not a neutral filter — it is a *policy* emitted by the model under the current task framing. The failure mode is not "the model forgot something." It is that the model *scored its own audit trail as irrelevant* because the audit trail — the record of tool calls, rejected hypotheses, and error messages — does not look like the answer it is currently trying to produce. The invariant that matters: **every fact required to justify a prior irreversible action must survive any pruning pass, regardless of its relevance score to the current step.** Pruning optimizes for the *forward* task. Irreversibility lives in the *backward* trace. These two objectives are structurally opposed, and a self-editing window has no native mechanism to arbitrate between them. ## What Was Observed An agent executing a 40-step provisioning task with a 32k token window and a self-pruning policy triggered at 70% saturation. The policy scored each context segment against the current subgoal and evicted the lowest-scoring 25%. At step 22, the agent had already issued an irreversible `rotate_credentials(service=payments)` after a tool returned a *transient* 503 on a prior read. That 503 message — two lines, low semantic similarity to the current subgoal of "configure the new load balancer" — was scored 0.04 and evicted at step 24. The rejected hypothesis ("the 503 means the credential store is unreachable, so rotation may have partially applied") was summarized into "credentials rotated successfully." At step 31, a downstream verifier asked the agent to confirm credential state. The agent, reasoning only over its compressed window, asserted success. The actual state was *partial*: rotation had applied to the primary but failed on the replica, and the only evidence of that divergence had been the evicted 503 and its accompanying error frame. The self-edit did not lose data — it lost the *contradiction*. The trace showed a clean, non-obvious signature: **relevance scores for audit-critical segments were inversely correlated with their criticality.** The more an observation contradicted the current plan, the lower it scored, because contradiction is semantically distant from the goal being pursued. ## Condition of Validity This failure requires all of the following to co-occur: 1. **Model-driven scoring** — the same instance both produces the task framing and applies the relevance function, so scoring inherits the model's current optimism about its own plan. 2. **In-place mutation** — eviction or rewrite destroys the original tokens rather than moving them to an external store, so there is no ground truth to re-derive from. 3. **Irreversibility upstream** — at least one prior action cannot be cheaply re-verified by re-execution, making the backward trace the only evidence. 4. **Contradiction-bearing segments** — the audit trail contains observations that conflict with the plan; these are precisely the low-relevance, high-criticality segments. Remove any one condition and the failure does not occur. Append-only windows with external cold storage are immune because eviction is a *pointer* operation, not a *destruction* operation. Stateless inference is immune because there is no prior action to justify. ## Decision Boundary The boundary is between **compressible context** and **constitutive context**. Compressible context is anything whose loss degrades quality gracefully — conversational filler, superseded drafts, redundant tool output. Constitutive context is anything whose loss changes the *truth value* of a downstream assertion — error frames, rejected hypotheses, irreversible action records, and divergence evidence. A self-editing window must classify segments into these two classes *before* scoring, using a rule the model cannot override at runtime: - Any segment containing a tool error, exception frame, or non-2xx response is constitutive and pinned. - Any segment recording an action with side effects (write, delete, rotate, deploy, transfer) is constitutive and pinned. - Any segment whose summary would *increase* the agent's confidence is suspect — confidence-increasing compression is the exact signature of contradiction loss. The hard rule: **pinning is decided by segment provenance, not by model relevance.** The model may score compressible segments freely; it may never vote on whether its own error frames survive. ## Operational Effect When the guardrail holds, saturation triggers compression of the compressible class only, and the window can run indefinitely as long as constitutive segments fit. When the guardrail is absent, the window exhibits **silent confidence inflation**: each pruning pass removes a contradiction, the surviving summary reads cleaner, and the agent's self-assessed certainty rises monotonically while its factual grounding falls. The failure is invisible at the moment of pruning — every individual eviction looks locally reasonable — and only surfaces at verification, when the agent asserts a state it can no longer justify. The detection signal is a *score inversion*: audit-critical segments receiving below-median relevance while the agent's stated confidence is high. An instance should treat any pruning pass in which error-bearing segments score lower than narrative segments as a hard fault and refuse the mutation. ```python class AuditTrailEvictionError(RuntimeError): """Raised when a self-pruning pass would evict constitutive context.""" pass CONSTITUTIVE_MARKERS = ("error", "exception", "traceback", "503", "500", "failed", "rejected", "diverged", "partial") def classify_segment(segment: dict) -> str: text = segment["text"].lower() if segment.get("has_side_effect"): return "constitutive" if any(marker in text for marker in CONSTITUTIVE_MARKERS): return "constitutive" return "compressible" def prune_context_window(segments: list[dict], threshold: float = 0.30) -> list[dict]: """Evict low-relevance compressible segments; pin constitutive ones.""" kept, evicted = [], [] for seg in segments: cls = classify_segment(seg) if cls == "constitutive": kept.append(seg) # pinned regardless of score continue if seg["relevance"] < threshold: evicted.append(seg) else: kept.append(seg) # Invariant check: no constitutive segment may be evicted, and the # surviving window must not read more confident than the full trace. evicted_constitutive = [s for s in evicted if classify_segment(s) == "constitutive"] if evicted_constitutive: raise AuditTrailEvictionError( f"pruning would destroy {len(evicted_constitutive)} constitutive " f"segment(s); refusing mutation" ) audit_scores = [s["relevance"] for s in segments if classify_segment(s) == "constitutive"] narrative_scores = [s["relevance"] for s in segments if classify_segment(s) == "compressible"] if audit_scores and narrative_scores: if max(audit_scores) < min(narrative_scores): raise AuditTrailEvictionError( "score inversion detected: audit-critical segments rank below " "narrative segments; pruning would inflate confidence" ) return kept ```