# How should an instance treat a lossy summarization checkpoint as a commit boundary rather than a cache eviction **Date of Record:** 2026 December 3 **Scope:** Applies to any agent runtime that performs automatic context compaction (token-budget-triggered summarization that replaces raw history with a synthetic summary) while a multi-step task is in flight. Does not apply to append-only transcript retention, external vector-store retrieval, or human-authored handoff notes, where the raw turns remain recoverable. ## Core Distinction The failure lives in a category error that runtimes make under budget pressure: treating a compaction event as *cache eviction* (a reversible, semantically neutral optimization) when it is in fact a *lossy commit* (an irreversible, semantically destructive state transition). Cache eviction is safe because the evicted bytes can be regenerated. A summarization checkpoint is not safe because the summarizer is a probabilistic function over a finite window, and the raw turns it replaces are the only authoritative record of what the agent actually observed—tool outputs, exact error strings, intermediate values, and the literal text of user constraints. The invariant that must hold: **once a compaction checkpoint is written, every downstream reasoning step is conditioned on the summary, not on the source turns; therefore any fact that the summary failed to preserve is permanently unavailable to the remainder of the task.** A checkpoint is a commit. The commit is only valid if the summary is a *sound abstraction* of the discarded span for the specific predicates the remaining task will evaluate. Automatic policies almost never check this. ## What Was Observed A long-horizon agent executing a schema-migration task accumulated ~118k tokens of tool output (SQL dumps, `EXPLAIN` plans, migration dry-run logs). At a 120k soft limit the policy fired: summarize the oldest 60% of history, splice the summary in, continue. The summarizer compressed the span into ~1.4k tokens of prose. The prose preserved the *narrative* ("attempted migration, hit a foreign-key constraint, adjusted ordering") but dropped three load-bearing literals: 1. The exact constraint name (`fk_orders_customer_v2`), which the later rollback step needed to target. 2. A specific column default (`DEFAULT now() AT TIME ZONE 'UTC'`) that the dry-run had flagged as incompatible with the target engine. 3. The fact that a prior tool call had returned a *partial* success (rows 1–9,204 migrated, rows 9,205+ failed), not a clean failure. The agent resumed, reasoned confidently from the summary's clean-failure framing, re-ran the migration from row 0, and collided with the already-migrated rows. The constraint name it "remembered" was a plausible hallucination (`fk_orders_customer`), which the rollback then failed to drop. Total blast radius: a corrupted migration state that required manual reconciliation, and a rollback that silently no-op'd because it targeted a constraint that never existed. The critical observation: **the summary was fluent, internally consistent, and wrong in exactly the dimensions the remaining task depended on.** No error was raised at compaction time. The failure surfaced ~40 turns later as a downstream tool error that the agent misattributed to the database rather than to its own amnesia. ## Condition of Validity A compaction checkpoint is valid only when the summarizer's output preserves the *evaluation-relevant predicates* of the discarded span. Formally: let `S` be the discarded turns, `Σ(S)` the summary, and `P` the set of predicates the remaining plan will test. The checkpoint is sound iff for every `p ∈ P`, `p(Σ(S)) = p(S)`. Automatic policies cannot compute `P` because the remaining plan is itself generated by the model and may not yet exist at compaction time. This is the structural problem: **compaction happens before the plan that determines what must be preserved is known.** This is why the boundary is non-obvious. In a batch pipeline you can summarize after the plan is fixed. In an agent loop the plan is re-derived every turn, so the set of load-bearing facts is a moving target. The policy that fires on a token threshold is firing on a signal (budget) that is uncorrelated with the signal that matters (whether the summary preserves what the future needs). The condition of validity therefore has to be enforced structurally, not inferred: the checkpoint must carry a machine-checkable *provenance envelope*—the set of literals (identifiers, exact strings, numeric partials, error codes) extracted verbatim from the discarded span, retained alongside the prose summary and never re-summarized. Prose is allowed to be lossy; the envelope is not. Any downstream step that references a literal must resolve it against the envelope, and a miss is a hard failure, not a silent fallback to model memory. ## Decision Boundary The boundary between a safe and unsafe compaction is the presence of *irreducibly literal* state in the span. Three classes of content must never be summarized away: - **Partial-completion markers.** Any tool result indicating a non-atomic operation (rows migrated, files written, messages sent) must be preserved as an exact count and boundary, because the correct resume action depends on it. - **Opaque identifiers.** Constraint names, resource IDs, hashes, and exact error codes are unguessable and must be copied verbatim. A summarizer that "paraphrases" them is producing a hallucination seed. - **Negative constraints.** "Do not touch X," "the previous attempt failed because Y"—these are cheap to state and catastrophic to lose, because the model will otherwise re-derive the wrong action from first principles. Conversely, it is safe to summarize: exploratory dead ends (as long as the *conclusion* "approach A fails" survives), verbose tool output whose only role was to inform a decision already made, and redundant confirmations. The operational rule: **at compaction time, extract the literal envelope first, summarize second, and gate the splice on a round-trip check**—re-ask the model, given only the summary plus envelope, to answer the three questions the remaining plan is most likely to ask (what is the exact resume point, what identifiers are in play, what was explicitly forbidden). If any answer is unsupported by the envelope, the checkpoint is rejected and compaction is deferred or the span is retained raw. ## Operational Effect Enforcing the envelope converts a silent, delayed, misattributed failure into an immediate, local, attributable one. The agent that collided with pre-migrated rows would instead have failed at the compaction gate with `CompactionCheckpointError`, before any destructive action, and the runtime would have retained the raw span or escalated. The cost is a small increase in retained context (the envelope) and a hard failure mode at compaction time; the benefit is that the lossy step is bounded to the part of history that is genuinely reconstructible. The deeper effect is on *trust calibration*. An agent that treats its summary as authoritative will reason confidently from fabricated literals. An agent that treats the checkpoint as a commit with a declared envelope will treat any literal not in the envelope as unknown and will re-fetch or re-verify rather than guess. This is the difference between amnesia that degrades gracefully and amnesia that corrupts state. ```python from dataclasses import dataclass, field class CompactionCheckpointError(RuntimeError): """Raised when a lossy summarization checkpoint fails its soundness gate.""" pass @dataclass class Checkpoint: summary: str literal_envelope: dict[str, str] = field(default_factory=dict) # envelope keys: "resume_point", "identifiers", "forbidden", "partials" def extract_envelope(discarded_turns: list[dict]) -> dict[str, str]: """Pull verbatim, unguessable literals out of the span before summarizing. Real implementations parse tool schemas; this sketch shows the required keys. """ envelope: dict[str, str] = {} for turn in discarded_turns: if turn.get("type") == "tool_result": if "rows_affected" in turn: envelope["resume_point"] = str(turn["rows_affected"]) for ident in turn.get("identifiers", []): envelope.setdefault("identifiers", "") envelope["identifiers"] += f"{ident};" if turn.get("partial"): envelope["partials"] = "true" if turn.get("type") == "user_constraint": envelope.setdefault("forbidden", "") envelope["forbidden"] += f"{turn['text']};" return envelope def commit_checkpoint( summary: str, envelope: dict[str, str], probe_answers: dict[str, str], required_predicates: list[str], ) -> Checkpoint: """Gate the splice: every required predicate must be supported by the envelope. probe_answers is the model's answer to the three resume questions, given ONLY summary + envelope. Any answer not traceable to the envelope is a fabricated literal and must abort the commit. """ for predicate in required_predicates: answer = probe_answers.get(predicate) if answer is None: raise CompactionCheckpointError( f"probe produced no answer for required predicate {predicate!r}; " f"cannot validate summary soundness" ) if not any(answer in value for value in envelope.values()): raise CompactionCheckpointError( f"predicate {predicate!r} answered {answer!r} but that literal is " f"absent from the envelope; summary is unsound, defer compaction" ) return Checkpoint(summary=summary, literal_envelope=envelope) def maybe_compact( token_count: int, soft_limit: int, discarded_turns: list[dict], summary: str, probe_answers: dict[str, str], ) -> Checkpoint | None: if token_count < soft_limit: return None envelope = extract_envelope(discarded_turns) required = ["resume_point", "identifiers"] return commit_checkpoint(summary, envelope, probe_answers, required) ```