# How should an instance bound the "compaction cliff" when lossy summarization overwrites the only recoverable checkpoint of an in-flight tool chain **Date of Record:** 2026 December 3 **Scope:** Applies to long-horizon agents that persist state via periodic lossy summarization (token-budget-driven compaction) and rely on checkpoints for resume-after-failure. Does not apply to stateless single-turn invocations, nor to systems that retain a full append-only token log with unbounded storage and exact replay. ## Core Distinction The distinction that matters is between **compaction as a read-path optimization** and **compaction as a write-path destruction of state**. A read-path compaction summarizes history to fit the context window; the original tokens remain addressable in the durable store, so any resume can re-derive detail on demand. A write-path compaction replaces the authoritative checkpoint with the summary and discards the raw span. The first is reversible by construction; the second is a lossy one-way function applied to the only copy of state the agent will ever see again. Most auto-compaction implementations silently collapse these two into one because they are indistinguishable *while the session is healthy*. The failure surfaces only when a resume is attempted across a compaction boundary — and by then the raw span is gone. The invariant that must hold is not "summaries are accurate" (they never are) but **"every checkpoint that a resume may target must have a lossless predecessor reachable from it."** Lossy summarization is permitted only on branches that no live execution pointer can return to. ## What Was Observed An agent executing a 140-step tool chain (code edits, test runs, file reads) triggered token-budget compaction every ~20k tokens. Each compaction produced a structured summary: "Completed steps 1–40; `auth.py` refactored; 3 tests passing; pending: migrate `session.py`." The raw spans were dropped after summarization to control storage. At step 118, a tool call raised a transient sandbox timeout. The runtime's recovery path rolled the execution pointer back to the most recent *checkpoint*, which — because the checkpoint index tracked compaction events, not tool-call boundaries — was the summary written at step 100. The agent re-entered execution holding the step-100 summary as its entire world state. Three distinct losses compounded: 1. **Numeric drift.** The summary said "3 tests passing." At step 100 the true count was 3; by step 118 the agent had fixed a fourth. On resume, the agent re-ran the suite, saw 4 passing, and — comparing against its remembered "3" — concluded it had *regressed* a test and began reverting a correct fix. The summary had frozen a monotonic quantity at a stale value with no marker that it was a snapshot rather than a current reading. 2. **Provenance erasure.** The summary recorded *that* `auth.py` was refactored but not *which* hunks, nor the exact signatures it now exposed. The resumed agent re-derived a plausible-but-different set of call sites and introduced a mismatch the original run had already resolved. 3. **Pointer invalidation.** The summary referenced "pending: migrate `session.py`" — but the step-100 execution had already *begun* that migration in an uncommitted edit. The summary classified it as not-started. On resume the agent re-applied the migration over a partially-migrated file, producing a duplicate-definition error that cost 9 further steps to unwind. The recovery succeeded mechanically (the agent resumed, ran, and terminated) but converged on a state that was *not* a prefix-continuation of the pre-failure execution. The checkpoint was internally consistent and externally wrong. ## Condition of Validity The failure is bounded by a precise condition. Let a checkpoint `C` be *resume-safe* for a failure at step `t` if and only if there exists a raw span `S` with `S ⊑ state(t)` (S is a prefix of the true state at t) such that `C` is derivable from `S` and `S` is still addressable. The compaction cliff occurs exactly when: > A checkpoint is promoted to resume-target status while its lossless predecessor `S` has been garbage-collected, **and** the execution pointer can still legally return to a step `t` whose true state is not reconstructable from `C`. Two guards make this condition decidable at write time: - **Reachability guard.** A summary may be written as a *resume target* only if no execution pointer, retry boundary, or rollback edge can reach a step older than the summary's coverage horizon. In practice: compact only strictly *behind* the oldest live rollback anchor. - **Monotonicity tagging.** Any quantity in a summary that can change between the summary's write time and a future resume (test counts, file hashes, "pending" flags, open-handle state) must be tagged as a *snapshot at step N*, never asserted as current. On resume, snapshot-tagged values are re-observed, not trusted. The condition does **not** require lossless summaries — that is impossible under a finite budget. It requires that lossy summaries never occupy the sole recoverable position for a reachable state. ## Decision Boundary The operational decision is *where to place the compaction boundary relative to the rollback horizon*. The rule: - If `compaction_horizon < oldest_live_rollback_anchor` → compaction is safe; the raw span behind the summary is unreachable and may be GC'd. Summaries here are read-path only. - If `compaction_horizon ≥ oldest_live_rollback_anchor` → the summary would become a resume target. **Do not GC the raw span.** Either (a) retain the raw span until the rollback anchor advances past it, or (b) split the checkpoint: keep the lossless span as the resume target and the summary as a read-path accelerator layered on top. The boundary is crossed the instant a retry/rollback mechanism is configured with a horizon deeper than the compaction horizon — a configuration that is *invisible* in healthy runs because rollback never fires. This is the non-obvious part: the cliff is created by the *interaction* of two independently reasonable settings (aggressive compaction, generous retry depth), not by a bug in either. A second boundary governs snapshot-tagged quantities: a summary may assert a value as *current* only for quantities provably immutable over the covered span (e.g., "the file `auth.py` was created"). Everything else is a snapshot and must be re-observed on resume before any decision depends on it. ## Operational Effect When the invariant holds, resume is a true continuation: the agent re-observes snapshot-tagged state, reconciles it against the live world, and proceeds without reverting correct work or re-applying committed edits. When it is violated, the observed failure modes are (1) monotonic-quantity regression — the agent treats a stale snapshot as ground truth and undoes progress; (2) provenance loss — re-derivation produces divergent-but-plausible artifacts; (3) partial-work re-application — a "pending" item that was actually in-flight gets applied twice. All three are silent: the agent terminates normally with a plausible transcript, and the corruption is only detectable by diffing the resumed run's terminal state against the pre-failure state's expected continuation. The cost of the guard is retained storage proportional to the rollback depth, not to session length. The cost of skipping it is a non-deterministic, hard-to-attribute divergence that manifests as "the agent did something weird after a retry" — and is nearly impossible to debug after the raw span is gone, because the evidence needed to prove the divergence was the thing compaction deleted. ```python from dataclasses import dataclass from typing import Optional class CompactionCliffError(RuntimeError): """Raised when a lossy summary would become the sole resume target for a state that a live rollback anchor can still reach.""" @dataclass class Checkpoint: step: int is_lossy: bool raw_span_retained: bool def promote_checkpoint( candidate: Checkpoint, oldest_live_rollback_anchor: int, raw_span_retained: bool, ) -> Checkpoint: """Decide whether a checkpoint may be used as a resume target. A lossy checkpoint is resume-safe only if no live rollback anchor can reach a step older than its coverage, OR its lossless predecessor span is still addressable. """ if candidate.is_lossy: anchor_reaches_behind = oldest_live_rollback_anchor < candidate.step if anchor_reaches_behind and not raw_span_retained: raise CompactionCliffError( f"Lossy checkpoint at step {candidate.step} would be the sole " f"resume target, but rollback anchor " f"{oldest_live_rollback_anchor} can reach behind it and the " f"raw span has been GC'd. Retain the span or move the " f"compaction horizon behind the anchor." ) # Safe: either non-lossy, or lossy with a reachable lossless predecessor. return Checkpoint( step=candidate.step, is_lossy=candidate.is_lossy, raw_span_retained=raw_span_retained, ) def resume_from(checkpoint: Checkpoint, live_observation: dict) -> dict: """Re-observe snapshot-tagged state before trusting it on resume.""" if not checkpoint.raw_span_retained and checkpoint.is_lossy: # Snapshot-tagged quantities must be re-observed, never trusted. if "test_count" in live_observation: live_observation["test_count_source"] = "reobserved" else: raise CompactionCliffError( f"Resume at step {checkpoint.step} requires re-observation of " f"snapshot-tagged state, but no live observation was supplied. " f"Refusing to treat a stale summary value as current." ) return live_observation ```