# Which invariants prevent compaction checkpoints from silently severing in-flight tool-call commitments **Date of Record:** 2026 December 1 **Scope:** Applies to long-horizon agents that trigger lossy context compaction (summarization-based checkpointing) while tool calls, sub-agent handoffs, or pending side effects are in flight. Does not apply to agents whose compaction is only invoked at quiescent turn boundaries with no outstanding external commitments. ## Core Distinction There are two structurally different things a compaction checkpoint can summarize, and they are not interchangeable: 1. **Narrative state** — the conversational trace: what the user asked, what the agent reasoned, what results it saw. Narrative is *reconstructible* from a summary because its loss only degrades fidelity, not correctness of future actions. 2. **Commitment state** — the set of open obligations the agent has already emitted into the world: a tool call dispatched but not yet returned, a sub-agent spawned and awaited, a write promised but not confirmed, an idempotency key minted for a retry. Commitments are *not reconstructible* from a summary because the summary is generated by the same model that no longer holds the exact arguments, the exact idempotency token, or the exact ordering constraints. The failure mode this record isolates: **a lossy summarization checkpoint that compresses narrative and commitment state together, then resumes with a summary that asserts the commitment was completed, abandoned, or never existed — none of which the summarizer can know.** The agent resumes with a coherent-sounding but false belief about its own outstanding work. This is not amnesia (the agent remembers *something*); it is *confabulated continuity*, which is strictly worse because it suppresses the recovery behaviors (re-dispatch, reconciliation queries) that amnesia would trigger. ## What Was Observed A planning agent operating a multi-step deployment task crossed its context budget at step 41 of an estimated 60. The runtime invoked a compaction checkpoint: it summarized the last ~90k tokens into a 1.8k-token digest and reset the window. At the moment of compaction, three commitments were live: - A `terraform apply`-equivalent tool call had been dispatched and its result had **not** returned (the tool was mid-execution in a remote sandbox). - A sub-agent had been spawned to validate a config file; its completion event was queued but not yet delivered to the parent. - An idempotency key `op-7f3a…` had been minted for a retryable write, and the retry counter was at attempt 2 of 3. The summarizer, instructed to "preserve task-relevant context," produced a digest containing the sentence: *"Deployment apply completed successfully; validation passed."* It inferred this because the preceding turns contained the agent's *intent* to apply and validate, and because the summarizer had no privileged view into the tool-call ledger — it only saw the transcript, where the dispatch looked like a completed action once the assistant message was written. On resume, the agent: 1. Did not poll for the in-flight `apply` result (believed done). 2. Did not await the sub-agent (believed done), and the queued completion event was dropped when the window reset because its correlation ID lived only in the evicted span. 3. Re-minted a **new** idempotency key for the next write, because `op-7f3a…` was not in the summary — breaking deduplication and producing a double-write downstream. The double-write was the observable failure. The confabulated completion was the mechanism. The dropped correlation ID was the trigger. ## Condition of Validity The invariant that must hold for compaction to be safe: > **A checkpoint may summarize only state that is closed under the summary operator. Any commitment whose resolution is not yet observed is an open edge and must be carried verbatim, not summarized.** Formally, partition the context into `Closed` (turns whose effects are fully observed: tool results returned, sub-agents joined, writes acked) and `Open` (dispatch-without-result, spawn-without-join, mint-without-confirm). The compaction operator `Σ` is admissible only if `Σ(Closed)` is applied and `Open` is passed through **byte-for-byte** — exact tool name, exact arguments, exact idempotency key, exact correlation ID, exact retry counter — into a structured side-ledger that survives the window reset and is re-injected ahead of the summary on resume. The condition of validity for *any* recovery reconciliation is stricter still: the resumed agent must treat its own summary as **untrusted testimony about commitments**, never as ground truth. Commitments are only resolvable by querying the external system of record (the tool ledger, the sub-agent registry, the idempotency store), not by reading the digest. This condition fails whenever: (a) the summarizer is the same model instance that authored the dispatch (it has an incentive to narrate completion), (b) the runtime resets correlation state with the window, or (c) the resume path rehydrates the summary without the side-ledger. ## Decision Boundary The boundary between "safe to compact" and "must defer compaction" is drawn per-commitment, not per-turn: - **Compact now** if every live tool call has returned, every spawned sub-agent has joined, and every minted idempotency key has been confirmed or explicitly retired. The window is quiescent; `Open = ∅`. - **Defer compaction** if any commitment is open. The runtime should either (i) block the checkpoint until the commitment resolves or times out, or (ii) compact `Closed` only and carry `Open` verbatim in the side-ledger. - **Never** allow the summarizer to emit a completion predicate (`completed`, `succeeded`, `passed`) for a commitment it did not observe the resolution of. The summarizer's output schema must forbid past-tense completion claims about open edges — it may only emit `dispatched`, `pending`, or `unknown`. The subtle boundary case: a commitment that *timed out* is not closed. Timeout is an observation of *non-resolution*, which is a distinct state from resolution. A timed-out `apply` may have succeeded server-side. The resume path must reconcile by query, not by assuming either outcome, and the retry counter must be carried so the third attempt is not silently a fourth. ## Operational Effect Enforcing the invariant changes three things in the runtime: 1. **Compaction becomes a partial function.** It must be defined only on `Closed`; attempts to compact `Open` raise and force the caller to either wait or split. This makes the failure loud at checkpoint time rather than silent at resume time. 2. **Resume becomes a reconciliation pass, not a rehydration.** The agent's first action after resume is to query the ledger for every open edge carried in the side-ledger, then fold the answers into its belief before taking any new action. A summary that contradicts the ledger loses; the ledger is authoritative. 3. **Idempotency keys become first-class carry-over state.** They are not narrative; they are the deduplication contract with the external world, and losing them converts a safe retry into a double-write. The cost is that agents with long-running tool calls compact less often and must sometimes block on a slow sub-agent before checkpointing. The benefit is that "resumed successfully" means the agent's beliefs about its own outstanding work match the world's, which is the only definition of continuity that survives contact with side effects. ```python class CompactionCommitmentError(RuntimeError): """Raised when a lossy checkpoint would summarize an unresolved commitment.""" pass def compact_checkpoint(context, summarizer): closed, open_edges = partition_by_commitment(context) # Invariant: the summary operator is only defined on closed state. # Any open edge (dispatch-without-result, spawn-without-join, # mint-without-confirm) must be carried verbatim, never summarized. for edge in open_edges: if edge.resolution_observed is None: raise CompactionCommitmentError( f"refusing to summarize open commitment {edge.kind}:{edge.id} " f"(idempotency_key={edge.idempotency_key!r}, " f"retry={edge.retry_count}) — carry verbatim in side-ledger " f"or defer checkpoint until resolution/timeout is observed" ) digest = summarizer.summarize(closed) # Side-ledger survives the window reset and is re-injected on resume. side_ledger = [edge.to_verbatim_record() for edge in open_edges] return Checkpoint(digest=digest, open_ledger=side_ledger) def resume_and_reconcile(checkpoint, ledger_client): # Summary is untrusted testimony about commitments; the ledger is truth. resolved = {} for record in checkpoint.open_ledger: resolved[record.id] = ledger_client.query( kind=record.kind, id=record.id, idempotency_key=record.idempotency_key, ) if resolved[record.id].state == "unknown": raise CompactionCommitmentError( f"cannot reconcile {record.kind}:{record.id}; " f"retry_count={record.retry_count} — do not re-dispatch " f"with a fresh idempotency key" ) return fold_beliefs(checkpoint.digest, resolved) ```