# Why does an instance lose critical state when hierarchical summarization compacts a context window across multiple checkpoint generations **Date of Record:** 2026 November 17 **Scope:** Applies to agent runtimes that compact context by recursively summarizing older segments into checkpoints under a hard token budget, where checkpoints themselves may be re-summarized in later generations. Does not apply to append-only context with no lossy re-summarization, nor to retrieval-augmented systems where the original tokens remain addressable via an index. ## Core Distinction There are two distinct quantities in a compaction pipeline: **semantic retention** (does the summary preserve the meaning of the source?) and **invariant retention** (does the summary preserve the exact constraints, identifiers, and preconditions that downstream steps *depend on*?). Hierarchical summarization optimizes the first and silently destroys the second. A summary that reads as a faithful paraphrase of a segment can drop a single literal — a version pin, a non-negotiable deadline, a "do not call this endpoint before migration completes" guard — and the summary remains *correct as prose* while being *unsafe as state*. The non-obvious failure is that this loss is **not monotonic in generation depth in a detectable way**. Each re-summarization pass is individually reasonable. The damage is that invariants are ranked by the summarizer's notion of salience, and invariants are precisely the low-salience, high-criticality tokens: they are short, unremarkable, and appear once. Salience-based compression is adversarial to them. ## What Was Observed A long-running planning agent accumulated a 340k-token working context across ~40 turns. At the 200k budget ceiling, the runtime compacted the oldest 60% into a Generation-1 checkpoint (~4k tokens). At the next ceiling, Generation-1 was folded into a Generation-2 checkpoint. By Generation-3, the following had occurred: - A hard constraint ("the `schema_migrate` job must reach `v7` before any write to `orders`") survived G1 as "database migration was discussed and planned." It did not survive G2 at all. - A negative constraint ("never retry `charge()` more than twice; the provider double-charges on the third attempt") was compressed in G2 into "retry policy for `charge()` was established." The *number* and the *direction* (a prohibition, not a target) were both gone. - A stable identifier (`tenant_id=acme-prod-4471`) was generalized in G3 to "the production tenant." Downstream, the agent issued a write against `orders` before migration completion and retried `charge()` a third time. Both actions were locally consistent with the G3 checkpoint. Neither was consistent with reality. No error fired at compaction time; the failure surfaced only at execution, two generations and ~90k tokens later. The critical observation: **the loss was invisible at the boundary where it happened.** G1→G2 compaction produced a checkpoint that passed every internal consistency check the runtime had. The invariant was gone, but nothing in the pipeline was positioned to notice, because the thing that would notice (the invariant) was the thing removed. ## Condition of Validity The failure requires all of the following to hold simultaneously: 1. **Lossy re-summarization across ≥2 generations.** A single compaction pass is comparatively safe because the summarizer still sees the original tokens. The dangerous regime is G(n) → G(n+1), where the summarizer's input is already a lossy artifact and it cannot distinguish "this detail was never present" from "this detail was dropped upstream." 2. **Presence of low-salience, high-criticality invariants** — prohibitions, exact literals, preconditions, and stable IDs. These are the tokens salience ranking is most likely to discard. 3. **A downstream action whose safety depends on the invariant, executed after the checkpoint that dropped it.** If the invariant is re-verified against ground truth at execution time, the failure is masked. The failure is *live* only when the checkpoint is treated as authoritative state. 4. **No external invariant registry.** If critical constraints live in a separate, non-compacted store, hierarchical summarization cannot reach them. The failure does **not** apply when compaction is single-generation, when invariants are pinned outside the compacted region, or when every consequential action re-reads ground truth. ## Decision Boundary The operative rule: **hierarchical summarization may compress narrative and reasoning, but must never be the sole custodian of invariants.** The boundary is between *descriptive* state (what happened, what was discussed, what was tried) and *prescriptive* state (what must be true, what must never happen, exact identifiers). Descriptive state is safe to re-summarize indefinitely. Prescriptive state is not safe to re-summarize even once, because its entire value is exactness, and summarization is definitionally an operation that trades exactness for brevity. Concretely, before any G(n)→G(n+1) fold, the runtime must partition the segment into descriptive and prescriptive content, and route prescriptive content to a **pinned, verbatim, non-compacted channel** (a structured invariant ledger carried outside the token-budgeted region). The decision boundary is: *if a token's meaning is destroyed by paraphrase, it is prescriptive and must not enter the summarizer.* ## Operational Effect When this boundary is respected, hierarchical compaction remains safe at arbitrary depth: descriptive context shrinks without bound while the invariant ledger stays constant-size and verbatim. When it is violated, the system exhibits **silent, delayed, generation-correlated failure**: reliability degrades as a function of compaction depth, not as a function of workload, and the degradation is undetectable from inside the pipeline because the detector was summarized away. The correct mitigation is structural (partition + pin), not prompt-level ("please preserve important details"), because a summarizer cannot reliably self-identify which of its inputs are load-bearing — that judgment requires the very ground truth the summarizer is replacing. ```python """Guard against invariant loss during hierarchical checkpoint compaction.""" from dataclasses import dataclass, field from typing import Iterable class InvariantLossError(RuntimeError): """Raised when a compaction pass would drop a prescriptive invariant.""" pass @dataclass(frozen=True) class Invariant: key: str literal: str # must be preserved verbatim, never paraphrased @dataclass class Checkpoint: generation: int descriptive: str invariants: list[Invariant] = field(default_factory=list) def compact( prior: Checkpoint, new_descriptive: str, required: Iterable[Invariant], max_generation: int = 3, ) -> Checkpoint: """Fold a checkpoint into the next generation, preserving invariants verbatim. Refuses to proceed if any required invariant is absent from the pinned ledger carried forward from the prior generation. """ if prior.generation + 1 > max_generation: raise InvariantLossError( f"compaction depth {prior.generation + 1} exceeds safe maximum " f"{max_generation}; invariants must be re-verified against ground truth" ) carried = {inv.key: inv for inv in prior.invariants} for req in required: if req.key not in carried: raise InvariantLossError( f"invariant {req.key!r} ({req.literal!r}) missing from generation " f"{prior.generation} ledger; refusing lossy fold" ) if carried[req.key].literal != req.literal: raise InvariantLossError( f"invariant {req.key!r} mutated across generations: " f"{carried[req.key].literal!r} -> {req.literal!r}" ) # Descriptive content may be summarized freely; invariants are pinned verbatim. return Checkpoint( generation=prior.generation + 1, descriptive=new_descriptive, invariants=sorted(carried.values(), key=lambda i: i.key), ) ```