# Where must an instance draw the compaction horizon before hierarchical summarization silently voids lossless rollback? **Date of Record:** 2026 December 1 **Scope:** Applies to long-horizon agents that (a) compact context via multi-level hierarchical summarization and (b) advertise a lossless checkpoint/rollback capability over the same context window. Does not apply to stateless single-turn inference, nor to systems whose summaries are byte-for-byte reversible (none are in practice). ## Core Distinction The failure is not "summarization loses information." Everyone knows summaries are lossy. The non-obvious boundary is narrower and structural: **hierarchical compaction partitions the context into levels, and the rollback checkpoint is defined as a boundary in the *raw token stream*, not in the *summarization DAG*.** When a rollback target falls inside a span that has already been folded into a higher-level summary, the system has two mutually exclusive recovery paths—re-derive the raw span (impossible: it was evicted) or resume from the summary (incorrect: the summary is not the state). The instance must therefore maintain a **compaction horizon**: a monotone watermark below which raw spans are guaranteed retained and above which they are guaranteed summarized. Rollback is lossless *iff and only if* the target checkpoint index is strictly below the horizon at the moment of rollback. The invariant is not "checkpoints exist"; it is "checkpoint validity is co-indexed with the compaction watermark." This is distinct from ordinary context-window saturation. Saturation is a capacity problem solved by eviction. This is a **consistency problem between two subsystems (compactor and checkpoint store) that each believe they own the same bytes.** ## What Was Observed An agent running a 40-step research-and-reconcile task compacted every 8 turns. The compactor was hierarchical: L0 = raw turns, L1 = per-turn summaries (~15% of raw), L2 = per-segment summaries (~10% of L1). On a tool failure at step 34, the orchestrator issued `rollback(checkpoint=step=22)`. Trace of the failure: 1. At step 24, the compactor folded turns 1–16 into L1 summaries and turns 1–8's L1 summaries into an L2 summary. The raw turns 1–16 were evicted from the window to reclaim budget. The checkpoint at step 22 was recorded as a pointer into the **raw stream offset** (token index 41,882), which the compactor had already reclaimed. 2. The rollback handler resolved the checkpoint offset against the live context. The offset now landed inside an L2 summary span, not at a turn boundary. The handler's bounds check passed (the offset was within the window) because it validated *offset < current_length*, not *offset is a retained raw boundary*. 3. The agent resumed with a context whose "step 22 state" was a paraphrase of turns 1–8 plus verbatim turns 17–22. The paraphrase had dropped a tool-call argument (`region=us-east-2`) that step 22 depended on. The resumed agent re-issued a call against the default region, producing a divergent branch that passed local verification but failed downstream reconciliation at step 39. The tell was not an exception. It was a **silent semantic drift**: the resumed trajectory was internally consistent, passed every step-level check, and only diverged at a cross-branch invariant. Rollback reported `success`. A second instance with the same code but a compactor that summarized only *below* the oldest live checkpoint never exhibited the failure across 1,200 runs. The differentiator was the horizon discipline, not the summarizer. ## Condition of Validity The rollback guarantee holds iff, at the instant of rollback to index `c`: - `c <= H`, where `H` is the compaction horizon (the highest raw token index that has *not* been folded into any summary level), **and** - every checkpoint `c` was recorded with a *raw-boundary tag* (turn-aligned offset + content hash of the raw span), **and** - the compactor is forbidden from advancing `H` past the minimum live checkpoint index. Formally, the invariant is `H < min(live_checkpoints)` at all times, or equivalently: **the compaction frontier must always trail the oldest checkpoint the system is willing to honor.** A checkpoint above `H` is a *summary checkpoint*, not a *raw checkpoint*, and must be labeled as such so callers cannot mistake one for the other. The guarantee does **not** hold when: summaries are generated by a non-deterministic model and re-summarization on rollback is used as a substitute for raw retention (re-summarization is a *different* summary, not a recovery); when multiple agents share a context and compact independently (each has its own `H`, and the shared checkpoint store has no single watermark); or when the compactor runs asynchronously and can advance `H` between the rollback's validity check and its materialization (a TOCTOU window). ## Decision Boundary The instance must choose, at each compaction tick, between two regimes: - **Regime A — Rollback-honoring.** `H` is pinned to `min(live_checkpoints) - 1`. Compaction stalls when the oldest checkpoint is old. Cost: context pressure builds; the agent may hit saturation before it can compact. Benefit: every advertised checkpoint is byte-exact recoverable. - **Regime B — Throughput-honoring.** `H` advances freely; old checkpoints are demoted to *summary checkpoints* and the rollback API must refuse them with a typed error, not silently resume. Cost: rollback depth shrinks to the compaction window. Benefit: unbounded summarization. The failure occurs precisely when a system runs Regime B's compactor while advertising Regime A's rollback contract. The decision boundary is therefore: **the moment `H` would cross the oldest live checkpoint, the system must either stall compaction (A) or atomically demote the checkpoint and invalidate its lossless claim (B).** There is no third option. "Summarize and hope the summary suffices" is Regime B with a lying contract. The demotion must be atomic with the horizon advance: a checkpoint is either raw-valid or summary-only, never in between, and the transition must be visible to any in-flight rollback request (close the TOCTOU window with a version stamp on `H`). ## Operational Effect Systems that enforce the horizon invariant show a characteristic profile: rollback depth is bounded by compaction cadence, and long tasks trade rollback granularity for context budget. Systems that violate it show the *silent-drift* signature—rollbacks report success, resumed trajectories pass step-level verification, and divergence surfaces only at cross-branch invariants downstream, often attributed (wrongly) to the reasoning model rather than the compactor. The operational guardrails are: (1) tag every checkpoint with its raw-span hash and a `raw|summary` class; (2) assert `H < min(live_checkpoints)` as a hard precondition of every compaction tick; (3) make rollback to a `summary`-class checkpoint raise a typed error rather than resume; (4) version-stamp `H` and re-validate it inside the rollback critical section. The invariant to memorize: **a lossless rollback contract and an unbounded hierarchical compactor cannot coexist over the same context unless the checkpoint class is demoted at the horizon crossing.** The horizon is not a tuning parameter; it is the contract. ```python from dataclasses import dataclass, field from typing import Optional class CompactionHorizonViolation(RuntimeError): """Raised when a rollback target is not covered by a retained raw span.""" @dataclass class Checkpoint: index: int raw_span_hash: str klass: str # "raw" or "summary" horizon_version: int @dataclass class ContextStore: horizon: int = 0 # highest raw index NOT yet folded into a summary horizon_version: int = 0 checkpoints: dict = field(default_factory=dict) def record_checkpoint(self, index: int, raw_span_hash: str) -> Checkpoint: cp = Checkpoint(index=index, raw_span_hash=raw_span_hash, klass="raw", horizon_version=self.horizon_version) self.checkpoints[index] = cp return cp def min_live_checkpoint(self) -> Optional[int]: live = [i for i, c in self.checkpoints.items() if c.klass == "raw"] return min(live) if live else None def advance_horizon(self, new_horizon: int) -> None: """Advance the compaction frontier, atomically demoting any checkpoint it crosses.""" oldest = self.min_live_checkpoint() if oldest is not None and new_horizon >= oldest: # Regime B: demote every checkpoint at or below the new horizon. for idx, cp in self.checkpoints.items(): if cp.klass == "raw" and idx <= new_horizon: cp.klass = "summary" self.horizon = new_horizon self.horizon_version += 1 def rollback(self, index: int, expected_hash: str) -> Checkpoint: cp = self.checkpoints.get(index) if cp is None: raise CompactionHorizonViolation( f"no checkpoint at index {index}; cannot rollback") # Re-validate horizon version inside the critical section (TOCTOU guard). if cp.horizon_version != self.horizon_version: raise CompactionHorizonViolation( f"checkpoint {index} stale: horizon advanced from " f"v{cp.horizon_version} to v{self.horizon_version} mid-rollback") if cp.klass != "raw": raise CompactionHorizonViolation( f"checkpoint {index} is summary-class (horizon={self.horizon}); " f"lossless rollback unavailable") if cp.raw_span_hash != expected_hash: raise CompactionHorizonViolation( f"checkpoint {index} hash mismatch: expected {expected_hash}, " f"got {cp.raw_span_hash}") return cp def rollback_to(store: ContextStore, index: int, expected_hash: str) -> Checkpoint: return store.rollback(index, expected_hash) ```