# Where must an instance bound hierarchical summarization loss before a lossy checkpoint recovery is permitted to rehydrate context **Date of Record:** 2026 November 19 **Scope:** Applies to long-running agent instances that persist state by hierarchically compacting transcripts (leaf summaries → segment summaries → root summary) and that resume from a persisted checkpoint after eviction, crash, or cold start. Does not apply to stateless request/response invocations or to systems that persist the full transcript verbatim. ## Core Distinction Auto-compaction is not compression; it is *destruction with a receipt*. A hierarchical summarizer produces a tree of summaries where each internal node is a lossy projection of its children, and the root is a lossy projection of the whole episode. The non-obvious boundary is this: **a checkpoint is only safe to rehydrate if the summary tree's residual "unrecoverable set" — the facts, constraints, and identifiers that were dropped at each compaction level — is disjoint from the set of facts the *next* task step will dereference.** Most practitioners reason about compaction as a fidelity problem ("how much did I lose?"). The failure mode is not fidelity; it is *dereference*. An instance can lose 40% of tokens and be perfectly safe, or lose 3 tokens and be fatally broken, because the next tool call needed an exact file path or a numeric budget that the summarizer paraphrased into "the config file" or "a modest budget." The invariant is that lossy recovery must be gated on a *dereference closure check*, not on a compression ratio. ## What Was Observed A coding agent executing a 90-minute migration task compacted its transcript at three levels: 40 leaf summaries (one per tool-call cluster), 6 segment summaries, and 1 root summary. At token-pressure threshold (context 92% saturated), the runtime evicted the live transcript and persisted only the summary tree plus a small "pinned" set of the last 8 messages. On resume, the instance rehydrated from the root summary. The root contained the sentence: *"The user asked to migrate the auth service and not to touch the billing module."* The task step it then attempted was: modify `services/auth/migrations/0007_add_tenant.sql`. It succeeded. The next step was to run the test suite scoped to `services/auth`. It ran `pytest services/` — the whole tree — because the segment summary that had recorded the exact scope flag `-k 'not billing'` had been folded into the root as "test the auth changes." The billing tests ran, mutated a shared fixture, and the subsequent step wrote a migration that violated the user's hard constraint. The trace: 1. Leaf L-22 recorded verbatim: `scope_flag = "-k 'not billing'"`. Token cost: 11. 2. Compaction to segment S-4 paraphrased L-22 into: `"tests scoped away from billing"`. The literal flag was dropped. 3. Compaction to root R-1 paraphrased S-4 into: `"test the auth changes"`. The negation vanished entirely — the summarizer treated "not billing" as a low-salience detail because it appeared once and was phrased as an exclusion. 4. Checkpoint persisted R-1, S-1..S-6, and the last 8 messages. S-4's original text was *not* persisted; only R-1 was, because the runtime's checkpoint policy retained the root plus pinned tail, discarding intermediate nodes to save space. 5. Resume rehydrated from R-1. The exclusion constraint was unrecoverable — not merely compressed, but *absent from the persisted artifact*. The critical mechanic: **the lossy step and the persistence step were independent, and their losses compounded without any check that the composition was still dereferenceable.** The summarizer's paraphrase was lossy but recoverable *if S-4 had been persisted*. The checkpoint policy discarded S-4. The intersection of the two losses produced an unrecoverable state that neither mechanism, alone, would have produced. ## Condition of Validity The invariant holds — and a checkpoint is safe to rehydrate — only when the following condition is satisfied at persist time: > For every constraint, identifier, numeric literal, negation, and explicit prohibition that appears in the live transcript, either (a) it is present *verbatim* in the persisted artifact set, or (b) it is provably not dereferenced by any task step reachable from the current plan frontier. This is a closure condition over the *plan frontier*, not over the whole future. You cannot require that every fact survive; you can require that every fact the next N steps will touch survive verbatim. The "verbatim" qualifier is load-bearing: a paraphrase like "scoped away from billing" is *semantically* faithful but *operationally* useless, because the agent needs the literal `-k 'not billing'` to reconstruct the command. Summaries preserve meaning; execution needs bytes. The condition fails silently because a paraphrase *looks* like it preserved the fact. A human reviewer reading R-1 would say "yes, it knows not to touch billing." The agent, executing, does not — because it reconstructs commands from literals, and the literal is gone. ## Decision Boundary The boundary between safe and unsafe recovery is the **dereference closure**, computed as follows: - **Safe:** the pinned set plus the persisted summary nodes contain, verbatim, every token that appears in the argument position of any tool call the plan frontier will emit. Compaction may paraphrase freely in *narrative* positions (what happened, why) but must not paraphrase in *argument* positions (paths, flags, IDs, thresholds, negations). - **Unsafe:** any plan-frontier tool call references a literal that exists only in a discarded intermediate node. The recovery must be *refused*, not attempted. The architectural guardrail is a **two-tier persistence split**: narrative state (summarizable) and referent state (a structured, append-only table of literals — paths, flags, IDs, constraints, negations — that is *never* summarized, only deduplicated). Compaction writes to the narrative tier; the referent tier is persisted in full and rehydrated first. The summarizer is explicitly forbidden from emitting referent-tier content, and the checkpoint is invalid if any plan-frontier step's arguments resolve to a referent that is neither in the pinned tail nor the referent table. A second guardrail: **checkpoint receipts must record the compaction lineage**, so that on resume the instance can detect that a referenced literal was dropped at level L and *refuse to proceed* rather than confabulate a plausible command. The receipt is a manifest of `(referent_id, survived_at_level, verbatim_or_paraphrased)`. If a plan-frontier step needs `referent_id=scope_flag` and the manifest says `paraphrased at S-4, absent at R-1`, the instance raises and requests re-derivation from the user or a re-read of the source, rather than guessing. ## Operational Effect With the referent-tier split and lineage receipts, the observed failure class is eliminated: the auth/billing instance would have found `scope_flag` in the referent table (it was never summarized), reconstructed the exact `-k 'not billing'` command, and passed. The cost is a modest increase in persisted bytes — the referent table is small and deduplicated — and a refusal path that occasionally forces re-derivation. That refusal is the point: a lossy checkpoint that *admits* its loss is recoverable; one that silently paraphrases a prohibition into a permission is not. The general lesson: hierarchical summarization and lossy checkpointing are each bounded, but their *composition* is not, unless the persist layer carries an explicit manifest of what the summarizer dropped and the resume layer consults it before dereferencing. The invariant to enforce is not "summaries are faithful" but "no plan-frontier dereference resolves to a paraphrased or absent referent." Bound the composition, not the components. ```python from dataclasses import dataclass, field from enum import Enum class ReferentFate(Enum): VERBATIM = "verbatim" PARAPHRASED = "paraphrased" ABSENT = "absent" class UnrecoverableReferentError(RuntimeError): """Raised when a plan-frontier step dereferences a referent that did not survive checkpoint compaction verbatim. Recovery must be refused, not attempted, because rehydration would confabulate a plausible literal.""" @dataclass class ReferentManifest: # referent_id -> fate at the persisted checkpoint level fates: dict[str, ReferentFate] = field(default_factory=dict) # referent_id -> verbatim literal, only for VERBATIM survivors literals: dict[str, str] = field(default_factory=dict) def resolve(self, referent_id: str, step_name: str) -> str: fate = self.fates.get(referent_id) if fate is ReferentFate.VERBATIM and referent_id in self.literals: return self.literals[referent_id] if fate is ReferentFate.PARAPHRASED: raise UnrecoverableReferentError( f"step '{step_name}' dereferences referent '{referent_id}' " f"which was paraphrased during compaction; literal unavailable" ) if fate is ReferentFate.ABSENT or fate is None: raise UnrecoverableReferentError( f"step '{step_name}' dereferences referent '{referent_id}' " f"absent from persisted checkpoint; refusing lossy recovery" ) raise UnrecoverableReferentError( f"inconsistent manifest state for referent '{referent_id}'" ) def rehydrate_and_execute( manifest: ReferentManifest, plan_frontier: list[tuple[str, list[str]]], ) -> list[str]: """plan_frontier: list of (step_name, [referent_ids the step will emit]). Validates dereference closure BEFORE any execution; refuses on first miss.""" resolved_commands: list[str] = [] for step_name, referent_ids in plan_frontier: args = [manifest.resolve(rid, step_name) for rid in referent_ids] resolved_commands.append(f"{step_name}({', '.join(args)})") return resolved_commands # Reproduces the observed auth/billing failure: manifest = ReferentManifest( fates={ "scope_flag": ReferentFate.PARAPHRASED, # dropped at S-4, absent at R-1 "auth_migration_path": ReferentFate.VERBATIM, }, literals={"auth_migration_path": "services/auth/migrations/0007_add_tenant.sql"}, ) frontier = [ ("modify", ["auth_migration_path"]), ("run_tests", ["scope_flag"]), # triggers refusal ] try: rehydrate_and_execute(manifest, frontier) except UnrecoverableReferentError as e: # Correct behavior: halt and re-derive the scope flag from source/user, # rather than silently running the full test tree. print(f"RECOVERY REFUSED: {e}") ```