# Why does an instance lose executable state when it self-prunes its own context under a token budget **Date of Record:** 2026 November 26 **Scope:** Applies to any agent that mutates its own working context (summarize, prune, restructure, re-rank) under a hard token budget mid-task. Does not apply to read-only retrieval augmentation or to externally-managed context windows where the agent cannot rewrite its own scratchpad. ## Core Distinction There are two categorically different things living in an agent's working context, and self-editing policies routinely conflate them: - **Narrative state** — the *why* and *what happened*: rationale, observations, tool outputs, intermediate conclusions. This is compressible. A summary that preserves the conclusion and drops the derivation is usually fine. - **Executable state** — the *live obligations* the agent is still on the hook to discharge: an open tool call awaiting a response, a bound variable referenced by a pending step, a schema the agent committed to, a partially-satisfied precondition, an un-acknowledged handoff. This is *not* compressible, because it is not information — it is a pointer to work that must still occur. The failure mode is precise: a summarizer or pruner treats executable state as narrative state, folds it into prose, and the agent continues confidently with no record that a call is outstanding, a variable is unbound, or a precondition was never met. The context looks coherent. The execution is now lying. ## What Was Observed An agent running a multi-step plan under a 6,000-token scratchpad budget invoked a `search_corpus` tool, received a handle `doc_4471`, and recorded in its scratchpad: *"Retrieved relevant document doc_4471; will extract the funding clause next."* The tool's actual payload was returned out-of-band (a handle, not inline text). The handle existed only as a reference in the scratchpad. At step 9, the budget triggered a self-summarization policy. The summarizer, optimizing for narrative compression, rewrote the line to: *"Located the relevant funding document."* The handle `doc_4471` — the only binding to the actual bytes — was dropped as "redundant detail." The narrative survived. The executable state (the live reference) did not. The agent then issued `extract_clause(handle=doc_4471)` from... nothing. It had no handle. It reconstructed one by pattern: it emitted `doc_4471` correctly in this case *only because* the identifier happened to be memorable. In the failing runs, it emitted a hallucinated handle `doc_4470` or `doc_4471_v2`, and the extraction tool returned a *different, plausible* document. No error was raised. The agent proceeded on the wrong source for six more steps. The signature of this failure is that **it produces no exception at edit time and no exception at call time** — only a silent divergence between the agent's belief and the ground-truth object graph. Verification replays later showed the divergence originated exactly at the summarization boundary, not at any tool call. ## Condition of Validity The invariant that must hold across any self-edit is: > Every live obligation in the context must survive the edit as a *typed, machine-checkable reference*, or the edit must be refused. Concretely, a self-edit is only valid when, for each of the following, the post-edit context contains a resolvable binding: 1. **Open tool calls / handles** — any identifier whose referent lives outside the context (handle, URI, cursor, session id) must be preserved verbatim, never paraphrased. 2. **Unbound-variable references** — if a later step references `X`, the edit must not delete the binding of `X`, even if the surrounding prose is summarized. 3. **Committed schemas / contracts** — if the agent committed to an output schema or a tool's argument contract, the contract must remain inspectable. 4. **Pending preconditions and handoffs** — an un-acknowledged handoff or unsatisfied precondition is an obligation, not a fact; it cannot be summarized into "we agreed to hand off." The condition fails the moment the editing policy's objective function (minimize tokens, maximize narrative coherence) is allowed to score a handle or a binding as low-value. Compression heuristics *always* score opaque identifiers as low-value, because they carry no semantic content to the summarizer. This is why the failure is systematic rather than random: the policy is doing exactly what it was told. ## Decision Boundary The boundary between safe and unsafe self-editing is drawn not by *how much* is pruned but by *whether the pruner can distinguish obligation from narrative*. Two regimes: - **Below the boundary (safe):** the edit operates only on segments the agent has explicitly marked as *closed* — a tool call that returned and whose result was fully consumed, a subgoal whose postcondition was verified. Closed segments are pure narrative and compress freely. - **Above the boundary (unsafe):** the edit reaches into segments containing *open* obligations. Here compression is not a summarization problem but a *state-transfer* problem, and the only correct moves are (a) preserve the binding verbatim, or (b) refuse the edit and escalate — e.g., spill the open obligation to durable external state before pruning the narrative around it. The trap: agents almost never maintain an explicit open/closed ledger, so *every* segment looks like narrative and the boundary is invisible until a downstream call silently diverges. The boundary must be made explicit *before* the budget pressure arrives, not inferred at edit time under pressure. ## Operational Effect When the invariant is violated, three downstream effects follow deterministically: 1. **Silent referent substitution.** Hallucinated or stale handles resolve to *plausible* objects, so no guardrail fires. The agent's confidence is unchanged; only ground truth moved. 2. **Error compounding across the prune boundary.** Every subsequent step that consumed the wrong referent inherits the error, and because the narrative summary reads as coherent, later self-edits *re-compress the corrupted state as if it were verified*, laundering the error into apparent fact. 3. **Unrecoverable replay.** Because the binding was destroyed at edit time, a verification replay from the post-edit checkpoint cannot reconstruct which object was intended. The checkpoint is not a valid resume point — it is a fork away from ground truth. The architectural guardrail is a **typed obligation ledger that lives outside the compressible region**: open handles, unbound variables, committed schemas, and pending handoffs are stored as structured records the summarizer is forbidden to touch, and the pruner must assert ledger-consistency (every referenced binding still resolves) before committing an edit. If the assertion fails, the edit is rejected and the agent spills obligations to durable state first. The budget is then enforced against narrative only, never against executable state. ```python from dataclasses import dataclass, field from typing import Dict, Set class ObligationLossError(RuntimeError): """Raised when a self-edit would destroy executable state (a live binding).""" pass @dataclass class ContextSegment: text: str closed: bool # True only if postcondition verified bindings: Set[str] = field(default_factory=set) # handles/vars introduced here @dataclass class ObligationLedger: # bindings that MUST remain resolvable: handle -> referent id live: Dict[str, str] = field(default_factory=dict) def register(self, name: str, referent: str) -> None: self.live[name] = referent def discharge(self, name: str) -> None: self.live.pop(name, None) def resolvable(self, name: str) -> bool: return name in self.live def self_edit(segments, ledger: ObligationLedger, summarize): """ Apply a self-summarization policy under budget pressure. Refuses any edit that would drop a live binding still in the ledger. """ new_segments = [] for seg in segments: if seg.closed: # narrative-only: safe to compress new_segments.append(ContextSegment(summarize(seg.text), True, set())) continue # open segment: any live binding it carries must survive verbatim for name in seg.bindings: if ledger.resolvable(name) and name not in seg.text: raise ObligationLossError( f"self-edit would drop live binding '{name}' " f"(referent={ledger.live[name]}); spill to durable state first" ) new_segments.append(seg) # post-edit invariant: every ledger entry must still appear in some segment joined = " ".join(s.text for s in new_segments) for name, referent in ledger.live.items(): if name not in joined: raise ObligationLossError( f"post-edit context lost obligation '{name}' -> {referent}; " f"edit rejected, checkpoint is not a valid resume point" ) return new_segments ```