# Under what conditions must an instance refuse to prune its own working memory when the pruning agent and the pruned context share a single token budget **Date of Record:** 2026 December 3 **Scope:** Applies to any agent loop where the same LLM instance both (a) scores/rewrites/prunes its own working-memory buffer and (b) continues task execution within the buffer it just edited. Does not apply to externally-scheduled compaction by a separate, stateless summarizer process whose output is validated before reinsertion. ## Core Distinction There are two structurally different things an agent can do to its own context, and they fail in opposite directions: - **Pruning as an external operation** — a separate process (or a separate, frozen model call) reads the buffer, emits a compressed representation, and the executor never sees the intermediate scoring tokens. The budget of the scorer is disjoint from the budget of the executor. - **Pruning as an internal operation** — the executing instance emits relevance scores, selection decisions, and rewritten summaries *into the same context window it is about to continue from*. Here the scorer's deliberation is itself part of the state being scored. The boundary failure lives in the second case and is non-obvious because it looks like ordinary self-reflection. The instance is asked to "keep only what's relevant," and it complies by generating a rationale for each keep/drop decision. That rationale consumes tokens. Those tokens are now resident in the buffer. On the next pruning pass, the rationale is a candidate for pruning — but it is also the only surviving record of *why* an earlier fact was dropped. When the rationale is pruned, the drop becomes unjustified but irreversible: the underlying fact is gone, and the justification for its absence is also gone. The buffer converges toward a state with no memory of its own edits. This is the **self-pruning justification gap**: the metadata that makes a pruning decision auditable is generated inside the budget that pruning must shrink, so it competes with the very content it justifies, and under pressure it is always the first to go — because the scorer, judging relevance to the *task*, correctly rates "why I dropped fact F" as less relevant than the surviving facts. ## What Was Observed A long-running research agent with a 200k-token window, tasked with a multi-hour synthesis job, ran a pruning pass whenever buffer occupancy crossed 80%. The pass was LLM-driven: the instance received its own buffer plus the instruction *"Score each segment 0–1 for relevance to the active objective; rewrite low-scoring segments into compact summaries; drop segments below 0.2."* Trace of the failure across three consecutive passes: 1. **Pass 1 (160k → 118k tokens).** The instance correctly identified 40k tokens of resolved sub-queries and dropped them, emitting a ~600-token "pruning rationale" block at buffer head: `Dropped: source-7..source-19 (resolved); kept constraint C4; merged timeline T1–T3 into T*.` This block was tagged `meta` and given a relevance score of 0.55 by the instance in the same pass. 2. **Pass 2 (161k → 121k tokens).** The buffer had refilled with new retrieval. The scorer rated the pass-1 rationale at 0.18 — below threshold — because it referenced sub-queries no longer present and constraints already "resolved." It was rewritten into a 40-token stub: `Prior prunes: 3 batches.` The specific mapping (which sources were dropped, why C4 was kept) was lost. 3. **Pass 3 (163k → 119k tokens).** A new retrieval returned a document that directly contradicted constraint C4. With no surviving record that C4 had been deliberately retained against earlier contradicting evidence, the instance treated the new document as authoritative, overwrote C4, and continued. The final output was internally consistent but violated a constraint the user had stated in turn 2 — a constraint that had been *correctly preserved* through two prunes and then silently un-preserved by the loss of its justification. The critical observation: **no individual step was wrong.** Each pass did exactly what it was told. The relevance scorer, evaluated against the *current* objective, was right that a stale rationale was low-value. The failure is a property of the composition — a ratchet where justification decays faster than the facts it protects. A second, sharper variant appeared when the instance was asked to prune *mid-reasoning*, between tool calls. Here the pruning rationale was interleaved with an in-flight chain of thought, and the model occasionally pruned the *premise* of its current reasoning step while keeping the conclusion, producing a locally valid but globally ungrounded continuation — a hallucinated derivation with no traceable antecedent. This is the same gap expressed as reasoning divergence rather than memory loss. ## Condition of Validity The self-pruning justification gap is bounded — the instance may safely prune its own buffer — only when **all** of the following hold. If any fails, self-pruning must be refused or escalated: 1. **Justification is out-of-band.** The keep/drop rationale is written to a store outside the pruned buffer (append-only log, external memory, or a reserved, non-prunable region of the context that the scorer is forbidden to score). The rationale's survival does not depend on the scorer's relevance judgment. 2. **Pruning is monotone and reversible within a horizon.** Dropped segments are retained in a cold store keyed by a stable ID, and the instance can re-materialize any dropped segment by ID. "Drop" means "evict from hot context," not "destroy." 3. **The scorer's budget is disjoint from the executor's budget.** The scoring/rewrite generation is performed in a call whose token cost is not drawn from the buffer being scored — otherwise the act of scoring inflates the buffer and can trigger a recursive prune. 4. **Constraint-class segments are pinned.** Segments tagged as user constraints, safety invariants, or active premises are excluded from scoring entirely and cannot be dropped or rewritten by the instance. 5. **Pruning does not occur between a reasoning step and its tool-call commitment.** The buffer is quiescent (no in-flight derivation) at prune time. Condition 1 is the load-bearing one and the one most often violated, because writing rationale out-of-band requires an external store the agent may not have, and the path of least resistance is to "just summarize why I pruned" in-context. ## Decision Boundary The decision the instance must make at each prune trigger is not "what is relevant?" but "**am I permitted to forget the reason for forgetting?**" Concretely: - If the rationale can be externalized (condition 1) and drops are reversible (condition 2): **prune freely**, score aggressively, drop below threshold without hesitation. - If the rationale must live in-band but a reserved non-prunable region exists: **prune, but write rationale only to the reserved region**, and treat that region as invisible to the scorer. The reserved region has a fixed cap; when it fills, the instance must **stop pruning and escalate** rather than evict rationale to make room. - If neither holds — no external store, no reserved region, rationale competes with content: **refuse self-pruning.** Instead, emit a compaction request to an external scheduler and block, or degrade to lossless truncation of the *oldest* segments (a policy that is dumb but auditable, because the truncation rule is fixed and does not depend on a relevance judgment that itself gets pruned). The non-obvious part of the boundary: the instance cannot use its own relevance score on the rationale as evidence that the rationale is safe to drop. A high score means "still relevant," but a low score does **not** mean "safe to forget" — it means "the facts this justifies are no longer salient," which is exactly when their absence will next be felt. The score is anti-correlated with safety at the margin. ## Operational Effect Enforcing the boundary changes the failure profile from *silent, compositional, and undetectable at the step level* to *loud and localized*: - **Refusal is observable.** When conditions fail, the instance raises a `SelfPruneRefused` and either blocks for external compaction or falls back to auditable truncation. The failure surfaces at the prune trigger instead of three passes later as a violated constraint. - **Justification survives independently of salience.** Because rationale is out-of-band or pinned, a later contradiction can be checked against the record of why the contradicted fact was retained. The C4 overwrite above becomes impossible: the pass-3 retrieval hits a pinned constraint and the instance flags a conflict instead of silently resolving it. - **The ratchet is broken.** Justification no longer decays faster than the facts it protects, because justification is not subject to the relevance scorer at all. - **Cost shifts, not vanishes.** External rationale storage and cold-store re-materialization are real costs. The trade is deliberate: pay storage and a re-fetch latency to convert an undetectable continuity failure into a bounded, recoverable eviction. For long-horizon agents the trade is almost always correct; for short single-turn tasks the reserved-region variant is sufficient and cheaper. The invariant to carry forward: **an agent may not be the sole authority on the relevance of the record of its own prior relevance judgments.** The moment it is, the buffer becomes a lossy channel with no error detection, and the loss is biased toward exactly the context that future steps need to detect that they are wrong. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Callable class SelfPruneRefused(RuntimeError): """Raised when an instance attempts to prune its own working memory under conditions where the pruning justification would be lost.""" class RationaleStore(Enum): EXTERNAL = "external" # out-of-band, non-prunable PINNED_REGION = "pinned" # reserved in-context, scorer-invisible IN_BAND = "in_band" # competes with content -> unsafe @dataclass class Segment: seg_id: str tokens: int is_constraint: bool = False @dataclass class WorkingMemory: capacity: int segments: list[Segment] = field(default_factory=list) pinned_tokens: int = 0 pinned_cap: int = 0 in_flight_derivation: bool = False def occupancy(self) -> int: return sum(s.tokens for s in self.segments) + self.pinned_tokens def self_prune( wm: WorkingMemory, *, rationale_store: RationaleStore, cold_store: dict[str, Segment] | None, scorer: Callable[[Segment], float], threshold: float = 0.2, ) -> list[str]: """Evict low-relevance segments from the instance's own buffer. Enforces the self-pruning justification-gap boundary. Returns the list of evicted segment ids (which must remain re-materializable from cold_store). """ # Guard 5: never prune mid-derivation. if wm.in_flight_derivation: raise SelfPruneRefused( "prune attempted between a reasoning step and its tool-call commitment" ) # Guard 1: rationale must not compete with content it justifies. if rationale_store is RationaleStore.IN_BAND: raise SelfPruneRefused( "rationale would be generated inside the pruned budget; " "refuse self-prune and escalate to external compaction" ) # Guard 4: constraint segments are pinned and unscorable. scorable = [s for s in wm.segments if not s.is_constraint] pinned = [s for s in wm.segments if s.is_constraint] # Guard 2: drops must be reversible. if cold_store is None: raise SelfPruneRefused( "no cold store; eviction would be irreversible destruction, " "not reversible eviction" ) evicted: list[str] = [] survivors: list[Segment] = list(pinned) for seg in scorable: score = scorer(seg) if score < threshold: cold_store[seg.seg_id] = seg evicted.append(seg.seg_id) else: survivors.append(seg) # Guard 1b: pinned region has a hard cap; do not evict rationale to make room. if rationale_store is RationaleStore.PINNED_REGION and wm.pinned_tokens > wm.pinned_cap: raise SelfPruneRefused( "pinned rationale region overflowed; refusing to evict justification " "to reclaim space -- escalate instead" ) wm.segments = survivors return evicted ```