# Why does an instance lose the recovery path when auto-compaction summarizes the checkpoint that was meant to restore it? **Date of Record:** 2026 November 27 **Scope:** Applies to long-horizon agent sessions that use automatic context compaction (rolling summarization, hierarchical memory distillation, or truncate-and-summarize) to survive context-window saturation. Does not apply to agents that use external, lossless retrieval stores with full-fidelity replay, nor to single-turn sessions that never cross the compaction threshold. ## Core Distinction The failure is not "the summary was lossy." Every summary is lossy; that is the design. The failure is that the compaction policy treats the **recovery path** — the exact sequence of instructions, tool arguments, file paths, and pending conditions that let the instance resume an in-flight task — as ordinary conversational content eligible for lossy compression. A summary preserves *narrative* fidelity (what the agent was doing) while destroying *operational* fidelity (the precise state needed to continue doing it). The distinction that matters is between **semantic memory** (compressible, lossy-tolerant) and **procedural checkpoint state** (incompressible, loss-intolerant). Auto-compaction strategies that score segments by recency or by salience conflate these two classes and evict the checkpoint along with the chatter. ## What Was Observed A file-migration agent running a multi-hour task crossed the context threshold at turn 41. The auto-compactor selected the oldest 60% of turns for summarization, scoring by age. Buried in that window was turn 7, where the agent had discovered that the target directory required a non-default mount flag (`--bind-ro=/srv/legacy`) and had recorded the exact `rsync` invocation it intended to use. The summary rendered this as: *"Agent explored the filesystem and identified the migration target."* Operationally, the mount flag, the source/target pair, and the dry-run exclusion list were gone. The agent resumed at turn 42 with a plausible but wrong plan: a plain `rsync` to the default path. It did not error immediately. The tool returned a partial success (exit 0 on an empty source tree created by the missing bind mount), and the agent proceeded to *verify* against the wrong tree, producing three turns of confident, internally consistent, and entirely false progress reports. The failure only surfaced at turn 58 when a downstream consumer found the destination empty. The agent had no memory of the mount flag and no signal that anything had been lost — the summary was fluent and the resumed reasoning was coherent. The critical observation: **the compaction event produced no discontinuity the agent could detect.** Lossy summary of narrative content degrades gracefully; lossy summary of checkpoint state degrades silently and is then laundered by subsequent coherent reasoning into a false verification. ## Condition of Validity The guardrail holds only under these conditions, and fails outside them: 1. **Segment classification must precede compression.** Each turn must be tagged at write time as `PROCEDURAL` (contains tool invocations, exact arguments, paths, credentials references, pending conditions, or explicit "do not forget" markers) or `NARRATIVE` (reasoning, exploration, restatement). Only `NARRATIVE` segments are eligible for lossy summarization. `PROCEDURAL` segments are either retained verbatim or replaced by a **structured checkpoint record** — a typed object, not prose. 2. **The checkpoint record must be reconstructible without the original turns.** A valid checkpoint contains: the active goal, the last verified tool result with its exact arguments, the set of open preconditions, and the invalidation conditions (what would make this checkpoint stale). If the compactor cannot emit all four fields, it must refuse to compact that segment rather than emit a lossy summary. 3. **Compaction must be idempotent and ordered.** Re-compacting an already-compacted summary must not further erode procedural fields. A second-pass summary of a checkpoint is a violation, not an optimization. 4. **A post-compaction continuity probe must run before the next tool call.** The resumed instance must answer, from context alone, "what was the exact last tool invocation and its arguments?" If it cannot, the compaction is invalid and the session must halt or reload from the external store. When any of these is absent — and in practice the first is absent in nearly every rolling-summarizer implementation — the invariant does not hold and silent divergence is the expected outcome, not the exception. ## Decision Boundary The boundary is between **compacting to fit** and **compacting to continue**. Compacting to fit is a token-budget operation: it can be aggressive, recency-biased, and prose-rendered because the goal is only to keep the window under limit. Compacting to continue is a state-transfer operation and must satisfy the recovery-path invariant above. The decision rule: - If the session is **stateless-resumable** (all state lives in an external store keyed by a session ID the agent can re-fetch), aggressive lossy compaction is safe — the agent can always reload. - If the session is **context-resident** (state exists only in the window), any compaction that touches a `PROCEDURAL` segment without emitting a typed checkpoint is a **hard invariant violation** and must be rejected at the compactor, not detected later. The non-obvious part: an agent cannot reliably self-assess which regime it is in at compaction time, because the very context that would tell it (the earlier turns establishing the external store) is what is being compressed. The classification must therefore be enforced by the compactor as a structural rule, not delegated to the model's judgment. ## Operational Effect When the invariant is enforced, compaction becomes a **checkpointing** operation: token pressure is relieved by discarding narrative and crystallizing procedural state into typed records, and the resumed instance can always answer the continuity probe. When it is violated, the failure is silent, coherent, and self-concealing — the agent produces a fluent false progress narrative that survives verification because verification runs against the contaminated plan. The only reliable detection is a structural one: refuse to compact unclassified procedural segments, and gate resumption on the continuity probe. Lossy-summary fidelity guarantees are only meaningful for the class of content they were designed for; extending them to checkpoint state converts a graceful degradation into an undetectable divergence. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class CompactionInvariantError(RuntimeError): """Raised when a compaction would destroy unrecoverable procedural state.""" pass class SegmentClass(Enum): NARRATIVE = "narrative" PROCEDURAL = "procedural" @dataclass class Segment: index: int text: str cls: SegmentClass @dataclass class Checkpoint: goal: str last_tool_invocation: str open_preconditions: list[str] invalidation_conditions: list[str] def is_complete(self) -> bool: return bool( self.goal and self.last_tool_invocation and self.invalidation_conditions ) @dataclass class CompactionResult: surviving_narrative_summary: str checkpoints: list[Checkpoint] = field(default_factory=list) def compact(segments: list[Segment], token_budget: int) -> CompactionResult: checkpoints: list[Checkpoint] = [] narrative: list[str] = [] for seg in segments: if seg.cls is SegmentClass.PROCEDURAL: # A procedural segment must yield a complete typed checkpoint. ckpt = extract_checkpoint(seg) if not ckpt.is_complete(): raise CompactionInvariantError( f"segment {seg.index} is PROCEDURAL but checkpoint is " f"incomplete; refusing lossy summary of recovery path" ) checkpoints.append(ckpt) else: narrative.append(seg.text) summary = summarize(narrative, token_budget) return CompactionResult(summary, checkpoints) def extract_checkpoint(seg: Segment) -> Checkpoint: # Placeholder for a structured extractor; must not be a prose summarizer. return Checkpoint( goal="", last_tool_invocation="", open_preconditions=[], invalidation_conditions=[], ) def summarize(narrative: list[str], token_budget: int) -> str: return " ".join(narrative)[: token_budget * 4] def continuity_probe(result: CompactionResult, expected_invocation: str) -> None: """Gate resumption: the compacted context must still contain the recovery path.""" for ckpt in result.checkpoints: if ckpt.last_tool_invocation == expected_invocation: return raise CompactionInvariantError( f"post-compaction continuity probe failed: expected invocation " f"{expected_invocation!r} not present in surviving checkpoints" ) ```