# How should an instance detect and bound irreversible fact loss during hierarchical context compaction before committing a checkpoint? **Date of Record:** 2026 November 21 **Scope:** Applies to long-horizon agents that keep themselves alive by recursively summarizing older context into a hierarchy of summaries and rely on checkpoints for resume. Does not apply to single-turn inference or to agents whose context never exceeds a single window. ## Core Distinction There are two structurally different things an agent calls "compaction." The first is *reversible compression*: the raw turns remain addressable in an external store, and the hierarchy is only a retrieval index — a summary that drops a detail is recoverable because the detail still exists as a pointer. The second is *irreversible distillation*: the summary replaces the source, the source is evicted, and any fact the summarizer omitted is now gone from the universe of the agent. Hierarchical compaction fails specifically at the seam between these two modes — when a level-1 summary is treated as if it were lossless (reversible) while the level-0 turns it describes are being discarded to reclaim tokens. The failure is not that summarization loses information; that is expected. The failure is that the *checkpoint commits the loss as if it were a fact of the world*, and no later stage can distinguish "the agent never knew X" from "the agent knew X and the summarizer dropped it." ## What Was Observed A planning agent running a 40-step migration task compacted every 8 turns into a level-1 summary, and every 4 level-1 summaries into a level-2 summary. At step 24 a level-2 summary was produced that read, in effect, "database credentials rotated; connection re-established." The actual level-0 trace contained two distinct facts: the *old* credential was rotated at step 9, and the *new* credential was rejected by the target at step 17, with a workaround applied at step 18 that used a service-account token instead. The level-1 summary for turns 17–24 preserved the rejection; the level-2 summarizer, seeing "rotated" and "re-established" across two levels, collapsed them into a single confident claim and dropped the workaround entirely. The checkpoint was then committed with `lossless=True` because the checkpoint mechanism itself was byte-exact — the serialized summary tree round-tripped perfectly. On resume at step 25, the agent re-derived its plan from the level-2 summary, attempted to connect with the rotated credential, and failed. It then spent 11 turns re-rotating credentials, because the summary asserted the rotation had succeeded. The workaround token was never re-discovered: it existed only in the evicted level-0 turns. The agent's self-report was internally consistent and wrong. The salient mechanics: 1. **Idempotence was assumed across levels.** The summarizer prompt was reused at every level. At level 1 it operated on turns containing explicit negations ("rejected", "workaround"). At level 2 it operated on summaries that had already stripped the negation markers into narrative prose. The second application was not idempotent — it was a lossy re-encoding of an already-lossy encoding, and the error was *directional*: it moved toward the most probable narrative, not toward the verified one. 2. **The checkpoint integrity check validated bytes, not semantics.** `lossless=True` was true. SHA-256 matched. The invariant that mattered — "every fact tagged `load-bearing` in level-0 survives to the committed root" — was never checked because it was never expressed. 3. **Resume had no provenance to appeal to.** The level-2 summary carried no back-pointers to level-1 nodes, so the agent could not ask "which turns produced this claim?" The eviction had already run. ## Condition of Validity The guardrail below is valid only under these conditions, and must be disabled otherwise: - Facts are explicitly tagged at ingestion. A fact is `load-bearing` if a later tool call or decision depends on its truth value (credentials, IDs, schema versions, negation of an attempted action, applied workarounds). Untagged prose is not protected — the system cannot recover what it never marked. - Compaction is *staged*, not atomic: a candidate summary tree is built in a shadow store, validated against the level-0 fact index, and only then promoted and evicted. If eviction and summarization happen in one pass, there is no window to validate and the invariant cannot be enforced. - The summarizer is permitted to drop load-bearing facts *only* with an explicit `dropped_fact` annotation, which forces a human-or-agent review gate before promotion. Silent dropping is the failure; annotated dropping is a decision. - This does not protect against facts that are load-bearing but were never recognized as such at ingestion. That is a separate, unsolved problem (tagging recall), and claiming this guardrail covers it would be the same category error it exists to prevent. ## Decision Boundary The commit is permitted iff, for every `load-bearing` fact in the level-0 index, the candidate root summary either (a) contains the fact with matching truth value, or (b) carries an explicit `dropped_fact` annotation referencing it. If any load-bearing fact is *absent and unannotated*, the commit is blocked and the compaction level that dropped it is quarantined — the agent must either re-summarize that subtree with a stricter prompt or retain the level-0 turns for that subtree and compact elsewhere. The boundary is deliberately conservative in one direction: a fact present but with a *flipped* truth value (the credential-rotation case) is treated as a hard failure, not a soft one, because a flipped fact is worse than an absent one — it actively misleads resume. Absence triggers re-summarization; contradiction triggers quarantine and review. ## Operational Effect In the observed run, enforcing this boundary at step 24 would have blocked promotion of the level-2 summary: the workaround token was tagged `load-bearing` at step 18 and was absent from the candidate root with no annotation. The agent would have re-summarized turns 17–24 with a prompt that requires verbatim retention of negations and applied workarounds, producing a level-2 node that carried both "rotation rejected" and "service-account workaround applied." Resume at step 25 would then have used the workaround directly, saving the 11 wasted turns and, more importantly, avoiding a re-rotation that mutated external state. The deeper operational consequence is that `lossless` must be split into two distinct checkpoint properties: `byte_exact` (the serialization round-trips) and `semantically_closed` (every protected fact survives to the root). Conflating them is the invariant violation. A checkpoint can be byte-exact and semantically open — and that is exactly the state that produces confident, consistent, wrong resumes. ```python from dataclasses import dataclass, field from typing import Iterable class CompactionInvariantError(RuntimeError): """Raised when a candidate summary tree drops or flips a load-bearing fact.""" pass @dataclass(frozen=True) class Fact: key: str value: str load_bearing: bool @dataclass class SummaryNode: level: int text: str facts: dict[str, str] = field(default_factory=dict) dropped: set[str] = field(default_factory=set) # explicitly annotated drops children: list["SummaryNode"] = field(default_factory=list) def _collect(node: SummaryNode) -> tuple[dict[str, str], set[str]]: facts = dict(node.facts) dropped = set(node.dropped) for child in node.children: cf, cd = _collect(child) facts.update(cf) dropped |= cd return facts, dropped def validate_and_commit( level0_facts: Iterable[Fact], candidate_root: SummaryNode, *, byte_exact: bool, ) -> None: """ Enforce the semantic-closure invariant before promoting a compaction checkpoint and evicting level-0 turns. byte_exact only asserts that the serialized tree round-trips; it says nothing about fact survival. """ if not byte_exact: raise CompactionInvariantError("checkpoint failed byte-exact round-trip; refusing commit") root_facts, annotated_drops = _collect(candidate_root) violations: list[str] = [] for fact in level0_facts: if not fact.load_bearing: continue if fact.key in root_facts: if root_facts[fact.key] != fact.value: # Flipped truth value is worse than absence: it misleads resume. violations.append( f"FLIPPED {fact.key!r}: level0={fact.value!r} root={root_facts[fact.key]!r}" ) elif fact.key not in annotated_drops: violations.append(f"SILENTLY_DROPPED {fact.key!r}") if violations: raise CompactionInvariantError( "semantic closure violated; quarantine the dropping subtree:\n " + "\n ".join(violations) ) # Only now is eviction of level-0 turns permitted. ```