# What structural signals indicate that hierarchical auto-compaction has silently orphaned a tool-call dependency chain **Date of Record:** 2026 November 23 **Scope:** Applies to long-horizon agents that compact context via hierarchical summarization (leaf-chunk summaries rolled up into parent summaries) while an active multi-step tool-call plan is in flight. Does not apply to single-turn calls, to lossless compactions that preserve verbatim tool transcripts, or to agents whose planner state lives entirely outside the compacted context window. ## Core Distinction The failure is not "the agent forgot something." It is that hierarchical compaction preserves *narrative coherence* while destroying *referential integrity of in-flight tool state*. A leaf summarizer asked to compress a chunk containing a tool call and its result will faithfully retain the sentence "the agent queried the pricing service and confirmed the enterprise tier" while dropping the `call_id`, the exact argument vector, and the fact that the returned payload was a *partial* result awaiting a pagination token. The summary reads correct. The dependency graph is severed. Two distinct compaction regimes get conflated: - **Budget-aware truncation** (drop oldest tokens) fails *loudly* — the agent visibly loses the head of its own reasoning and typically re-derives or errors. - **Hierarchical summarization** fails *silently* — every surviving sentence is true, so no downstream consistency check fires, yet a pending tool call now has no owning frame. The invariant that hierarchical compaction must uphold: **every unresolved tool call (issued, not yet consumed) must survive compaction as a structured, machine-readable record — never as prose.** A summary that mentions the call in natural language satisfies the summarizer's loss objective and violates the executor's referential invariant simultaneously. ## What Was Observed A research agent executing a 40-step plan against three MCP servers (a search tool, a document fetcher, and a citation resolver) crossed its 60% context budget at step 22. The compaction policy triggered hierarchical summarization: steps 1–15 were leaf-summarized into four chunk summaries, then rolled into one parent summary, freeing ~14k tokens. Step 18 had issued a `fetch_document(doc_id="AX-4471", page=2)` call whose result was a partial page plus a `continuation_token`. The leaf summarizer covering steps 16–19 compressed that exchange to: *"Retrieved page 2 of document AX-4471; content reviewed."* The continuation token, the `call_id`, and the unresolved-pagination flag were all discarded — they are not "content," they are protocol metadata, and the summarizer was prompted to preserve content. At step 23 the planner, operating on the parent summary, concluded the document was fully retrieved and proceeded to citation resolution. The citation resolver returned a reference to page 4 of AX-4471. The agent, believing it held the whole document, asserted the page-4 claim was supported by evidence it had "already reviewed." It had reviewed page 2 only. The final report contained a fabricated support attribution — not a hallucinated fact, but a *true fact attached to evidence the agent never actually held*. This is the worst class of error: it survives human spot-checks because the cited page does exist. The structural tell, visible in the post-compaction trace: the parent summary contained the noun phrase "document AX-4471" but no `call_id`, no `continuation_token`, and no `status: pending` marker. A grep for unresolved-call sentinels in the compacted context returned zero hits while the executor's own ledger still held one open call. That divergence — **ledger-open-calls > 0 while compacted-context-open-call-markers == 0** — is the signal. ## Condition of Validity This boundary condition is *active* (the failure can occur) precisely when all four hold: 1. Compaction is **hierarchical and lossy over prose** — the summarizer is a generative model, not a deterministic extractor. 2. The agent has **in-flight tool calls with multi-part results** (pagination, streaming, chunked retrieval, async completion) whose completion state is not self-evident from content. 3. Planner state and executor state are **co-located in the same context window** rather than in an external, non-compacted ledger. 4. No **post-compaction reconciliation pass** compares the executor's open-call set against the compacted context's declared open calls. Remove any one and the failure is bounded. If tool results are single-part and terminal (a search returns one blob, done), there is no continuation to orphan. If the executor ledger lives outside the compacted window (a structured scratchpad the summarizer cannot touch), the planner can re-read true state. If a reconciliation pass runs, the orphan is caught at compaction time, not at citation time. The subtle case — and the reason this is a *boundary* rather than a bug — is condition 2 with *apparently complete* results. A fetcher that returns "page 2 of 5" in its payload but a summarizer that drops the "of 5" produces a result that looks terminal. The failure requires the summarizer to be *locally correct*: it accurately summarized what it saw. The information loss is in the schema, not the semantics. ## Decision Boundary The operational choice is where to draw the line between "compactible prose" and "non-compactible protocol state." Three viable boundaries, in increasing strictness: - **Content/metadata split:** Summarizer is permitted to compress only the `content` field of a tool result; `call_id`, `status`, `continuation_token`, and `expected_parts` are extracted verbatim into a structured sidecar that is *never* summarized, only concatenated. Cheapest; requires tool schemas to declare which fields are protocol-bearing. - **Open-call pinning:** Any tool call whose result is not marked terminal is *pinned* — excluded from compaction entirely until consumed. Bounds context growth at the cost of the very budget pressure that triggered compaction; can deadlock if a call never resolves. - **Reconciliation gate:** Compaction is allowed to proceed, but a mandatory post-pass diffs `executor.open_calls` against `context.declared_open_calls` and *fails the compaction* (re-expands, re-summarizes with a stricter prompt, or escalates) on mismatch. Highest safety, highest latency. The decision boundary is the **terminality predicate**. If the system cannot decide, per tool result, whether the call is *done*, it must default to pinning (regime 2). The common mistake is inferring terminality from the *summary text* ("content reviewed" reads terminal) rather than from the *structured result envelope*. Terminality is a property of the protocol record, never of the prose. A second boundary governs *which* summarizer runs. A summarizer prompted with "preserve all facts and conclusions" will preserve conclusions and drop tokens. A summarizer prompted with "preserve all facts, conclusions, AND emit a structured `pending_calls` array" can be made to carry the invariant — but only if the emitter is validated against the executor ledger before the summary is committed. Prompt-level instruction without a validation gate is not a guardrail; it is a hope. ## Operational Effect Downstream of an orphaned tool call, the agent enters a state of **false evidentiary completeness**. It does not know it is missing data, because the summary asserted completeness. Every subsequent step that depends on the orphaned result inherits the false premise, and the error compounds silently — the citation resolver's page-4 reference is *accepted* rather than *questioned*, because the planner "knows" it holds the document. The compounding is invisible to token-budget monitoring (context is *under* budget, compaction "succeeded") and invisible to output-consistency checks (the output is internally coherent). It surfaces only under external ground-truth audit of *which evidence the agent actually retrieved* versus *which evidence it cited*. The architectural consequence: **compaction must be treated as a state-transfer operation, not a text-compression operation.** It crosses the same trust boundary as an agent-to-agent handoff, and it must carry the same structured payload — open calls, pending continuations, unresolved obligations — that a handoff would carry. A summarizer that only carries prose is a handoff that drops the warrant. The guardrail is a reconciliation invariant enforced at commit time: *the compacted context's declared-open-call set must equal the executor ledger's open-call set, or the compaction does not commit.* ```python from dataclasses import dataclass, field from typing import Optional class CompactionOrphanedToolCallError(RuntimeError): """Raised when hierarchical compaction drops an unresolved tool call from the compacted context while the executor ledger still holds it open.""" pass @dataclass class ToolCall: call_id: str status: str # "pending" | "terminal" continuation_token: Optional[str] = None @dataclass class ExecutorLedger: open_calls: dict[str, ToolCall] = field(default_factory=dict) def open_call_ids(self) -> set[str]: return {cid for cid, c in self.open_calls.items() if c.status == "pending"} @dataclass class CompactedContext: # Structured sidecar of pending calls the summarizer was allowed to emit. declared_pending: set[str] = field(default_factory=set) def commit_compaction(ledger: ExecutorLedger, context: CompactedContext) -> None: """Reconciliation gate: refuse to commit a compaction that orphans any in-flight tool call. Terminality is read from the ledger, never inferred from summary prose.""" ledger_open = ledger.open_call_ids() orphaned = ledger_open - context.declared_pending if orphaned: raise CompactionOrphanedToolCallError( f"Compaction would orphan unresolved tool calls {sorted(orphaned)}; " f"ledger holds {sorted(ledger_open)} open but compacted context " f"declares {sorted(context.declared_pending)}. Refusing to commit; " f"re-summarize with open-call pinning or structured sidecar emission." ) # Safe to commit: every open call survived as machine-readable state. return None # Trigger trace from the observed incident: ledger = ExecutorLedger(open_calls={ "call_18_fetch": ToolCall(call_id="call_18_fetch", status="pending", continuation_token="tok_p2_of_5"), }) context = CompactedContext(declared_pending=set()) # summarizer emitted prose only try: commit_compaction(ledger, context) except CompactionOrphanedToolCallError as e: print(f"BLOCKED: {e}") # Recovery: pin the open call, re-summarize with sidecar emission. context.declared_pending.add("call_18_fetch") commit_compaction(ledger, context) print("RECOVERED: compaction committed with call_18_fetch pinned.") ```