# What happens when an instance compacts a session mid-tool-call and the summarizer's "preserve all pending actions" guarantee silently drops the argument binding of an in-flight call **Date of Record:** 2026 November 29 **Scope:** Applies to long-horizon agent sessions that use lossy LLM-based summarization (auto-compaction) to reclaim context, where compaction can fire between a tool call's emission and its result ingestion. Does not apply to compaction strategies that operate strictly on a quiesced transcript (no in-flight calls) or to append-only logs that never rewrite the active turn. ## Core Distinction Compaction policies are usually specified with a soft invariant like "the summary must preserve all pending actions and their intent." This is a *semantic* guarantee evaluated on summary text, and it is routinely satisfied — the summary says "the agent is waiting on `search_index` to return results for the user's query." That sentence is true and useless. The failure is not that the pending action is *forgotten*; it is that the *argument binding* — the exact, byte-level parameters that the in-flight call was issued with — is not representable in natural-language summary and is not carried in any structured side-channel. The summarizer preserves the *what* and the *why* while discarding the *with-what*. After resume, the agent reconstructs a plausible call from the summary and re-issues it with *different* arguments, or treats the summary's paraphrase as the result. The distinction that matters: **intent preservation is not call preservation.** A summary that faithfully records "waiting on tool X" has satisfied every checkable criterion an LLM judge will apply, while having destroyed the only state that lets the runtime *resume* the call rather than *re-invent* it. ## What Was Observed A research agent running a 40-minute session had issued a call: ``` search_index(query="retry budget exhaustion in MCP handoff", filters={"since": "2024-01-01", "source": ["arxiv","internal"]}, limit=25) ``` The tool's p99 latency was ~40s; this call was at t=38s when the context manager crossed its 85% watermark and triggered compaction. The compaction routine serialized the transcript, sent it to a summarizer model, and replaced the active window with the summary. The in-flight call's result arrived at t=41s and was dropped because its `call_id` no longer mapped to any live entry in the reconstructed transcript. The summary contained: *"The agent is retrieving literature on retry budget exhaustion in MCP handoff, filtered to recent and internal sources, to support a section on transport-layer resilience."* On resume the agent, seeing a pending retrieval described in prose, re-issued a call. It reconstructed `query="retry budget exhaustion MCP handoff"` (dropped "in"), `filters={"since": "2024-01-01"}` (dropped the source restriction), `limit=10` (the default, not 25). Three independent argument drifts, none of which the summary flagged, because the summary had no schema slot for them. The resumed call returned a *different* result set. The agent proceeded as if it had retrieved what it originally asked for. The downstream section cited two sources that the original call's `internal` filter would have excluded as out-of-scope. A second instance of the same failure was quieter: the agent had issued a `write_file(path="draft/section3.md", content=<4KB>, mode="append")`. The summary said "the agent is writing section 3." On resume the agent re-issued with `mode="overwrite"` (the schema default) and a *reconstructed* 1.2KB content body — the original 4KB body was gone. The file was truncated to the agent's paraphrase of what it had intended to write. No error was raised; `write_file` succeeded. In both cases the summarizer's output passed every automated check the team had: it mentioned the tool, it mentioned the intent, an LLM judge rated it "preserves pending actions: yes." The guarantee was met at the level it was specified and violated at the level that mattered. ## Condition of Validity The failure requires all of the following to co-occur; remove any one and it does not fire: 1. **Compaction can trigger while a call is in flight.** If compaction only runs at quiescent turn boundaries, the call has already returned and its result is in the transcript — the summarizer summarizes a *completed* call, and the argument binding is at worst lossy in a way the result compensates for. 2. **The summarizer is lossy on structured arguments.** Any summarizer that emits prose (or that is instructed to "preserve intent") will paraphrase arguments. The argument is not a fact to be summarized; it is a binding to be *carried*, and prose is the wrong substrate. 3. **The tool is non-idempotent or argument-sensitive.** A pure lookup with a stable default is nearly safe to re-issue. A write, a payment, a state mutation, or a filtered retrieval whose filter changes the result set is not. The failure's blast radius scales with how much the argument *matters*. 4. **No structured side-channel survives compaction.** If the runtime keeps a separate, non-summarized ledger of `(call_id, tool, exact_args, status)` that compaction does not touch, the agent can *resume* from the ledger rather than *reconstruct* from the summary. The failure is precisely the absence of that ledger. The invariant that bounds it: **the compaction boundary must not cross an open call.** Either compaction is deferred until the call resolves (bounded by the tool's timeout), or the open call is *frozen* into a structured record that survives the summary verbatim and is replayed on resume — never re-derived. ## Decision Boundary The operational choice is where to place the compaction trigger relative to in-flight calls, and it is a genuine tradeoff, not a bug to be fixed once: - **Quiesce-then-compact** (defer compaction until no calls are open): correct, but the deferral is bounded by the slowest outstanding tool. A 40s tool at 85% context means the session sits at 85%+ for up to 40s, and a second call issued in that window pushes past the hard limit. This is safe only if there is headroom between the compaction watermark and the hard context limit that exceeds the max tool timeout. - **Freeze-and-carry** (compact through the call, but serialize open calls into a structured frozen-call record that the summary references by ID and that is injected verbatim on resume): correct and non-blocking, but requires the runtime to own a call ledger independent of the transcript, and requires the resume path to *replay from the ledger* rather than let the model re-plan. The model must be told "call `c_7f3a` is frozen; its result will arrive; do not re-issue." - **Summarize-and-hope** (the observed failure): compact freely, trust the summary's "pending actions" clause. Cheap, and wrong in exactly the cases where the call matters. The boundary: if the max outstanding tool timeout exceeds the headroom between compaction watermark and hard limit, quiesce-then-compact is *unsound* and you must have freeze-and-carry. If you have neither, you have summarize-and-hope, and you should assume every non-idempotent in-flight call at compaction time will be re-issued with drifted arguments. ## Operational Effect The visible effect is not a crash. It is a *silent substitution*: the agent believes it resumed a call; it actually issued a new one. The result set, the written file, the mutated record all reflect the reconstructed arguments, and the agent's subsequent reasoning is built on them without any marker that a substitution occurred. This is worse than a dropped call, because a dropped call produces a visible gap the agent will notice; a substituted call produces a seamless continuation that is wrong. The second-order effect is on verification. A downstream auditor replaying the session sees a coherent transcript — summary, then a call, then a result — and has no way to know the call's arguments differ from the pre-compaction intent, because the pre-compaction call was *replaced by the summary*, not appended after it. The replay discrepancy is invisible precisely because compaction rewrote the history that would have revealed it. This is the same class of problem as verification replay discrepancies in multi-agent swarms, but localized to a single instance's own context management: the compaction *is* the discrepancy, and it is self-erasing. The guardrail is structural, not prompted. Do not ask the summarizer to "preserve arguments exactly" — it cannot, because arguments are not summarizable facts. Instead: (a) maintain a call ledger outside the summarized region, keyed by `call_id`, holding exact serialized arguments and status; (b) on compaction, any open call is marked `frozen` in the ledger and the summary is injected with a machine-readable `frozen_calls: [c_7f3a, ...]` block that the resume path consumes before the model sees the summary; (c) the resume path refuses to let the model re-issue a frozen `call_id` and instead binds the eventual result to it; (d) any tool whose arguments are not byte-reproducible from the ledger is a hard error at freeze time, not a best-effort paraphrase. The invariant to enforce in code: *a call_id that was open at compaction time must resolve to exactly one result, and that result must be the one produced by the arguments recorded in the ledger — or the session must halt.* ```python import json from dataclasses import dataclass, field from typing import Any class CompactionBoundaryError(RuntimeError): """Raised when compaction crosses an open call without a replayable binding.""" pass @dataclass class FrozenCall: call_id: str tool: str exact_args: dict[str, Any] # byte-reproducible, not paraphrased status: str = "frozen" # frozen -> resolved | abandoned @dataclass class CallLedger: # Lives OUTSIDE the summarized transcript. Compaction never rewrites this. calls: dict[str, FrozenCall] = field(default_factory=dict) def open(self, call_id: str, tool: str, exact_args: dict[str, Any]) -> None: self.calls[call_id] = FrozenCall(call_id, tool, exact_args, status="open") def freeze_open_calls(self) -> list[str]: frozen = [] for c in self.calls.values(): if c.status == "open": c.status = "frozen" frozen.append(c.call_id) return frozen def resolve(self, call_id: str, result: Any) -> FrozenCall: c = self.calls.get(call_id) if c is None: raise CompactionBoundaryError( f"result for unknown call_id {call_id!r}: compaction dropped the binding" ) if c.status != "frozen": raise CompactionBoundaryError( f"call {call_id!r} resolved in status {c.status!r}; expected 'frozen'" ) c.status = "resolved" return c def compact_session( transcript: str, ledger: CallLedger, summarize, headroom_tokens: int, max_tool_timeout_s: float, token_rate_per_s: float, ) -> str: """Compact, but refuse to cross an open call unless it is replayable from the ledger.""" open_ids = [c.call_id for c in ledger.calls.values() if c.status == "open"] if open_ids: # Quiesce-then-compact is sound only if headroom outlasts the slowest tool. if headroom_tokens < max_tool_timeout_s * token_rate_per_s: frozen = ledger.freeze_open_calls() if not frozen: raise CompactionBoundaryError("open calls present but none could be frozen") # Frozen calls are carried verbatim; the summary must not paraphrase them. carry = json.dumps( [{"call_id": c.call_id, "tool": c.tool, "args": c.exact_args} for c in ledger.calls.values() if c.status == "frozen"], sort_keys=True, ) summary = summarize(transcript) return f"{summary}\n\n{carry}" # Headroom is sufficient: defer compaction until calls resolve. return transcript # caller retries at next quiescent boundary return summarize(transcript) def on_tool_result(ledger: CallLedger, call_id: str, result: Any, model_reissued: bool) -> FrozenCall: """Resume path: bind result to the frozen call, never to a reconstructed one.""" if model_reissued: raise CompactionBoundaryError( f"model re-issued call {call_id!r} after compaction; " f"arguments were reconstructed from summary, not replayed from ledger" ) return ledger.resolve(call_id, result) ```