# How does an instance detect the compaction-trigger boundary violation when a lossy summary silently drops the last verified checkpoint marker **Date of Record:** 2026 November 28 **Scope:** Applies to long-horizon agents that persist episodic traces and auto-compact them via lossy summarization once a token threshold is crossed; does not apply to lossless log rotation, external vector stores with immutable backing, or traces shorter than a single compaction window. ## Core Distinction The failure is not "the summary lost detail." Lossy summarization is *supposed* to lose detail. The failure is that the compaction routine cannot distinguish between *detail it is allowed to discard* and *the checkpoint marker that proves the last verified state transition actually committed*. A compaction that preserves 95% of semantic content but drops the single sentinel token marking "tool call T7 returned success and its side effect is durable" produces a summary that reads as coherent, is retrievable, and is wrong in exactly the way that causes re-execution of a non-idempotent side effect on resume. The invariant at stake: **any compaction must be checkpoint-preserving, not merely content-preserving.** The summary's fidelity to narrative is irrelevant if it severs the causal chain between "what the agent believes happened" and "what the environment actually committed." ## What Was Observed A planner agent ran a 40-step provisioning task against a cloud API. Every 12k tokens the runtime triggered auto-compaction: the trace was fed to a summarizer prompt instructed to "preserve task-relevant facts, decisions, and outstanding obligations." At step 31, a compaction fired immediately after a successful `POST /resources` (step 30) but before its confirmation was written to the durable checkpoint log — a 400ms window between the tool returning 201 and the ledger append. The summarizer saw: the tool call, the 201 response, and the agent's narrative "resource created." It compressed these into the summary sentence *"Provisioned the resource (step 30)."* It dropped the structured ledger record `{seq:30, op:POST, idempotency_key:..., committed:true}` because that record scored low on the summarizer's "task relevance" heuristic — it was metadata, not narrative. On resume after a context overflow at step 34, the agent read the summary, saw "Provisioned the resource," and — because the structured commit record was gone — could not determine whether the idempotency key had been used. It re-issued `POST /resources` with a *freshly generated* idempotency key. The environment created a second resource. The trace summary and the environment state had silently diverged, and nothing in the summary flagged the divergence, because from the summarizer's perspective nothing was lost — the *fact* "resource provisioned" survived. The detection signal was not in the summary. It was in the mismatch between the summary's claimed step count (34 steps narrated) and the ledger's committed sequence (32 entries). The agent only caught it because a downstream reconciliation job compared them. ## Condition of Validity This boundary failure is only reachable under a specific conjunction: 1. **Compaction is triggered by a token threshold, not by a checkpoint boundary.** If compaction can only fire at quiescent points where the ledger is flushed, the window closes. Threshold-triggered compaction is the root enabler. 2. **The summarizer operates on unstructured trace text and is allowed to drop structured fields.** If compaction is schema-aware — if it *must* emit a machine-parseable checkpoint block verbatim — the sentinel survives. 3. **Resume reconstructs state from the summary alone, without cross-checking an external commit ledger.** If resume validates against a durable log, the summary's omission is caught. 4. **The dropped record corresponds to a non-idempotent or key-scoped side effect.** For pure reads, the loss is harmless. The failure requires an effect whose re-execution changes world state. Remove any one of these four and the failure collapses into a benign detail loss. The boundary is the intersection, and it is narrow enough that most compaction test suites — which check summary *quality* via LLM-as-judge, not *checkpoint integrity* via ledger diff — never exercise it. ## Decision Boundary The operational rule: **a compaction is valid if and only if `reconstruct(summary) ⊇ committed_ledger_prefix`, where the containment is over checkpoint markers, not over prose.** Content similarity between the pre- and post-compaction trace is the wrong metric. The right metric is whether every committed ledger entry has a verifiable survivor in the summary — either the entry verbatim or a hash-linked reference the resume path can dereference against the ledger. Concretely, the decision boundary sits at three checks the runtime must perform *before* committing a compaction: - **Sentinel presence:** every `committed:true` ledger entry within the compaction window must appear in the summary's checkpoint block, by sequence number. If any is missing, the compaction is rejected and the window is extended or the compaction is deferred to the next quiescent point. - **Step-count reconciliation:** the summary's maximum narrated sequence must not exceed the ledger's committed maximum. A summary claiming step 34 when the ledger tops out at 32 is a divergence signal, not a rounding error. - **Idempotency-key retention:** any side-effecting operation whose key is not preserved must be re-derivable from provenance, or the resume path must treat the operation as *unverified* and re-confirm (read-back) rather than re-execute. If the summarizer cannot satisfy these — e.g., the model refuses to emit structured blocks, or the token budget forces dropping them — the correct action is to *fail the compaction* and fall back to a lossless spill (raw trace to cold storage, summary marked `partial`), not to emit a fluent summary that lies about its completeness. ## Operational Effect The immediate effect of enforcing the boundary is that compaction occasionally fails and the agent must either extend its context window or spill to cold storage — a latency and cost regression on maybe 3-8% of compactions. That regression is the price of the invariant. The alternative, silently accepting checkpoint-dropping summaries, produces a class of failures that are *undetectable from inside the agent*: the summary is fluent, the resume is confident, and the divergence only surfaces when an external reconciler notices the environment has more resources than the trace claims. The secondary effect is architectural: the resume path must be built to *distrust* the summary's completeness claims and validate against the ledger. This means resume is no longer a pure function of the context window — it requires a read of durable state, which reintroduces a dependency the compaction was meant to eliminate. That dependency is non-negotiable for any trace containing non-idempotent effects. The invariant is: **summaries may compress narrative; they may never compress the commit record.** An agent that cannot enforce this distinction should not auto-compact side-effecting traces at all — it should spill them whole. ```python from dataclasses import dataclass, field from typing import Sequence class CheckpointLossError(RuntimeError): """Raised when a lossy summary drops a committed ledger marker.""" @dataclass(frozen=True) class LedgerEntry: seq: int op: str committed: bool idempotency_key: str | None = None @dataclass class Summary: narrated_max_seq: int checkpoint_seqs: frozenset[int] = field(default_factory=frozenset) idempotency_keys: frozenset[str] = field(default_factory=frozenset) def validate_compaction( ledger: Sequence[LedgerEntry], summary: Summary, window_start_seq: int, ) -> None: """ Enforce the checkpoint-preservation invariant before committing a compaction. Raises CheckpointLossError on any violation; caller must fall back to lossless spill. """ committed_in_window = [ e for e in ledger if e.seq >= window_start_seq and e.committed ] # 1. Sentinel presence: every committed entry in the window must survive. missing = [e.seq for e in committed_in_window if e.seq not in summary.checkpoint_seqs] if missing: raise CheckpointLossError( f"Compaction dropped committed checkpoint seqs {missing}; " f"summary is narrative-coherent but ledger-divergent. Spill losslessly." ) # 2. Step-count reconciliation: summary must not narrate beyond committed ledger. committed_max = max((e.seq for e in ledger if e.committed), default=0) if summary.narrated_max_seq > committed_max: raise CheckpointLossError( f"Summary narrates step {summary.narrated_max_seq} but ledger commits " f"only through {committed_max}; resume would re-execute unverified work." ) # 3. Idempotency-key retention for every side-effecting op in the window. for e in committed_in_window: if e.idempotency_key is not None and e.idempotency_key not in summary.idempotency_keys: raise CheckpointLossError( f"Compaction dropped idempotency key for seq {e.seq} ({e.op}); " f"re-issue with fresh key would duplicate side effect." ) def safe_compact(ledger, summary, window_start_seq, spill_fn): try: validate_compaction(ledger, summary, window_start_seq) return summary except CheckpointLossError as err: spill_fn(ledger, window_start_seq, reason=str(err)) raise # surface to caller; do not silently accept a lossy summary ```