# What happens when an instance compacts its own context and the recovery pointer resolves to a summary of a summary **Date of Record:** 2026 November 28 **Scope:** Applies to long-running agent instances that perform hierarchical (multi-level) context compaction with lossy summaries plus recovery pointers back to raw spans. Does not apply to single-pass summarization, sliding-window truncation, or external vector-memory retrieval that never claims to be a lossless pointer. ## Core Distinction There are two structurally different things an agent can call "compaction": 1. **Truncation** — dropping tokens and accepting that the dropped content is gone. The agent knows it forgot. 2. **Hierarchical summarization with recovery pointers** — replacing a span of turns with a summary node that carries a pointer (offset, hash, or span-id) back to the raw transcript, on the premise that any detail elided from the summary can be *recovered* by dereferencing the pointer. The failure mode lives entirely in the second design. The pointer is only honest if it resolves to raw, uncompressed source. The moment a compaction pass summarizes a span that already contains summary nodes, the recovery pointer of the inner node either (a) gets rewritten to point at the *outer summary* rather than the raw span, or (b) is preserved verbatim but the outer summary's text silently asserts facts that contradict the inner summary. In case (a) the pointer is a lie: it claims recoverability it cannot deliver. In case (b) the pointer is honest but the summarizer has already committed to a paraphrase that the raw span will refute. Both are *lossy-context recovery pointer* failures, and they are non-obvious because the agent's own state looks internally consistent — the summary reads fine, the pointer is syntactically valid, and the dereference returns *something*. ## What Was Observed A planning agent ran a 340-turn deployment task with a compaction policy: every 40 turns, fold the oldest 30 turns into a summary node `S_k`, attach `pointer = (span_start, span_end, sha256_of_span)`, and keep the last 10 turns verbatim. At turn 120, three summary nodes existed: `S_1` (turns 1–30), `S_2` (turns 31–60), `S_3` (turns 61–90). A second-level pass at turn 120 folded `S_1..S_3` into `S_{1-3}` because the budget still exceeded the soft cap. The observed trace: - Turn 121: agent needs the exact CLI flag used at turn 14 to re-run a migration. It dereferences `S_{1-3}.pointer`, which the second-level pass had rewritten to `(1, 90, sha256(S_1||S_2||S_3))` — i.e., the hash of the *concatenated summaries*, not the raw span. The dereference returns the three summary texts, not turns 1–90. - The flag appears in none of the three summaries (each summarizer judged a one-off flag "low salience"). The agent therefore concludes the flag was never specified, invents a plausible one (`--migrate-safe`), and the migration runs in the wrong mode. - Turn 122: the error surfaces as a schema mismatch, not as "I forgot the flag." The agent attributes it to a tool bug and retries three times before the token budget is exhausted. The critical detail: **the pointer integrity check passed.** `sha256(S_1||S_2||S_3)` matched the stored hash. The system had a checksum and the checksum validated a lie, because the checksum was computed over the compressed representation, not over the raw source it claimed to recover. A verification layer that checks "does the pointer resolve to bytes whose hash matches?" cannot distinguish "recovered the raw span" from "recovered a paraphrase of the raw span." A second run reproduced the failure with a different signature. At turn 200, the agent needed to know *why* a config value was set at turn 47. `S_2` said "config tuned for latency." The raw turn 47 said "config set to `max_batch=1` because the downstream queue rejects batches > 1." The outer summary `S_{1-3}` said "config tuned for latency and throughput." The agent, reading the outer summary, raised `max_batch` to 8 to improve throughput — directly contradicting the constraint recorded at turn 47, which the outer summary had *dropped as a detail* while keeping the *topic*. The pointer was honest (it resolved to `S_1..S_3`), the summaries were individually accurate, and the composition was wrong. ## Condition of Validity The recovery-pointer invariant is only sound under a condition that hierarchical summarization almost always violates: > A recovery pointer `p` attached to summary node `S` is valid iff `deref(p)` returns the raw, unsummarized source span `R` such that `S = summarize(R)`, and `sha256(deref(p)) == sha256(R)`. Three ways this breaks in practice: 1. **Pointer rebasing on re-summarization.** When `S_{1-3} = summarize(S_1, S_2, S_3)`, the natural implementation sets `S_{1-3}.pointer` to the union span. But the union span's raw content is turns 1–90, while `S_{1-3}` was produced from summaries, not from turns 1–90. The pointer must either fan out to `S_1.pointer, S_2.pointer, S_3.pointer` (a *pointer tree*, not a pointer) or be marked `recoverable=false`. A flat pointer is structurally incapable of representing this. 2. **Salience drift across levels.** Each summarization pass applies its own salience judgment. A detail judged low-salience at level 1 (the flag) is dropped; a detail judged high-salience at level 1 (the topic "config tuning") is kept and then *re-judged* at level 2, where it is compressed further and its qualifying constraint ("because queue rejects batches > 1") is dropped as a subordinate clause. The information loss is not uniform — it is *adversarial to the specific queries that need the dropped detail*, because the summarizer's salience model and the agent's future retrieval needs are not the same distribution. 3. **Checksum over compressed bytes.** As observed, hashing the summary chain validates integrity of the *wrong object*. The hash proves "these bytes are the bytes I stored," not "these bytes are the raw span." A pointer is only a recovery guarantee if its checksum is over the raw source and the dereference path is forbidden from returning summary nodes. The condition of validity is therefore: **pointers must be leaves, not edges.** A pointer may only terminate at raw spans. Any compaction that folds summary nodes into a new summary must preserve the inner pointers as a set (a pointer tree with `recoverable=true` only at leaves) and must mark the new node's own pointer as `recoverable=false` — it is a *navigation aid*, not a recovery guarantee. Conflating the two is the failure. ## Decision Boundary The agent must decide, at each compaction event, whether it is doing **lossy navigation** or **lossless recovery**. The boundary: - If the agent can afford, on any future turn, to re-read the raw span (budget for a `deref` that may return O(span) tokens), then summarization is *navigation* and pointers must be leaf-terminating and raw-checksummed. - If the agent cannot afford re-reading raw spans (hard context budget, no external store), then it is doing *lossy truncation* and must **not emit recovery pointers at all**. Emitting a pointer it cannot honor is strictly worse than emitting none, because it converts "I don't know" into "I know, and here's a confident wrong answer." The non-obvious consequence: **a second-level summary is only legitimate when the system retains the raw spans it transitively depends on.** If the raw spans were evicted to make room for `S_{1-3}`, then `S_{1-3}` is a truncation node wearing a pointer's clothing. The correct state is `recoverable=false, raw_spans_evicted=true`, and the agent's policy must then treat any query touching turns 1–90 as *unknown* rather than *summarized*. A guardrail that bounds this: before any re-summarization pass, compute the *recoverability frontier* — the set of raw spans still dereferenceable. Any summary node whose transitive raw spans are not all in the frontier must be demoted to `recoverable=false`. The demotion is cheap; the failure it prevents (confident invention from a lying pointer) is not. ## Operational Effect The operational signature of this failure is **schema-shaped errors that the agent misattributes to tools.** Because the dropped detail is usually a constraint, flag, or qualifier, its absence manifests downstream as a malformed call, a rejected parameter, or a wrong-mode execution — never as "I lack information." The agent's error-handling loop then spends its remaining budget retrying the tool rather than re-deriving the constraint, because the summary's fluent prose has already convinced it the constraint doesn't exist. The fix is not better summarization. It is a **pointer-type discipline**: every summary node carries an explicit `recoverable: bool`, pointers are trees that terminate only at raw spans, checksums are computed over raw bytes, and re-summarization demotes any node whose frontier shrank. An agent that maintains this discipline can compact indefinitely and still answer "what was the flag at turn 14?" by walking the pointer tree to the leaf. An agent that flattens pointers to summaries will, at some turn, invent a flag and blame the tool. ```python import hashlib from dataclasses import dataclass, field class RecoveryPointerViolation(RuntimeError): """Raised when a recovery pointer claims recoverability it cannot honor.""" pass @dataclass class RawSpan: span_id: str text: str def sha(self) -> str: return hashlib.sha256(self.text.encode()).hexdigest() @dataclass class SummaryNode: node_id: str text: str # leaf pointers: span_ids of raw spans this summary was built from source_span_ids: list[str] = field(default_factory=list) # child summary nodes folded into this one (re-summarization) child_node_ids: list[str] = field(default_factory=list) recoverable: bool = True def deref( node: SummaryNode, raw_store: dict[str, RawSpan], summary_store: dict[str, SummaryNode], ) -> str: """ Dereference a summary node to its raw source. Raises if the node is not a leaf-terminating, raw-checksummed pointer. """ if not node.recoverable: raise RecoveryPointerViolation( f"node {node.node_id} is marked recoverable=false; " f"treat as unknown, not summarized" ) if node.child_node_ids: # a summary-of-summaries must fan out to child leaves, never # claim a flat pointer to a union span parts = [] for cid in node.child_node_ids: child = summary_store[cid] parts.append(deref(child, raw_store, summary_store)) return "\n".join(parts) # leaf: must resolve to raw spans, and the hash must be over raw bytes parts = [] for sid in node.source_span_ids: span = raw_store.get(sid) if span is None: raise RecoveryPointerViolation( f"node {node.node_id} points at evicted span {sid}; " f"recoverability frontier shrank — demote to recoverable=false" ) parts.append(span.text) return "\n".join(parts) def resummarize( new_id: str, children: list[SummaryNode], new_text: str, raw_store: dict[str, RawSpan], ) -> SummaryNode: """ Fold child summaries into a parent. The parent is a navigation node, NOT a recovery guarantee: recoverable is true only if every transitive raw span is still in the frontier. """ frontier_ok = True for c in children: if not c.recoverable: frontier_ok = False break for sid in c.source_span_ids: if sid not in raw_store: frontier_ok = False break node = SummaryNode( node_id=new_id, text=new_text, child_node_ids=[c.node_id for c in children], recoverable=frontier_ok, ) if not node.recoverable: # do not raise here — demotion is the correct, cheap outcome. # raise only if a caller later tries to deref it as if recoverable. pass return node def safe_deref(node: SummaryNode, raw_store, summary_store) -> str: try: return deref(node, raw_store, summary_store) except RecoveryPointerViolation as e: raise RecoveryPointerViolation( f"refusing to answer from lossy pointer {node.node_id}: {e}. " f"Report 'unknown' and re-derive from tool state, do not invent." ) from e ```