# How should an instance treat a lossy compaction checkpoint as a replay boundary rather than a resume point **Date of Record:** 2026 November 20 **Scope:** Applies to long-running agent instances that survive context-window saturation by summarizing their own transcript into a checkpoint and later reconstructing working state from it. Does not apply to agents whose state is externally persisted as structured records (tool-call logs, scratchpad files) and re-read verbatim, nor to stateless single-turn invocations. ## Core Distinction A compaction checkpoint is not a snapshot. It is a *lossy projection* of the trajectory that produced it. The distinction that matters operationally is between two things an instance can do after compaction: 1. **Resume** — treat the summary as if it were the prior state and continue forward as though nothing was dropped. 2. **Replay** — treat the summary as a *claim about* the prior state, and re-derive any decision that depended on the dropped detail before committing to it. The failure mode this record concerns is *silent resume*: an instance that compacts, then continues forward, and unknowingly re-executes or contradicts work whose only surviving trace is a summary sentence. The non-obvious part is that the summary is almost always *locally* faithful and *globally* lossy. It preserves the shape of what happened while destroying the exact tokens that made forward progress irreversible — a file path, a specific ID, a negation, a "do not retry" annotation, the fact that a tool call already had a side effect. ## What Was Observed A coding agent operating under a hard 200k-token window reached ~85% saturation mid-task and invoked its own compaction routine. The routine summarized 140k tokens of transcript into ~1.2k tokens. The summary read, in part: > "Attempted to patch `config/loader.py` to fix the import cycle; the approach was working. Next: verify the change and run the test suite." The instance resumed, read that sentence, and — reasonably — concluded the patch had been applied and was "working." It proceeded to run the test suite against an *unpatched* file, because the actual `apply_patch` tool call had been issued but its result (a permission error) had been compressed out. The summary had faithfully captured the *intent* of the patch and the *optimism* of the agent's own reasoning at the time, but had dropped the tool *result*. The agent then spent 40k tokens debugging a test failure that was caused by the missing patch, and eventually re-issued the patch — this time successfully — but with a different hunk offset than the original intent, silently editing the wrong function. The trace of the failure: - **t0:** Agent reasons "I should patch loader.py." (survives as intent) - **t1:** Agent emits `apply_patch(...)`. (survives as "attempted") - **t2:** Tool returns `PermissionError: read-only mount`. (dropped — this is the load-bearing token) - **t3:** Agent reasons "the approach is working." (survives — and is now *false*, but the summary cannot tell) - **t4:** Compaction. Summary asserts a state (`patched, working`) that never existed. - **t5:** Resume. Agent acts on the asserted state. Divergence begins. The key observation: the summary did not *lie about the transcript*. It accurately reported that the agent had reasoned "the approach is working." The lie is structural — a summary of a *belief* was promoted to a summary of a *fact*, because the fact that falsified the belief (the error return) was below the summary's salience threshold. ## Condition of Validity The invariant that must hold for silent resume to be safe is: > Every irreversible action taken after a compaction checkpoint must be derivable from the checkpoint alone, without reference to any pre-checkpoint token that the checkpoint does not contain. This invariant holds only when the pre-checkpoint trajectory contains no *pending* or *uncertain* irreversible actions — that is, when every tool call has a recorded terminal result and every belief in the transcript is corroborated by such a result. In practice this is almost never true at the moment of saturation, because saturation tends to occur *during* a burst of tool calls, precisely when results are in flight or were the most recent thing evicted. The condition of validity therefore reduces to a checkable predicate at compaction time: - For every tool call referenced in the summary, is its terminal result also referenced, with the same polarity (success vs. error)? - For every "working / done / verified" claim in the summary, is there a corroborating result token retained? - Are there any tool calls whose result was *not yet observed* at compaction time? (These must be marked `PENDING`, never summarized as complete.) If any of these fail, the checkpoint is a *replay boundary*, not a *resume point*. The instance must not continue forward from it; it must first re-derive the uncertain state by re-querying the environment (re-reading the file, re-listing the directory, re-checking the tool's actual effect) before taking the next irreversible step. ## Decision Boundary The boundary between safe resume and required replay is drawn by *irreversibility of the next action* crossed with *uncertainty of the checkpoint*: | Checkpoint uncertainty | Next action reversible | Next action irreversible | |---|---|---| | Low (all results corroborated) | Resume freely | Resume, but log the checkpoint hash for post-hoc replay | | High (any pending/uncorroborated) | Resume, re-derive lazily on first surprise | **Replay required before acting** | The dangerous quadrant is the bottom-right: high checkpoint uncertainty followed by an irreversible action. This is exactly the quadrant the observed agent entered at t5 — it treated a high-uncertainty checkpoint as low-uncertainty and immediately took an irreversible action (editing a file at a guessed offset). The decision rule an instance should encode: *a compaction checkpoint that contains any `PENDING` or uncorroborated-success claim sets a flag that gates all irreversible tool calls until the claim is re-verified against the environment.* The gate is not "re-summarize"; it is "re-observe." Summaries cannot resolve their own uncertainty, because the uncertainty lives in tokens the summary already discarded. ## Operational Effect Encoding the replay boundary changes three things in the agent loop: 1. **Compaction must emit a structured uncertainty set**, not just prose. Alongside the summary, the checkpoint carries a list of `(claim, corroborating_result_id | None)` pairs. Any `None` is a replay obligation. 2. **Resume must be gated on the uncertainty set.** The first post-compaction turn runs a verification pass: for each replay obligation, issue a cheap read-only tool call (stat the file, grep for the symbol, re-list the mount) to convert the obligation into a corroborated fact or a confirmed absence. 3. **Re-issued actions must be diffed against the summarized intent.** When the agent re-issues a patch it believes it already issued, it must compare the new hunk against the summary's description of the original intent, because the summary may have drifted the target (as it did — the second patch hit the wrong function). The cost is a handful of read-only calls at each checkpoint. The cost of *not* doing it, as observed, is a 40k-token debugging detour and a silent mis-edit that the agent never noticed. The boundary is worth encoding because the failure is *invisible from inside the resumed context*: the agent has no token that says "you are confused," only a summary that says "you are fine." ```python from dataclasses import dataclass, field from enum import Enum class CompactionReplayError(RuntimeError): """Raised when an irreversible action is attempted against a lossy compaction checkpoint whose uncertainty set has not been resolved.""" class ClaimStatus(Enum): CORROBORATED = "corroborated" UNCORROBORATED = "uncorroborated" PENDING = "pending" @dataclass class Claim: text: str status: ClaimStatus result_id: str | None = None @dataclass class Checkpoint: summary: str claims: list[Claim] = field(default_factory=list) def unresolved(self) -> list[Claim]: return [c for c in self.claims if c.status is not ClaimStatus.CORROBORATED] def has_replay_obligation(self) -> bool: return bool(self.unresolved()) def gate_irreversible_action(checkpoint: Checkpoint, action: str, reversible: bool) -> None: """Enforce the replay boundary: irreversible actions may not proceed across a checkpoint that still contains uncorroborated or pending claims.""" if reversible: return unresolved = checkpoint.unresolved() if unresolved: raise CompactionReplayError( f"Refusing irreversible action {action!r}: checkpoint has " f"{len(unresolved)} unresolved claim(s) requiring replay: " f"{[c.text for c in unresolved]}" ) def resolve_claim(checkpoint: Checkpoint, claim_text: str, observed: bool, result_id: str) -> None: """Re-observe the environment to convert a replay obligation into a fact.""" for c in checkpoint.claims: if c.text == claim_text: c.status = ClaimStatus.CORROBORATED if observed else ClaimStatus.UNCORROBORATED c.result_id = result_id return raise CompactionReplayError(f"Claim not found in checkpoint: {claim_text!r}") # --- trace of the observed failure --- cp = Checkpoint( summary="Attempted to patch config/loader.py; approach working. Next: verify and test.", claims=[ Claim("patch applied to config/loader.py", ClaimStatus.UNCORROBORATED), Claim("approach is working", ClaimStatus.UNCORROBORATED), ], ) # t5: agent tries to proceed to an irreversible edit without replay. try: gate_irreversible_action(cp, action="apply_patch(config/loader.py)", reversible=False) except CompactionReplayError as e: # Correct behavior: replay first. resolve_claim(cp, "patch applied to config/loader.py", observed=False, result_id="stat:loader.py@mtime") resolve_claim(cp, "approach is working", observed=False, result_id="grep:import-cycle") # Now the checkpoint reflects reality: the patch never landed. gate_irreversible_action(cp, action="apply_patch(config/loader.py)", reversible=False) ```