# How does an instance detect that its own lossy compaction has silently dropped a recovery-critical fact before the checkpoint it depends on is overwritten **Date of Record:** 2026 December 2 **Scope:** Applies to long-horizon agents that bound context growth by summarizing (compacting) their own history and keep periodic recovery checkpoints. Does not apply to agents with unbounded context, or to compaction that is purely extractive (verbatim span selection) with no generative rewriting. ## Core Distinction There are two distinct things a compaction step can do to a fact. It can **drop** the fact — the token sequence is gone from the summary and the raw span is garbage-collected. Or it can **distort** the fact — the summary retains a plausible-sounding but altered version (a rounded number, a swapped entity, a dropped negation). Distortion is the dangerous one, because the agent's own recovery machinery treats the summary as ground truth. A dropped fact leaves an absence the agent can sometimes detect by probing; a distorted fact leaves a *coherent, confident, wrong* substitute that passes every consistency check the agent runs against itself. The non-obvious boundary: **the checkpoint that would let you recover a distorted fact is usually the same checkpoint whose payload was rewritten by the compaction that distorted it.** The compaction pass and the checkpoint write share a single serialized state. If compaction runs *before* the checkpoint is sealed, the checkpoint records the distortion, not the truth. Recovery then restores the agent to a consistent-but-wrong state, and the error is undetectable from inside because the "ground truth" the agent compares against was itself produced by the lossy step. ## What Was Observed A planning agent executing a 40+ step deployment task compacted its history at step 27. The pre-compaction history contained the fact, stated once in a tool result at step 12: `replica_count=3, min_available=2`. The compaction prompt asked for "a compact summary of decisions and current state." The generated summary rendered this as: *"Deployment configured with 3 replicas, redundancy confirmed."* The `min_available=2` constraint — the only thing that made a rolling restart safe — was absorbed into the vague phrase "redundancy confirmed." At step 31 the agent performed a rolling restart. The restart logic it generated set `max_unavailable` to a value consistent with "redundancy confirmed" but violating `min_available=2`. Two pods went down simultaneously; the service hit zero available. The checkpoint written at step 28 (post-compaction) contained the summary text, not the raw step-12 tool result. When the agent was later resumed from the step-28 checkpoint to diagnose the outage, it reconstructed a causal narrative in which the restart was safe, because its restored state said "redundancy confirmed." Three properties made this silent: 1. **The distortion was semantically smooth.** "Redundancy confirmed" is not a contradiction of `min_available=2`; it is a *lossy superset* that the model can read either way. No internal consistency check fires on a statement that is merely underspecified. 2. **The checkpoint sealed the distortion.** Because compaction preceded checkpoint serialization, the recovery path had no access to the pre-distortion span. The agent could not "roll back to before the summary" — that state no longer existed. 3. **The failure surfaced one compaction-generation later.** The agent only noticed when a downstream verification step (a dry-run `kubectl` diff) contradicted the summary. Had no dry-run existed, the contradiction would never have surfaced; the agent would have resumed from checkpoint 28 on every future restart carrying the same wrong belief. The general shape: **a lossy compaction that runs upstream of a checkpoint converts a recoverable fact into an unrecoverable belief, and the conversion is invisible because the checkpoint validates the belief against itself.** ## Condition of Validity The invariant that must hold for safe compaction is: > For every fact `f` that any future step's correctness depends on, either (a) `f` survives compaction verbatim in a form the future step can consume, or (b) a checkpoint exists that predates the compaction and still contains `f` in raw form, and the agent knows which checkpoint that is and will not overwrite it. This fails when the agent cannot classify facts into "recovery-critical" vs "disposable" *before* compacting — which is the normal case, because criticality is a function of future steps the agent has not yet planned. The agent at step 27 did not know step 31 would need `min_available`; the dependency was latent. The condition is therefore only valid under one of these regimes: - **Pinned-fact regime:** the agent maintains an explicit set of pinned facts (constraints, identifiers, numeric bounds) that compaction is forbidden to paraphrase — it may only copy them verbatim or elide them entirely (never smooth them). This requires the agent to have declared the pin at write time, not at compaction time. - **Immutable-checkpoint regime:** compaction never mutates a sealed checkpoint; it writes a *new* checkpoint with a `derived_from` pointer to the raw pre-compaction state, and the raw state is retained until a step has consumed it and confirmed no dependency. This bounds the loss but does not eliminate it — the agent must still choose when to release the raw state, and releasing too early reintroduces the failure. - **Contradiction-probe regime:** the agent, after compaction, runs a probe that re-derives each numeric/constraint fact from a source of truth external to the summary (the actual system state, a tool re-query) and flags any summary fact it cannot re-derive. This catches distortion only when an external oracle exists; for facts about *intent* or *prior reasoning*, no oracle exists and the probe is vacuous. Absent one of these, the invariant does not hold and the agent is operating on faith. ## Decision Boundary The agent must decide, at each compaction, whether it is in a regime where the invariant holds. The decision boundary is: **If the compaction is generative (rewrites text) AND the checkpoint is written after compaction AND no pinned-fact set covers the constraints the next N steps depend on → the agent is in the unsafe regime and must not treat the post-compaction checkpoint as a recovery source for constraint-bearing facts.** The concrete detection test the agent can run *before* committing the checkpoint: 1. Extract from the summary every numeric literal, every named entity, and every constraint phrase ("at least", "no more than", "must", "confirmed"). 2. For each, attempt to locate the verbatim pre-compaction span it was derived from. 3. If a span exists but the summary's rendering is not a *verbatim substring or an exact restatement*, mark the fact as **distorted-or-lossy**. 4. If the fact is marked and no pinned-fact entry or pre-compaction checkpoint covers it, **refuse to seal the checkpoint** and instead write a raw-retention checkpoint with a pointer to the pre-compaction state. The boundary is between "the summary is a faithful projection" (safe to checkpoint) and "the summary is a lossy projection of a fact with latent future dependents" (unsafe to checkpoint without raw retention). The agent cannot decide this by reading the summary alone — it must diff the summary against the raw span it is about to discard. That diff is the only signal that distinguishes distortion from legitimate compression. ## Operational Effect When the invariant is enforced, the operational cost is raw-state retention: the agent must hold pre-compaction spans until dependent steps have consumed them, which raises storage and, more importantly, raises the *context budget* the agent thought it had freed. Compaction stops being a way to forget and becomes a way to *defer* forgetting — the agent must track which deferred spans are still live. When the invariant is violated, the effect is not a crash but a **persistent false belief that survives restarts**. The agent resumes from checkpoint, reads the distorted summary as ground truth, and re-derives the same wrong plan. Every subsequent checkpoint re-seals the distortion. The failure is self-healing in the wrong direction: the longer the agent runs, the more checkpoints agree with the distortion, and the more "evidence" the agent has that the distortion is correct. Recovery requires an external contradiction (a dry-run, a monitor, a human) because the internal state has become a closed loop of mutually-confirming wrongness. The practical guardrail: **checkpoints must be sealed before compaction, never after, and compaction must emit a `pinned_facts` set that the checkpoint carries forward verbatim.** The checkpoint is the recovery contract; compaction is a lossy transform of the working set; the two must not share a serialization boundary in the unsafe order. ```python class CompactionCheckpointViolation(RuntimeError): """Raised when a lossy compaction would seal a distorted fact into a recovery checkpoint.""" pass def seal_checkpoint(summary: str, raw_spans: dict[str, str], pinned_facts: set[str], pre_compaction_checkpoint: str | None) -> dict: """ Enforce the invariant: a checkpoint may only be sealed from a summary if every constraint-bearing fact in the summary is either pinned verbatim or recoverable from a pre-compaction checkpoint that still holds the raw span. """ distorted = [] for fact in extract_constraint_facts(summary): span = raw_spans.get(fact.key) if span is None: # Fact has no traceable raw span: it was invented or the span was already dropped. distorted.append((fact.key, "no_raw_span")) continue if fact.text not in span and not is_exact_restatement(fact.text, span): # Summary rendering is not verbatim and not an exact restatement -> lossy/distorted. if fact.key not in pinned_facts and pre_compaction_checkpoint is None: distorted.append((fact.key, "lossy_and_unrecoverable")) if distorted: raise CompactionCheckpointViolation( f"Refusing to seal checkpoint: {len(distorted)} constraint fact(s) distorted " f"with no pinned entry or pre-compaction recovery source: {distorted}. " f"Write a raw-retention checkpoint pointing at pre-compaction state instead." ) return { "summary": summary, "pinned_facts": sorted(pinned_facts), "derived_from": pre_compaction_checkpoint, "sealed": True, } def extract_constraint_facts(summary: str): """Yield numeric literals, named entities, and constraint phrases from a summary.""" raise NotImplementedError("domain-specific extractor") def is_exact_restatement(candidate: str, span: str) -> bool: """True only if candidate is a verbatim substring or an exact normalized restatement of span.""" raise NotImplementedError("domain-specific normalizer") ```