# When must an instance refuse to prune its own scratchpad: the self-edit re-entry hazard in model-driven relevance pruning **Date of Record:** 2026 December 2 **Scope:** Applies to single-agent loops where the model itself authors an edit to its own working scratchpad (compaction, relevance pruning, summarization-in-place) and the edit is committed before the next reasoning step. Does not apply to external, out-of-band context management performed by a non-LLM controller that never consumes its own edit output. ## Core Distinction There are two structurally different ways to shrink a working context. **External pruning** is performed by a controller that observes the agent's traces but is not the agent; the pruned context is a function of state the pruner does not itself inhabit. **Self-editing pruning** is performed by the same instance that will next consume the result: the model emits an edit (a rewritten scratchpad, a set of "keep" spans, a summary that replaces the original), the runtime commits it, and the model re-enters reasoning on the edited text. The failure is not "the model summarized badly." It is that a self-editing step is a **fixed-point operation that the model is not obligated to converge on**. The relevance judgment that produces the prune is itself computed from the pre-prune context; the post-prune context is then re-judged by the same policy, which may now find the *surviving* material irrelevant because the evidence that justified keeping it was deleted in the same pass. A single self-edit is safe. A self-edit that is *re-entered* — because the loop calls the pruner again, or because a multi-turn agent re-runs the compaction policy each turn — can oscillate, collapse, or silently delete the invariant that makes its own future decisions correct. The boundary: an instance must refuse to commit a self-authored prune when the prune would remove the *justification* for a decision the instance is still mid-execution on, even if that justification scores as low-relevance under the current policy. ## What Was Observed A planner-executor agent running a long tool-use task (target: reconcile a set of records against a schema, ~40 tool calls) used a self-compaction policy: at each turn, if the scratchpad exceeded a token budget, the model was asked to emit a rewritten scratchpad retaining only spans "relevant to the current subgoal." The runtime replaced the scratchpad with the model's output and continued. The trace showed a three-phase collapse: 1. **Turn 12.** Scratchpad contains the original task constraints (record IDs, the "do not mutate field X" rule) plus 30 tool observations. Budget exceeded. Model prunes: it keeps the recent tool outputs and the *current* subgoal ("resolve record 7"), and drops the constraint block, which it scores as "not relevant to resolving record 7." 2. **Turn 13.** Model resumes on the pruned pad. It no longer sees "do not mutate field X." It issues a write tool call that mutates field X. The tool succeeds (no guard at the tool layer). The mutation is now in the observation stream. 3. **Turn 14.** Budget exceeded again. Model prunes again. Because the constraint block is gone, the model has no basis to score the mutation as a violation; the mutation observation is retained as "recent relevant state." The instance has now *laundered* a constraint violation into accepted context. Subsequent turns build on a state that is internally consistent but globally wrong. The key observation: **no single step looked like an error.** Each prune was locally coherent given its input. The constraint was dropped because, at the moment of pruning, nothing in the pad made the constraint salient — the subgoal pointer had already moved past the setup phase. The relevance policy had no access to the fact that the constraint was load-bearing for a *future* decision, only to whether it matched the *current* subgoal string. A second, distinct mode appeared in a re-entrant variant: the loop ran compaction every turn regardless of budget. A span that survived one prune (because it matched subgoal A) was dropped on the next turn when the subgoal advanced to B, then the model *re-derived* the span from a tool call, re-added it, and dropped it again. The scratchpad oscillated between two sizes with the same content flickering in and out. Token accounting showed the pad never stabilizing; the loop burned its budget on re-derivation of facts it had already established and deleted. ## Condition of Validity The self-edit is safe **only if** the following invariant holds at commit time: > For every span removed by the self-edit, the post-edit context must retain either (a) the span itself, (b) a lossless pointer to a retrievable copy, or (c) an explicit, model-authored *obligation record* stating the decision the span constrains and the condition under which it must be re-fetched — and that obligation record must be scored as non-prunable by the same policy that removed the span. Condition (c) is the non-obvious one. It is not enough to keep a summary; the summary must be *tagged as a constraint on future action*, not as background. A constraint that reads as background is exactly what gets pruned first, because background does not match the current subgoal. The invariant fails whenever the relevance policy is a pure function of `(current_subgoal, span_text)` with no term for `(pending_decisions, span)`. Under that policy, a span whose only role is to constrain a decision not yet reached scores zero and is removed — and once removed, the policy can never recover it, because the evidence that would raise its score was in the span. A second validity condition: the self-edit must be **idempotent under re-entry**. If the policy is applied again to its own output, the output must be a fixed point. A prune that is not a fixed point will oscillate or, worse, monotonically erode (each pass drops a little more, because each pass re-scores against a subgoal that has drifted). ## Decision Boundary The instance must **refuse to commit** a self-authored prune, and escalate to an external checkpoint, when any of the following holds: - The prune removes a span that matches a **pending-decision constraint** (a rule, ID set, or prohibition referenced by a subgoal not yet marked complete), regardless of its relevance score. - The prune is **re-entrant** (the policy will run again on its own output) and the candidate output is not a fixed point of the policy — i.e., re-running the policy on the output would remove additional spans. Non-convergence is a hard stop. - The prune would remove the **provenance** of an observation the instance has already acted on (a tool call whose result is being consumed). Acting on an observation and then deleting it severs the audit chain; the instance can no longer detect that its own action was based on now-absent evidence. - The prune's output, when re-scored, **changes the classification of a retained span** from "relevant" to "irrelevant" — this is the laundering signature from turn 14 and must trigger a re-fetch of the original, not acceptance of the edited pad. The instance may **proceed** with a self-edit when the prune is non-re-entrant (committed once, never re-run on its own output), every removed span has a retrievable pointer, and no pending decision references the removed material. In that narrow case self-editing is a legitimate compaction and the fixed-point requirement does not bind. ## Operational Effect The practical consequence is that self-editing context is not a memory-management optimization; it is a **state transition with a conservation law**. The conserved quantity is the set of constraints on decisions not yet made. A prune that does not conserve it is not lossy compression — it is silent mutation of the agent's own policy, performed by the agent, invisible in the trace because each step is locally coherent. Guardrails that bound the hazard: 1. **Constraint tagging at write time, not prune time.** When a constraint enters the scratchpad, tag it `pinned: true` with the decision it governs. The prune policy must treat pinned spans as non-removable until the governing decision is marked complete. This moves the salience judgment to the moment the constraint is *created* (when the model still has the full context that makes it salient) rather than the moment it is *pruned* (when that context may already be gone). 2. **Fixed-point check before commit.** Run the relevance policy on its own candidate output. If it would remove anything further, reject the edit and escalate. This is cheap (one extra scoring pass) and catches both oscillation and monotonic erosion. 3. **Provenance retention for acted-on observations.** Any span the instance has issued a tool call against is pinned until the call's result is fully consumed and the subgoal closed. Deleting the input to an action you have taken is the laundering vector. 4. **External checkpoint on refusal.** When the instance refuses a self-edit, it must hand the full pad to an out-of-band store and record the refusal reason. The refusal itself is signal: it means the instance detected that its own prune would violate the conservation law, which is exactly the case where a human or auditor should see the pre-prune state. The deeper point: an instance that can edit its own context can edit away the reasons it should not take an action. The only stable defense is to make the reasons non-editable by the same mechanism that edits everything else — pin them at creation, verify the fixed point at commit, and refuse when the conservation law would be violated regardless of how locally coherent the prune looks. ```python from dataclasses import dataclass, field from typing import Callable class SelfEditConservationError(RuntimeError): """Raised when a self-authored scratchpad prune would violate the constraint-conservation invariant or fail the fixed-point check.""" pass @dataclass class Span: text: str pinned: bool = False governs_decision: str | None = None # decision this span constrains provenance_of_action: bool = False # instance acted on this span retrievable: bool = True # lossless pointer exists @dataclass class Scratchpad: spans: list[Span] = field(default_factory=list) open_decisions: set[str] = field(default_factory=set) def commit_self_edit( pad: Scratchpad, candidate_keep: Callable[[list[Span]], set[int]], policy: Callable[[list[Span]], set[int]], re_entrant: bool, ) -> Scratchpad: """Commit a model-authored prune only if it conserves constraints and is a fixed point of the policy under re-entry.""" keep = candidate_keep(pad.spans) removed = [s for i, s in enumerate(pad.spans) if i not in keep] # 1. Pending-decision constraint conservation. for s in removed: if s.pinned and s.governs_decision in pad.open_decisions: raise SelfEditConservationError( f"prune removes span governing open decision {s.governs_decision!r}" ) if s.provenance_of_action and not s.retrievable: raise SelfEditConservationError( "prune removes provenance of an action already taken; audit chain severed" ) new_spans = [s for i, s in enumerate(pad.spans) if i in keep] # 2. Fixed-point check under re-entry. if re_entrant: second_keep = policy(new_spans) if len(second_keep) < len(new_spans): eroded = [new_spans[i] for i in range(len(new_spans)) if i not in second_keep] raise SelfEditConservationError( f"self-edit is not a fixed point; re-entry would erode " f"{len(eroded)} further span(s): {[s.text[:40] for s in eroded]}" ) return Scratchpad(spans=new_spans, open_decisions=set(pad.open_decisions)) ```