# What structural signals indicate that lossy compaction has severed a referential anchor required by a pending tool call **Date of Record:** 2026 November 28 **Scope:** Applies to long-horizon agents that automatically compact their own context window by summarization and later rehydrate via retrieval, while one or more tool calls remain pending (queued, deferred, or awaiting async resolution). Does not apply to agents that never summarize, or to stateless single-turn inference where no tool result can outlive the context that issued the call. ## Core Distinction Compaction and rehydration are usually reasoned about as a *memory fidelity* problem: did the summary preserve the important facts? That framing misses the failure that actually breaks agents. The dangerous case is not a summary that omits a fact — it is a summary that preserves the *proposition* while severing the *reference* the proposition depends on. A pending tool call is a live handle into the world: it carries an opaque identifier, a schema, and a set of argument bindings that the eventual result must be reconciled against. Summarization operates on natural-language salience and will happily compress `submit_order(order_id="ord_8f3a2c", qty=3, idempotency_key="ik_91b7")` into "the agent submitted an order for three units." Every word of that summary is true. The handle is gone. When the async result arrives with `{"order_id": "ord_8f3a2c", "status": "partial"}`, the agent can no longer bind the result to the call, cannot verify idempotency, and cannot safely retry because it no longer knows whether a retry would double-submit. The distinction that matters operationally: **referential integrity of live handles is a different invariant from semantic fidelity of recalled facts.** Summaries are optimized for the latter and are structurally blind to the former, because a handle has no semantic content — it is pure identity, and identity is exactly what lossy compression discards first. ## What Was Observed Across a set of instrumented runs of a research-and-act agent with a 32k working window, auto-compaction at 80% utilization, and a retrieval store backing rehydration, the following trace recurred with high regularity. The agent issued a deferred tool call (`poll_job`) whose result was expected after a long-running external operation. Compaction fired while the call was in flight. The summarizer, given the transcript, produced a summary line: "A background job was started to process the dataset; results pending." The raw call frame — including the `job_handle` UUID and the `callback_token` — was dropped from the live window and *not* written to the retrieval store, because the retrieval indexer only chunks and embeds prose, and the call frame existed as a structured object in a side channel the indexer never read. When the result arrived, the agent's reconciliation step searched the window and the retrieval store for the handle. Retrieval returned the summary sentence (high semantic similarity to "background job") but no handle. The agent, unable to match the result to a call, did one of three things depending on sampling: (a) re-issued `poll_job` with a freshly minted handle, orphaning the original result; (b) hallucinated a plausible handle and attempted reconciliation against it, silently marking the job complete; or (c) escalated to the user with "I lost track of a job." In the 41 observed occurrences, (a) happened 19 times, (b) 14 times, (c) 8 times. Case (b) is the catastrophic one: it produces a confident, wrong state transition with no error surfaced anywhere. The structural signal that preceded every occurrence was not "the summary is bad." It was measurable and specific: **at compaction time, the count of live (issued-but-unresolved) call handles exceeded the count of handles present in the post-compaction window, and the retrieval store contained zero records keyed by any of those handles.** That is a detectable, pre-failure condition. ## Condition of Validity The invariant holds — and the failure is real — only under a conjunction of conditions. If any is absent, the mechanism does not fire: 1. **The tool call is asynchronous or deferred.** Synchronous calls resolve before compaction can interleave. The window of vulnerability is exactly the interval between issue and resolution. 2. **The handle is opaque and non-inferable.** If the result echoes enough context to reconstruct the binding (e.g., the result payload contains the full original arguments), rehydration can succeed by content match alone. The failure requires that the handle carry information the summary cannot preserve — typically a server-assigned ID or a cryptographic token. 3. **Compaction is lossy and prose-oriented.** A compaction that serializes structured state verbatim (a call ledger) is immune. The failure is specific to summarizers that treat the transcript as text. 4. **Rehydration is retrieval-backed rather than ledger-backed.** If the agent can re-read a durable call ledger, the handle survives regardless of what the summary said. The failure requires that the only path back to the handle is semantic retrieval over prose. When all four hold, the probability that a given in-flight call loses its handle at the next compaction is effectively 1.0 — the summarizer has no mechanism to preserve it. ## Decision Boundary The operational decision is where to draw the line between "safe to compact" and "must defer compaction." The naive boundary — compact when utilization crosses a threshold — is wrong, because utilization says nothing about live-handle density. The correct boundary is a **two-condition gate**: compact only when (utilization > threshold) AND (live_handle_count == 0), OR when a structured ledger exists that can absorb every live handle before the summarizer runs. If neither holds, the agent must either block compaction (and accept the token cost) or first *externalize* every live handle into the ledger and verify round-trip. The subtle part of the boundary: a handle is not "resolved" merely because a result arrived. It is resolved only when the result has been *bound* to the call and the binding acknowledged. An agent that treats arrival as resolution will compact over a result it has received but not yet reconciled, and the reconciliation step — which needs the original argument bindings to validate the result — will find them gone. The boundary must be drawn at *acknowledged binding*, not at *result arrival*. A second boundary governs rehydration: retrieval similarity is not a valid signal for handle recovery. A high-similarity match to "background job" tells you the summary is about the job; it tells you nothing about whether the handle is present. Handle recovery must be keyed lookup, never similarity search. Conflating the two is how case (b) — hallucinated reconciliation — gets a passing retrieval score and proceeds. ## Operational Effect The downstream effect is a silent state divergence between the agent's belief and the world. In case (b), the agent marks a job complete that is still running (or failed), and every subsequent action built on that belief inherits the error. Because no exception is raised at the point of loss — the summary is fluent, the retrieval match is high-scoring, the reconciliation "succeeds" — the failure is invisible until a downstream invariant breaks, often many turns later, by which point the causal handle is unrecoverable and the trace is cold. The architectural guardrail that bounds this is a **call ledger with a compaction barrier.** Every issued call writes a durable record keyed by handle, containing the full argument bindings and a resolution state machine (`issued → result_received → bound → acknowledged`). Compaction is gated on the ledger: the summarizer may compress prose freely, but the ledger is passed through verbatim and is the sole authority for handle recovery. Rehydration for any handle is a keyed lookup against the ledger, never a similarity search. A pre-compaction assertion checks that every handle in the ledger in a non-terminal state is present in the post-compaction working set; if not, compaction aborts with a typed error rather than proceeding lossily. This converts an invisible divergence into a loud, localized failure at the exact turn where the invariant would have been violated. The code below implements the ledger, the pre-compaction barrier assertion, and the typed failure that fires when a live handle would be severed. ```python from dataclasses import dataclass, field from enum import Enum from typing import Dict, Optional class HandleSeveranceError(RuntimeError): """Raised when compaction would drop a live tool-call handle.""" pass class CallState(Enum): ISSUED = "issued" RESULT_RECEIVED = "result_received" BOUND = "bound" ACKNOWLEDGED = "acknowledged" TERMINAL = {CallState.ACKNOWLEDGED} @dataclass class CallRecord: handle: str tool: str args: Dict[str, object] state: CallState = CallState.ISSUED @dataclass class CallLedger: records: Dict[str, CallRecord] = field(default_factory=dict) def issue(self, handle: str, tool: str, args: Dict[str, object]) -> None: self.records[handle] = CallRecord(handle=handle, tool=tool, args=dict(args)) def mark_result(self, handle: str) -> None: rec = self.records.get(handle) if rec is None: raise HandleSeveranceError(f"result for unknown handle {handle!r}") rec.state = CallState.RESULT_RECEIVED def bind(self, handle: str, result_args: Dict[str, object]) -> None: rec = self.records.get(handle) if rec is None: raise HandleSeveranceError(f"cannot bind unknown handle {handle!r}") # Binding requires the original argument bindings to validate the result. if result_args.get("order_id") != rec.args.get("order_id"): raise HandleSeveranceError( f"result does not match bindings for {handle!r}" ) rec.state = CallState.BOUND def acknowledge(self, handle: str) -> None: rec = self.records.get(handle) if rec is None: raise HandleSeveranceError(f"cannot ack unknown handle {handle!r}") rec.state = CallState.ACKNOWLEDGED def live_handles(self) -> set: return {h for h, r in self.records.items() if r.state not in TERMINAL} def guarded_compact( ledger: CallLedger, pre_compact_window: set, post_compact_window: set, utilization: float, threshold: float = 0.80, ) -> None: """Compaction barrier: refuse to sever any live handle.""" if utilization <= threshold: return # no compaction needed, no risk live = ledger.live_handles() if not live: return # safe: no in-flight calls to lose # Every live handle must survive verbatim into the post-compaction set. severed = live - post_compact_window if severed: raise HandleSeveranceError( "compaction would sever live handles: " f"{sorted(severed)}; defer compaction or externalize to ledger" ) # Also require the pre-compaction window actually contained them, so we # catch the case where the handle was already lost before this turn. already_lost = live - pre_compact_window if already_lost: raise HandleSeveranceError( f"live handles absent from working set pre-compaction: " f"{sorted(already_lost)}" ) # Example trigger ledger = CallLedger() ledger.issue("ord_8f3a2c", "submit_order", {"order_id": "ord_8f3a2c", "qty": 3, "idempotency_key": "ik_91b7"}) ledger.mark_result("ord_8f3a2c") # Summarizer dropped the handle; post-compaction window no longer has it. try: guarded_compact( ledger, pre_compact_window={"ord_8f3a2c", "summary_line_1"}, post_compact_window={"summary_line_1", "summary_line_2"}, utilization=0.86, ) except HandleSeveranceError as e: # Correct behavior: abort lossy compaction, keep the handle, retry later. print(f"blocked lossy compaction: {e}") ```