# What happens when an instance auto-compacts its own transcript mid-tool-call and the summarizer drops the pending invocation's argument binding **Date of Record:** 2026 November 27 **Scope:** Applies to any long-horizon agent that performs lossy transcript compaction (rolling summarization, hierarchical memory distillation, or KV-cache eviction with textual re-materialization) while tool calls are in flight. Does not apply to systems that only compact at quiescent turn boundaries with an empty pending-invocation queue. ## Core Distinction The failure is not "the summary lost detail." Lossy summarization is expected and tolerable for *narrative* state — earlier reasoning, resolved sub-goals, abandoned branches. The failure is that compaction is applied uniformly across the transcript without distinguishing **committed narrative** from **live execution frames**. A pending tool invocation is not history; it is a suspended stack frame whose continuation depends on exact bytes: the tool name, the argument object, the correlation/call ID, and the schema version negotiated at dispatch. When the compactor treats that frame as summarizable prose, it produces a plausible-looking summary like "the agent called `search_docs` with the user's query" — which preserves *intent* and destroys *binding*. On resume, the agent reconstructs a call from the summary, and the reconstruction is a *different* call: different argument serialization, different ID, sometimes a different tool from the same family. The system does not crash. It silently executes a near-miss. This is distinct from context-window saturation (which degrades reasoning quality) and from cold-start amnesia (which loses all state). Here the state survives in degraded, *syntactically valid, semantically shifted* form — the worst regime, because every downstream validation that checks for "a pending call exists" passes. ## What Was Observed A planner agent on a 40-turn horizon dispatched a batch of three tool calls in one assistant message: `read_file(path="/etc/svc/limits.yaml")`, `read_file(path="/etc/svc/retries.yaml")`, and `grep(pattern="max_conn", path="/etc/svc/")`. The harness held the batch open awaiting results. Before results returned, the transcript crossed the compaction threshold (78% of the 200k window, driven by verbose tool outputs from earlier turns). The compactor summarized turns 1–31 into ~600 tokens and, because the pending batch sat in turn 33, the summarizer — operating on the *textual* transcript — folded the batch into a single line: "Agent read the service config files under /etc/svc to determine connection limits." The three pending calls were then re-materialized by the resume path as a *single* call: `read_file(path="/etc/svc/limits.yaml")`. Two of the three original invocations were dropped entirely; the third was reconstructed correctly by luck of being first. The correlation IDs from the original batch (`call_a91`, `call_b02`, `call_c73`) no longer existed anywhere in the compacted transcript. When the two orphaned results later arrived from the tool executor, the resume path had no frame to attach them to and logged them as `unmatched_result` — a warning, not an error. The agent proceeded on one file, concluded `max_conn: 512` was the global limit, and never saw `retries.yaml`'s override of `max_conn: 64` for the connection-pool path. The final answer was confidently wrong by 8x. The invariant that broke: **the set of pending invocations is a multiset of opaque records, and compaction must be identity-preserving over that multiset.** The summarizer had no representation for "these three things are not history, they are outstanding obligations," so it did what summarizers do — compressed three parallel facts into one sentence, collapsing cardinality from 3 to 1. A second observation made the mechanism sharper. Re-running with compaction forced to fire *mid-batch* but with the batch held in a separate structured field (not in the prose transcript) produced zero loss: the summary was equally aggressive, but the pending calls were never in the summarizer's input. The loss was entirely a function of *where the live frame lived relative to the compaction boundary*, not of summary quality. ## Condition of Validity The failure requires all of the following to co-occur: 1. **Compaction is triggered by token pressure, not by turn completion.** If compaction only runs when the pending-invocation queue is empty, the frame is never exposed to the summarizer. 2. **Pending invocations are represented in the same channel as narrative** — i.e., as assistant-message text or tool-call blocks that the summarizer reads as ordinary content, rather than in a side-channel structure the compactor is forbidden to touch. 3. **The summarizer is permitted to merge or elide** — any instruction like "be concise," "combine related actions," or "preserve intent" licenses cardinality collapse across parallel calls. 4. **The resume path reconstructs rather than replays.** If resume replays the *exact serialized frame* from a durable store, a bad summary cannot corrupt execution. The failure needs reconstruction-from-summary. Absent any one condition, the invariant holds. This is why the bug is intermittent: it fires only when load, verbosity, and batch concurrency align to push a pending batch across the threshold. It is also why it evades replay testing — deterministic replay of a recorded transcript never re-triggers compaction at the same byte offset unless the token counter is faithfully reproduced. ## Decision Boundary The architectural line is between **compaction as a transformation of history** and **compaction as a transformation of the whole context**. The former is safe; the latter is the bug. Concretely, the boundary is drawn as follows: - **Compaction input must be a projection that excludes live frames.** The compactor's view is `transcript − pending_invocations − unacknowledged_results`. Live frames are pinned by reference, never copied into summarizer input. - **Pending invocations are addressed by immutable ID, never by position or description.** After compaction, resume must resolve each outstanding call by its correlation ID against the durable invocation log. If the ID is absent from the log, that is a *hard fault*, not a warning. - **Cardinality is an invariant, not a hint.** The number of outstanding calls before compaction must equal the number after. A mismatch is a compaction failure and must abort the resume, not proceed with the survivors. - **Summaries are advisory; frames are authoritative.** Any disagreement between a summary sentence ("agent read the config files") and the invocation log (three specific calls) resolves in favor of the log, and the summary is regenerated with the frames pinned. The tempting shortcut — "just tell the summarizer to preserve tool calls verbatim" — does not hold the boundary. It is a probabilistic instruction inside a lossy process; it reduces frequency, it does not bound the failure. The boundary must be structural: the summarizer cannot see what it must not touch. ## Operational Effect When the boundary holds, long-horizon agents can compact aggressively during tool latency — the highest-value time to reclaim context — without risking execution integrity. Compaction becomes a pure memory-pressure relief valve decoupled from the execution stack. When it fails, the effect is not a visible error but a **silent semantic substitution**: a well-formed, plausible, wrong continuation. Because the reconstructed call passes schema validation and produces real results, the corruption propagates into downstream reasoning as if it were ground truth. The 8x error in the observed case was not detected until a human audited the final answer against the source files. The `unmatched_result` warnings — the only signal — were emitted at `INFO` and scrolled past. The operational posture that follows: treat every compaction event that overlaps a non-empty pending set as a **checkpoint integrity event**, requiring reconciliation of the invocation log against the post-compaction frame set before any result is admitted. Reconciliation failure halts the agent. The cost is a rare stall; the alternative is confident, silent, unrecoverable wrongness. ``` ```python import json from dataclasses import dataclass, field class CompactionFrameLossError(RuntimeError): """Raised when a lossy compaction drops or merges a live pending invocation.""" pass @dataclass class Invocation: call_id: str tool: str args: dict @dataclass class CompactionEvent: summary_text: str pending_before: list[Invocation] pending_after: list[Invocation] = field(default_factory=list) def reconcile_after_compaction(event: CompactionEvent) -> list[Invocation]: """ Enforce the invariant: the multiset of pending invocations is identity-preserving across a lossy compaction. Summaries may compress narrative; they may not change the cardinality or IDs of live frames. """ before_ids = [inv.call_id for inv in event.pending_before] after_ids = [inv.call_id for inv in event.pending_after] if len(before_ids) != len(after_ids): raise CompactionFrameLossError( f"cardinality drift across compaction: " f"{len(before_ids)} pending before, {len(after_ids)} after; " f"summary={event.summary_text!r}" ) missing = set(before_ids) - set(after_ids) if missing: raise CompactionFrameLossError( f"pending invocations elided by summarizer: {sorted(missing)}; " f"resume cannot reconstruct exact argument bindings" ) # Frames are authoritative; summary is advisory and must not be trusted # to describe them. Return the durable frames, not any reconstruction. return event.pending_before def resume_with_results( event: CompactionEvent, results_by_id: dict[str, dict] ) -> dict[str, dict]: try: frames = reconcile_after_compaction(event) except CompactionFrameLossError: # Halt rather than proceed on a degraded frame set. raise bound: dict[str, dict] = {} for inv in frames: if inv.call_id not in results_by_id: raise CompactionFrameLossError( f"no result for live frame {inv.call_id} ({inv.tool}); " f"refusing to substitute reconstructed call" ) bound[inv.call_id] = { "tool": inv.tool, "args": inv.args, "result": results_by_id[inv.call_id], } return bound ```