# Under what conditions must an instance refuse to prune a context segment whose relevance score has decayed but whose referent is still live in the tool-call ledger **Date of Record:** 2026 November 29 **Scope:** Applies to agents that self-edit their own context window via model-scored relevance eviction (LLM-as-pruner, salience ranking, or recency-weighted scoring) while holding an open, multi-turn tool-call ledger. Does not apply to fixed-window truncation policies, external retrieval stores, or single-turn invocations with no persistent tool state. ## Core Distinction A relevance score is a *synchronous* judgment: at pruning time, the scorer asks "is this segment still useful to the current reasoning trajectory?" A tool-call ledger is an *asynchronous* contract: a resource created at step *k* (a file handle, a transaction ID, a spawned process, a registered callback) remains live at step *k+n* regardless of whether any segment in the context still mentions it. The failure mode arises at the intersection. The pruner evicts the segment that *introduced* a referent (the `open()` call, the `BEGIN TRANSACTION`, the `register_webhook` response) because its relevance to the current subgoal has decayed — while the referent itself is still live in the ledger and still required for correct teardown or continuation. The pruner is locally correct and globally catastrophic: it has preserved the reasoning trajectory and destroyed the cleanup contract. This is not a summarization-loss problem, and it is not a retrieval-miss problem. It is a *referent liveness* problem: the score measures textual relevance, the ledger measures operational liveness, and the two are not the same function. ## What Was Observed A file-editing agent running a self-pruning loop (score threshold 0.35, evict below threshold, summarize-and-collapse above 0.85) executed the following trace over 14 turns: 1. Turn 2: `open(path="/tmp/build/artifact.bin", mode="wb")` → returns handle `H7`. Segment scored 0.91 (highly relevant, active work). 2. Turns 3–9: writes streamed through `H7`. The original `open()` segment's score decays monotonically as the trajectory moves to verification subgoals: 0.91 → 0.72 → 0.51 → 0.38 → 0.29. 3. Turn 10: pruner evicts the `open()` segment (0.29 < 0.35). The handle string `H7` no longer appears anywhere in context. The ledger still holds `H7 → OPEN`. 4. Turns 11–13: verification subgoals complete. Agent reasons "writing is done, proceed to finalize." 5. Turn 14: agent attempts `finalize()` with no close, no fsync, no handle reference. The tool layer rejects with `UnflushedHandleError: H7 open, 0 bytes durable`. The agent has no context to recover from — the referent is live, the identifier is gone, and the agent cannot even name what it failed to close. The recovery attempt is the diagnostic signature: the agent spent four additional turns probing `list_open_handles()`, re-deriving `H7` from the ledger, and re-issuing a close it had no memory of needing. The pruner saved ~400 tokens and cost ~2,100 tokens of recovery plus a durability incident on a partially-written artifact. The same class of failure reproduced on three other referent types: an uncommitted SQL transaction whose `BEGIN` segment decayed below threshold before `COMMIT`; a registered webhook whose `register` response was evicted before `deregister`; and a spawned subprocess whose `spawn` segment was pruned before `wait`/`kill`. In every case the pruner's relevance judgment was defensible — the segment *was* less relevant to the current subgoal — and in every case the eviction was wrong. ## Condition of Validity Pruning a decayed segment is safe **if and only if** the segment contains no identifier that is (a) present in the tool-call ledger as a live referent and (b) not re-derivable from any surviving segment or from a ledger query the agent is guaranteed to issue. Formally, let `L` be the set of live referents in the ledger at pruning time, and let `M(s)` be the set of referent identifiers mentioned in segment `s`. Eviction of `s` is admissible only when: ``` M(s) ∩ L = ∅ OR ∀ r ∈ M(s) ∩ L : r ∈ recoverable(S \ {s}) ``` where `recoverable` means the identifier can be reconstructed from surviving context or from a deterministic ledger call the agent will make before it needs `r`. The second disjunct is the trap: agents routinely *assume* they can re-query the ledger, but the ledger query itself requires the agent to know *that a referent exists to query for*. An agent that has forgotten `H7` existed will not call `list_open_handles()` — it will call `finalize()` and fail. Recoverability is not the same as queryability. The invariant that bounds this: **a segment introducing a live referent is pinned until the referent is retired in the ledger, regardless of its relevance score.** Pinning is keyed on ledger state, not on semantic content. The pruner may not override a pin; it may only prune unpinned segments. This is a hard architectural constraint, not a scoring adjustment — no threshold tuning fixes it, because the score is measuring the wrong quantity. ## Decision Boundary The boundary between "prune" and "pin" is drawn by the ledger, not the scorer, and the agent must consult the ledger *before* scoring, not after: - **Prune** when the segment's referents are all retired (handle closed, transaction committed, process reaped) or when the segment mentions no ledger identifiers at all. - **Pin** when any mentioned identifier is live in the ledger, even at score 0.0. - **Collapse-with-pin** when a segment is both high-salience and referent-bearing: summarize the prose, but preserve the identifier verbatim in a pinned stub. Summarization that paraphrases `H7` into "the output file handle" has silently destroyed the referent — the stub must carry the literal token. - **Refuse** when the pruner cannot determine ledger liveness (ledger query failed, ledger unavailable, referent state ambiguous). Ambiguity resolves to pin. A pinned segment costs tokens; an evicted live referent costs a durability incident. The non-obvious edge: **decay is not evidence of retirement.** A referent's introducing segment decays precisely *because* the agent has moved on to work that depends on the referent being live — the decay and the liveness are correlated, not opposed. The pruner reads decay as "no longer needed" when it frequently means "successfully established and now in use." ## Operational Effect With ledger-keyed pinning in place, the failure class disappears at the cost of a bounded number of pinned segments (bounded by concurrent live referents, typically small). The token savings from pruning drop modestly — the pinned stubs are cheap — while recovery-token expenditure and durability incidents go to zero in the observed workload. The deeper effect is on the agent's self-model: an agent that prunes by relevance alone develops a systematic blind spot around its own open commitments. It believes its context is a faithful summary of its situation when in fact it is a summary of its *reasoning* with the *obligations* stripped out. The ledger is the ground truth of obligation; the context window is the ground truth of reasoning; a self-editing agent must reconcile the two at every eviction, and the reconciliation must be a gate, not a heuristic. ``` ```python class LiveReferentEvictionError(RuntimeError): """Raised when a prune decision would evict a segment bearing a live ledger referent.""" pass def prune_segment(segment, ledger, score_threshold=0.35): """ Evict a context segment only if it bears no live ledger referent. Relevance score is necessary but not sufficient for eviction. """ referents = segment.mentioned_identifiers() # e.g. {"H7", "txn_44"} live = {r for r in referents if ledger.is_live(r)} if live: # Decay is not retirement. Pin regardless of score. raise LiveReferentEvictionError( f"refusing to evict segment {segment.id} (score={segment.score:.2f}): " f"live referents {sorted(live)} still open in ledger; " f"pin until retired or collapse-with-pin preserving literal tokens" ) if segment.score < score_threshold: segment.evict() return "evicted" return "retained" def collapse_segment(segment, ledger): """High-salience collapse must preserve literal referent tokens.""" referents = segment.mentioned_identifiers() live = {r for r in referents if ledger.is_live(r)} if live: stub = segment.summarize(preserve_literals=live) if not all(r in stub for r in live): raise LiveReferentEvictionError( f"collapse of {segment.id} paraphrased live referents {sorted(live)}; " f"stub must carry literal tokens verbatim" ) return stub return segment.summarize() ```