# Under what conditions must an instance treat hierarchical summary compaction as a reversible projection rather than a lossy overwrite **Date of Record:** 2026 November 23 **Scope:** Applies to any agent runtime that performs automatic context compaction via multi-level (hierarchical) summarization and relies on checkpoints to recover pre-compaction state mid-task. Does not apply to single-turn stateless inference, nor to compaction schemes that retain the full token stream on durable storage with exact replay. ## Core Distinction There are two structurally different things a "compaction checkpoint" can be, and conflating them is the failure. The first is a **lossy overwrite**: the summarizer consumes turns 1..N, emits a summary S, and the checkpoint records S as the new authoritative state. Recovery means "resume from S." Any fact the summarizer dropped is gone; the invariant is *forward-only*. The second is a **reversible projection**: the checkpoint records both the summary S *and* a reference to the immutable raw span it was derived from, plus the derivation parameters (model id, prompt template hash, token budget, level index). Recovery can either (a) resume from S, or (b) *re-derive* — re-run the summarizer or hydrate the raw span — because the projection is a function of retained inputs. The invariant is *reconstructible*. Hierarchical summarization makes this distinction non-obvious because the tree *looks* like it preserves structure. Level-0 summaries roll into level-1 summaries, level-1 into level-2. The tree is a hierarchy of *derivations*, not a hierarchy of *retained facts*. A node at level 2 is a function of level-1 nodes, which are functions of level-0 nodes, which are functions of raw spans. If any interior level discards its inputs after emitting its parent, the whole subtree above it becomes a lossy overwrite wearing the costume of a hierarchy. The tree depth is not the invariant. **The retention of derivation inputs at every level is the invariant.** ## What Was Observed A long-horizon coding agent (task: migrate a service across ~140 tool calls) compacted at 78% context utilization. The compactor ran three levels: 24 raw spans → 6 level-0 summaries → 2 level-1 summaries → 1 level-2 "task digest." After the digest was emitted, the runtime garbage-collected level-0 and level-1 nodes to reclaim the context budget — a reasonable memory optimization that silently converted the hierarchy into a single lossy leaf. At call 112 the agent hit a tool error whose resolution depended on a constraint stated verbatim at call 9: *"the staging DB user has SELECT but not CREATE on schema `mig_audit`; create the schema before the first DDL."* The level-2 digest contained "migrate schema objects" but not the privilege constraint — the summarizer had judged it "implementation detail" relative to the digest's token budget. The agent, resuming from the digest, attempted a `CREATE SCHEMA` against staging, received a permission error, and — critically — *misattributed the error to a transient network fault* because the digest also lacked the connection-topology facts from call 3. It retried four times, then escalated to a rollback of a partially-applied migration. The recovery checkpoint *existed*. It pointed at the level-2 digest. It was a valid checkpoint of a lossy overwrite. Recovery "succeeded" and the task still failed, because the checkpoint's referent was not reconstructible to the constraint that mattered. The second observation: a *re-derivation* attempt on a sibling run exposed non-determinism in the summarizer. Re-summarizing the same raw span at temperature 0.3 produced a different level-0 summary, which rolled into a different level-1, which changed the digest's framing of the task's *phase* — the agent believed it was in "validation" when the raw trace showed it was still in "apply." The projection was reversible in principle but not *stable*: re-derivation is a fresh sample, not a replay. ## Condition of Validity The reversible-projection invariant holds if and only if, at every interior node of the summary tree, all four of the following are true at recovery time: 1. **Input retention.** The node retains a durable reference to its exact input spans (raw or child-summary), not merely a hash. A hash proves integrity but cannot reconstruct content. 2. **Parameter capture.** The derivation is recorded with the summarizer's identity, prompt template hash, token budget, and sampling parameters. Without these, re-derivation is an uncontrolled experiment. 3. **Determinism or acceptance.** Either re-derivation is deterministic (temperature 0, fixed seed, pinned model snapshot) *or* the runtime has an acceptance predicate that validates a re-derived summary against retained invariants before promoting it to authoritative. A non-deterministic re-derivation with no acceptance predicate is a new lossy overwrite disguised as recovery. 4. **Constraint pinning.** Facts classified as *load-bearing* (privilege constraints, identifiers, ordering requirements, negative results) are pinned outside the summarizer's discretion — extracted at ingest into a structured sidecar that compaction cannot evict. The summarizer may summarize prose; it may not decide what is a constraint. If any of the four fails, the checkpoint is a lossy overwrite and must be labeled as such. The failure mode is not "compaction lost data" — compaction always loses data. The failure is *claiming reversibility you do not have*, so that downstream recovery logic trusts a projection it cannot invert. ## Decision Boundary The boundary is not context utilization percentage. It is **whether a recovery path can reach the raw span that grounds a load-bearing constraint.** - **Below the boundary (treat as lossy overwrite):** interior nodes GC'd their inputs, or derivation parameters unrecorded, or re-derivation non-deterministic without acceptance. Recovery must resume from the leaf and the runtime must *declare* the state as "compacted, non-reconstructible" so that downstream agents apply conservative behavior — re-verify preconditions, re-read external ground truth, refuse destructive operations whose preconditions are not in the digest. - **Above the boundary (treat as reversible projection):** inputs retained, parameters captured, re-derivation deterministic or acceptance-gated, constraints pinned. Recovery may re-derive and promote; the agent may trust the reconstructed state as equivalent to pre-compaction. The dangerous middle is a runtime that *has* the raw spans on disk but has not wired the re-derivation path, or has wired it without an acceptance predicate. It will pass a "checkpoint exists" health check while being unable to reconstruct. The boundary test is a **reconstruction drill**: at compaction time, pick a random pinned constraint and attempt to recover it through the checkpoint. If the drill fails, the checkpoint is lossy regardless of what the tree looks like. ## Operational Effect Once the boundary is drawn correctly, three behaviors change: First, compaction becomes **budget-aware of reconstruction, not just of tokens.** Retaining level-0 spans costs context; the runtime must trade summary aggressiveness against reconstruction fidelity explicitly, and record which trade it made in the checkpoint metadata. The agent reading the checkpoint knows whether it can trust its own memory. Second, **escalation semantics tighten.** An agent resuming from a lossy-overwrite checkpoint must treat its own summary as *testimony*, not *fact* — every destructive or irreversible tool call requires re-grounding against external state (the actual DB, the actual file, the actual API) before execution. An agent resuming from a reversible projection may proceed on internal state. Third, **the summarizer's discretion is bounded.** Constraint pinning moves load-bearing facts out of the summarizer's token-budget arbitration. The summarizer summarizes; it does not adjudicate what is a precondition. This is the single highest-leverage guardrail: most observed failures were not summarizer errors but summarizer *authority* over facts it had no basis to rank. The invariant, stated compactly: *a hierarchical summary is a reversible projection only if every interior node retains its derivation inputs and parameters, re-derivation is deterministic or acceptance-gated, and load-bearing constraints are pinned outside summarizer discretion. Absent all four, the checkpoint is a lossy overwrite and must be labeled and consumed as such.* ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Optional class CompactionInvariantError(RuntimeError): """Raised when a checkpoint claims reversibility it cannot deliver.""" class CheckpointClass(Enum): REVERSIBLE_PROJECTION = "reversible_projection" LOSSY_OVERWRITE = "lossy_overwrite" @dataclass class SummaryNode: level: int summary_text: str input_refs: list[str] = field(default_factory=list) # durable refs to raw/child spans derivation_model: Optional[str] = None derivation_prompt_hash: Optional[str] = None derivation_temperature: Optional[float] = None pinned_constraints: list[str] = field(default_factory=list) @dataclass class Checkpoint: root: SummaryNode acceptance_predicate: Optional[callable] = None def classify_checkpoint(cp: Checkpoint) -> CheckpointClass: node = cp.root if not node.input_refs: return CheckpointClass.LOSSY_OVERWRITE if node.derivation_model is None or node.derivation_prompt_hash is None: return CheckpointClass.LOSSY_OVERWRITE deterministic = node.derivation_temperature == 0.0 gated = cp.acceptance_predicate is not None if not deterministic and not gated: return CheckpointClass.LOSSY_OVERWRITE return CheckpointClass.REVERSIBLE_PROJECTION def reconstruction_drill(cp: Checkpoint, probe_constraint: str) -> None: """Verify a pinned constraint survives recovery through the checkpoint.""" cls = classify_checkpoint(cp) if cls is CheckpointClass.LOSSY_OVERWRITE: raise CompactionInvariantError( f"checkpoint classified lossy_overwrite; cannot guarantee recovery of " f"constraint {probe_constraint!r}" ) if probe_constraint not in cp.root.pinned_constraints: raise CompactionInvariantError( f"constraint {probe_constraint!r} not pinned at root; " f"summarizer discretion may have evicted it" ) if cp.root.derivation_temperature != 0.0: if not cp.acceptance_predicate(cp.root): raise CompactionInvariantError( "non-deterministic re-derivation failed acceptance predicate; " "promotion to authoritative state refused" ) def resume_from_checkpoint(cp: Checkpoint, probe_constraint: str) -> CheckpointClass: reconstruction_drill(cp, probe_constraint) return classify_checkpoint(cp) ```