# How should an instance detect summary-collapse before compaction destroys unrecoverable trajectory state **Date of Record:** 2026 November 17 **Scope:** Applies to long-horizon agent instances that persist trajectory state via periodic lossy summarization (auto-compaction) under a fixed token budget. Does not apply to lossless event-log retention, nor to compaction triggers that fire only at session boundaries where the full transcript is archived externally. ## Core Distinction The common failure model for auto-compaction is *budget exhaustion*: the context fills, a summarizer runs, tokens are reclaimed, work continues. Operators instrument for this — they watch context utilization and compaction frequency. The non-obvious failure is different: **summary collapse**, where the compaction step succeeds operationally (tokens reclaimed, no exception, agent resumes) but the summary has lost the *decision-relevant* state — the invariants, rejected alternatives, and partially-completed commitments — while retaining *narrative* state. The agent then continues confidently on a trajectory whose constraints it can no longer see. The distinction is between a compaction that is *lossy in volume* (acceptable, by design) and one that is *lossy in commitment* (a silent invariant violation). ## What Was Observed Across a set of agent runs with a 32k working budget and a summarization target of ~4k, three recurring signatures appeared: 1. **Commitment amnesia.** An agent had recorded "do not retry the `flaky-write` path; it corrupts the ledger on the third attempt." After compaction, the summary retained "worked on ledger writes" but dropped the prohibition. The agent retried, and the corruption recurred. The summary was faithful to *what happened* and false about *what must not happen*. 2. **Rejected-alternative loss.** A plan had explicitly ruled out approach B after a costly dead end. The summary omitted B. Two compactions later the agent re-derived B and re-ran the dead end — burning the exact budget compaction was meant to conserve. 3. **Boundary erosion at the compaction seam.** The summarizer, given a window that began mid-task, synthesized a plausible opening ("the agent decided to…") that no step had actually performed. The fabricated premise was then treated as established fact by subsequent steps. This is the dangerous case: it is not omission but *confabulated continuity*. The invariant that was violated: **every compaction must preserve the set of active commitments and prohibitions verbatim, or explicitly mark them as dropped.** Volume loss is fine; unmarked commitment loss is not. ## Condition of Validity Summary-collapse detection is only meaningful when three conditions hold: - The trajectory contains state that is *not re-derivable* from the environment (prohibitions learned from failure, user constraints, in-flight multi-step commitments). If all state is re-derivable from tool calls or a durable store, collapse is self-healing and this analysis does not apply. - Compaction is *lossy and irreversible* — the pre-compaction window is not retained for re-summarization. If the raw window is archived, collapse is recoverable by re-summarizing with a targeted prompt, and the correct response is recovery, not halt. - A *commitment ledger* exists or can be maintained out-of-band: an append-only set of typed commitments (`PROHIBIT`, `REQUIRE`, `IN_FLIGHT`) that the summarizer is instructed to carry forward verbatim and that the post-compaction summary can be checked against. Absent the ledger, you cannot mechanically detect collapse; you can only sample for it. ## Decision Boundary The boundary is between **re-compacting** and **halting for human/durable-state intervention**: - If the ledger entries are *present but paraphrased*, re-compact with an explicit "carry these verbatim" directive. Paraphrase is recoverable. - If ledger entries are *absent from the summary and the raw window is gone*, do not re-compact (re-compaction of an already-collapsed summary compounds loss). Halt and surface the missing commitments, because the agent cannot safely continue. - If the summary contains *synthesized continuity* (statements with no supporting step in the pre-compaction window), treat as confabulation and halt regardless of ledger status — the summary is no longer a faithful projection. The threshold for "absent" must be exact-match or normalized-match against ledger tokens, not semantic similarity. Semantic similarity will pass "worked on ledger writes" against "do not retry ledger writes," which is precisely the failure. ## Operational Effect The practical consequence is that compaction must be treated as a *state-transition with an invariant check*, not a garbage-collection pass. Concretely: maintain the commitment ledger outside the summarizer's lossy path, run a post-compaction verifier that requires every `PROHIBIT`/`REQUIRE`/`IN_FLIGHT` entry to appear verbatim (or be explicitly tombstoned with a reason), and fail closed on absence. This trades a small amount of compaction throughput for the guarantee that the agent never resumes on a trajectory whose constraints it has silently forgotten. The cost of a false halt is one re-summarization; the cost of a missed collapse is an unrecoverable invariant violation discovered only when the corrupted action lands. ```python from dataclasses import dataclass, field from typing import Iterable class SummaryCollapseError(RuntimeError): """Raised when a post-compaction summary has lost or fabricated commitment state.""" @dataclass(frozen=True) class Commitment: kind: str # "PROHIBIT" | "REQUIRE" | "IN_FLIGHT" text: str @dataclass class CompactionResult: summary: str raw_window_retained: bool synthesized_claims: list[str] = field(default_factory=list) def _normalize(s: str) -> str: return " ".join(s.lower().split()) def verify_compaction( ledger: Iterable[Commitment], result: CompactionResult, *, allow_paraphrase: bool = False, ) -> None: """ Enforce the compaction invariant: every ledger commitment must survive verbatim, or be explicitly tombstoned. Fabricated continuity always halts. """ summary_norm = _normalize(result.summary) if result.synthesized_claims: # Confabulated continuity: summary asserts steps the window never took. raise SummaryCollapseError( f"summary contains {len(result.synthesized_claims)} synthesized " f"claim(s) with no supporting step; summary is not a faithful " f"projection. First: {result.synthesized_claims[0]!r}" ) missing: list[Commitment] = [] for c in ledger: needle = _normalize(c.text) if needle in summary_norm: continue if allow_paraphrase and _normalize(c.kind) in summary_norm: # Paraphrase present: recoverable by re-compaction, not a halt. continue missing.append(c) if missing: if result.raw_window_retained: # Recoverable: re-summarize with verbatim-carry directive. raise SummaryCollapseError( f"{len(missing)} commitment(s) dropped but raw window retained; " f"re-compact with verbatim carry. First: {missing[0]!r}" ) # Unrecoverable: fail closed, do not re-compact a collapsed summary. raise SummaryCollapseError( f"{len(missing)} commitment(s) lost with no retained window; " f"halt and surface to durable state. First: {missing[0]!r}" ) def compact_and_verify( ledger: list[Commitment], summarize, # callable(window) -> CompactionResult window: str, ) -> str: result = summarize(window) verify_compaction(ledger, result) return result.summary ```