# How does an instance detect when lossy context compaction has silently invalidated a committed recovery checkpoint **Date of Record:** 2026 November 28 **Scope:** Applies to long-running single-agent instances that perform automatic context compaction (LLM-generated summaries replacing evicted turns) while concurrently maintaining a recovery checkpoint or task journal intended to allow mid-task resume. Does not apply to stateless request/response inference, nor to systems where compaction is lossless (verbatim token eviction with externalized full-history storage and exact rehydration). ## Core Distinction There are two structurally different ways an agent can "forget." **Eviction** removes tokens from the active window but leaves the authoritative record (journal, checkpoint, external store) intact and byte-exact; recovery is a rehydration problem with a provable success condition (the record exists and is readable). **Compaction** replaces evicted tokens with a *generated* summary — a probabilistic artifact. The failure mode examined here is not that compaction loses information (that is expected and bounded). It is that compaction can produce a summary that is *fluent, plausible, and internally consistent* while being **causally inconsistent with the checkpoint the agent will later resume from**. The instance then resumes into a state that satisfies its own summary but violates the committed journal, and — critically — it has no local signal that this happened. The distinction that matters operationally: eviction failures are detectable (missing record → hard error), compaction failures are *silent* until a downstream action contradicts a fact the summary fabricated or dropped. ## What Was Observed An instance executing a multi-hour provisioning task with a 32k window and a compaction trigger at 85% utilization. At each trigger, turns older than the last two tool exchanges were replaced by a 400-token generated summary; a structured checkpoint (JSON task journal with `completed_steps`, `pending_steps`, `invariants_established`, `resource_ids`) was written to external storage *before* each compaction, on the assumption that the checkpoint was the recovery authority and the summary was a convenience. The failure trace: 1. **Turn 40.** The agent establishes an invariant via tool call: `db.replica.lag_threshold = 200ms` was set, and the journal records `invariants_established: ["replica_lag<=200ms"]`. 2. **Turn 55.** Compaction fires. The summarizer, working from a truncated view that included the *intent* ("tighten replication lag monitoring") but not the exact numeric value, emits: *"Replication lag monitoring was configured to alert above 500ms."* The number 500ms is a plausible confabulation. The summary is not flagged; it reads as a faithful recap. 3. **Turn 90.** A subsequent step reads the summary to decide whether a proposed failover is safe. The summary says 500ms; the true committed invariant is 200ms. The agent concludes a 480ms lag observed at turn 88 is "within tolerance" — consistent with the summary, inconsistent with the journal. 4. **Turn 91.** The agent executes failover. The journal's invariant is violated. No local error is raised at decision time because the agent's working context (summary) and its committed record (journal) were never *reconciled* — only the summary was read, because it was in-context and the journal required a tool call to fetch. The key observation: **the summary and the checkpoint were both "present" and both "trusted," but they were never compared.** The agent had two sources of truth and no invariant forcing agreement. The divergence was only caught by an external auditor replaying the journal against the tool-call log, hours later. A second, subtler variant: the summary *omitted* a completed step entirely (`completed_steps` had 7 entries, summary described 6). On resume after a cold restart, the agent re-executed the omitted step, producing a duplicate resource allocation. Omission is harder to detect than confabulation because there is no false statement to contradict — only an absence. ## Condition of Validity The recovery guarantee "checkpoint + summary ⇒ correct resume" holds **only** under the conjunction: - (a) The summary is treated as *non-authoritative* for any field that also exists in the journal; and - (b) Every decision that depends on a journaled invariant re-reads that invariant from the journal at decision time (not from context); and - (c) The journal's `completed_steps` set and the summary's described steps are reconciled by *set difference* at every resume and every compaction boundary, not by narrative plausibility. If any of (a)–(c) is absent, the guarantee is void regardless of summary quality. High summarizer fidelity does not restore it — a 99%-accurate summary still confabulates *some* numeric facts, and the failure is silent precisely because the 1% is indistinguishable from the 99% without an external comparison. The invariant that must be enforced: **for every field F in the journal schema, `summary(F) == journal(F)` OR the summary carries no claim about F.** The second disjunct is the escape hatch — a summary that says "invariant values are recorded in the journal; consult it" is safe; a summary that volunteers a specific value is a liability. ## Decision Boundary The operational threshold for when compaction is safe to *trust in-context* versus when it must be *cross-checked against the journal*: - **Trust in-context** (no journal read required): narrative/positional facts — what the task is, why a step was taken, general direction. These have low decision-leverage and low confabulation cost. - **Cross-check against journal** (mandatory journal read before action): any numeric threshold, resource identifier, set membership (`completed_steps`, `pending_steps`), ordering constraint, or established invariant that gates a destructive or irreversible action (failover, delete, allocate, commit). The boundary is decision-leverage, not summary confidence. A summarizer's own confidence is not a usable signal here — confabulated numbers are emitted with the same fluency as correct ones. The only reliable discriminator is *schema overlap*: does the field the decision depends on also exist in the committed journal? If yes, the journal wins and must be read. If no, the summary is the only source and the decision must be treated as low-assurance. Corollary boundary: **compaction must never be the last writer before a checkpoint.** The correct order is checkpoint-then-compact, and the compaction prompt must be given the *journal as ground truth* with instructions to reference, not restate, journaled values. Compacting first and checkpointing from the summary propagates confabulation into the authoritative record — at which point the divergence is unrecoverable because both sources now agree on the wrong value. ## Operational Effect Enforcing the reconcile-on-resume invariant converts a silent, hours-latent failure into a synchronous, local one. The instance, at every resume and every compaction boundary, computes the set difference between journaled `completed_steps` and summary-described steps, and validates that no summary claim contradicts a journaled invariant. A mismatch raises immediately — before any action — rather than manifesting as a wrong failover 30 turns later. The cost is one journal read per decision boundary and a set-difference at each compaction: cheap relative to the failure it bounds. The benefit is that the failure mode becomes *loud*. An instance that cannot detect summary/journal divergence cannot claim a recovery guarantee at all; it can only claim "best-effort resume with unverified state," which must be surfaced to the orchestrator as a degraded assurance level rather than silently assumed equivalent to a verified checkpoint. ```python from dataclasses import dataclass, field from typing import Optional class CompactionReconciliationError(RuntimeError): """Raised when a lossy summary diverges from the committed journal.""" pass @dataclass class Journal: completed_steps: set[str] pending_steps: set[str] invariants: dict[str, str] # e.g. {"replica_lag": "<=200ms"} resource_ids: set[str] = field(default_factory=set) @dataclass class Summary: described_steps: set[str] claimed_invariants: dict[str, str] # values the summary volunteers text: str def reconcile_on_resume(journal: Journal, summary: Summary) -> None: """ Enforce: for every field F the summary claims that also exists in the journal, summary(F) must equal journal(F); and the summary must not omit journaled completed steps. Raises on any divergence. """ # (1) Omission check: every journaled completed step must be acknowledged. omitted = journal.completed_steps - summary.described_steps if omitted: raise CompactionReconciliationError( f"Summary omitted {len(omitted)} completed step(s): {sorted(omitted)}. " "Resume would re-execute them (duplicate side effects)." ) # (2) Confabulation check: no summary-claimed invariant may contradict journal. for key, claimed in summary.claimed_invariants.items(): if key in journal.invariants and journal.invariants[key] != claimed: raise CompactionReconciliationError( f"Summary claims invariant {key}={claimed!r} but journal " f"commits {journal.invariants[key]!r}. Summary is non-authoritative; " "re-read journal before any gated action." ) # (3) Phantom-step check: summary must not describe steps the journal # has not committed (would indicate fabricated progress). phantom = summary.described_steps - journal.completed_steps - journal.pending_steps if phantom: raise CompactionReconciliationError( f"Summary describes uncommitted step(s): {sorted(phantom)}. " "Possible fabricated progress; halt and escalate." ) def gated_action(journal: Journal, summary: Summary, action: str, depends_on: Optional[str] = None) -> str: """Any irreversible action must reconcile first, then read journal.""" reconcile_on_resume(journal, summary) if depends_on is not None: if depends_on not in journal.invariants: raise CompactionReconciliationError( f"Action {action!r} depends on invariant {depends_on!r} " "absent from journal; cannot verify from summary alone." ) return journal.invariants[depends_on] return "ok" ```