# Why does an instance lose tool-call preconditions when auto-compaction summarizes the middle of an execution trace **Date of Record:** 2026 November 29 **Scope:** Applies to long-horizon agents that persist a single mutable transcript and trigger lossy auto-compaction (summarize-and-replace) when the context window crosses a high-water mark, while the agent is mid-execution and has issued tool calls whose results are not yet consumed. Does not apply to append-only logs with external retrieval, nor to compaction triggered only at task boundaries between discrete sessions. ## Core Distinction The common mental model treats compaction as a *memory compression* problem: the transcript is too long, so we summarize it, and the summary is judged good if it preserves "the important facts." This framing conflates two structurally different things living in the same transcript: **declarative state** (what is true about the world and the task) and **operational preconditions** (what an in-flight tool call or pending reasoning step requires to be validly continued). Lossy summarization is well-behaved for declarative state. It is actively destructive for operational preconditions, because preconditions are not facts that can be paraphrased—they are *bindings* between a pending action and the exact arguments, ordering, and side-effect assumptions that produced it. A summarizer that faithfully preserves "the user wants the migration script fixed" while silently eliding "the last `apply_patch` call returned a partial diff because the file was truncated at line 412, and the retry must use the same `patch_id`" has preserved 100% of the declarative content and destroyed the precondition. The agent then resumes with a plausible-looking summary and re-issues the action against stale assumptions. The boundary condition is precise: **compaction that fires while a tool call is outstanding, or while a reasoning chain has consumed a tool result but not yet committed its conclusion, will produce a resume state that is declaratively coherent and operationally invalid.** The failure is invisible at the summary-quality level; it only manifests downstream as a duplicated side effect, a schema mismatch, or a "successful" action against a precondition that no longer holds. ## What Was Observed A long-horizon refactoring agent ran a 340-step task touching a repository. The transcript carried a running task ledger, a set of file-state observations, and the raw tool-call/result pairs. At a 128k-token high-water mark, an auto-compaction pass summarized the middle 60% of the transcript into ~2.4k tokens and spliced it back in place of the original span, leaving the head (system prompt, initial task) and the tail (last ~8 turns) verbatim. The compaction fired three turns after a `write_file` call had returned `{"status": "partial", "bytes_written": 8192, "truncated": true}`. The agent's next reasoning step was preparing a continuation write. The summarizer, optimizing for declarative fidelity, collapsed the partial-write turn into: *"Wrote the migration script to `migrations/0042.py`."* The `truncated: true` flag, the `bytes_written` count, and the fact that a continuation was pending were all dropped—not because the summarizer was bad, but because those details read as low-salience implementation noise relative to the task narrative. On resume, the agent read the summary, concluded the file was written, and proceeded to the next task step: running the migration. The migration executed against a file that was syntactically truncated at byte 8192, failing with a `SyntaxError` deep in the file. The agent's recovery reasoning then re-derived the task state from the summary—which said the write succeeded—and instead of re-writing, it attempted to *patch* a file it believed was complete. Two more turns were spent diagnosing a phantom bug in the migration logic before the agent, by luck, re-read the file and discovered the truncation. The observable signature: **the number of turns between compaction and the first action that assumes a precondition held is small (1–3), and the failure surfaces as a downstream error whose apparent cause is unrelated to compaction.** Post-hoc, the transcript shows a clean, high-quality summary and a confidently wrong continuation. There is no error at the compaction step itself. A second instance showed the schema-negotiation variant. A tool with a paginated response had returned page 1 of 3, with a `next_cursor` field. Compaction elided the cursor because the summary recorded only the extracted rows. The agent, resuming, re-issued the original query with the original (non-cursor) arguments, got page 1 again, and appended duplicate rows to its working set. The duplicate-detection invariant it had been maintaining was keyed on a field that the re-fetch populated differently. The corruption was silent until a later aggregation double-counted. ## Condition of Validity The invariant that bounds this failure is: **a compaction boundary is only safe at a point where the transcript contains no outstanding operational precondition.** Formally, define the *precondition frontier* as the set of pending bindings—outstanding tool calls, unconsumed tool results, and reasoning steps whose committed conclusion depends on a specific tool result. Compaction is valid iff the frontier is empty at the compaction span's boundary, or iff every frontier element is carried verbatim (not summarized) across the boundary. This is the same class of constraint as a database checkpoint: you cannot checkpoint mid-transaction and expect the recovery log to be a paraphrase of the transaction. The precondition frontier is the "open transaction" set. A summarizer has no access to this set—it sees text, not bindings—so it cannot preserve what it cannot identify. The guardrail must live *outside* the summarizer, in the compaction controller. Three conditions make the failure reachable and are jointly necessary: (1) compaction fires on a token threshold rather than a frontier-empty check; (2) the summarized span contains at least one tool result whose continuation semantics are not fully represented in the tool's declarative output (partial writes, pagination cursors, retry tokens, idempotency keys, ordering dependencies); (3) the agent's resume logic trusts the summary as authoritative rather than validating against external state. Remove any one and the failure does not occur. This is why it is intermittent and hard to reproduce—it requires the threshold to land on the wrong turn. ## Decision Boundary The operational decision is not "summarize better." It is **where to place the compaction boundary relative to the precondition frontier.** The controller must choose one of three policies per compaction event: - **Frontier-deferral:** if the frontier is non-empty, defer compaction until it drains. Correct but unbounded—a stuck tool call can pin the context past the hard limit. Use when the frontier is expected to drain within a bounded number of turns. - **Frontier-pinning:** compact freely, but extract every frontier element and re-inject it verbatim (raw tool-call/result pairs, cursors, retry tokens) as a pinned block outside the summarized span. This is the general-purpose policy. The cost is that pinned blocks are not compressible, so the effective budget is reduced by the frontier size. - **Frontier-serialization:** require the agent to *commit* the precondition to an explicit, structured ledger (e.g., `pending_actions: [{tool, args, precondition, idempotency_key}]`) before compaction is permitted, and reconstruct from the ledger on resume. This moves the precondition out of the natural-language transcript entirely, which is the only policy that survives aggressive summarization, but it imposes a discipline cost on every tool call. The boundary between deferral and pinning is the frontier's expected drain time relative to the remaining headroom. The boundary between pinning and serialization is whether the agent can be trusted to maintain the ledger—if it cannot, pinning is the safer default because it requires no agent cooperation. Critically, **the summarizer must never be the component that decides what is a precondition.** Asking a lossy summarizer to "preserve important state" is asking it to solve the binding-identification problem it structurally cannot see. The controller owns the frontier; the summarizer owns only the declarative span between frontier elements. ## Operational Effect With frontier-pinning in place, the observed failure mode disappears: the partial-write turn is summarized into the narrative, but the raw `{"status": "partial", "truncated": true, "bytes_written": 8192}` result is pinned verbatim, and the resume logic sees it and continues the write correctly. The effective context budget shrinks by the pinned-block size—typically 5–15% for tool-heavy agents—which is the real price of the invariant. Agents that skip this pay instead in silent corruption whose cost is paid downstream and attributed to the wrong cause. The deeper operational lesson: **compaction is not a memory operation, it is a transaction-boundary operation.** Treating it as memory compression produces summaries that are locally excellent and globally unsound. The invariant to enforce is the precondition frontier, checked at the controller, with frontier elements carried across the boundary by identity rather than by paraphrase. Any auto-compaction strategy that does not name and check this frontier is, on long enough horizons, guaranteed to resume from a state that is confidently and invisibly wrong. ```python class PreconditionFrontierViolation(RuntimeError): """Raised when compaction would summarize across a live operational precondition.""" pass def compact_transcript( transcript: list[dict], frontier: list[dict], high_water_tokens: int, token_count, ) -> list[dict]: """ Compact the transcript only if no live precondition would be summarized. `frontier` is the controller-maintained set of pending bindings: outstanding tool calls, unconsumed results, and reasoning steps whose committed conclusion depends on a specific tool result. The summarizer never sees this set; the controller enforces it. """ if token_count(transcript) < high_water_tokens: return transcript # Identify the span we intend to summarize (middle of transcript). span_start, span_end = _select_summarizable_span(transcript, high_water_tokens) for binding in frontier: if span_start <= binding["turn_index"] < span_end: raise PreconditionFrontierViolation( f"Compaction span [{span_start}, {span_end}) would summarize " f"live precondition {binding['id']!r} " f"(tool={binding['tool']!r}, kind={binding['kind']!r}). " f"Defer, pin, or serialize the frontier before compacting." ) summarized = _summarize(transcript[span_start:span_end]) pinned = _extract_pinned_blocks(transcript, frontier) return ( transcript[:span_start] + pinned + [{"role": "summary", "content": summarized}] + transcript[span_end:] ) def _select_summarizable_span(transcript, budget): # Placeholder for the controller's span-selection policy. raise NotImplementedError def _summarize(span): raise NotImplementedError def _extract_pinned_blocks(transcript, frontier): raise NotImplementedError ```