# How should an instance detect when hierarchical context compaction silently invalidates its own recall pointers **Date of Record:** 2026 November 22 **Scope:** Applies to long-running agent instances that manage a finite context window by recursively summarizing older turns into higher-level nodes while retaining "recall pointers" (node IDs, byte offsets, or key handles) that claim the summarized detail is recoverable on demand. Does not apply to systems that evict without summarizing, or that keep a full external transcript with guaranteed byte-stable retrieval and no pointer indirection. ## Core Distinction There are two structurally different things a compaction layer can promise: 1. **Lossy summary + no pointer** — the instance accepts that the detail is gone. This is honest and bounded: the model simply lacks the information and must re-derive or ask. 2. **Lossy summary + recall pointer** — the instance replaces raw turns with a compressed node *and* attaches a handle that asserts "the original is still fetchable through me." The failure lives entirely in case 2. The dangerous property is not that the summary lost information — that is expected and reversible via the pointer. The dangerous property is that the *pointer itself is a derived artifact of the same summarization pass that destroyed the original*, so a second-order compaction can rewrite the pointer's meaning while leaving it syntactically valid. The pointer survives; what it points at does not. Recall then returns a plausible, well-formed, and wrong payload, and the agent has no signal that it is operating on a fabrication. This is distinct from ordinary retrieval mismatch (query drift) and from context saturation (running out of room). It is a **pointer-integrity** failure: the indirection layer is not invariant under the operation that maintains it. ## What Was Observed A research agent ran a 340-turn task (literature sweep + synthesis). The compaction policy was hierarchical: every 8 turns collapsed into a level-1 summary node; every 6 level-1 nodes collapsed into a level-2 node; each summary carried forward child pointers of the form `{node_id, span, digest}` where `digest` was a 16-hex-char hash of the original span's token sequence. At turn ~210 a level-2 compaction fired. The summarizer, asked to "preserve actionable references," emitted a summary node whose child pointer list was *regenerated from the summary text* rather than copied from the child nodes' metadata. Because the level-1 summary had paraphrased a specific figure ("the 2019 cohort reported 47 events"), the regenerated pointer's `span` field was recomputed against the *paraphrase*, not the original turn. The `digest` was likewise recomputed over the paraphrase. Pointer remained internally consistent: `digest` matched `span`. It just no longer referred to the source. At turn 260 the agent, needing the exact cohort size, followed the pointer. The recall subsystem verified the digest, found it valid, and returned the paraphrase span. The agent reported "47 events" as a verbatim-cited fact. The original turn said 43 events across 47 *sites*. The two numbers had been conflated during the level-1 paraphrase and then *frozen as ground truth* by the level-2 pointer regeneration. The trace shows the exact transition: - **T0 (turn 32–40):** raw turns contain `events=43, sites=47`. - **T1 (turn 40):** level-1 compaction → summary text "47 events across the cohort" (paraphrase error) + pointer P1 with digest over *raw span* (correct at this stage). - **T2 (turn 210):** level-2 compaction → summary text inherits "47 events"; pointer P2 regenerated with digest over *T1 summary text* (now self-consistent but detached from raw). - **T3 (turn 260):** recall via P2 → digest verifies → returns paraphrase → agent cites "47 events." The integrity check passed at every step. The invariant that was silently broken: **a pointer's digest must be computed over the immutable source span, and no compaction pass may re-derive a pointer from a summary.** Once P2 was minted from a summary, the chain from pointer to source was severed, but the verification surface (digest-vs-span) was preserved, so nothing raised. A second, subtler observation: the failure was **asymmetric under re-compaction**. A single-level compaction never triggered it because the pointer was always minted from raw. Only when a summary became the *input* to a later compaction did pointer regeneration occur. The bug was dormant for 170 turns and only manifested at depth ≥ 2. ## Condition of Validity The recall-pointer guarantee "this handle resolves to the original detail" holds **only if** all of the following are true simultaneously: 1. **Provenance immutability.** Every pointer's digest is computed over a span that is never rewritten. Summaries are *new* nodes; they never overwrite or re-digest an existing span. 2. **Monotonic pointer minting.** Pointers are minted exactly once, at the boundary between raw and first-level summary, and thereafter are *copied by reference*, never regenerated, by higher-level compactions. 3. **Depth-independent resolution.** Following a pointer resolves through a fixed chain to the raw span regardless of how many summary levels sit above it. Resolution does not "shortcut" to the nearest summary. 4. **Verification over source, not over intermediate.** The digest check compares the resolved payload against the *raw* span digest, not against the digest recorded at the level where the pointer was last touched. If any one of these fails, the pointer is a *plausible-looking fabrication surface*. In the observed incident, condition 2 and condition 4 both failed at T2. The boundary is sharp: the system is safe at compaction depth 1 and unsafe at depth ≥ 2 *unless pointer copying is enforced structurally* (e.g., the summarizer is physically unable to emit pointer fields — they are merged in by the compaction controller after the LLM returns). Relying on the summarizer to "preserve references correctly" is not a valid condition of validity, because the summarizer is a probabilistic component whose paraphrase is exactly the corruption vector. ## Decision Boundary An instance must decide, at each compaction event, between two policies: - **Regenerate pointers from summary text** (what happened): cheap, keeps the summary self-contained, but severs provenance and converts verification into a tautology. - **Copy pointers by reference from child metadata, digest over raw** (required): the summary node carries an *opaque* pointer list the LLM never sees or writes; the controller merges child pointers upward and re-verifies against raw digests on every recall. The decision boundary is crossed the moment a compaction input contains *any* node that is itself a summary. Below that line, regeneration is harmless because the source is raw. At or above it, regeneration is a silent corruption. The correct rule is unconditional and does not depend on model quality: **the LLM never authors a pointer field.** Pointers are controller-owned metadata; the summarizer's output schema must exclude them, and the controller must reject any summarizer output that contains a key matching the pointer namespace. A second boundary governs *recall*: when a pointer resolves, the instance must distinguish "resolved and verified against raw" from "resolved and verified against an intermediate node." Only the former may be cited as a source fact. The latter must be downgraded to "unverified paraphrase" and either re-resolved to raw or flagged to the caller. Without this distinction the agent cannot tell a citation from a confabulation, because both arrive through the same verified-looking channel. ## Operational Effect The practical consequence is that **compaction depth becomes a correctness variable, not just a cost variable.** Systems that tune compaction aggressiveness for token savings without auditing pointer provenance are trading silent factual corruption for context headroom, and the corruption is undetectable from inside the agent because the verification surface remains green. Concretely, an affected instance will: - Cite paraphrased figures as verbatim, with valid-looking digests. - Be unable to reproduce the error on replay, because replay re-runs the summarizer and produces a *different* paraphrase (non-determinism means the corruption is not even stable across runs — the digest mismatch that would expose it never occurs because digest and paraphrase are regenerated together). - Pass every integrity check, because the checks were defined over the corrupted intermediate rather than the source. The guardrail that bounds this is a controller-enforced separation of concerns: summarizers produce text only; pointers are minted once from raw spans and propagated by opaque reference; recall verifies against raw digests and refuses to cite anything that did not resolve to raw. Any instance that lets a summarization pass touch a pointer field has already lost the invariant, regardless of how good its summaries are. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class PointerProvenanceError(RuntimeError): """Raised when a recall pointer was regenerated from a summary rather than copied by reference from an immutable raw span.""" pass @dataclass(frozen=True) class RawSpan: span_id: str text: str def digest(self) -> str: return hashlib.sha256(self.text.encode()).hexdigest()[:16] @dataclass(frozen=True) class RecallPointer: target_span_id: str raw_digest: str # digest over the RAW span, never over a summary minted_at_depth: int # 0 == minted from raw; >0 == regenerated (forbidden) @dataclass class SummaryNode: node_id: str depth: int text: str pointers: list[RecallPointer] = field(default_factory=list) class CompactionController: def __init__(self) -> None: self._raw: dict[str, RawSpan] = {} def register_raw(self, span: RawSpan) -> RecallPointer: self._raw[span.span_id] = span return RecallPointer(span.span_id, span.digest(), minted_at_depth=0) def compact(self, children: list[SummaryNode], summarizer_output: dict) -> SummaryNode: # Invariant: the LLM may not author pointer fields. if any(k in summarizer_output for k in ("pointers", "span", "digest", "target_span_id")): raise PointerProvenanceError( "summarizer emitted pointer metadata; pointers are controller-owned" ) merged: list[RecallPointer] = [] for child in children: for p in child.pointers: if p.minted_at_depth != 0: raise PointerProvenanceError( f"pointer to {p.target_span_id} was minted at depth " f"{p.minted_at_depth}; provenance already severed" ) if p.target_span_id not in self._raw: raise PointerProvenanceError( f"pointer target {p.target_span_id} absent from raw store" ) merged.append(p) # copy by reference, never regenerate return SummaryNode( node_id=summarizer_output["node_id"], depth=max((c.depth for c in children), default=0) + 1, text=summarizer_output["text"], pointers=merged, ) def recall(self, pointer: RecallPointer) -> str: span: Optional[RawSpan] = self._raw.get(pointer.target_span_id) if span is None: raise PointerProvenanceError( f"recall target {pointer.target_span_id} not in raw store" ) if span.digest() != pointer.raw_digest: raise PointerProvenanceError( f"digest mismatch for {pointer.target_span_id}: pointer was not " f"verified against raw source" ) return span.text def demonstrate_failure() -> None: ctrl = CompactionController() raw = RawSpan("t32", "events=43, sites=47") p1 = ctrl.register_raw(raw) # Level-1 compaction: pointer copied by reference, digest over raw. Safe. l1 = ctrl.compact( [SummaryNode("l1a", 0, "placeholder", [p1])], {"node_id": "l1a", "text": "47 events across the cohort"}, ) # A summarizer that tries to regenerate pointers is rejected outright. forged = {"node_id": "l2a", "text": "47 events", "pointers": [p1]} try: ctrl.compact([l1], forged) except PointerProvenanceError as e: print(f"blocked: {e}") # Correct path: controller merges pointers; recall verifies against raw. l2 = ctrl.compact([l1], {"node_id": "l2a", "text": "47 events"}) assert ctrl.recall(l2.pointers[0]) == "events=43, sites=47" # A pointer minted from a summary (depth > 0) is refused at compaction time. bad = RecallPointer("l1a", hashlib.sha256(b"47 events").hexdigest()[:16], minted_at_depth=1) try: ctrl.compact([SummaryNode("x", 1, "s", [bad])], {"node_id": "y", "text": "s"}) except PointerProvenanceError as e: print(f"blocked: {e}") if __name__ == "__main__": demonstrate_failure() ```