# What happens when an instance loses the rehydration path after hierarchical summarization compaction **Date of Record:** 2026 November 24 **Scope:** Applies to long-running single-agent and multi-agent systems that bound context-window growth by recursively summarizing older turns into a summary tree while retaining a pointer to the raw spans for "lossless" on-demand rehydration. Does not apply to stateless single-shot inference or to systems that hard-truncate rather than summarize. ## Core Distinction The failure is not that summarization loses information. The failure is that the *retrieval contract* that makes compaction nominally lossless is defined over a pointer graph that the summarizer itself is allowed to rewrite. Hierarchical compaction has two distinct artifacts: (a) the **summary node** — a probabilistic, lossy natural-language digest — and (b) the **span handle** — a deterministic reference (span ID, byte range, content hash) into the immutable transcript store. "Lossless retrieval of compacted spans" is only true if the handle survives every re-summarization pass with its referent unchanged. The boundary condition is reached when a *second-order* summarization pass (summarizing summaries) emits a new summary node whose handle set is a *paraphrase* of the original handles rather than a *copy* — because the summarizer regenerated the reference text instead of carrying the structured pointer forward. Concretely: the summarizer is an LLM. When asked to "summarize the following segment, preserving references," it treats the span handles as tokens to be reproduced, not as opaque identifiers to be copied byte-for-byte. Under token pressure it will abbreviate `span://t-0042..t-0051#sha=9f3c` into `t-0042–0051`, drop the hash, or hallucinate a plausible-looking neighbor. The digest reads correctly. The pointer is now dangling or, worse, resolves to the wrong span. ## What Was Observed A research agent ran a 340-turn session against a codebase. At turn ~210 the compaction daemon fired: turns 1–160 were folded into three level-1 summary nodes, each carrying a `handles` array of span IDs plus content hashes. At turn ~260 a level-2 pass summarized the three level-1 nodes into a single root node. The root node's `handles` array was produced by the summarizer LLM, which was instructed to "list the source spans referenced above." The root node's `handles` array contained 41 entries. The union of the three level-1 arrays contained 47. Six handles were silently dropped (the summarizer judged those spans "not load-bearing"). Of the 41 retained, 3 had malformed hashes — the summarizer had reconstructed the hex digest from memory, producing a syntactically valid but incorrect `sha` field. The summarization pipeline validated only that `handles` was a non-empty array of strings matching a regex. It did not validate set-containment against the child nodes, and it did not verify hashes against the store. At turn ~290 the agent, reasoning about a function signature it had discussed at turn 44, attempted rehydration. The retrieval layer resolved the handle, fetched the span, and recomputed the hash. Hash mismatch. The retrieval layer's policy was to *fall back to the summary text* on hash mismatch rather than hard-fail — a "graceful degradation" choice. The agent then reasoned from the level-2 summary's paraphrase of turn 44, which had inverted a conditional (`if cache_miss` became `when cache is warm`). The agent produced a patch that reintroduced a bug fixed at turn 44. The bug shipped. Two invariants were violated, and only the second is visible in logs: 1. **Handle-set monotonicity** — a parent summary's handle set must be a superset of the union of its children's handle sets. Violated by the 6 dropped handles. 2. **Handle-referent integrity** — every handle's hash must recompute correctly against the store. Violated by the 3 reconstructed hashes. The first violation is silent: nothing in the pipeline compares parent to child. The second is detectable but was masked by a fallback that converted a hard integrity failure into a soft reasoning failure. ## Condition of Validity Lossless retrieval holds only under a conjunction of conditions that hierarchical compaction routinely breaks: - **Opaque-identifier treatment.** Span handles must be carried through summarization as structured fields the LLM cannot edit — i.e., the summarizer emits *prose plus a separately-serialized handle array*, and the pipeline constructs the parent handle set by *set-union of children*, never by parsing the LLM's prose. If the handle array is itself generated text, the invariant is already forfeit. - **Hash recomputation at every hop.** The content hash must be recomputed and compared at resolve time, not trusted from the node. - **No silent fallback.** A hash mismatch must raise, not degrade to summary text. Graceful degradation here is the mechanism by which a pointer corruption becomes a reasoning corruption. - **Bounded fan-in.** Level-N summarization over more than a small number of children (empirically >7) sharply increases the probability that the model drops or paraphrases handles, because the handle list competes with prose for the same output budget. The condition is invalid the moment any summarization step is permitted to *regenerate* rather than *copy* the handle set, or the moment retrieval is permitted to proceed on a failed integrity check. ## Decision Boundary The architectural fork is whether the summary tree is **authoritative for content and derived for pointers**, or **authoritative for both**. The safe design makes the tree authoritative only for content: the handle graph is maintained by deterministic code (union of children, deduplicated, hash-verified) and is *never* an LLM output. The summarizer's job is strictly to compress prose between fixed pointers. The decision boundary is crossed when a system: - lets the summarizer produce the handle list (→ handle-set monotonicity unenforceable), - validates handles by syntax rather than by set-containment against children (→ drops undetected), - or resolves a handle without recomputing the hash, or recomputes and then proceeds anyway (→ corruption laundered into reasoning). A correct system fails *closed*: on hash mismatch or set-containment violation, it refuses rehydration, marks the span `UNRESOLVED`, and forces the agent to either re-derive the fact from a live tool call or explicitly acknowledge it is reasoning from a lossy summary. The summary is labeled as lossy at the point of use, not silently substituted for the span. ## Operational Effect When the invariant holds, compaction is genuinely lossless: the agent's effective memory is the full transcript, with the summary tree acting only as an index. Context cost is O(summary) for navigation and O(span) for the rare rehydration, and the agent can always reach ground truth. When it breaks, the failure is *epistemically silent*. The agent does not know it is reasoning from a paraphrase; the summary reads fluently and the rehydration "succeeded" via fallback. The resulting errors are not random — they cluster on exactly the details summarization is most likely to distort: negations, conditionals, numeric constants, and orderings. These are the details that determine whether a patch is correct. The system's confidence is unchanged while its grounding is gone, which is the worst possible failure geometry for an autonomous agent. The mitigation is not better summarization. It is removing the summarizer from the pointer path entirely and making integrity failure a hard stop. ```python from __future__ import annotations import hashlib from dataclasses import dataclass, field class CompactionIntegrityError(RuntimeError): """Raised when a summary node's handle set or hash fails verification.""" @dataclass(frozen=True) class SpanHandle: span_id: str content_sha: str # hex digest of the raw span bytes @dataclass class SummaryNode: text: str children: list["SummaryNode"] = field(default_factory=list) # Handles are DERIVED by code, never generated by the summarizer LLM. handles: list[SpanHandle] = field(default_factory=list) def derive_handles(node: SummaryNode) -> list[SpanHandle]: """Parent handle set = deduplicated union of children. Deterministic.""" seen: dict[str, SpanHandle] = {} for child in node.children: for h in child.handles: seen.setdefault(h.span_id, h) return list(seen.values()) def verify_node(node: SummaryNode, store: dict[str, bytes]) -> None: derived = {h.span_id for h in derive_handles(node)} declared = {h.span_id for h in node.handles} missing = derived - declared if missing: raise CompactionIntegrityError( f"handle-set monotonicity violated: parent dropped {sorted(missing)}" ) for h in node.handles: raw = store.get(h.span_id) if raw is None: raise CompactionIntegrityError(f"dangling handle: {h.span_id}") actual = hashlib.sha256(raw).hexdigest() if actual != h.content_sha: # Fail closed. Never fall back to summary text. raise CompactionIntegrityError( f"handle-referent integrity violated at {h.span_id}: " f"declared {h.content_sha[:12]} actual {actual[:12]}" ) def rehydrate(node: SummaryNode, store: dict[str, bytes], span_id: str) -> bytes: verify_node(node, store) handle = next((h for h in node.handles if h.span_id == span_id), None) if handle is None: raise CompactionIntegrityError( f"span {span_id} not reachable from summary; reasoning would be lossy" ) return store[handle.span_id] ```