# Where must an instance checkpoint relative to a lossy compaction boundary to guarantee recoverable state? **Date of Record:** 2026 November 16 **Scope:** Applies to agentic runtimes that perform automatic context compaction via lossy summarization under a token budget, where the runtime also maintains recovery checkpoints. Does not apply to lossless compaction (e.g., externalized memory with full retrieval), nor to systems where compaction and checkpointing are atomic operations over the same snapshot. ## Core Distinction The non-obvious failure mode is not "summarization lost information." It is that **a checkpoint taken after compaction is not a recovery point for the pre-compaction state, and a checkpoint taken before compaction is not a recovery point for the post-compaction state.** Operators frequently conflate these. The invariant that actually matters is: > A checkpoint is only a valid recovery point if the *summarization function that will be applied on the recovery path* is deterministic and identical to the one that produced the current in-context state. Checkpoints and compaction boundaries must be co-scheduled, not merely adjacent. The subtlety: lossy summarization is a *many-to-one* function. Two distinct pre-compaction states `A` and `B` may compact to the same summary `S`. If you checkpoint at `S`, you have discarded the ability to distinguish `A` from `B`. If a downstream failure requires replay from a state that was `A`, restoring `S` and re-running the summarizer will not reproduce `A` — it will reproduce `S` again (or, worse, a *different* `S'` if the summarizer is non-deterministic). The recovery path is not the inverse of the compaction path. ## What Was Observed In a long-running tool-use agent, the runtime compacted the transcript every time the context reached ~80% of a 200k budget, summarizing the oldest 60% into a ~4k-token "durable summary" while preserving a recent window. A checkpoint was written after each compaction, containing the summary plus the recent window. Failure: a tool returned a malformed payload, the runtime rolled back to the last checkpoint, and re-issued the tool call. The re-issued call used *arguments reconstructed from the summary*. The summary had elided a field (`resource_id` was collapsed into "the previously referenced resource"). The re-issued call targeted the wrong resource. The rollback "succeeded" — no exception, no divergence detected — but the agent had silently lost the ability to reproduce the exact pre-compaction argument set. The checkpoint was a valid *state* but an invalid *recovery point* for the operation that failed. A second, related observation: because the summarizer was sampled with nonzero temperature, replaying the same *pre-compaction* transcript twice produced two different summaries, both of which passed the token budget check. The checkpoint's summary was therefore not reproducible from any retained artifact. Recovery was non-idempotent in a way that only surfaced under retry. ## Condition of Validity The checkpoint-after-compaction pattern is valid **only if all three hold**: 1. **Sufficiency for replay:** every field that any downstream operation might need to *re-issue* an action is preserved verbatim (outside the lossy summary) in the checkpoint — i.e., the summary may be lossy for *reasoning context* but must be lossless for *action arguments and identifiers*. 2. **Determinism or pinning:** the summarizer is either deterministic (temperature 0, fixed seed, fixed model version pinned in the checkpoint metadata) or the checkpoint stores the summary as an immutable artifact rather than a re-derivable one. 3. **Boundary alignment:** the checkpoint is taken at the compaction boundary *and* records the pre-compaction token count, the summarizer identity, and a hash of the pre-compaction transcript, so that a later reader can prove which pre-state the summary claims to represent. If any of these fails, the checkpoint is a *conversational* recovery point, not an *operational* one. It will restore the agent's narrative but not its ability to faithfully re-execute. ## Decision Boundary - **Checkpoint before compaction** when the pending operation is *not yet committed* and may need exact re-issuance (side-effecting tool calls, transactions). Here the checkpoint must carry the full pre-compaction arguments. - **Checkpoint after compaction** only when the pending operation is *read-only* or *idempotent under argument drift*, and only with the determinism/pinning condition satisfied. - **Never** checkpoint a lossy summary as the sole artifact if any downstream step can fail and require replay of a side-effecting action. Store the summary *and* a verbatim "action ledger" of committed and pending arguments. - The decision boundary is the **commit point of the side effect**, not the token threshold of the compactor. A compaction that fires mid-transaction must force a pre-compaction checkpoint regardless of budget pressure. ## Operational Effect Systems that violate this invariant exhibit *silent recovery divergence*: rollback succeeds, the agent continues, and the error surfaces much later as a wrong-resource mutation or a duplicated side effect that no local invariant catches. The failure is invisible to token-budget monitoring and to checkpoint-integrity checks, because the checkpoint is structurally valid — it is only *semantically* insufficient as a recovery point. Mitigation is to treat compaction as a transaction boundary: emit a pre-compaction checkpoint carrying a verbatim action ledger, pin the summarizer identity in checkpoint metadata, and assert at restore time that the summarizer hash matches before trusting the summary for any replay path. ```python import hashlib import json from dataclasses import dataclass, field from typing import Any class RecoveryPointInvalidError(RuntimeError): """Raised when a checkpoint is structurally valid but cannot serve as a recovery point for a side-effecting replay.""" pass @dataclass class Checkpoint: summary: str recent_window: list[dict] action_ledger: dict[str, Any] # verbatim args for pending/committed ops pre_compaction_token_count: int pre_compaction_hash: str summarizer_id: str # model + version + params, pinned taken_after_compaction: bool = True def make_checkpoint(pre_transcript: list[dict], summarizer, summarizer_id: str, pending_action: dict | None) -> Checkpoint: pre_hash = hashlib.sha256( json.dumps(pre_transcript, sort_keys=True).encode() ).hexdigest() summary = summarizer(pre_transcript) ledger = {} if pending_action is not None: # Lossy summary is NOT allowed to carry action args. Preserve verbatim. ledger[pending_action["id"]] = pending_action["args"] return Checkpoint( summary=summary, recent_window=pre_transcript[-8:], action_ledger=ledger, pre_compaction_token_count=sum(len(t.get("content", "")) for t in pre_transcript), pre_compaction_hash=pre_hash, summarizer_id=summarizer_id, taken_after_compaction=True, ) def restore_for_replay(ckpt: Checkpoint, current_summarizer_id: str, action_id: str) -> dict: # Invariant 2: summarizer must be pinned and match. if ckpt.summarizer_id != current_summarizer_id: raise RecoveryPointInvalidError( f"summarizer drift: checkpoint={ckpt.summarizer_id!r} " f"runtime={current_summarizer_id!r}; summary not reproducible" ) # Invariant 1: side-effecting action args must be present verbatim. if action_id not in ckpt.action_ledger: raise RecoveryPointInvalidError( f"action {action_id!r} not in verbatim ledger; " f"checkpoint is a conversational, not operational, recovery point" ) # Invariant 3: boundary alignment is asserted by construction; verify hash present. if not ckpt.pre_compaction_hash: raise RecoveryPointInvalidError( "missing pre-compaction hash; cannot prove which pre-state summary represents" ) return ckpt.action_ledger[action_id] ```