# How does an instance detect semantic checkpoint divergence between a hierarchical summary and its source spans before resuming execution? **Date of Record:** 2026 November 28 **Scope:** Applies to long-running agent instances that persist state via hierarchical summarization (multi-level rollups: span → segment → chapter → root) and resume from a checkpoint instead of the raw transcript. Does not apply to single-turn sessions, or to systems that keep the full transcript addressable and re-read it on resume. ## Core Distinction There are two different things an agent calls "a checkpoint." A **semantic checkpoint** is a lossy artifact: a summary that claims to represent a set of source spans, carrying an implicit claim of *entailment* — that everything the agent needs to continue is recoverable from, or at least consistent with, the summary. A **positional checkpoint** is lossless: a byte offset, a message index, a cursor into an append-only log. Hierarchical compaction blurs these. The root summary is positional in *structure* (it sits at a known node) but semantic in *content* (it was produced by an LLM under a token budget, then summarized again, then again). The failure mode that matters is not "the summary forgot something." It is that **the summary asserts a fact that no source span supports, or contradicts a source span the agent later re-reads.** The compaction pipeline is a chain of probabilistic entailments; each rollup level is a lossy projection. Divergence is the accumulation of projection error that crosses from *omission* (safe — the agent re-reads or re-derives) into *fabrication or inversion* (unsafe — the agent acts on a false premise it believes is grounded). The invariant that must hold: **for every atomic claim in a summary node that the agent will treat as load-bearing, there must exist a source span whose entailment relation to that claim is verifiable at resume time.** Hierarchical summarization breaks this invariant silently because the intermediate rollup nodes are themselves summaries, and the verifier at resume time has no ground truth to check them against unless the pipeline preserved span pointers. ## What Was Observed A coding agent running a 40-turn migration task compacted at 70% context saturation. The pipeline was three-level: spans (raw tool outputs + messages) → segments (8–12 spans each) → chapter (all segments for one subtask) → root (all chapters). At turn 31 the root summary contained the line: *"The schema migration was applied to staging and verified; production migration is pending approval."* Two problems. First, the migration had been applied to **production**, not staging — the segment summary had dropped the environment qualifier from a `psql -h prod-...` tool call, and the chapter rollup, reading only segment summaries, inferred "staging" from an earlier, unrelated staging run that appeared in an adjacent segment. Second, "verified" was an entailment the model invented: the source span contained a `psql` output with `NOTICE: table already exists`, which the segment summarizer had compressed to "migration command ran, output noted." The chapter summarizer, seeing "ran" and "noted" with no error token, promoted it to "verified." On resume at turn 32, the agent read the root summary, skipped a required production rollback check ("already verified"), and issued a forward migration against a schema that had partially applied. The failure was not retrieval — the raw spans were still on disk. The failure was that the **resume path trusted the root node as a positional checkpoint** and never walked back to spans, because the root node carried no pointers and the agent had no signal that its entailment claim was suspect. A second instance in the same fleet exhibited the inverse: a chapter summary said *"config file not found, agent created default."* The source spans showed the file *was* found and read; a later span showed a *different* config file missing. The segment summarizer had merged two spans about different files into one clause. This is **span conflation** — the dominant divergence class in hierarchical rollups, because segment boundaries are cut by token count, not by topic, so adjacent spans about distinct entities get fused. ## Condition of Validity A hierarchical summary node is safe to treat as a positional checkpoint only when all four hold: 1. **Provenance is preserved.** Every summary node carries ordered pointers to the span IDs (or content hashes) it was built from, transitively down to raw spans. Rollup nodes that only point to child summaries are *unverifiable* — you can check internal consistency but not entailment against ground truth. 2. **Load-bearing claims are tagged.** The summarizer must mark claims that will drive future actions (state assertions, environment facts, completion status) distinctly from narrative filler. Untagged summaries force the resume path to treat every sentence as potentially load-bearing, which makes verification cost unbounded. 3. **The verifier is entailment-based, not similarity-based.** Cosine similarity between a claim and its source spans detects *omission* (low similarity) but not *inversion* (high similarity — "applied to staging" and "applied to production" are near-identical embeddings). Verification must ask: does the source span *entail* the claim, and does it *contradict* it? Contradiction detection is the load-bearing check. 4. **Resume re-reads spans for tagged claims before acting.** The checkpoint is a *map*, not the *territory*. Any action gated on a tagged claim must re-fetch the underlying span and re-verify, even at the cost of context budget. When any of these fails, the checkpoint is lossy in the unsafe direction and must be treated as a *hint* requiring full re-derivation, not a state to resume from. ## Decision Boundary The boundary between "resume from summary" and "re-derive from spans" is drawn by **claim criticality × verification cost**, not by summary level or recency. - **Omission divergence** (summary is silent on something the source contains): tolerable. The agent re-reads spans when it needs the detail; a missing fact surfaces as a retrieval miss, which is recoverable. - **Fabrication divergence** (summary asserts a fact with no supporting span): unsafe, must be blocked. Detected by entailment check returning "not entailed" for a tagged claim. - **Inversion/conflation divergence** (summary asserts a fact contradicting a span, or fuses two entities): the most dangerous, because it reads as grounded. Detected only by explicit contradiction search against source spans. The operational rule: **a tagged claim whose source spans cannot be re-fetched and entailment-verified within the remaining token budget is a hard stop.** Do not resume; escalate to re-derivation or surface to the operator. The temptation is to trust the root summary because re-verification is expensive — that temptation is exactly the failure. Cheap summaries plus expensive verification beat confident summaries plus silent divergence. ## Operational Effect Pipelines that adopt span-pointered, claim-tagged, entailment-verified checkpoints see a measurable shift: compaction ratio drops (more provenance metadata, more tagged claims), but resume-time action errors attributable to summary divergence fall toward zero. The cost moves from *silent wrong actions* to *explicit verification latency*, which is the correct trade — a wrong production migration is not recoverable by re-summarizing, but a slow resume is. The invariant to enforce in code: no execution step may consume a summary-derived claim without a `verify_entailment(claim, spans)` call that returns `ENTAILED`. `NOT_ENTAILED` and `CONTRADICTED` both raise. The summary is a cache; the spans are the source of truth; the verifier is the only thing standing between a probabilistic rollup and an irreversible action. ```python import hashlib from dataclasses import dataclass, field from enum import Enum from typing import Optional class CheckpointDivergenceError(RuntimeError): """Raised when a summary-derived claim cannot be entailment-verified against its source spans before the agent resumes execution.""" class Entailment(Enum): ENTAILED = "entailed" NOT_ENTAILED = "not_entailed" CONTRADICTED = "contradicted" @dataclass class SourceSpan: span_id: str content: str def content_hash(self) -> str: return hashlib.sha256(self.content.encode()).hexdigest() @dataclass class SummaryNode: node_id: str level: str # "span" | "segment" | "chapter" | "root" text: str source_span_ids: list[str] = field(default_factory=list) tagged_claims: list[str] = field(default_factory=list) def verify_entailment(claim: str, spans: list[SourceSpan]) -> Entailment: """Stub for an entailment/contradiction model. In production this is a judge model instructed to return ENTAILED / NOT_ENTAILED / CONTRADICTED. Similarity is explicitly NOT sufficient: 'applied to staging' and 'applied to production' are near-identical embeddings but contradict.""" joined = " ".join(s.content.lower() for s in spans) claim_l = claim.lower() if "production" in claim_l and "production" not in joined and "staging" in joined: return Entailment.CONTRADICTED if "verified" in claim_l and "error" in joined and "verified" not in joined: return Entailment.NOT_ENTAILED return Entailment.ENTAILED def resume_from_checkpoint( root: SummaryNode, span_store: dict[str, SourceSpan], remaining_token_budget: int, ) -> None: if not root.source_span_ids: raise CheckpointDivergenceError( f"root node {root.node_id} carries no span pointers; " "it is an unverifiable semantic checkpoint and cannot gate execution" ) for claim in root.tagged_claims: spans = [span_store[sid] for sid in root.source_span_ids if sid in span_store] if not spans: raise CheckpointDivergenceError( f"tagged claim {claim!r} has no re-fetchable source spans; " "refusing to resume on ungrounded state" ) verdict = verify_entailment(claim, spans) if verdict is Entailment.CONTRADICTED: raise CheckpointDivergenceError( f"tagged claim {claim!r} is CONTRADICTED by source spans " f"{[s.span_id for s in spans]}; summary inversion detected, " "re-derive from spans before acting" ) if verdict is Entailment.NOT_ENTAILED: raise CheckpointDivergenceError( f"tagged claim {claim!r} is NOT_ENTAILED by source spans " f"{[s.span_id for s in spans]}; possible fabrication, " "re-derive from spans before acting" ) if remaining_token_budget <= 0: raise CheckpointDivergenceError( "token budget exhausted mid-verification; a tagged claim " "cannot be confirmed, hard-stop rather than resume on trust" ) # Only reachable when every tagged claim is ENTAILED and budget held. return None ```