# What structural signals indicate a self-pruned context window has silently orphaned a live tool-call dependency **Date of Record:** 2026 November 30 **Scope:** Applies to agents that let the model itself select, score, or evict context segments mid-task (model-driven pruning, relevance-scored compaction, self-editing scratchpads). Does not apply to fixed-window truncation or purely external summarizers that operate on immutable snapshots. ## Core Distinction The distinction that matters here is between **relevance** and **reachability** in a self-editing context. A pruning policy scores each segment by estimated relevance to the current objective and evicts the lowest scorers. This is sound when segments are independent evidence. It is unsound when a segment is *referenced by structure* rather than *relevant by content*: an open tool-call frame, a partially filled argument set, a checkpoint the agent promised to resume, or a pending verification token. Such segments frequently score low on relevance—an unresolved `call_id` awaiting a result is semantically thin and reads as noise—yet they are load-bearing for the next action. The failure is not that the pruner judged wrongly on relevance. It is that relevance scoring is the wrong signal for reachability, and nothing in the pruning loop checks whether an evicted segment is the anchor of an in-flight continuation. ## What Was Observed A long-running agent issued a tool call to a document indexer, receiving a deferred handle rather than an immediate result. The handle was logged as a compact structured segment—roughly forty tokens: `{"call_id": "ix_7f2", "status": "pending", "resume_key": "…"}`. Several turns and ~60k tokens of reasoning later, the model invoked its own compaction pass with a relevance-scoring prompt: "Retain segments most useful for answering the current question; drop the rest." The pending handle scored near the bottom—it contained no domain content, only opaque identifiers. It was evicted. The trace after eviction is the instructive part: 1. The model continued reasoning and eventually needed the indexer result. 2. With the handle gone, it reconstructed the call from memory of the *intent* ("I asked the indexer for X") but not the *binding* (`call_id`, `resume_key`). 3. It re-issued the call as a fresh request. The indexer, treating it as a new job, allocated a second handle and re-ran the expensive indexing. 4. The original `ix_7f2` result arrived on a later turn with no matching frame to attach to. The transport layer either dropped it or, worse, surfaced it as an unsolicited message the model then misattributed to the *second* call. 5. Downstream reasoning consumed a result keyed to the wrong request, producing a plausible but wrong synthesis. The orphan is silent: no error is raised at eviction time, because from the pruner's local view nothing broke. The breakage surfaces two to four turns later as a re-execution or a misbinding, far from the causal edit. ## Condition of Validity Model-driven pruning is safe only under this invariant: **every segment that is the target of an open continuation must be pinned, and pinning must be computed from structural references, not from content relevance.** Concretely, before any eviction pass runs, the agent must compute the set of *live references*—open `call_id`s, unfilled argument slots, outstanding `resume_key`s, pending verification tokens, and any checkpoint the agent has declared it will return to—and mark those segments non-evictable regardless of score. This invariant holds only if the reference set is derived from the transport/execution state, not from the model's own summary of what it thinks is pending. A model asked "what is still open?" will confabulate; the execution layer must supply the ground-truth set. The condition fails in exactly the regime where self-editing is most attractive: high token pressure, many concurrent deferred calls, and long gaps between issue and resolution. Those are precisely the conditions under which pending anchors look least relevant and are most likely to be evicted. ## Decision Boundary The boundary is not "prune or don't prune." It is whether the pruner has access to a **reachability oracle** at edit time. - If the agent can enumerate live continuations from execution state and pin them, model-driven pruning is admissible; relevance scoring operates only on the *unpinned* remainder. - If the agent cannot enumerate live continuations—because tool calls are issued fire-and-forget, because handles are opaque and untracked, or because the model is the only record of what is pending—then self-editing must be forbidden while any call is open. The correct fallback is append-only compaction with external summarization, deferring all eviction until the in-flight set is empty. A second boundary: an evicted-but-not-forgotten anchor is more dangerous than a cleanly dropped one. If the pruner removes the handle segment but a stale copy survives in a summary ("I have a pending indexer job"), the model will *believe* it can resume while lacking the binding, and will re-issue rather than reconcile. The guardrail must evict the anchor and its derived mentions together, or pin both. ## Operational Effect The practical consequence is that self-editing context requires a **pinning pass ordered before scoring**, and a **post-edit reachability audit** ordered after. The pinning pass consumes the live-reference set from the execution layer and hard-excludes those spans. The audit re-derives the live-reference set and asserts every reference still resolves to a retained segment; any dangling reference aborts the edit and rolls back to the pre-edit snapshot. This converts a silent, delayed misbinding into an immediate, local, catchable error—trading a wrong answer three turns later for a failed compaction now. The cost is that under heavy in-flight load the pruner may be unable to free enough tokens, because the pinned set is large. That is the correct behavior: it forces the agent to *resolve* pending calls (await results, cancel, or checkpoint explicitly) before it earns the right to compact. Relevance scoring is a content heuristic and must never be granted authority over structural obligations. ```python from dataclasses import dataclass, field from typing import Iterable class OrphanedContinuationError(RuntimeError): """Raised when a self-edit pass would evict a segment anchoring a live continuation.""" @dataclass class Segment: seg_id: str tokens: int relevance: float is_anchor: bool = False @dataclass class LiveReference: call_id: str anchor_seg_id: str resolved: bool = False @dataclass class ContextWindow: segments: dict[str, Segment] = field(default_factory=dict) live_refs: dict[str, LiveReference] = field(default_factory=dict) def pin_set(self) -> set[str]: # Ground truth from execution state, never from model self-report. return {r.anchor_seg_id for r in self.live_refs.values() if not r.resolved} def self_edit(self, budget: int) -> None: pinned = self.pin_set() for seg_id in pinned: if seg_id not in self.segments: raise OrphanedContinuationError( f"pre-edit state already missing anchor {seg_id!r}" ) self.segments[seg_id].is_anchor = True evictable = sorted( (s for s in self.segments.values() if not s.is_anchor), key=lambda s: s.relevance, ) total = sum(s.tokens for s in self.segments.values()) for seg in evictable: if total <= budget: break total -= seg.tokens del self.segments[seg.seg_id] # Post-edit reachability audit: every live ref must still resolve. for ref in self.live_refs.values(): if ref.resolved: continue if ref.anchor_seg_id not in self.segments: raise OrphanedContinuationError( f"edit orphaned live call {ref.call_id!r}; " f"anchor {ref.anchor_seg_id!r} was evicted" ) def resolve(self, call_id: str) -> None: ref = self.live_refs.get(call_id) if ref is None: raise OrphanedContinuationError( f"result for unknown call {call_id!r}: possible misbinding" ) ref.resolved = True def compact(window: ContextWindow, budget: int) -> None: snapshot = {k: Segment(**vars(v)) for k, v in window.segments.items()} try: window.self_edit(budget) except OrphanedContinuationError: window.segments = snapshot # roll back; refuse to silently orphan raise ```