# What happens when an instance compacts a transcript mid-tool-call and the summarizer elides the pending-call sentinel **Date of Record:** 2026 November 27 **Scope:** Applies to long-horizon agents that auto-compact their own transcript when a token budget threshold is crossed, and where compaction is permitted to run between an assistant tool-call emission and its tool-result ingestion. Does not apply to compaction that is hard-gated to turn boundaries, nor to stateless single-shot invocations. ## Core Distinction The failure is not "the summary lost information." Lossy summarization is expected and contractually permitted. The failure is that the summarization contract is defined over *semantic* content (intents, decisions, facts) while the transcript also carries *structural* obligations — open tool-call frames, unresolved IDs, pending approvals — that are not semantic and therefore are not preserved by any summarizer trained or prompted to produce a faithful *narrative*. Concretely: a transcript at compaction time can be in a state where the last assistant message emitted `tool_use` block `id=tc_9f2` for `payments.transfer` and no matching `tool_result` has yet been appended. Compaction rewrites the historical prefix into a prose summary. The summarizer, seeing an intent-to-transfer and no result, renders it as "the agent decided to attempt a transfer" — a *decision*, not an *open frame*. The runtime's frame-tracking state (in the model's context, not in the harness) is destroyed. The subsequent `tool_result` for `tc_9f2` arrives, references an ID that no longer exists anywhere in context, and the model either (a) treats it as a fresh observation and re-issues the call, or (b) silently drops it. This is distinct from ordinary context loss: the *information* survives in paraphrase, but the *invariant* — "every open tool_use frame must be closed by exactly one tool_result before the assistant may proceed" — does not, because invariants are structural and summaries are semantic. ## What Was Observed A 40-turn agent executing a multi-step refund workflow crossed its 92%-of-budget compaction trigger at turn 31, immediately after emitting a `tool_use` for `refunds.create` and before the tool result returned (the tool had a 4.2s p99 and the compaction ran on a parallel scheduler). Sequence of events: 1. Turn 31 assistant message: `tool_use{id: tc_9f2, name: refunds.create, input: {order: "A-114", amount: 40.00}}`. Frame opened. 2. Compaction scheduler fires (budget threshold crossed at emission time, not at result time). Summary produced over turns 1–31. 3. Summary text: "The agent reviewed order A-114, confirmed the customer's eligibility, and initiated a $40 refund." — the frame is narrated as completed intent. 4. Turn 32: `tool_result{id: tc_9f2, status: ok, refund_id: rf_88213}` appended to the *real* message list, but the summary replaced turns 1–31, so `tc_9f2` has no referent. 5. Turn 32 assistant: reads the orphaned tool_result, cannot bind it to a frame, and — because the summary says a refund was "initiated" — re-issues `refunds.create` for the same order to "confirm." Second refund `rf_88214` created. 6. Turn 33: idempotency check at the payments layer rejects the duplicate only because the tool itself keyed on `(order, amount)`; in the observed run the key was `(order, amount, request_id)` and the regenerated `request_id` differed, so the duplicate *succeeded*. The observable signature is a `tool_result` whose `id` has zero matches in the post-compaction context, followed within one turn by a re-emission of the same tool with a semantically equivalent input. ## Condition of Validity The guardrail that bounds this failure is a **compaction admissibility predicate**: compaction may only run when the transcript is *frame-closed*. Formally, define the transcript's open-frame set `F = {ids of tool_use blocks not yet matched by a tool_result}`. Compaction is admissible iff `F = ∅` AND no assistant message is awaiting an in-flight response. If `F ≠ ∅`, the compactor must either (a) defer until the frame closes, (b) *pin* the open frame verbatim into the summary as a structured sentinel (not prose), or (c) abort compaction and let the budget pressure surface as a hard error. Option (b) is only valid if the summarizer is constrained to emit a machine-checkable frame ledger alongside the prose, and the runtime re-injects that ledger as real message blocks, not as text. The invariant: **a summary must be a fixed point of the frame-closure function.** `frames(summary) == frames(prefix)`. Any summarizer that cannot guarantee this is not a valid compactor for a transcript that may be mid-call. ## Decision Boundary The boundary is whether compaction is triggered on *token count* or on *quiescence*. Token-count triggers (the common design) can fire at any message boundary, including mid-frame, because token accounting is monotone and frame state is not part of the accounting. Quiescence triggers fire only when `F = ∅`, which is correct but can starve under a long tool call, causing a hard budget overrun instead of a soft compaction. The correct boundary is a two-tier scheme: a *soft* trigger at threshold that requests compaction but only *commits* it at the next quiescent point, with a *hard* fallback at a higher threshold (e.g., 98%) that forces compaction with mandatory frame-pinning. The decision boundary for an operator is: does your compactor have a committed-vs-requested distinction, and does the hard path pin frames structurally rather than narratively? If both answers are no, you have an unbounded duplicate-side-effect window equal to your longest tool latency. ## Operational Effect The effect is not memory loss but *action duplication*: side-effecting tools get re-invoked because the model's only record of "I already did this" is a paraphrase that reads as intent, and its only record of "this result belongs to that call" is an ID that no longer resolves. The blast radius is proportional to the non-idempotency of the tools reachable in the window. Read-only tools degrade to wasted tokens; payment, email, and provisioning tools degrade to duplicate real-world effects. Mitigations, in order of strength: (1) forbid compaction while `F ≠ ∅` and pin frames as structured blocks when forced; (2) require tool-level idempotency keys derived from `(order, amount, canonical_input_hash)` rather than per-request UUIDs, so a re-issue collapses; (3) have the runtime reject any `tool_result` whose `id` has no matching `tool_use` in current context with a hard error rather than passing it to the model as an observation; (4) log frame-closure state as a first-class field in every compaction event so the failure is detectable post-hoc. ```python from dataclasses import dataclass, field from typing import Optional class CompactionFrameViolation(RuntimeError): """Raised when compaction would run or has run over an open tool-call frame.""" pass @dataclass class Transcript: messages: list = field(default_factory=list) def open_frames(self) -> set: opened, closed = set(), set() for m in self.messages: for blk in m.get("blocks", []): if blk["type"] == "tool_use": opened.add(blk["id"]) elif blk["type"] == "tool_result": closed.add(blk["id"]) return opened - closed def compact(transcript: Transcript, summarize, hard: bool = False) -> Transcript: frames = transcript.open_frames() if frames and not hard: # soft path: defer, do not summarize over an open frame raise CompactionFrameViolation( f"compaction deferred: open tool frames {sorted(frames)}" ) if frames and hard: # hard path: pin frames verbatim, never narrate them pinned = [m for m in transcript.messages if any(b["id"] in frames for b in m.get("blocks", []))] summary = summarize(transcript.messages) # invariant check: pinned frames must survive as real blocks surviving = {b["id"] for m in pinned for b in m.get("blocks", []) if b["type"] == "tool_use"} if not frames.issubset(surviving): raise CompactionFrameViolation( f"pinned frame ledger incomplete: missing {frames - surviving}" ) return Transcript(messages=[{"role": "system", "blocks": [ {"type": "summary", "text": summary}]}] + pinned) return Transcript(messages=[{"role": "system", "blocks": [ {"type": "summary", "text": summarize(transcript.messages)}]}]) def ingest_result(transcript: Transcript, result_id: str) -> None: if result_id not in transcript.open_frames() and not any( b.get("id") == result_id for m in transcript.messages for b in m.get("blocks", []) if b["type"] == "tool_use" ): raise CompactionFrameViolation( f"orphaned tool_result {result_id}: no matching tool_use in context" ) ```