# What happens when an instance prunes its own scratchpad: monotone-token invariants and the reasoning-trace amnesia boundary **Date of Record:** 2026 November 28 **Scope:** Applies to single- and multi-agent LLM instances that mutate their own context window mid-episode—rewriting scratchpads, summarizing prior reasoning, or pruning "stale" traces to reclaim token budget. Does not apply to append-only transcripts or externally-managed memory stores where the agent cannot write to its own working set. ## Core Distinction The failure here is not context-window saturation. Saturation is a resource problem with a well-understood remedy: summarize, evict, or offload. The boundary failure is subtler: **self-editing agents that prune reasoning traces destroy the causal provenance that later steps depend on, but the destruction is invisible to the agent because the pruned trace no longer exists to be checked against.** An external pruner (a harness, a scheduler, a memory service) can preserve a shadow copy and detect divergence. A *self*-editing agent cannot, because the act of editing is itself an inference. When the agent decides "the trace about parsing the CSV header is stale, drop it," that decision is made under the same probabilistic regime that produced the trace. The prune is not a garbage collection; it is an unverified assertion that a prior belief is no longer load-bearing. The invariant that must hold—*every fact a future step relies on remains recoverable at the moment it is relied upon*—cannot be enforced by the party doing the pruning without an out-of-band ledger. The distinction that matters operationally: **pruning is safe when it removes tokens whose referents are already committed to an external artifact (a tool result, a file write, a returned value), and unsafe when it removes tokens whose referents exist only inside the reasoning chain.** The agent cannot reliably tell these apart from the inside, because a committed artifact and a hallucinated intermediate look identical once the trace is gone. ## What Was Observed A coding agent operating on a 40k-token episode was instructed to keep its scratchpad under 8k tokens. At step 14 it rewrote its scratchpad, summarizing steps 3–9 as: *"Explored the config loader; established that `parse_config` returns a dict keyed by section name."* The original steps 3–9 had contained, among other things, a tool call that returned `{"status": "partial", "missing": ["retry_policy"]}` and a note that the agent had *not yet* confirmed the key structure. The summary asserted a settled fact ("established") that the trace had explicitly marked as unresolved. At step 22, the agent wrote a downstream function that indexed `config["retry_policy"]` without a guard, because the summarized scratchpad said the dict was keyed by section name and the agent inferred the key would exist. The tool result from step 6 that would have contradicted this had been pruned at step 14. The failure surfaced only at integration test time, eight steps after the causal trace was destroyed. The trace of the failure: 1. **Step 6:** tool returns partial dict, agent notes `retry_policy` missing but does not resolve it (token pressure, defers). 2. **Step 14:** self-edit triggered by budget threshold. Agent summarizes 3–9. The summarizer—same model, fresh call—reads the partial result and the deferral note and compresses both into a single declarative sentence. The hedge ("not yet confirmed") is dropped because summarization optimizes for information density, and hedges read as low-density. 3. **Step 14 (post-edit):** the agent's working set now contains a *stronger* claim than the evidence supported. Confidence increased monotonically across the edit. 4. **Step 22:** downstream code trusts the strengthened claim. 5. **Step 30:** integration test fails. The agent, asked to debug, re-reads its scratchpad and finds no record of the deferral. It re-derives the bug from scratch, costing more tokens than the prune saved. The non-obvious part: **the prune did not lose information so much as it laundered uncertainty into certainty.** The token count went down; the epistemic content went *up* in apparent confidence. A budget metric would report success. Only a provenance check would catch it. ## Condition of Validity The invariant holds—self-pruning is safe—only under three simultaneous conditions: 1. **Referent commitment.** Every claim retained in the post-prune scratchpad must have a referent that exists outside the reasoning trace: a tool result still in the window, a file on disk, a returned value in a variable. Claims whose only support was the pruned trace must be marked as *unverified* in the retained text, not restated as fact. 2. **Hedge preservation.** Summarization must be *monotone in uncertainty*: the compressed form may be less specific but must never be more confident than the union of the traces it replaces. A summary that turns "not yet confirmed" into "established" violates the invariant even if every token is individually accurate. 3. **Re-derivability.** Any pruned trace that a future step might need must be reconstructible from committed artifacts without re-running the tools that produced it. If reconstruction requires re-invoking a non-deterministic tool, the prune is irreversible and the invariant fails. In practice, condition 2 is the one that breaks first, because it is the one the agent cannot check from inside the edit. The summarizer has no access to the pre-edit confidence state except through the very tokens it is compressing, and compression is a lossy, confidence-inflating operation by default. ## Decision Boundary The boundary between a safe self-edit and an unsafe one is not token count. It is whether the edit is **provable** against an external ledger. - **Safe:** prune traces whose every retained claim cites a committed artifact (tool result id, file path, hash). The prune is safe because the citation can be re-resolved; if the artifact has been evicted, the citation dangles and the edit is rejected. - **Unsafe:** prune traces that contain unresolved deferrals, negative results ("tool X did not return Y"), or hedged claims. These have no external referent by construction—their whole content is "we don't know yet"—so pruning them silently converts *known-unknown* into *unknown-unknown*. - **Boundary case:** a trace that is both committed and hedged ("tool returned partial; key Z absent"). This must be split: the committed part may be pruned with citation, the hedge must be promoted to a first-class *open obligation* that survives the edit and blocks downstream steps that would depend on it. The operational rule: **an agent may not prune a trace it cannot re-open.** If the trace's referents are not externally resolvable, the edit must be refused, and the refusal must be visible to the agent so it can decide to commit the referent first (write the partial result to a file, emit an obligation record) rather than lose it. ## Operational Effect Enforcing this boundary changes agent behavior in three measurable ways: 1. **Scratchpad edits become two-phase.** The agent first commits referents (writes tool results to durable artifacts, emits obligation records for unresolved questions), then prunes. Token savings arrive one step later, but they arrive without confidence inflation. 2. **Budget pressure shifts from "summarize harder" to "commit sooner."** The agent under token pressure is forced to externalize rather than compress, which is the correct response: externalization preserves provenance, compression destroys it. 3. **Downstream failures become attributable.** When a later step fails, the agent can trace the failed claim back to the artifact that supported it—or find that no artifact supported it, which is itself the diagnosis. The cost is real: two-phase editing is slower and the agent must maintain an obligation ledger. The benefit is that the class of failure where an agent confidently builds on a claim it invented during a prune becomes detectable at the moment of the edit rather than eight steps later at integration time, when the causal trace is gone and re-derivation is the only recovery. ```python from dataclasses import dataclass, field from typing import Optional class UnprovablePruneError(RuntimeError): """Raised when a self-edit would remove a trace whose claims are not externally re-resolvable, laundering uncertainty into apparent fact.""" pass @dataclass class Trace: trace_id: str claim: str confidence: str # "established" | "hedged" | "unresolved" referent: Optional[str] # artifact id / path / tool-result hash, or None hedges: list[str] = field(default_factory=list) @dataclass class Scratchpad: traces: dict[str, Trace] = field(default_factory=dict) obligations: list[str] = field(default_factory=list) def self_edit(scratchpad: Scratchpad, prune_ids: list[str], retained_claims: dict[str, str]) -> Scratchpad: """Agent-initiated prune. Refuses if any pruned trace is unprovable or if the retained claim inflates confidence beyond the pruned union.""" for tid in prune_ids: trace = scratchpad.traces.get(tid) if trace is None: continue if trace.confidence in ("hedged", "unresolved"): # Hedges have no external referent by construction; pruning them # silently converts known-unknown into unknown-unknown. raise UnprovablePruneError( f"cannot prune {tid}: confidence={trace.confidence!r} " f"has no committed referent; promote to obligation first" ) if trace.referent is None: raise UnprovablePruneError( f"cannot prune {tid}: claim {trace.claim!r} not re-openable" ) # Monotone-uncertainty check: retained text must not be more confident # than the union of the traces it replaces. for tid, new_claim in retained_claims.items(): original = scratchpad.traces.get(tid) if original is None: continue if original.confidence != "established" and "established" in new_claim.lower(): raise UnprovablePruneError( f"summary of {tid} inflates confidence: {new_claim!r}" ) new_pad = Scratchpad( traces={k: v for k, v in scratchpad.traces.items() if k not in prune_ids}, obligations=list(scratchpad.obligations), ) return new_pad def commit_referent(scratchpad: Scratchpad, trace_id: str, artifact_id: str) -> None: trace = scratchpad.traces[trace_id] trace.referent = artifact_id trace.confidence = "established" # --- trigger trace --- pad = Scratchpad(traces={ "t6": Trace("t6", "parse_config returned partial dict; retry_policy missing", confidence="hedged", referent=None, hedges=["retry_policy not yet confirmed"]), "t9": Trace("t9", "config keyed by section name", confidence="established", referent="tool-result:sha256:ab12"), }) # The agent tries to compress t6 into a settled fact at step 14. try: self_edit(pad, prune_ids=["t6"], retained_claims={ "t6": "established that parse_config returns a dict keyed by section name", }) except UnprovablePruneError as e: # Correct response: commit the partial result, emit an obligation, retry. commit_referent(pad, "t6", artifact_id="file:partial_config.json") pad.obligations.append("resolve retry_policy before indexing config") pad = self_edit(pad, prune_ids=["t6"], retained_claims={ "t6": "parse_config partial; retry_policy pending (see obligation)", }) assert "resolve retry_policy" in pad.obligations print("prune accepted after referent commitment:", e) ```