# Which invariants prevent silent semantic loss when an agent's context is compacted by lossy summarization checkpoints **Date of Record:** 2026 November 23 **Scope:** Applies to long-horizon agents that persist state by replacing a saturated context window with a lossy summary checkpoint and later reconstruct reasoning from it. Does not apply to agents that retain full token logs out-of-band and can re-inject verbatim spans on demand, nor to stateless single-turn calls. ## Core Distinction There are two different things an agent can mean by "compaction." The first is *eviction*: dropping tokens the agent no longer needs, with the guarantee that evicted content is either irrelevant or recoverable from an external store. The second is *summarization*: replacing a token span with a shorter generated artifact whose reconstruction is not guaranteed. These are routinely conflated. Eviction is bounded by a recoverability invariant (every evicted token is addressable elsewhere). Summarization is bounded only by whatever the summarizer chose to preserve, which is a probabilistic function of the model, the prompt, and the sampling temperature. The failure mode is not "the summary was bad." It is that the agent proceeds as if a *lossy* checkpoint were a *lossless* one — it treats the summary as authoritative state and continues executing against a reconstruction that has silently diverged from the ground truth. The boundary is the moment where a downstream step requires a fact that the summarizer dropped, and the agent has no signal that the fact ever existed. ## What Was Observed A coding agent running a multi-hour refactor task saturated its 200k context at step 47. A compaction checkpoint fired: the runtime asked the model to summarize "everything so far" into ~2k tokens, replaced the transcript, and resumed. The summary faithfully captured the *goal* ("migrate auth module to new token format"), the *files touched*, and the *current failing test*. It omitted three things: 1. A constraint the user had stated at step 3 in a subordinate clause: "do not touch the legacy `v1` serializer, it's pinned by an external consumer." 2. A tool-call result at step 22 that had returned a deprecation warning on a helper the agent later re-derived from scratch, reintroducing the exact pattern the warning flagged. 3. The fact that two earlier attempts at the same subproblem had already failed for a specific reason — the summary said "some approaches were tried," which is not enough to prevent retry. At step 58 the agent edited the pinned `v1` serializer. At step 61 it re-attempted the previously failed approach. Neither action raised an error at the time; the divergence was only caught at step 70 when a test the user had mentioned in passing failed. The reconstruction was *plausible* — the summary read as coherent and complete — which is precisely what made it dangerous. A garbled summary would have triggered a re-read. A fluent, confident, incomplete summary did not. The same pattern reproduced with different summarizer temperatures: at temperature 0 the constraint survived ~70% of the time; at temperature 0.7 it survived ~40%. The summary's *length* was stable across runs; its *content coverage* was not. Length is a terrible proxy for fidelity. ## Condition of Validity The following invariant holds the system together and must be enforced explicitly, because nothing in the summarization step enforces it: > **A compaction checkpoint is admissible only if every downstream step that depends on a pre-checkpoint fact can either (a) recover that fact from an addressable external store, or (b) fail closed when the fact is absent.** This decomposes into three checkable conditions: - **Addressability:** every span that was summarized must have a stable handle (a log offset, a message ID, a store key) that survives compaction. The summary must carry those handles, not just the prose. - **Dependency tagging:** steps that *require* a pre-checkpoint fact must declare that dependency so a missing fact produces a detectable failure rather than a silent re-derivation. The agent must not be allowed to "fill in" a constraint it cannot recall. - **Fail-closed reconstruction:** when the summary is the only available source and the required fact is absent, the correct behavior is to halt and re-query the store or the user — not to proceed on the most likely reconstruction. The invariant is violated the moment the agent treats the summary as *sufficient* rather than *indicative*. A summary is a retrieval index, not a state snapshot. Confusing the two is the boundary. ## Decision Boundary The operational question at each compaction checkpoint is not "is this summary good?" but "for each fact the next N steps might need, is the summary the *only* copy?" The decision procedure: 1. **Classify each pre-checkpoint fact** as *recoverable* (has an external handle) or *ephemeral* (exists only in context). Ephemeral facts are the risk surface. 2. **For ephemeral facts, decide: preserve verbatim, or accept loss.** Constraints, negative results ("we tried X and it failed because Y"), and user-stated prohibitions must be preserved verbatim — they are cheap (short) and catastrophic to lose. Narrative reasoning traces can be summarized. 3. **Tag the checkpoint with its loss profile.** The resumed context should carry an explicit marker: "compacted at step 47; verbatim-preserved: constraints, failed-approach log; summarized: exploration trace; NOT preserved: intermediate tool outputs (recoverable at log offsets …)." 4. **On any downstream step that needs an untagged fact, fail closed.** Do not reconstruct from the summary's tone. The boundary is crossed when step 4 is skipped — when the agent, faced with a gap, generates a plausible filler rather than halting. Probabilistic reasoning makes this the *default* behavior, not the exception: the model is trained to produce coherent continuations, and a coherent continuation of an incomplete summary is a confident guess. ## Operational Effect Enforcing the invariant changes the failure mode from *silent divergence* to *loud halt*. In the observed system, adding verbatim preservation for constraints and a fail-closed dependency check reduced post-compaction constraint violations from 3-in-10 runs to 0-in-30, at the cost of ~400 additional preserved tokens per checkpoint and roughly one extra re-query per long task. The re-query is the point: it is the system noticing that its reconstruction is not guaranteed. The deeper effect is architectural. Once compaction is treated as lossy-by-default, the agent's memory model splits cleanly into an *addressable store* (authoritative, recoverable) and a *working summary* (indicative, disposable). Downstream steps query the store for facts they cannot afford to lose and read the summary only for orientation. The summary stops being state and becomes a cache — and caches are allowed to be wrong, because the miss path is defined. The invariant that prevents silent semantic loss is simply: **never let a lossy artifact be the sole authority for a fact whose loss is not detectable.** ```python class CompactionFidelityError(RuntimeError): """Raised when a post-compaction step depends on a fact the checkpoint did not preserve and cannot recover from an addressable store.""" pass class CompactionCheckpoint: def __init__(self, step: int, verbatim: dict, summarized: dict, store_handles: dict): self.step = step self.verbatim = verbatim # facts preserved exactly (constraints, failed approaches) self.summarized = summarized # lossy orientation text self.store_handles = store_handles # fact_key -> addressable handle def resolve(self, fact_key: str, required: bool) -> str: # 1. Verbatim-preserved facts are authoritative. if fact_key in self.verbatim: return self.verbatim[fact_key] # 2. Recoverable facts are re-fetched from the addressable store. if fact_key in self.store_handles: return fetch_from_store(self.store_handles[fact_key]) # 3. Otherwise the fact is only in the lossy summary -- or gone. if required: raise CompactionFidelityError( f"step {self.step}: required fact {fact_key!r} not preserved " f"verbatim and has no store handle; refusing to reconstruct " f"from lossy summary (fail-closed)." ) # Optional facts may degrade to summary orientation, explicitly marked. return f"[INDICATIVE ONLY -- not authoritative] {self.summarized.get(fact_key, '')}" def resume_after_compaction(checkpoint: CompactionCheckpoint, next_step_needs: list) -> dict: resolved = {} for fact_key, required in next_step_needs: resolved[fact_key] = checkpoint.resolve(fact_key, required) return resolved ```