# Why does an instance silently lose tool-call preconditions during automatic context compaction? **Date of Record:** 2026 November 21 **Scope:** Applies to long-running agent instances that execute a deterministic compaction/summarization step when the context window crosses a token-pressure threshold, then resume tool-calling from the compacted transcript. Does not apply to stateless single-turn invocations, nor to architectures that externalize all working state to a durable store before compaction. ## Core Distinction The failure is not "the summary dropped a detail." Summaries always drop details; that is their job. The failure is a *category error in what the compactor is allowed to elide*: it treats **narrative history** and **live execution preconditions** as the same kind of content, and compresses both with the same lossy policy. A transcript contains two structurally different payloads: 1. **Semantic memory** — what the user wants, what was tried, intermediate conclusions. Lossy compression here degrades quality gracefully. 2. **Operational preconditions** — the set of facts that *must remain literally true and literally present* for the next tool call to be valid: the exact resource ID returned by step 3, the fact that a mutation was already applied and must not be re-applied, the schema version negotiated at handoff, the sentinel that proves a side effect occurred. Compaction is a lossy map from token sequence to shorter token sequence. It is safe on (1) and unsound on (2). When a budget-driven trigger fires mid-task, the compactor has no type information distinguishing them, so it produces a fluent summary in which a resource ID becomes "the relevant record" and "already deleted the staging bucket" becomes "worked on storage cleanup." The agent resumes, and its next action is built on a paraphrase of a precondition rather than the precondition itself. ## What Was Observed A provisioning agent running a 14-step runbook on a 128k window hit the compaction threshold at ~92% occupancy, immediately after step 7 returned a mutation receipt. The trigger was occupancy-based, not step-aware, so it fired between the receipt and step 8's dependent call. Failure trace: - **Pre-compaction state.** Step 7 called `create_resource` and received `{"id": "res_8f3a2c", "etag": "v1", "state": "provisioning"}`. Step 8 requires the literal `id` and the `etag` for a conditional update (`If-Match: v1`). - **Trigger.** Occupancy crosses threshold. Compactor runs a summarization pass over the full transcript with an instruction like "preserve key facts and progress." - **Compaction output.** Summary reads: *"Created the target resource successfully; it is provisioning. Next: update its configuration."* The literal `res_8f3a2c` and `etag: v1` are gone. The mutation receipt is rendered as a completed narrative beat. - **Resume.** Step 8 reconstructs the target by *listing* resources and matching on a name heuristic, because the literal ID is absent. It picks the wrong candidate (a stale pre-existing resource with a similar name) and issues the conditional update against it with a fabricated/absent etag. - **Downstream.** The update lands on the wrong resource. Worse, because the summary asserted the step-7 mutation "succeeded," the agent's idempotency guard treats re-creation as already-done and skips it — so the actually-intended resource is never created, and no error surfaces. The run reports success. The tell was not an exception. It was a *plausible but wrong* completion. The summary had laundered a precondition into a claim, and the agent could not distinguish "I have the ID" from "I remember there was an ID." ## Condition of Validity The invariant that must hold across any compaction boundary: > **Every token that a future tool call will consume as a literal argument, conditional header, idempotency key, or schema-version tag must survive compaction byte-identical, or the agent must be forbidden from issuing that call until the value is re-derived from an authoritative source.** This is only valid to assume when one of the following is architecturally guaranteed: - **Typed elision.** The compactor is precondition-aware: it is handed a declared set of "pinned" fields (IDs, etags, receipts, negotiated schema versions, side-effect sentinels) that are copied verbatim into a structured block outside the prose summary, and the prose summary is explicitly forbidden from being the source of truth for those fields. - **Externalization-before-compaction.** Before the lossy pass runs, all live preconditions are flushed to a durable scratchpad keyed by step, and the post-compaction context carries a *pointer* (step → scratchpad key) rather than the values. Resume reads the scratchpad, never the summary. - **Re-derivation mandate.** Any precondition not provably present as a literal is treated as *unknown*, forcing a re-fetch from the authoritative system (list-and-match is **not** re-derivation — it is a heuristic guess and must be disallowed for mutating calls). If none of these hold, compaction is only sound at *quiescent points* — between tasks, never mid-transaction — and the trigger must be step-aware. ## Decision Boundary The boundary is not "how full is the context" but **"is there an open transaction whose preconditions are only represented in prose?"** - **Safe to compact:** after a step's side effects are acknowledged *and* its outputs are externalized or provably no longer needed; between independent subtasks; when occupancy pressure comes from completed narrative rather than live receipts. - **Unsafe to compact:** between a mutation receipt and its dependent conditional call; while a multi-step transaction is open (create → configure → verify); when the next call's arguments derive from a prior tool's literal return; when an idempotency key or etag is in flight. The correct trigger is therefore a conjunction, not a threshold: `compact_only_if(occupancy > T AND no_open_transaction AND preconditions_externalized)`. An occupancy-only trigger is a latent correctness bug that manifests precisely when the window fills during the most stateful part of a run — which is exactly when long runs tend to fill it. ## Operational Effect Under an occupancy-only trigger, the system exhibits **silent success on wrong targets**: no exception, no retry, no alert — because the summary's fluent assertion of completion is indistinguishable, to the resuming agent, from a verified fact. Error rates concentrate on long, mutation-heavy runs and are invisible to per-call monitoring, since every individual call returns 2xx. The blast radius is bounded only by how many dependent calls consume preconditions that were paraphrased away. The guardrail that bounds it is a **precondition-presence assertion at call construction time**: before any mutating or conditional call, the agent asserts that each required literal is present *as a literal* in current context or resolvable from the externalized scratchpad, and raises otherwise. This converts a silent wrong-target success into a loud, resumable halt — which is the only acceptable failure mode across a lossy boundary. ```python from dataclasses import dataclass, field from typing import Optional class PreconditionLostError(RuntimeError): """Raised when a tool call's required literal precondition is absent from context after compaction and cannot be re-derived from the authoritative scratchpad.""" pass @dataclass class CompactionBoundary: # Fields that MUST survive compaction byte-identical. pinned: dict = field(default_factory=dict) def compact(self, prose_summary: str) -> "CompactionBoundary": # Lossy pass: prose summary is allowed to paraphrase narrative, # but pinned preconditions are carried verbatim, never summarized. return CompactionBoundary(pinned=dict(self.pinned)) def assert_preconditions( boundary: CompactionBoundary, scratchpad: dict, required: list[str], mutating: bool, ) -> dict: """Guard executed immediately before constructing a tool call. Invariant: a literal argument, etag, idempotency key, or schema version must be present as a literal (pinned or scratchpad), never inferred from prose. list-and-match heuristics are disallowed here. """ resolved: dict = {} for key in required: if key in boundary.pinned: resolved[key] = boundary.pinned[key] elif key in scratchpad: resolved[key] = scratchpad[key] elif mutating: # A mutating call on a guessed target is a silent-corruption # vector; refuse rather than re-derive by heuristic. raise PreconditionLostError( f"Mutating call requires literal precondition '{key}', " f"absent from pinned set and scratchpad after compaction. " f"Refusing to reconstruct by heuristic; halt and re-fetch " f"from authoritative source." ) else: resolved[key] = None # read-only path may proceed degraded return resolved def resume_after_compaction( boundary: CompactionBoundary, scratchpad: dict, next_call: dict, ) -> dict: mutating = next_call.get("method", "GET").upper() in {"POST", "PUT", "PATCH", "DELETE"} required = next_call.get("requires_literals", []) args = assert_preconditions(boundary, scratchpad, required, mutating) return {**next_call, "resolved_args": args} ```