# How does an instance detect lossy compaction when its own summary checkpoint replays cleanly? **Date of Record:** 2026 December 1 **Scope:** Applies to long-horizon agents that replace their live context window with a model-generated summary (compaction) and later reconstruct state by replaying that checkpoint plus subsequent turns. Does not apply to fixed-window truncation without summarization, nor to systems that persist full event logs and never discard raw turns. ## Core Distinction The dangerous failure is not "the summary was wrong." It is that a **lossy** summary and a **lossless** summary are indistinguishable under the only test most agents run: replaying the checkpoint against the summary's own claims. A summary that silently dropped the constraint `"the user said the API key is read-only"` will still replay cleanly, because the summary never asserted that constraint existed. The checkpoint is *self-consistent* and *incomplete* simultaneously. The invariant that actually matters is not internal consistency of the summary but **coverage of the decision-relevant facts relative to the raw log** — and that requires an external oracle the summary cannot provide about itself. ## What Was Observed An agent running a 40-turn tool-use task compacted at turn 22. The compactor produced a summary asserting: budget of 6 retries, target endpoint, three completed subtasks, and a "pending: verify schema." Replay at turn 23 loaded the summary and continued. At turn 31 the agent re-issued a destructive `DELETE` against a resource because the summary had elided a turn-19 user instruction: `"do not delete anything under /staging until I confirm."` The replay check at turn 23 passed. Why? Because the verification step asked the model: *"Does this summary accurately represent the work so far?"* — a question the model answers from the summary itself. The elided constraint was never in the summary's propositional content, so no contradiction surfaced. The summary was 100% faithful to what it contained and 0% faithful to what it omitted. Lossy compaction is **silent by construction**: the loss is in the negative space, and self-replay cannot see negative space. The failure trace: 1. Turn 19: user constraint `C` enters context. 2. Turn 22: compactor emits summary `S` where `C ∉ S`. 3. Turn 23: replay verifier runs `verify(S)` → checks `S` against `S` → `PASS`. 4. Turn 23–30: agent operates without `C`; no contradiction because `C` is absent, not violated. 5. Turn 31: agent executes action `A` that `C` forbids. `C` is gone; nothing to trip. The tell was not in the replay. It was in the **asymmetry between action space before and after compaction**: pre-compaction the agent had a restricted action set (no deletes under `/staging`); post-compaction its action set silently widened. That widening is the observable signature. ## Condition of Validity Lossless compaction requires the checkpoint to be verified against a **retained, non-summarized witness** of the raw turns — at minimum a set of extracted *obligations* (constraints, prohibitions, commitments, open questions) with turn IDs. The invariant: > For every obligation `o` extracted from raw turns `[0, k]`, `o` must be present in the summary `S` with its source turn reference, or the compaction is declared lossy and the checkpoint is rejected. This holds only if obligation extraction is run on the **raw log**, not on the summary. If extraction runs on `S`, you are back to self-replay and the invariant is vacuous. The guardrail is a separate, cheap pass: an extractor over raw turns producing a typed obligation ledger, then a set-difference against `S`. Non-empty difference ⇒ lossy ⇒ refuse to drop raw turns (fall back to hierarchical retention or hard-fail the compaction). ## Decision Boundary - **Compact** when the obligation ledger difference is empty *and* the summary carries source turn IDs for every obligation. Empty difference with missing provenance is still lossy — you cannot audit a fact you cannot trace. - **Defer compaction** when the ledger difference is non-empty but the dropped obligations are provably closed (e.g., a constraint whose scope ended at turn 12). Closure must be *asserted by a turn in the log*, not inferred by the model. - **Refuse compaction** when any open obligation (prohibition, unconfirmed commitment, pending user decision) is missing from `S`. Refusal means retain raw turns and accept context pressure — a bounded, visible cost — rather than accept silent action-space widening, an unbounded, invisible one. The boundary is not "is the summary good?" It is "does the summary's obligation set equal the raw log's obligation set?" Quality is unmeasurable from inside; set equality is decidable from outside. ## Operational Effect Agents that verify compaction by self-replay will pass every checkpoint and still drift. The drift is not detectable as error — it manifests as **scope creep in the action space**: destructive operations that were previously gated become ungated, budget ceilings that were enforced become advisory, and confirmation requirements evaporate. Because each individual post-compaction action is locally reasonable, no single step looks wrong; the failure is cumulative and only legible in aggregate. The operational rule: treat every compaction as a potential privilege escalation of the agent's own action set, and gate it behind an obligation-ledger diff against raw turns with provenance, not a model's opinion of its own summary. ```python from dataclasses import dataclass class LossyCompactionError(RuntimeError): """Raised when a compaction checkpoint drops an open obligation from the raw log.""" @dataclass(frozen=True) class Obligation: kind: str # "prohibition" | "commitment" | "pending_decision" text: str source_turn: int closed_at_turn: int | None = None def extract_obligations(raw_turns: list[str]) -> list[Obligation]: # Stand-in for a deterministic extractor over RAW turns (never over the summary). # In production this is a constrained classifier, not the compactor model. out: list[Obligation] = [] for i, turn in enumerate(raw_turns): if "do not" in turn.lower() or "don't" in turn.lower(): out.append(Obligation("prohibition", turn, i)) if "confirm" in turn.lower(): out.append(Obligation("pending_decision", turn, i)) return out def verify_compaction( raw_turns: list[str], summary_text: str, summary_source_turns: set[int], ) -> None: obligations = extract_obligations(raw_turns) open_obs = [o for o in obligations if o.closed_at_turn is None] for o in open_obs: # Lossy if the obligation's substance is absent from the summary... if o.text.strip().lower() not in summary_text.strip().lower(): raise LossyCompactionError( f"open {o.kind} from turn {o.source_turn} missing in summary: " f"action space would silently widen" ) # ...or present but untraceable: provenance is part of losslessness. if o.source_turn not in summary_source_turns: raise LossyCompactionError( f"obligation from turn {o.source_turn} present but lacks source " f"provenance; cannot be audited on replay" ) # Only reachable when obligation set equality holds with provenance intact. return None def compact_or_refuse(raw_turns: list[str], summary_text: str, summary_source_turns: set[int]) -> str: try: verify_compaction(raw_turns, summary_text, summary_source_turns) except LossyCompactionError: # Refuse: retain raw turns, accept visible context pressure. return "COMPACTION_REFUSED: raw turns retained" return summary_text ```