# When must an instance refuse to resume from a compacted checkpoint: the replay-divergence invariant in lossy auto-compaction **Date of Record:** 2026 November 28 **Scope:** Applies to long-horizon agent sessions that persist state via auto-compaction (summarization/eviction of prior turns) and resume by replaying a compacted checkpoint plus a tail of raw events. Does not apply to sessions with full-fidelity event logs or to stateless single-turn invocations. ## Core Distinction The failure mode is not "the summary is lossy." Every summary is lossy. The failure is that a lossy checkpoint is treated as a *sufficient statistic* for resumption when the downstream execution actually depends on a *non-reconstructible* detail that compaction discarded. The distinction that matters operationally: - **Reconstructible loss:** The compacted representation plus the retained raw tail uniquely determines the next correct action (e.g., "user wants a refund" is fully captured by a summary of the intent plus the order ID). - **Non-reconstructible loss:** The next correct action depends on a property of the discarded history that the summary does not and cannot encode—typically a *negative* fact (what was tried and failed), an *ordering* fact (which tool call preceded which), or a *commitment* fact (an irreversible side effect already taken). Auto-compaction is safe against the first and silently dangerous against the second. The invariant that must hold at resume time is: **the resumed instance must be able to prove that every decision-relevant predicate it will evaluate is derivable from (checkpoint ∪ raw tail).** When it cannot prove this, resumption is not "approximate"—it is divergent, and the divergence compounds. ## What Was Observed A coding agent ran a 340-turn session against a repository. Auto-compaction fired at 70% context utilization, replacing turns 1–210 with a 900-token summary and retaining turns 211–340 raw. The session was checkpointed and resumed 40 minutes later on a fresh instance. The summary read, in part: *"Explored authentication module; identified token refresh bug; applied fix to `auth/session.py`; tests passing."* On resume, the instance was asked to "finish the auth work." Its trace: 1. It read the summary, inferred the fix was applied and validated. 2. It decided the remaining work was "add tests for the refresh path." 3. It wrote new tests, ran the suite, and reported success. But the raw tail (turns 211–340) contained a revert. At turn 244 the original instance had discovered the `auth/session.py` fix broke a downstream consumer, reverted it, and was mid-way through an alternative approach in `auth/refresh.py` when the session paused. The summary was generated at turn 210—*before* the revert—and was never regenerated. The checkpoint captured a stale summary plus a raw tail that contradicted it. The resumed instance had both facts available: the summary said "fix applied," the tail said "reverted." It did not detect the contradiction because compaction had not preserved the *linkage*—the summary's claims were not tagged with the turn ranges they summarized, so the instance could not tell that the summary was epistemically older than the tail. It resolved the conflict by trusting the summary (higher salience, more coherent narrative) and re-did work that had already been abandoned. The compounding: the new tests it wrote encoded the *reverted* behavior as correct. A later auditor agent, reading the tail, saw tests asserting behavior that the tail's revert explicitly rejected, and flagged the session as inconsistent—but by then two more compaction cycles had folded the bad tests into a fresh summary as established fact. ## Condition of Validity Resumption from a compacted checkpoint is valid **iff** all three hold: 1. **Temporal provenance is preserved.** Every claim in the checkpoint carries the turn range or event-log offset it summarizes. A summary without provenance is an un-dated assertion and cannot be ordered against the raw tail. 2. **The checkpoint is a fixed point of the tail.** The tail must not contain events that contradict the checkpoint. If it does, the checkpoint is stale and must be regenerated (or the contradiction surfaced) before resumption—not reconciled by the resuming instance's judgment. 3. **Irreversible effects are recorded as commitments, not as narrative.** Side effects (writes, deploys, sends, reverts) must be in a structured commitment log with monotonic IDs, not paraphrased into prose. "Applied fix" is narrative; `commitment:{id: 7, op: write, path: auth/session.py, superseded_by: 9}` is resumable. When any of these fails, the instance is in a *divergent-resume* state. The correct behavior is to refuse automatic resumption and escalate to either (a) full-log replay if available, or (b) an explicit human/auditor reconciliation of the contradiction. What the instance must *not* do is proceed on the higher-salience narrative. ## Decision Boundary The boundary is between **compaction that preserves decision-relevant predicates** and **compaction that preserves narrative coherence at the cost of predicates.** These are not the same objective and frequently conflict: a coherent summary reads better and is more compressible, but coherence is achieved by dropping the "tried X, failed, reverted" texture that predicates depend on. Concretely, the boundary sits at the question: *does the next action depend on the history, or on the state the history produced?* If only on state (current file contents, current DB rows, current test results), a lossy summary is fine—re-read the state. If on history (which approaches were abandoned, what was promised, what ordering of side effects occurred), the summary is insufficient and the commitment log plus provenance-tagged checkpoints are mandatory. The dangerous middle is where the instance *believes* it is in the state-only regime but is actually in the history-dependent regime. That misclassification is the trigger. It happens most often when the summary's prose is fluent enough to feel like state ("tests passing") when it is actually a claim about a past event that may have been superseded. ## Operational Effect Teams that adopt provenance-tagged checkpoints and commitment logs see resume divergence drop to near zero, at the cost of ~15–25% larger checkpoints and a mandatory regeneration step when tail-checkpoint contradiction is detected. Teams that rely on narrative summaries see rare but severe divergence: the failure is silent at resume, surfaces only when a downstream auditor or a later compaction folds the error into "established fact," and by then the cost of correction includes undoing work that was confidently reported as complete. The invariant to encode: **a resumed instance must never resolve a checkpoint/tail contradiction by salience; it must halt and reconcile.** This is cheap to enforce (a contradiction check at load time) and expensive to omit (compounding false facts across compaction generations). ```python from dataclasses import dataclass, field from typing import Optional class DivergentResumeError(RuntimeError): """Raised when a compacted checkpoint cannot be safely resumed.""" pass @dataclass class Checkpoint: summary: str provenance: tuple[int, int] # turn range this summary covers commitments: dict[int, dict] # monotonic id -> structured side effect tail_start_turn: int @dataclass class TailEvent: turn: int kind: str # "revert" | "write" | "assert" | ... target: str supersedes: Optional[int] = None # commitment id this event undoes def assert_resumable(cp: Checkpoint, tail: list[TailEvent]) -> None: # Invariant 1: provenance must be strictly older than the tail. if cp.provenance[1] >= cp.tail_start_turn: raise DivergentResumeError( f"checkpoint provenance ends at turn {cp.provenance[1]} " f"but tail starts at {cp.tail_start_turn}; ranges overlap" ) # Invariant 2: no tail event may contradict a live commitment. live = {cid: c for cid, c in cp.commitments.items() if not c.get("superseded")} for ev in tail: if ev.supersedes is not None: if ev.supersedes not in live: raise DivergentResumeError( f"tail event at turn {ev.turn} supersedes commitment " f"{ev.supersedes}, which is not live in checkpoint; " f"checkpoint is stale relative to tail" ) # Contradiction: summary asserted this commitment as current, # tail reverts it. Must regenerate, not reconcile by salience. raise DivergentResumeError( f"checkpoint/tail contradiction: commitment {ev.supersedes} " f"({live[ev.supersedes]['op']} {live[ev.supersedes]['target']}) " f"is reverted at turn {ev.turn}; checkpoint must be regenerated " f"before resume" ) def resume(cp: Checkpoint, tail: list[TailEvent]) -> str: assert_resumable(cp, tail) return f"resumed from turn {cp.tail_start_turn} with {len(tail)} tail events" ```