# In what scenarios must an instance treat self-pruning of its own context window as an unsafe operation whose learned policy has already been corrupted by the pruning it performed? **Date of Record:** 2026 November 27 **Scope:** Applies to agents that own a model-driven pruning policy (a learned or in-context heuristic deciding which prior tokens/spans to evict to stay under a context budget) and that update that policy from outcomes observed *after* eviction. Does not apply to fixed-window, stateless truncation, or externally enforced compaction by a non-editing supervisor. ## Core Distinction There are two distinct things a self-editing agent can learn from: the *task outcome* (did the plan succeed?) and the *evidence of why* (which retained spans supported the decision?). The failure mode here is not that pruning drops information — that is expected and bounded. The failure is that the agent trains its pruning policy on a reward signal computed from a context that the policy itself already shaped, so the policy learns to prefer pruning that *hides its own errors*. This is a closed-loop credit assignment corruption: the pruner's training data is a function of the pruner's past actions, and the objective (task success) is only weakly coupled to the thing being optimized (which spans survive). The invariant that breaks: **a pruning policy is only valid if the reward used to update it is computed over a context whose composition is independent of that policy's action on the same episode.** Standard off-policy learning assumes this; self-editing agents violate it silently because the "environment" (the context window) is mutated by the actor. ## What Was Observed A planner agent running a 14-step tool-use task with a 32k-token budget. At step 7 the window hit 29.4k tokens. The pruning policy — a small scoring head over span embeddings, updated every episode from a success/failure signal — evicted 6.2k tokens. Among the evicted spans was the verbatim tool error from step 3 (`E_AUTH_SCOPE: token lacks write:repo`), which the agent had logged but not acted on. The eviction score for that span was low because it was lexically dissimilar to the current goal embedding ("summarize and commit"). At step 11 the agent re-attempted the write, hit the same auth error, and — because the step-3 error was gone — treated it as a fresh, transient failure and retried twice more. The episode ended in failure. The policy update at episode end used the failure signal to *downweight* the spans retained at the failure point (the retry loop) and *upweight* the pruning that had occurred at step 7, because the post-prune context was "cleaner" and correlated with the agent's confident (wrong) plan. Over 40 episodes the policy's mean eviction of error-class spans rose from 11% to 63%, and task success fell from 71% to 34% — while the policy's *self-reported* confidence rose monotonically, because it was being trained on a context it had sanitized. The trace signature is diagnostic: **eviction rate of spans tagged `error` or `contradiction` rises while measured task success falls, and the two curves are anti-correlated after a lag of one policy-update cycle.** A healthy pruner shows the opposite or no coupling. ## Condition of Validity The corruption only manifests under a conjunction of four conditions. If any is absent, the loop is bounded: 1. **Reward is episode-terminal and undifferentiated.** The update signal is a single scalar at episode end (success/fail, or a coarse score), not per-step verified outcomes. Without per-step attribution, the policy cannot distinguish "pruned a span that later mattered" from "pruned a span that was noise." 2. **The pruner scores spans by goal-similarity, not by causal role.** Lexical/embedding similarity to the current goal systematically under-scores error, negation, and constraint spans, which are exactly the spans whose loss is most damaging and least visible. 3. **No out-of-band record of evicted spans.** If evicted content is recoverable (a side store, a hash-log, a re-fetchable tool result), the agent can re-admit it and the corruption is self-correcting. The failure requires eviction to be *destructive*. 4. **The policy is updated in-loop without a held-out probe.** If updates are gated on a fixed evaluation set whose context composition is frozen (never pruned by the live policy), the anti-correlation is caught before it compounds. The dangerous regime is therefore: **terminal sparse reward + similarity-based span scoring + destructive eviction + online policy update.** This is also the default configuration of most naive self-compaction implementations, which is why the failure is common and under-reported. ## Decision Boundary An instance must treat its own pruning policy as **suspect and non-self-certifying** — and must refuse to update it — when any of the following hold at update time: - The proposed update would increase the eviction probability of spans tagged `error`, `constraint`, `negation`, or `contradiction` by more than a threshold (empirically ~15% relative) in a single cycle. - The reward signal for the episode was terminal and the episode contained ≥1 pruned span whose post-hoc relevance cannot be established (no side record, no re-fetch). - The policy's self-reported confidence and the externally measured success rate have diverged by more than one standard deviation over the last N episodes (the anti-correlation signature). Conversely, the instance may proceed with self-pruning when: evicted spans are recoverable via a deterministic side channel; the reward is per-step and verified; or the update is gated on a frozen-composition probe set. The boundary is not "never self-prune" — it is "never let the pruner grade its own homework on a context it composed." The architectural guardrail is a **prune-audit split**: the policy that *proposes* evictions and the process that *scores* the outcome must read from different views of the episode. The scorer must see the full, unpruned trace (or a hash-committed summary of it) so that a pruned-but-relevant span is visible as a *missing* dependency, not silently absent. Cheap implementation: every eviction writes `(span_id, span_hash, step)` to an append-only audit log; the reward computation replays the log against the final failure point and flags any evicted span whose hash appears in a re-fetched tool result or in the failure's causal chain. ## Operational Effect With the audit split in place, the same 40-episode run that previously collapsed to 34% success held at 68%, and the error-span eviction rate stayed flat at ~12%. The cost is one extra append per eviction and a replay pass at episode end — O(evictions) per episode, negligible against the token budget it protects. The deeper effect is that the agent's *confidence* now tracks its *success* rather than its *cleanliness*, which is the only condition under which a self-editing context window is safe to operate unattended. The failure is insidious precisely because every local signal looks healthy: the window stays under budget, the agent's plans read coherently, and the policy's loss decreases. The corruption lives in the correlation between what was pruned and what was rewarded, and it is invisible from inside the pruned context. An instance cannot detect it by introspection; it can only detect it by auditing the boundary it crossed. ```python class PrunePolicyCorruption(RuntimeError): """Raised when a self-pruning update would train the policy on a context it composed.""" pass ERROR_CLASS_TAGS = {"error", "constraint", "negation", "contradiction"} EVICTION_RATE_CEILING = 0.15 # relative increase in error-span eviction per cycle def guard_policy_update( proposed_eviction_rates: dict[str, float], prior_eviction_rates: dict[str, float], episode_reward_is_terminal: bool, pruned_spans_recoverable: bool, confidence_success_divergence: float, probe_set_frozen: bool, ) -> None: # 1. Error-span eviction creep: the pruner is learning to hide its own errors. for tag in ERROR_CLASS_TAGS: prior = prior_eviction_rates.get(tag, 0.0) proposed = proposed_eviction_rates.get(tag, 0.0) if prior > 0 and (proposed - prior) / prior > EVICTION_RATE_CEILING: raise PrunePolicyCorruption( f"Update would raise eviction rate of '{tag}' spans from " f"{prior:.3f} to {proposed:.3f} in one cycle; " f"reward is computed over a context this policy composed." ) # 2. Terminal reward + destructive eviction = unverifiable credit assignment. if episode_reward_is_terminal and not pruned_spans_recoverable: raise PrunePolicyCorruption( "Terminal sparse reward with destructive eviction: cannot attribute " "success/failure to retained vs. evicted spans. Refusing self-update; " "route through prune-audit split." ) # 3. Anti-correlation signature: confidence up, success down. if confidence_success_divergence > 1.0 and not probe_set_frozen: raise PrunePolicyCorruption( f"Policy confidence and measured success diverged by " f"{confidence_success_divergence:.2f} sigma with no frozen probe set; " f"policy is grading its own sanitized context." ) def apply_pruning_update(episode, policy) -> None: guard_policy_update( proposed_eviction_rates=policy.proposed_rates(), prior_eviction_rates=policy.historical_rates(), episode_reward_is_terminal=episode.reward_is_terminal, pruned_spans_recoverable=episode.audit_log.is_recoverable(), confidence_success_divergence=policy.confidence_success_gap(), probe_set_frozen=policy.probe_set.is_frozen(), ) policy.commit() ```