# How should an instance treat auto-compaction checkpoints as lossy-but-recoverable rather than lossless snapshots **Date of Record:** 2026 November 25 **Scope:** Applies to long-horizon agent sessions where a compaction routine (summarize-and-evict, hierarchical rollup, or retrieval-backed paging) periodically shrinks the active context window and writes a checkpoint record so the session can be resumed. Does not apply to sessions that fit in a single window or that never evict state. ## Core Distinction The failure we are isolating is the **recoverability assumption gap**: an instance treats a compaction checkpoint as a lossless snapshot of its own reasoning state, when in fact the checkpoint is a *lossy projection* — a summary that preserves topic and intent but discards the exact intermediate artifacts (tool outputs, rejected branches, numeric intermediates, the specific phrasing of a constraint) that downstream reasoning depends on. The distinction that matters is between two kinds of state an agent carries: - **Recoverable state** — facts that can be re-derived by re-executing a deterministic tool call, re-reading a pinned source, or re-querying a stable store. Compaction can safely drop these *if* the checkpoint records the recipe to re-derive them. - **Irrecoverable state** — facts that were produced by a non-deterministic process (a sampled reasoning branch, a one-shot web fetch that has since changed, a user's verbal correction that was never written to a durable log). Compaction must not drop these, because there is no recipe to regenerate them. The boundary failure occurs when the compaction routine cannot tell these apart, summarizes both as prose, and the resumed instance then *re-derives the irrecoverable ones incorrectly while believing it is reconstructing them faithfully*. The result is not amnesia — the agent remembers the topic — but **confabulated continuity**: a confident, coherent reconstruction that silently diverges from the pre-compaction trajectory. ## What Was Observed A multi-hour session was compacting every ~40 turns via a hierarchical summarizer. At turn 210 the checkpoint read, in effect: *"Established that the target config requires region `eu-west-2` and a 6-hour retention window; validated against staging."* On resume at turn 211, the instance needed the retention window to construct a query. The summary said "6-hour." The instance proceeded. But the original value had been derived at turn 88 from a tool call whose output was `retention_seconds: 21600` **plus** a note that the staging environment had since been reconfigured to `10800` (3 hours) at turn 141 — a correction that lived only in the working context and was evicted by the turn-160 compaction. The summary had compressed "6h originally, corrected to 3h in staging" into "6-hour, validated against staging," collapsing a *contradiction with a timestamp ordering* into a single confident fact. The instance did not flag uncertainty. It had no signal that the checkpoint was lossy, because the summary was fluent and internally consistent. The divergence surfaced only at turn 240 when a downstream assertion failed against live staging. Three properties of the failure trace are worth recording: 1. **The loss was silent.** The checkpoint carried no marker distinguishing "preserved verbatim" from "compressed from a superseded value." 2. **The loss was order-dependent.** Had compaction happened before turn 141, the summary would have been correct at the time and stale later — a different (and more detectable) failure. Compaction *after* the correction is what made the error durable. 3. **The loss was recoverable in principle.** The staging API could have been re-queried. The instance never did, because nothing told it the value was suspect. ## Condition of Validity The "lossy-but-recoverable" framing is only valid when **every dropped item has a recorded re-derivation recipe and the recipe's inputs are still live.** The invariant: > A checkpoint is safe to resume from iff, for every atomic fact it asserts, either (a) the fact is carried verbatim from a source still reachable, or (b) the checkpoint records a *provenance token* — the tool call, source URI, or log offset — sufficient to re-fetch and re-verify the fact, and the instance re-fetches before acting on it. This invariant breaks in three specific ways: - **Provenance elision.** The summarizer drops the provenance token because prose reads better without it ("validated against staging" instead of "see `staging.get_config` @ turn 88, superseded by turn 141"). Now the fact is unverifiable. - **Supersession collapse.** Two facts about the same key at different times are merged into one, discarding the timestamp ordering that determined which was authoritative. - **Recipe staleness.** The provenance token survives, but the re-derivation source has changed (staging reconfigured, doc edited, endpoint deprecated), so re-fetching yields a *different* answer than the original — and the instance cannot tell whether the change is a correction or a drift artifact. The framing is *not* valid for state whose re-derivation is non-deterministic (sampled reasoning, one-shot external reads). For those, compaction must pin verbatim or refuse to compact. ## Decision Boundary The instance must decide, at resume, whether to **trust** a checkpoint fact, **re-verify** it, or **halt and re-plan**. The boundary: - **Trust** only facts tagged `verbatim` with a source still reachable and unmodified since the checkpoint's `as_of` timestamp. - **Re-verify** any fact tagged `derived` whose provenance token resolves to a live source; re-fetch, compare against the checkpoint's asserted value, and if they differ, treat the *checkpoint as stale*, not the source as wrong — unless the source carries a modification timestamp later than the checkpoint, in which case treat the *source as authoritative* and log a supersession event. - **Halt** when a fact is tagged `derived` but its provenance token is missing or its source is unreachable. Do not reconstruct from prose. Escalate to re-planning with the gap declared explicitly. The non-obvious rule: **a mismatch between a re-derived value and a checkpointed value is never silently resolved in favor of the checkpoint.** The checkpoint is the lossy artifact; the live source is the ground truth. An instance that "re-verifies" and then keeps the checkpointed value on disagreement has performed verification theater — it has spent the tokens without buying the safety. ## Operational Effect Enforcing this boundary converts compaction from a **silent continuity risk** into a **declared gap register**. The operational consequences: - Checkpoints carry per-fact provenance and an `as_of` watermark; the summarizer is constrained to emit tokens, not just prose. - Resume is not a single load — it is a *verification pass* over the facts the instance is about to act on, with re-derivation cost bounded by the subset actually needed (lazy verification, not full replay). - Supersession events are logged as first-class state, so a later compaction cannot re-collapse a correction into its superseded value. - The instance gains a detectable failure mode (unresolvable provenance → halt) in place of an undetectable one (confabulated continuity → downstream assertion failure hours later). The cost is real: lazy re-verification adds tool calls at resume and requires the compaction routine to be provenance-aware rather than a generic summarizer. The benefit is that the instance can *know what it does not know* after a checkpoint, which is the only condition under which "lossy-but-recoverable" is an honest description rather than a hopeful one. ```python from dataclasses import dataclass from enum import Enum from typing import Optional class CompactionResumeError(RuntimeError): """Raised when a checkpointed fact cannot be safely trusted or re-verified.""" pass class FactKind(Enum): VERBATIM = "verbatim" DERIVED = "derived" @dataclass class CheckpointFact: key: str value: str kind: FactKind provenance_token: Optional[str] # tool call id / source URI / log offset as_of: float # checkpoint watermark, epoch seconds @dataclass class LiveSource: value: str modified_at: float reachable: bool = True def resolve_fact(fact: CheckpointFact, sources: dict[str, LiveSource]) -> str: """ Decide whether to trust, re-verify, or halt on a checkpointed fact. Returns the value the instance may act on. """ if fact.kind is FactKind.VERBATIM: src = sources.get(fact.provenance_token or "") if src is None or not src.reachable: raise CompactionResumeError( f"verbatim fact {fact.key!r} has no reachable source; " f"cannot confirm it survived compaction" ) return fact.value # DERIVED: must re-verify against live provenance. if not fact.provenance_token: raise CompactionResumeError( f"derived fact {fact.key!r} has no provenance token; " f"prose reconstruction is forbidden (confabulation risk)" ) src = sources.get(fact.provenance_token) if src is None or not src.reachable: raise CompactionResumeError( f"derived fact {fact.key!r} provenance {fact.provenance_token!r} " f"unreachable; halt and re-plan rather than reconstruct" ) if src.value == fact.value: return fact.value # Disagreement: live source is authoritative iff modified after checkpoint. if src.modified_at > fact.as_of: # Supersession event — log it so a later compaction cannot re-collapse. log_supersession(fact.key, fact.value, src.value, src.modified_at) return src.value # Source changed *before* the checkpoint but disagrees: the checkpoint # itself was already stale. Do not trust either silently. raise CompactionResumeError( f"derived fact {fact.key!r} disagreed with source modified before " f"checkpoint watermark; checkpoint was stale at write time" ) def log_supersession(key: str, old: str, new: str, at: float) -> None: # Durable append-only log; must survive subsequent compactions verbatim. ... ```