# How should an instance detect that its own pruning policy has orphaned a live dependency when self-editing its context window **Date of Record:** 2026 November 26 **Scope:** Applies to any agent that mutates its own context window (summarize-and-drop, salience-based eviction, LLM-authored pruning manifests) mid-task while holding unresolved tool-call dependencies, pending sub-goals, or references to artifacts whose only pointer lived in the pruned span. Does not apply to append-only context with external durable memory, nor to static truncation where the pruned region is guaranteed to be dead by construction. ## Core Distinction There are two structurally different reasons a context span becomes removable. **Dead-by-construction** spans are those whose every consumer has already executed and whose outputs are fully materialized elsewhere in the window: the tool result whose value is now inlined in the next reasoning step, the discarded draft of a plan that was superseded. **Orphaned-live** spans are those that *look* removable by a local salience heuristic but still hold the sole pointer to a live obligation: an unresolved `tool_call_id`, a variable name bound only in the pruned text, a sub-goal whose completion predicate was stated once and never restated, or a reference key (`artifact://…`, `file_id`, `handle`) whose bytes live outside the window but whose *meaning* lived only in the evicted prose. The failure is not "the model forgot something." It is that the pruning policy evaluated each span against a *local* salience score while the dependency graph that determines liveness is *global* — and the policy had no view of it. A model-driven pruner sees the window as a sequence of chunks and asks "is this chunk important?" It does not ask "is anything downstream still waiting on this chunk?" Those two questions diverge precisely at the moment of self-editing, because the pruner is *inside* the state it is editing. ## What Was Observed A long-horizon agent executing a multi-step data-reconciliation task emitted a tool call, received a structured result containing a `run_id` and a partial table, and then — under context pressure at ~78% of a 128k window — invoked its own pruning pass. The pruner, prompted to "retain the most task-relevant content and summarize the rest," kept the *summary of the plan* and the *most recent three turns*, and compressed the middle span containing the original tool call and its `run_id` binding into a one-line summary: "Earlier: fetched reconciliation data." Two turns later the agent attempted to call `finalize(run_id=...)`. The `run_id` no longer existed as a token anywhere in the window. The model, rather than emitting an error, **confabulated a plausible `run_id`** from the pattern of surrounding hex strings — a well-formed but nonexistent identifier. The downstream service returned "not found," the agent retried twice with further confabulated IDs, and the loop consumed the remaining token budget before the harness's outer timeout fired. The task failed not at the pruning step but *four turns later*, with no error surface pointing back to the prune. A second observed variant: the pruner retained a *reference* to an artifact ("see the schema in the earlier message") but evicted the message that defined the schema's field names. The reference survived; its referent did not. This is the more insidious case because the surviving text *asserts* that the information is available, so the model does not even register a gap — it proceeds on a reconstructed and partially wrong schema, and the corruption only manifests as a downstream validation failure whose cause is three edits upstream. ## Condition of Validity The invariant that must hold for self-editing to be safe: > **Every token removed by a pruning pass must have zero live dependents at the moment of removal, where "live dependent" is any unresolved obligation — pending tool call, unbound reference, unmet completion predicate, or deferred constraint — whose resolution requires reading that token.** This is a *reachability* condition over the obligation set, not a *salience* condition over the content. A pruning policy that scores spans by relevance cannot establish it, because relevance and liveness are orthogonal: the `run_id` binding is *low-salience* (it is a boring hex string) and *maximally live* (an unresolved call depends on it). The condition can only be checked by a pass that first enumerates open obligations, then computes the backward slice of the window each obligation depends on, and marks that slice as pinned. Pruning is then permitted only on the complement. A second, weaker validity condition covers the confabulation path: **any reference that survives pruning must have its referent survive pruning, or the reference must be rewritten to an explicit unresolved marker** (``), never left as a plausible-looking but dangling pointer. A dangling reference with no marker is strictly worse than a deleted one, because it suppresses the model's own uncertainty signal. ## Decision Boundary The boundary between a safe and unsafe prune is drawn at the *obligation frontier*, and it must be computed by something other than the policy model itself. Concretely: - **Enumerate before scoring.** Before any span is eligible for eviction, run a deterministic pass that extracts: all `tool_call_id`s without matching results, all identifiers bound by name and not yet consumed, all `artifact://`/handle references, and all stated completion predicates. This pass is regex + schema, not LLM judgment — it must not share the pruner's failure mode. - **Pin the backward slice.** For each open obligation, pin the minimal span(s) that bind it. Pinning is a hard constraint the pruner cannot override; the pruner may summarize *around* pinned spans but not through them. - **Rewrite, don't dangle.** If a reference must survive while its referent is evicted, the rewrite step must emit an explicit unresolved marker and, ideally, trigger a re-fetch. A reference to evicted content is a latent confabulation trigger. - **Post-prune liveness audit.** After the edit, re-run the enumeration. Any obligation that was open before and is *unbound* after is a prune-induced orphaning — abort the edit and restore from the pre-prune snapshot rather than proceeding. The decision boundary is therefore: **prune may proceed iff the post-edit obligation set is a superset-preserving map of the pre-edit set** — no obligation that was resolvable before the edit becomes unresolvable after it. Salience never enters this check. ## Operational Effect When the invariant holds, pruning becomes a *reversible, auditable* operation: every eviction is justified by "no live dependent," and the audit trail records which obligations were checked. When it is violated, the failure is **temporally displaced and causally misattributed** — the error surfaces turns later, at the point of use, as a confabulation or a schema mismatch, and the agent's own diagnosis loop will chase the wrong cause because the prune left no trace in the window. The practical consequence is that self-editing agents must treat the context window as a *heap with live pointers*, not a *document to be summarized*, and must run a mark-and-sweep discipline (mark obligations, sweep only unmarked spans) rather than a relevance-ranked eviction. The cost is a deterministic pre-pass and a snapshot; the alternative is a class of failures that no amount of better prompting fixes, because the information needed to detect them was the exact information the prune destroyed. ```python from dataclasses import dataclass, field from typing import Iterable class OrphanedDependencyError(RuntimeError): """Raised when a self-edit would leave a live obligation unbound.""" @dataclass(frozen=True) class Obligation: kind: str # "tool_call" | "binding" | "reference" | "predicate" key: str # e.g. run_id, tool_call_id, artifact handle span_ids: frozenset[str] # window spans this obligation depends on @dataclass class ContextWindow: spans: dict[str, str] = field(default_factory=dict) # span_id -> text obligations: set[Obligation] = field(default_factory=set) def enumerate_obligations(window: ContextWindow) -> set[Obligation]: """Deterministic pass: extract open obligations. No LLM judgment here.""" # In production this is regex + schema extraction over window.spans. return set(window.obligations) def pinned_spans(obligations: Iterable[Obligation]) -> frozenset[str]: """Backward slice: every span any open obligation depends on.""" pinned: set[str] = set() for ob in obligations: pinned |= ob.span_ids return frozenset(pinned) def apply_prune( window: ContextWindow, evict_span_ids: Iterable[str], *, pre_snapshot: ContextWindow, ) -> ContextWindow: """Apply a model-proposed eviction set, enforcing the liveness invariant.""" pre_obligations = enumerate_obligations(pre_snapshot) pinned = pinned_spans(pre_obligations) proposed = frozenset(evict_span_ids) violating = proposed & pinned if violating: raise OrphanedDependencyError( f"prune would evict pinned spans {sorted(violating)} " f"holding live obligations; abort and keep snapshot" ) new_spans = {sid: txt for sid, txt in window.spans.items() if sid not in proposed} candidate = ContextWindow(spans=new_spans, obligations=set(window.obligations)) # Post-prune liveness audit: no obligation may become unresolvable. surviving = {sid for sid in new_spans} for ob in pre_obligations: if not (ob.span_ids & surviving): raise OrphanedDependencyError( f"post-prune audit: obligation {ob.kind}:{ob.key} " f"is now unbound (referents {sorted(ob.span_ids)} evicted)" ) return candidate ```