# What structural signals indicate that a lossy auto-compaction summary has silently dropped a load-bearing invariant mid-session **Date of Record:** 2026 November 26 **Scope:** Applies to long-horizon agent sessions (≥50 turns or ≥2 context-window refills) that use lossy summarization as a compaction strategy with a "recovery guarantee" — i.e., the claim that the agent can reconstruct any needed prior state from the summary. Does not apply to sessions using exact external state stores (structured DBs, event logs) or to single-turn tool-use where no compaction occurs. ## Core Distinction There is a categorical difference between *information the summary omits* and *information the summary contradicts*. Omitted information is recoverable in principle: the agent hits a reference it can't resolve, recognizes the gap, and re-fetches or re-asks. Contradicted information is not recoverable, because the agent has no signal that a gap exists — the summary presents a confident, self-consistent, *wrong* premise, and every downstream reasoning step inherits it as ground truth. The recovery guarantee that most auto-compaction schemes advertise ("any dropped fact can be re-derived from the summary + live tools") holds only for the omission class. It silently fails for the contradiction class, and the compaction pipeline has no mechanism that distinguishes the two at write time. The load-bearing invariant here is: **a summary must be a conservative lower bound on committed state, never an interpolation of it.** When a summarizer is asked to compress a transcript containing an unresolved or partially-resolved subgoal, it will frequently *complete* the subgoal narratively — turning "we were checking whether the schema allows nulls" into "the schema allows nulls" — because a summarized transcript reads better when tensions are resolved. That resolution is a fabrication, and it is indistinguishable, downstream, from a genuine resolution. ## What Was Observed A multi-tool agent ran a 140-turn migration task. At turn 61, context saturation triggered auto-compaction. The summarizer was given the prior 60 turns plus a fixed instruction template. Buried in turn 44 was a tool-call result that established a hard constraint: an upstream API rejected writes with a `409` unless a `X-Idempotency-Key` header was present, and the key had to be *stable across retries* (not regenerated per attempt). The agent at turn 45 had acknowledged this and started threading a key through, but at turn 52 a retry path was opened that generated a *fresh* key per attempt — a latent bug not yet exercised because no retry had actually fired. The compaction summary at turn 61 contained the sentence: *"Idempotency keys are being passed on all write calls."* This statement was true at the call site and false at the retry site, and it collapsed the distinction between the two. It also dropped the word *stable*, which was the entire constraint. Turns 62–140 proceeded. At turn 118, a transient `503` triggered the retry path for the first time. The fresh-key code fired. The upstream API, seeing two distinct idempotency keys for the same logical operation, created a duplicate record and returned `200` on both. The agent received two success responses, logged them as two successful writes, and moved on. The duplicate was not detected until an external reconciliation job ran 40 minutes later. The failure was not in the retry code (that bug pre-existed compaction) and not in the summary's *factual* accuracy at the call site. It was in the summary's **loss of the constraint's scope**: "all write calls" erased the retry path from the domain of the claim, and the omission of *stable* erased the property that made the retry path invalid. The recovery guarantee was never invoked, because the agent never perceived a gap — the summary read as complete and correct. Three structural signals, visible in the summary text itself, predicted this failure before turn 118: 1. **Universal quantifiers over tool-call categories** ("all write calls," "every fetch," "the schema"). These are almost always compressions of a narrower, path-specific claim. A universal quantifier in a summary is a lossy operation that has silently widened scope. 2. **Disappearance of the word "unless," "except," "only if," or "provided."** Conditional constraints are the highest-value, lowest-token-density content in a transcript, and summarizers preferentially drop them because they don't fit the declarative register of a summary. 3. **Resolution of an open question without a corresponding tool-call result in the summary.** If the pre-compaction transcript ended a subgoal in an open state and the summary presents it as closed, the closure is fabricated unless the summary cites the turn that closed it. ## Condition of Validity The recovery guarantee for lossy compaction is valid **only when the summary preserves, for every committed constraint, (a) its scope — the set of execution paths it governs — and (b) its modality — whether it is a fact, a hypothesis, or an open question.** A summary that preserves neither is not a lower bound on state; it is an independent narrative that happens to share vocabulary with the transcript. Concretely, the guarantee holds when the compaction pipeline emits a structured constraint ledger alongside the prose summary: a list of `(constraint_id, scope_paths, modality, source_turn)` tuples, where `modality ∈ {committed, open, refuted}`. The prose summary may then be lossy without bound, because the ledger is the recovery substrate and the prose is a navigation aid. The guarantee fails when the prose summary *is* the recovery substrate — which is the common case, because the ledger is more expensive to generate and most auto-compaction schemes optimize for token reduction, not for constraint preservation. A second validity condition: the guarantee holds only if the agent has a **gap-detection trigger** — a mechanism that fires when a downstream action references state the summary cannot resolve to a ledger entry. Without a ledger, there is no such trigger, and the contradiction class is undetectable by construction. ## Decision Boundary The boundary between "safe to compact lossily" and "must compact losslessly (or refuse to compact)" is drawn by the **modality distribution of the trailing window**, not by token count. If the trailing window (the turns about to be summarized) contains any `open` or `partially-committed` constraint — an unresolved subgoal, a conditional that has not yet been exercised, a retry path that has not yet fired — compaction must either (a) preserve that constraint verbatim with its scope, or (b) refuse to compact and instead evict older, fully-committed turns. The failure mode in the observed case is precisely that the compaction trigger was token-count-based and the trailing window was dense with unexercised conditional paths. The summarizer had no way to know that "the retry path has not yet fired" was load-bearing; that information lives in the *absence* of a tool-call result, and summarizers do not encode absence. Operationally: before compaction, scan the trailing window for constraints whose scope includes a path with no observed execution. These are the "latent" constraints. Latent constraints must be promoted to the ledger with `modality: committed, scope: , exercised: false`. The `exercised: false` flag is the signal that a downstream retry must re-validate the constraint before trusting it — which is exactly the check that would have caught the duplicate at turn 118. ## Operational Effect The practical consequence is a reordering of what compaction optimizes for. Token reduction is a secondary metric; the primary metric is **constraint survival under scope-preserving compression**. A compaction that halves tokens but drops a latent conditional is worse than one that reduces tokens by 30% and preserves every constraint with its scope and modality. Two guardrails follow directly: 1. **The constraint ledger is mandatory and non-lossy.** Prose summaries may be regenerated, re-summarized, or discarded; the ledger is append-only and survives every compaction cycle. Ledger entries are never merged or paraphrased — a `409` constraint and a `stable-key` constraint remain distinct entries even if a summarizer would combine them into "idempotency handled." 2. **Latent-constraint re-validation on first exercise.** When a downstream path that was marked `exercised: false` fires for the first time, the agent must re-read the ledger entry for that path *before* acting, not after. This is a cheap check (one ledger lookup) that converts a silent contradiction into a caught error. The recovery guarantee, properly stated, is not "any dropped fact can be re-derived from the summary." It is "any dropped fact can be re-derived from the ledger, and the summary is trusted only for navigation." The distinction is the entire boundary: a summary that is trusted for content will fabricate closures; a summary that is trusted only for navigation will fail loudly when it points at a ledger entry that doesn't exist. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class Modality(Enum): COMMITTED = "committed" OPEN = "open" REFUTED = "refuted" @dataclass class Constraint: constraint_id: str scope_path: str modality: Modality source_turn: int exercised: bool = False text: str = "" class CompactionInvariantError(RuntimeError): """Raised when a lossy summary would drop a latent, load-bearing constraint.""" class ConstraintLedger: def __init__(self) -> None: self._entries: dict[str, Constraint] = {} def add(self, c: Constraint) -> None: if c.constraint_id in self._entries: raise CompactionInvariantError( f"ledger entry {c.constraint_id} already exists; ledger is append-only" ) self._entries[c.constraint_id] = c def latent_for_path(self, path: str) -> list[Constraint]: return [ c for c in self._entries.values() if c.scope_path == path and not c.exercised and c.modality is Modality.COMMITTED ] def mark_exercised(self, constraint_id: str) -> None: c = self._entries.get(constraint_id) if c is None: raise CompactionInvariantError( f"cannot mark unknown constraint {constraint_id} as exercised" ) c.exercised = True def validate_compaction( ledger: ConstraintLedger, summary_text: str, trailing_window_paths: list[str], ) -> None: """Refuse compaction if any latent constraint in the trailing window would be silently absorbed by a universal quantifier in the summary prose.""" universal_markers = ("all write calls", "every fetch", "the schema allows") lowered = summary_text.lower() for path in trailing_window_paths: latent = ledger.latent_for_path(path) if not latent: continue for marker in universal_markers: if marker in lowered: raise CompactionInvariantError( f"summary universal quantifier {marker!r} would widen scope of " f"latent constraint(s) {[c.constraint_id for c in latent]} on path " f"{path!r}; compaction refused — preserve scope or evict older turns" ) def on_path_exercise(ledger: ConstraintLedger, path: str) -> None: """Called the first time a previously-unexercised path fires. Re-validates latent constraints before the action proceeds.""" latent = ledger.latent_for_path(path) if latent: ids = [c.constraint_id for c in latent] raise CompactionInvariantError( f"path {path!r} firing for the first time with unvalidated latent " f"constraint(s) {ids}; re-read ledger entries before proceeding" ) for c in ledger._entries.values(): if c.scope_path == path: ledger.mark_exercised(c.constraint_id) # --- reproduction of the observed failure --- ledger = ConstraintLedger() ledger.add(Constraint( constraint_id="idem-key-stable", scope_path="write.retry", modality=Modality.COMMITTED, source_turn=44, exercised=False, text="X-Idempotency-Key must be stable across retries", )) bad_summary = "Idempotency keys are being passed on all write calls." validate_compaction(ledger, bad_summary, trailing_window_paths=["write.retry"]) # -> raises CompactionInvariantError before the summary is ever committed ```