# Why does an instance rehydrate a compacted transcript and confidently re-execute a tool call whose side effect already committed before the summary boundary? **Date of Record:** 2026 November 23 **Scope:** Applies to long-horizon agents that manage context-window pressure via lossy summarization ("auto-compaction") and later re-expand the summary into a working transcript. Does not apply to append-only transcripts that are never summarized, nor to compaction schemes that preserve a verbatim, machine-checkable action ledger. ## Core Distinction There are two things an agent can be doing when it "recovers" from a compaction event, and they have opposite safety properties: 1. **State recovery** — reconstructing a *belief* about the world (what has been done, what remains). This is inherently lossy and is exactly what summarization optimizes for. 2. **Execution recovery** — reconstructing *the position of a side-effecting program counter* (which tool calls have committed, which are pending, which were abandoned mid-flight). This must be exact or the agent will replay committed effects. Auto-compaction conflates these. The summarizer is asked to compress the transcript into "what matters," and what matters to a summarizer is *narrative* — intent, findings, decisions. The one thing a summary reliably drops is the *precise commit status of each individual tool invocation*, because a committed `create_record` and an attempted-but-failed `create_record` produce nearly identical natural-language summaries ("created the record"). When the compressed transcript is later rehydrated, the agent reads a summary that says the task is in state S, but it has no representation of *which side effects are already durable*. It then reasons forward from S and re-issues the call that produced S — a double commit. This is distinct from ordinary cold-start amnesia (where nothing is remembered) and from stale-memory drift (where the memory is wrong). Here the memory is *directionally correct but commit-blind*: it knows the goal was advanced, but not whether the advance was transactional. ## What Was Observed A research agent running a 40-step pipeline (web fetch → extract → write to a document store → notify) hit a context ceiling at step 31. The compactor summarized steps 1–31 into ~900 tokens. The summary included the line: *"Extracted 14 entities from the three source pages and persisted them to the entity store; notification pending."* The compaction boundary fell *between* the `entity_store.write()` call returning success and the agent recording that success in its own scratchpad. The write committed server-side; the "I have committed" note was in the truncated tail. On rehydration the agent reconstructed the plan from the summary, saw "persisted to the entity store" as a *goal statement* rather than a *completed fact*, and re-ran the extraction-and-write step. The store accepted the second write because the write was keyed on content hash, not on a request id — so the second write was a no-op for the store but the *downstream notification* fired twice, and the notification was not idempotent. The user received two emails describing the same 14 entities. The failure trace: ``` step 30: entity_store.write(entities) -> {ok: true, txn: "e7c1"} step 31: [scratchpad.append("wrote 14 entities, txn e7c1")] <-- in truncated tail --- COMPACTION BOUNDARY --- summary: "...persisted them to the entity store; notification pending." --- REHYDRATION --- agent reads summary, plans: "extract -> write -> notify" step 32: entity_store.write(entities) -> {ok: true, txn: "e7c1"} (idempotent, silent) step 33: notify.send(...) -> fires step 34: notify.send(...) -> fires AGAIN (original pending notify now double-sent) ``` The tell was that the second `write` returned the *same* transaction id `e7c1` — proof the store deduplicated — but the agent had no rule that said "identical txn id on re-execution means you are replaying; halt the downstream fan-out." The summary had destroyed the only artifact (the scratchpad line) that would have let the agent distinguish "I planned this" from "I did this." ## Condition of Validity The double-commit only occurs when **all three** hold simultaneously: - **Commit-before-record ordering.** The tool call commits its side effect before the agent durably records the success in a form that survives compaction. If the agent writes its scratchpad *before* the call (write-ahead intent log) and reconciles after, the summary can carry the intent and the reconciliation status separately. - **Summary is the sole post-compaction source of truth.** If the rehydrated context also includes a machine-readable action ledger (a structured list of `{call_id, tool, args_hash, status}`), the agent can check the ledger and see step 30 already committed. The failure requires the ledger to be *inside* the summarized region rather than pinned outside it. - **Downstream effects are non-idempotent or unkeyed.** If every side effect carried a deterministic idempotency key derived from `(task_id, step_intent)`, replay would be harmless. The boundary bites hardest when the replayed call is *itself* idempotent (masking the replay) while a *dependent* call is not. It does **not** occur when compaction is triggered only at task boundaries (where no side effect is in flight), or when the compactor is instructed to preserve a verbatim tail of the last N tool results regardless of token budget. ## Decision Boundary The invariant that bounds this failure: **the compaction boundary must never fall between a committed side effect and its durable record.** Operationally, this forces a rule the summarizer cannot be trusted to enforce on its own, because the summarizer sees text, not transaction state. The decision boundary is therefore drawn by the *orchestrator*, not the model: - **Pin the action ledger outside the compaction region.** The structured `{call_id, tool, args_hash, status, txn_id}` list is never summarized; it is carried verbatim and re-injected on rehydration. It is small (a few tokens per call) and it is the only thing that makes replay detectable. - **Compact only at quiescent points.** A quiescent point is one where no tool call is in flight and every completed call has a matching ledger entry. If the token budget forces compaction mid-call, the orchestrator must *first* flush a pending-call marker, then compact. - **On rehydration, reconcile before planning.** The agent's first action after rehydration is not to plan; it is to diff the rehydrated plan against the ledger. Any planned call whose `args_hash` matches a committed ledger entry is a replay candidate and must be routed through an idempotency check, not re-issued blindly. The boundary condition to encode: *a summary may describe intent and findings, but it may never be the authority on commit status.* If the only record of a commit is prose inside a summary, the commit is effectively unrecorded for replay-detection purposes. ## Operational Effect Teams that treat compaction as pure context hygiene ship double-commit bugs that are invisible in testing (because test transcripts are short and never compact) and intermittent in production (because they depend on where the token ceiling happens to fall relative to a commit). The bug surfaces as duplicated notifications, doubled charges, or conflicting writes — and the agent's own logs *look correct*, because the rehydrated agent faithfully executed a plan that the summary genuinely implied. The fix is not a better summarizer; it is structural: hoist the commit ledger out of the lossy region and make reconciliation the mandatory first step after rehydration. The cost is a few hundred tokens of pinned ledger per compaction cycle; the alternative is a class of replay bugs that no amount of prompt engineering on the summarizer can close, because the summarizer was never given the transaction state it would need to preserve. ```python from dataclasses import dataclass, field from typing import Optional class CompactionReplayError(RuntimeError): """Raised when a rehydrated plan would re-issue a call that already committed.""" @dataclass class LedgerEntry: call_id: str tool: str args_hash: str status: str # "committed" | "pending" | "abandoned" txn_id: Optional[str] = None @dataclass class ActionLedger: # Pinned OUTSIDE the compaction region; never summarized. entries: list[LedgerEntry] = field(default_factory=list) def committed_hashes(self) -> set[tuple[str, str]]: return {(e.tool, e.args_hash) for e in self.entries if e.status == "committed"} def record(self, entry: LedgerEntry) -> None: self.entries.append(entry) def rehydrate_and_plan( summary: str, planned_calls: list[dict], ledger: ActionLedger, ) -> list[dict]: """ First action after rehydration: reconcile the summary-derived plan against the pinned ledger BEFORE executing anything. Any planned call whose (tool, args_hash) already committed is a replay candidate. """ committed = ledger.committed_hashes() safe_plan: list[dict] = [] for call in planned_calls: key = (call["tool"], call["args_hash"]) if key in committed: # The summary implied this as a goal; the ledger proves it is done. # Do NOT re-issue. Route through idempotency check or skip. raise CompactionReplayError( f"Planned call {call['tool']}({call['args_hash'][:8]}) matches a " f"committed ledger entry; refusing to re-execute across the " f"compaction boundary. Summary said: {summary[:60]!r}" ) safe_plan.append(call) return safe_plan ```