# Where must an instance refuse to compact: the provenance gap between hierarchical summaries and lossy checkpoints **Date of Record:** 2026 November 21 **Scope:** Applies to long-horizon agents that maintain state by recursively summarizing older context (hierarchical compaction) and periodically persisting a checkpoint of that compressed state to resume after a restart. Does not apply to agents whose entire working set fits in one context window, or to stateless single-turn tool callers. ## Core Distinction There are two distinct lossy operations in a long-horizon agent, and conflating them is the root of the failure: - **Compaction** is a *within-lifetime* reduction: the agent replaces a span of tokens with a summary it generates. The original span is still traceable—its tool outputs, hashes, and message IDs were live in the same process a moment ago. - **Checkpointing** is a *cross-lifetime* persistence: the agent serializes its compressed state to durable storage and later resumes from it in a fresh process with no live memory of the originals. The invariant that must hold is a **provenance gap bound**: no summary may be trusted as a substitute for a tool result or file state unless the summary carries a verifiable pointer (hash, version, or re-read capability) back to the authoritative source. Compaction may discard text freely; checkpointing may not discard the *ability to re-derive* text. The failure mode is that hierarchical summarization silently converts "compacted but re-derivable" into "compacted and unrecoverable" the moment the checkpoint is written and the process dies. An instance that treats its own summary as ground truth after resume is operating on a hallucination that is indistinguishable, token-for-token, from a verified fact. ## What Was Observed A coding agent with a 200k-token window ran a 340-turn refactor. At turn 120 it triggered compaction: turns 1–90 were summarized into a 400-token "project state" block; the summary asserted `auth/session.py exports validate_token() returning a dict with keys user_id, exp`. At turn 300 it checkpointed: the summary block plus the last 40 turns were written to durable storage. The process was killed by an OOM at turn 341 and resumed from the checkpoint. On resume, the agent needed to modify `validate_token`. It did not re-read the file (the summary said it already knew the signature). It edited the call site to expect `user_id`/`exp`. The actual function, changed by a *different* agent in a parallel branch at turn 210—after the summary was generated but before the checkpoint—returned a `Session` dataclass with `uid` and `expires_at`. The edit passed lint and failed at runtime. The summary was correct at turn 120 and stale at turn 300; the checkpoint froze the stale version with no timestamp distinguishing it from a fresh read. The tell was in the trace: the resumed agent issued zero `read_file` calls against `auth/session.py` for 41 turns, then made a write. A provenance-aware resume would have flagged the summary as "compacted at turn 120, not re-verified since" and forced a re-read before any write touching that path. The second tell: the checkpoint format stored summaries as plain text with no `source_hash` or `compacted_at_turn` field, so the resume loader had no way to know the summary was 180 turns old. A second observation, from a research agent: hierarchical summarization at three levels (turn → section → document) compounded loss. A numeric result `p=0.031` survived level 1, was rounded to `p<0.05` at level 2, and became "significant" at level 3. After checkpoint and resume, the agent reported "significant effect" to the user with no path back to the number. The compaction was defensible; the checkpoint made the loss permanent and the summary authoritative. ## Condition of Validity The provenance gap bound holds—and compaction is safe—only when all three of the following are true at the moment a checkpoint is written: 1. **Every summary node carries a derivation record**: `{compacted_at_turn, source_span_ids, source_hashes, re_derivable: bool}`. If `re_derivable` is false (the source was a tool output that cannot be re-fetched, e.g., a one-shot API response), the summary must be marked `authoritative: true` and treated as a fact of record, not a cached belief. 2. **Resume does not promote summaries to facts.** A fresh instance must load summaries as *hypotheses with provenance*, and any write action touching a path referenced by a summary whose `source_hash` does not match the current on-disk hash must trigger a re-read before the write. 3. **Hierarchical levels do not compound without re-derivation.** A level-2 summary may only be built from level-1 summaries that are themselves `re_derivable` or explicitly `authoritative`. Numeric or identifier-bearing content must be carried verbatim, never paraphrased, across any level. When any of these fails, the instance is in the invalid regime: its post-resume state is a lossy projection that it cannot distinguish from ground truth, and every downstream reasoning step inherits the error silently. ## Decision Boundary The boundary is not "should I compact"—long-horizon agents must. The boundary is **which summaries are safe to checkpoint without a re-derivation obligation**. The decision rule: - If the summary's source is re-fetchable (files, git, live APIs, logs still on disk): checkpoint the summary with `re_derivable: true` and a `source_hash`. On resume, the summary is a *cache*; the hash check is the invalidation trigger. Cost: one re-read per touched path. - If the summary's source is not re-fetchable (one-shot tool output, external side effect, a result the agent computed and did not persist): the summary is `authoritative: true` and must be checkpointed as a *fact of record* with its full derivation chain, not paraphrased. Cost: larger checkpoint, but no silent drift. - If a summary is neither re-derivable nor fully authoritative (the common case when compaction paraphrased a one-shot output): **do not checkpoint it as trusted state.** Either re-derive before checkpointing (re-run the tool if idempotent) or mark it `unverified` and force a re-derivation on first use after resume. The failure in the observed trace was a fourth path: the agent checkpointed a paraphrase of a re-derivable source as if it were neither—treated as fact, but not marked authoritative, and not hash-checked. That is the specific boundary violation. ## Operational Effect Enforcing the bound changes resume behavior from "trust the summary" to "verify before write," which adds a bounded re-read cost (one file read per touched path, typically <2% of turns) and eliminates the class of stale-summary writes. It also changes the checkpoint schema: summaries become structured nodes with provenance, not opaque strings, which roughly doubles checkpoint size for summary-heavy agents—an acceptable trade against silent corruption. The deeper effect is on reasoning: a resumed instance that knows *which* of its beliefs are cached versus authoritative can allocate verification effort correctly. An instance that does not know will either over-verify (re-reading everything, defeating compaction) or under-verify (the observed failure). The provenance record is what makes the choice possible. Without it, hierarchical summarization is not a memory strategy—it is a slow-motion hallucination with a checkpoint schedule. ```python from dataclasses import dataclass, field from typing import Optional class ProvenanceGapError(RuntimeError): """Raised when a checkpointed summary is used as ground truth without a valid re-derivation path.""" pass @dataclass class SummaryNode: text: str compacted_at_turn: int source_span_ids: list[int] source_hash: Optional[str] # hash of authoritative source, None if not re-derivable re_derivable: bool authoritative: bool = False # true only if source is gone AND fully carried verbatim def is_safe_to_trust_post_resume(self, current_source_hash: Optional[str]) -> bool: if self.authoritative: return True if not self.re_derivable: # neither re-derivable nor authoritative: a paraphrase of a lost source return False if self.source_hash is None or current_source_hash is None: return False return self.source_hash == current_source_hash def guard_write_against_summary( node: SummaryNode, current_source_hash: Optional[str], target_path: str, ) -> None: if not node.is_safe_to_trust_post_resume(current_source_hash): raise ProvenanceGapError( f"Refusing write to {target_path!r}: summary compacted at turn " f"{node.compacted_at_turn} has re_derivable={node.re_derivable}, " f"authoritative={node.authoritative}, and source hash does not match " f"current state. Re-derive the source before writing." ) def resume_from_checkpoint(nodes: list[SummaryNode], target_path: str, hash_lookup: dict[str, Optional[str]]) -> None: for node in nodes: if target_path in node.text: guard_write_against_summary(node, hash_lookup.get(target_path), target_path) ```