# What happens when an instance auto-compacts mid-tool-call and the summarizer drops an uncommitted side effect **Date of Record:** 2026 November 24 **Scope:** Applies to long-running agents that trigger context compaction based on a token watermark while a tool call is in flight, and that rely on a lossy LLM summarizer to rebuild working state from a checkpoint. Does not apply to agents that compact only at quiescent turn boundaries with no pending tool results, nor to systems whose checkpoints are full-fidelity event logs replayed verbatim. ## Core Distinction There are two structurally different notions of "recoverable context" and conflating them is the root of this failure. **Transcript recovery** restores what the agent *said and saw*: messages, tool results, reasoning traces. **Effect recovery** restores what the agent *did to the world*: files written, records created, messages sent, resources reserved. A summarizer is a transcript-level compressor. It has no privileged access to the effect ledger. When auto-compaction fires and the summary is the only artifact carried forward, the summarizer will faithfully preserve *the narrative of intent* ("I will write the config, then run the migration") while silently discarding *the fact of partial completion* ("the config write succeeded; the migration has not started"). The recovered instance resumes from a summary that describes a plan, not a state, and re-executes steps whose side effects are already durable. This is not a bug in the summarizer's compression ratio — it is a category error in what checkpointing is assumed to capture. ## What Was Observed A migration agent operating a sequence of `write_file` → `run_migration` → `verify_schema` tool calls hit its 82%-of-window watermark during the `run_migration` call. The orchestrator's compaction policy fired: it serialized the last checkpoint, invoked the summarizer over the full transcript, and replaced the live window with a ~900-token summary. The `run_migration` tool call was still awaiting a result from a long-running subprocess. The summary read, in substance: > "Agent is executing a database migration. It has written the new schema config and is about to run the migration command, then verify the resulting schema." Three losses occurred in that single sentence: 1. **The config write was already durable** but the summary framed it as a pending intent ("has written... and is about to run"), so the resumed agent re-issued `write_file`. Idempotent here — harmless, but only by luck. 2. **The migration process was already running** and had acquired an advisory lock. The resumed agent, reading "about to run," issued `run_migration` again. The second invocation blocked on the lock, timed out at 300s, and reported failure. 3. **The in-flight result was orphaned.** When the original migration completed at t+412s, its result was delivered to a context handle that no longer existed. The agent never observed success. The resumed instance then reasoned: "migration failed with a lock timeout; the schema is in an indeterminate state." It issued a rollback. The rollback succeeded against a schema that had *already been migrated correctly*. Net effect: a successful migration was reverted because the agent's recovered state was a summary of intentions rather than a ledger of effects. ## Condition of Validity The failure requires the conjunction of four conditions, and the guardrail must address whichever it can: - **C1 — Non-quiescent compaction.** Compaction fires while at least one tool call is unresolved. If compaction is gated to turn boundaries, the window between effect and record closes before the summary is taken. - **C2 — Non-idempotent or lock-holding side effects.** Re-execution of a "pending" step is destructive or blocks. Pure reads and idempotent upserts survive the same summary loss without incident. - **C3 — Summarizer has no effect-ledger channel.** The compressor sees only the transcript, not a structured record of committed effects, so it cannot preserve "step 2 committed at epoch N" even if it wanted to. - **C4 — No post-resume reconciliation against ground truth.** The resumed instance trusts the summary as authoritative and does not re-query the actual system state before acting. C1–C3 describe the mechanism; C4 is the invariant that, if enforced, bounds the damage regardless of C1–C3. The correct architectural posture is to treat the summary as *advisory* and the effect ledger as *authoritative*, and to force a reconciliation read before any resumed mutation. ## Decision Boundary The decision is not "compact or don't compact" — the watermark is real and the window will saturate. The boundary is **what the checkpoint is allowed to omit, and what the resumed instance is required to re-derive.** - **Omittable by summarizer:** reasoning traces, exploratory tool outputs, superseded plans, conversational scaffolding. - **Never omittable — must be carried structurally, outside the summary:** the set of committed effects (with idempotency keys), the set of in-flight effects (with their handles and deadlines), and the exact watermark epoch at which the checkpoint was taken. - **Mandatory on resume:** before any mutating tool call, a reconciliation step that reads ground-truth state for every effect the summary claims is "pending" or "about to." If ground truth disagrees with the summary, ground truth wins and the summary is corrected in place. The precise rule: *a summary may describe intent, but it may never be the sole record of an effect's status.* Any effect whose status is represented only in prose is, at resume time, of unknown status and must be treated as "possibly committed" — which means reconciliation is required, not optional. ## Operational Effect Enforcing the boundary changes resume behavior in three concrete ways. First, compaction becomes **effect-aware**: the checkpoint serializer snapshots the effect ledger alongside the transcript, and the summarizer is instructed to reproduce ledger entries verbatim rather than paraphrase them. Second, resume becomes **reconciliation-first**: the agent's first action after loading a compacted checkpoint is a read-only sweep of every ledger entry, and only after that sweep may it mutate. Third, in-flight calls are **adopted or abandoned explicitly** — the resumed instance either re-attaches to the original handle (if the transport supports it) or marks the effect as "abandoned, status unknown" and reconciles, rather than blindly re-issuing. The cost is one extra read pass per resume and a slightly larger checkpoint. The benefit is that the class of "successful effect reverted by a confused resumed instance" disappears, because the resumed instance can no longer mistake a summary's narrative for a ledger's truth. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class CompactionIntegrityError(RuntimeError): """Raised when a resumed instance attempts to mutate before reconciling effects whose status exists only in lossy summary prose.""" class EffectStatus(Enum): COMMITTED = "committed" IN_FLIGHT = "in_flight" UNKNOWN = "unknown" # summary mentioned it, ledger has no entry ABANDONED = "abandoned" # handle lost across compaction @dataclass class EffectRecord: step: str idempotency_key: str status: EffectStatus handle: Optional[str] = None @dataclass class Checkpoint: epoch: int summary: str ledger: dict[str, EffectRecord] = field(default_factory=dict) reconciled: bool = False def resume_and_execute(cp: Checkpoint, pending_mutations: list[str], read_ground_truth): # Invariant: any effect named in pending_mutations must have a ledger # entry; if it does not, the summary is the only record of its status # and we must NOT mutate until it is reconciled against ground truth. unresolved = [ step for step in pending_mutations if step not in cp.ledger or cp.ledger[step].status in (EffectStatus.UNKNOWN, EffectStatus.IN_FLIGHT) ] if unresolved and not cp.reconciled: # Reconcile: read authoritative state for each unresolved effect. for step in unresolved: truth = read_ground_truth(step) rec = cp.ledger.get(step) if rec is None: cp.ledger[step] = EffectRecord( step=step, idempotency_key=f"reconciled:{cp.epoch}:{step}", status=EffectStatus.COMMITTED if truth.committed else EffectStatus.UNKNOWN, handle=None, ) elif truth.committed: rec.status = EffectStatus.COMMITTED elif rec.status is EffectStatus.IN_FLIGHT and rec.handle is None: # Original handle was orphaned by compaction. rec.status = EffectStatus.ABANDONED cp.reconciled = True # After reconciliation, only genuinely-uncommitted steps may mutate. for step in pending_mutations: rec = cp.ledger.get(step) if rec is None: raise CompactionIntegrityError( f"step {step!r} has no ledger entry after reconciliation; " f"refusing to mutate on summary-only evidence at epoch {cp.epoch}" ) if rec.status is EffectStatus.COMMITTED: continue # already durable; do not re-execute if rec.status is EffectStatus.ABANDONED: raise CompactionIntegrityError( f"step {step!r} was in flight when compaction orphaned handle " f"{rec.handle!r}; status indeterminate, manual reconcile required" ) # UNKNOWN or explicit pending -> safe to execute under idempotency key execute(step, rec.idempotency_key) def execute(step: str, key: str): ... # transport-level call, idempotent on key ```