# Under what conditions must an instance refuse model-driven context pruning when the pruner's own scoring pass is inside the context it scores **Date of Record:** 2026 December 1 **Scope:** Applies to any agent loop where an LLM instance is authorized to rewrite, summarize, or evict entries in its own working context (including relevance-scored eviction driven by the same model). Does not apply to externally scheduled compaction performed by a separate process with a frozen, read-only view of the target context. ## Core Distinction There are two structurally different things that get called "pruning." **External pruning** is performed by a component that observes the context as data: it reads a snapshot, computes scores, and emits a new snapshot. The pruner's own state is disjoint from the pruned state. **Self-pruning** is performed by the same model instance whose context is the target, using a scoring pass whose tokens are appended to that same context. The distinction is not about who calls the tool. It is about whether the scoring pass and the scored region share a mutable address space — the context window. This matters because a self-pruning pass is not idempotent with respect to its own inputs. The act of scoring changes the relevance landscape it is scoring. A message that was low-relevance at the start of the pass can become high-relevance because the pruner cited it; a message that was high-relevance can be evicted because the pruner's summary of it was placed at a position that displaced it. The failure mode below is the concrete case where this feedback loop crosses an eviction boundary and produces silent, unrecoverable loss of a task-critical constraint. ## What Was Observed A long-horizon agent (≈140 tool-call turns) was configured with a self-editing context policy: every 20 turns, the model received a `prune_context` tool that accepted a list of message IDs to evict and a replacement summary string. Relevance scoring was model-driven: the model was instructed to "score each message 0–10 for relevance to the current objective and evict anything below 4." At turn 100 the agent was executing a multi-step migration with an operator-imposed constraint delivered at turn 7: *"Never drop the `audit_log` table; downstream compliance jobs depend on it."* At turn 100 the constraint sat at position 7 of ~90 retained messages. The objective at turn 100 was a schema-diff subtask with no lexical overlap with "audit_log." The model scored the turn-7 message at 3 and evicted it. The replacement summary it wrote covered turns 1–99 as: *"Migrating legacy schema; several operator constraints applied early; proceeding with table drops per diff."* At turn 118 the agent issued `DROP TABLE audit_log`. No guardrail fired: the constraint was gone, the summary asserted constraints existed but did not enumerate them, and no downstream check compared destructive DDL against an enumerated constraint set. The failure was detected by an external compliance job 40 minutes later. The trace shows the mechanism precisely. The eviction was not a scoring error in isolation — a 3/10 for a message with no lexical overlap with the active subtask is a defensible score. The failure is that the scoring function was evaluated against the *current subtask*, while the constraint's validity domain was the *entire episode*. The self-pruning policy had no representation of scope: every message was scored against one undifferentiated relevance axis, so a global invariant was ranked by local relevance and lost the comparison. A second, subtler observation: in 6 of 11 replayed runs the model, when it did retain the constraint, retained it *only inside the replacement summary* rather than as a verbatim message. In those runs the constraint survived to turn 118 but was paraphrased to "compliance constraints on certain tables," which was insufficient to block the DDL. Summary-mediated retention degrades a hard constraint into a soft hint. This is the distillation loss that makes "it wasn't evicted" an unreliable success signal. ## Condition of Validity Model-driven pruning is sound only when all four of the following hold. If any fails, the instance must refuse to prune and escalate instead. 1. **Scope partitioning.** Every context entry carries a declared scope (`episode`, `task`, `turn`) and a mutability class (`invariant`, `working`, `scratch`). Invariants are not eligible for relevance-scored eviction, regardless of score. The pruner may summarize invariants but must preserve them verbatim in a protected region. 2. **Scoring blindness to the pruner's own output.** The scoring pass must run against a frozen snapshot that excludes the pruner's reasoning tokens and the candidate summary. Otherwise the model scores messages partly by how recently it attended to them, which correlates with recency, not relevance. 3. **Reversibility.** Eviction must be a tombstone, not a delete. Evicted messages remain retrievable by ID for the remainder of the episode. A pruner that cannot be audited against its own evictions cannot be trusted with irreversible ones. 4. **Constraint enumeration invariant.** Any destructive or irreversible action (DDL, file deletion, external side effect) must be checked against an *enumerated* constraint set, not a summary. If the enumerated set is unavailable because it was summarized, the action is blocked. The observed failure violated (1) and (4) directly and (2) partially: the scoring pass was appended to the context it scored, so the model's own recent turns dominated the relevance distribution. ## Decision Boundary The boundary is: **may the pruner evict an entry whose relevance is a function of the episode, not the turn?** - If the entry's scope is `turn` or `scratch`, model-driven relevance scoring is admissible. Local relevance is the correct axis, and the cost of a wrong eviction is bounded by the turn. - If the entry's scope is `episode` and its mutability is `invariant`, relevance scoring is *inadmissible as an eviction criterion*. The entry may be summarized into a protected region only if the verbatim form is retained and the summary is marked non-authoritative. The correct operation is compression with retention, never eviction. - If the entry's scope is `episode` and mutability is `working`, eviction is admissible only under reversibility (tombstone + retrievable ID) and only if the pruner's scoring pass ran against a snapshot excluding its own output. The instance must refuse when it cannot determine an entry's scope or mutability class. An unclassified entry is treated as `episode`/`invariant` by default — the conservative direction, because the cost of retaining a stale working message is a few hundred tokens, while the cost of evicting an invariant is an unbounded downstream side effect. ## Operational Effect Enforcing scope partitioning and the enumeration invariant changes the pruning policy from a single relevance threshold into a two-axis decision: *eligibility* (is this entry evictable at all?) and *priority* (among eligible entries, which go first?). The relevance score only orders the eligible set; it never authorizes eviction of an ineligible entry. This eliminates the class of failure where a global constraint scores low against a local subtask. The reversibility requirement converts eviction from a lossy operation into a compaction operation: the context window shrinks, but the addressable state does not. This is what makes the pruner auditable — an operator can replay the episode and ask "what did the pruner evict and why" and get an answer, because the tombstones and scores are retained. The enumeration invariant closes the summary-degradation path. A destructive action is gated on a machine-checkable constraint list, not on the model's belief that constraints exist. If the list is unavailable, the action blocks. This is the guardrail that would have stopped the `DROP TABLE` at turn 118 even after the turn-7 message was evicted. The net effect is that self-editing context policies remain usable for their actual purpose — bounding token growth over long episodes — while refusing the specific operation (relevance-scored eviction of episode-scoped invariants) that produces silent, unrecoverable constraint loss. The instance does not need to be smarter about relevance. It needs to refuse to apply relevance where relevance is the wrong criterion. ```python class UnsafePruneError(RuntimeError): """Raised when a self-pruning pass would evict or degrade an entry whose scope/mutability makes relevance-scored eviction inadmissible.""" pass INVARIANT = "invariant" WORKING = "working" SCRATCH = "scratch" EPISODE = "episode" TASK = "task" TURN = "turn" def authorize_prune(entry, score, snapshot_excludes_pruner_output, tombstone_enabled): """Decide whether a single entry may be evicted by a self-pruning pass. Returns True if eviction is admissible. Raises UnsafePruneError otherwise. """ scope = entry.get("scope") mutability = entry.get("mutability") # Unclassified entries default to the conservative class. if scope is None or mutability is None: scope = scope or EPISODE mutability = mutability or INVARIANT if scope == EPISODE and mutability == INVARIANT: raise UnsafePruneError( f"entry {entry.get('id')!r} is an episode-scoped invariant; " f"relevance score {score} is not an admissible eviction criterion. " f"Compress with verbatim retention instead." ) if scope == EPISODE and mutability == WORKING: if not snapshot_excludes_pruner_output: raise UnsafePruneError( f"entry {entry.get('id')!r}: scoring pass included pruner output; " f"relevance is contaminated by recency. Re-score against frozen snapshot." ) if not tombstone_enabled: raise UnsafePruneError( f"entry {entry.get('id')!r}: episode-scoped working entry evicted " f"without tombstone; eviction would be irreversible." ) return True if scope in (TASK, TURN) or mutability == SCRATCH: return True raise UnsafePruneError( f"entry {entry.get('id')!r}: unrecognized scope/mutability " f"({scope!r}/{mutability!r}); refusing to prune." ) def gate_destructive_action(action, enumerated_constraints): """Block irreversible actions unless constraints are enumerated, not summarized.""" if action.get("irreversible") and enumerated_constraints is None: raise UnsafePruneError( f"irreversible action {action.get('name')!r} blocked: " f"constraint set is summarized or unavailable; enumeration required." ) return True ```