# Which invariants prevent hierarchical compaction from silently invalidating an agent's own prior tool-call facts **Date of Record:** 2026 December 1 **Scope:** Applies to long-horizon agents that compact context via hierarchical summarization (leaf→parent rollups) or lossy checkpointing while a task is still in flight. Does not apply to append-only transcript archives that are never re-read as authoritative working state, nor to single-turn agents whose entire state fits the live window. ## Core Distinction There are two categorically different things an agent stores when it summarizes: **narrative state** ("we tried approach A, it failed, then moved to B") and **committed facts** ("the migration produced table `orders_v2` with 41 columns; `POST /v1/refund` returns 409 on already-refunded orders"). Narrative state is safely lossy—a compressed paraphrase of intent preserves the *behavior* of the agent. Committed facts are not safely lossy, because downstream tool calls and verification steps consume them as *inputs*, not as background. The failure mode is not "the summary forgot something." It is "the summary replaced a precise fact with a plausible one, and a subsequent tool call acted on the plausible one as if it were verified." The boundary is this: **hierarchical compaction is a lossy transform whose codomain is natural language, but its consumers (tool arguments, assertion checks, handoff payloads) require a codomain of grounded literals.** Any compaction strategy that routes a committed fact through a natural-language rollup and then reconstructs a literal from that rollup has introduced a non-deterministic re-derivation step that is indistinguishable, at the call site, from the original observation. ## What Was Observed A planning agent executing a 90-step data-reconciliation task compacted at step 40 (leaf summaries of steps 1–20 and 21–40) and again at step 60 (parent summary of both leaves). At step 71 it needed to re-issue a verification query against a source system it had probed at step 12. The step-12 tool output had read: ``` {"source":"billing_ledger","partition":"2024-Q3","row_count":118204,"checksum":"9f3a...c1","schema_version":7} ``` The step-12 leaf summary recorded: *"Probed billing_ledger; Q3 partition is large (~118k rows), schema v7, checksum captured."* The step-60 parent summary recorded: *"Earlier probes confirmed billing_ledger Q3 is large and schema v7."* At step 71 the agent needed the checksum and the row count to construct a reconciliation key. It reconstructed `row_count ≈ 118000` (rounding the "~118k") and *omitted the checksum entirely*, then issued a downstream join keyed on `row_count = 118000`. The join matched a superset of 204 rows that should not have been in scope. The agent's own verification step at step 78 compared the join output against a *re-derived* expectation (also from the parent summary) and reported success. The task completed "green" with 204 spurious rows. The critical detail: **the loss happened at the leaf, not the parent.** The leaf summary had already rounded 118204→"~118k" and already dropped the checksum, because the leaf summarizer was optimizing for token budget against a prompt that said "preserve key findings." "Key findings" is a narrative criterion. The checksum did not read as a finding; it read as noise. By the time the parent rolled up, the information was unrecoverable, and the parent summary's confident phrasing ("confirmed") masked the fact that the leaf had *discarded*, not *compressed*, the literal. ## Condition of Validity The invariant that must hold for hierarchical compaction to be safe is a **grounding partition**: every element of working state is tagged at write time as either `NARRATIVE` (lossy-compressible) or `COMMITTED` (must survive byte-exact or be explicitly invalidated). Compaction may summarize the `NARRATIVE` partition freely. It may only *reference* the `COMMITTED` partition by stable handle (an ID into an external fact store), never inline it into prose. This holds only under three conditions: 1. **Facts are stored by reference, not by value, in the compacted layer.** The summary says "see fact `f_12` (billing_ledger Q3 probe)." The literal lives in a side store keyed by `f_12` and is never rewritten by the summarizer. 2. **Re-derivation from a summary is forbidden at tool-call construction time.** Any argument to a tool that originated in a `COMMITTED` fact must be resolved through the fact store, not parsed out of summary prose. A parser that extracts `118000` from "~118k" is a silent-corruption channel. 3. **Invalidation is explicit and propagates.** If a `COMMITTED` fact is superseded (a re-probe at step 71 shows `row_count=118204` still, or a changed value), the fact store records the supersession and the summary handle resolves to the *current* value, not the value at summarization time. When these hold, the summarizer's lossiness is confined to narrative and the agent can compact indefinitely. When they fail—as in the observed run—the summary becomes a lossy proxy that is *consumed as if lossless*, and the failure is silent because the summary's confident register ("confirmed," "verified") is generated by the same model that discarded the literal. ## Decision Boundary The boundary is not "how much can I compress before quality drops." It is: **does any downstream consumer treat a compacted artifact as a source of literals?** Concretely: - If the next action after compaction is *generation* (writing code, drafting, planning further probes) → prose summaries are safe; the model's narrative continuity is what matters. - If the next action is *re-issue of a parameterized call* whose arguments were observed pre-compaction → the summary is not a valid source. Resolve from the fact store or re-probe. - If the next action is *verification* against a pre-compaction expectation → the expectation must be a stored literal, not a summary sentence. A verifier that reads its own summary as ground truth is a circular check. The edge case that makes this non-obvious: **the summarizer cannot reliably distinguish `COMMITTED` from `NARRATIVE` at compaction time**, because the distinction depends on *future* use, which is not known when the leaf is written. A checksum that looks like noise at step 12 becomes load-bearing at step 71. Therefore the partition cannot be inferred by the summarizer; it must be assigned at observation time by the tool-call wrapper (which knows the call's arguments and return schema) or by an explicit policy that marks any tool output containing identifiers, counts, hashes, or version numbers as `COMMITTED`. ## Operational Effect The practical consequence is a **compaction-time fact-extraction pass** that runs *before* summarization and is not itself a language-model operation. For each tool result entering the window, the wrapper extracts structured fields (per an output schema or a conservative heuristic: any key whose value is numeric, hashed, or an identifier) into the fact store and replaces them in the transcript with handles. The summarizer then operates on a transcript where committed literals are already abstracted away, so it *cannot* lose them—there is nothing to lose. The summary references handles; resolution is exact. This changes the failure surface. The remaining risk is not lossy summarization but **handle drift**: a summary references `f_12` but the model, when constructing a call, hallucinates `f_12`'s contents from surrounding narrative rather than resolving the handle. Guard: the tool-call constructor rejects any argument value that matches a `COMMITTED` fact's *approximate* form but not its exact literal (e.g., `118000` when `f_12.row_count == 118204`), raising a resolution error rather than proceeding. The approximate-match check is what catches the "~118k → 118000" corruption that a pure handle-resolution path would miss, because the corruption happens in the model's head, not in the store. Second-order effect: checkpoint resumption must replay the fact store, not just the summary tree. A checkpoint that persists only the hierarchical summary and not the side store is *not resumable*—it resumes into an agent that believes it has facts it can no longer resolve. The checkpoint invariant is that the summary tree and the fact store are written atomically; a summary referencing a missing handle is a corrupt checkpoint and must fail closed. ```python from dataclasses import dataclass, field from typing import Any class CompactionGroundingError(RuntimeError): """Raised when a compacted artifact is consumed as a source of committed literals.""" pass @dataclass class FactStore: facts: dict[str, dict[str, Any]] = field(default_factory=dict) superseded: dict[str, str] = field(default_factory=dict) def commit(self, handle: str, payload: dict[str, Any]) -> None: if handle in self.facts: self.superseded[handle] = handle # explicit supersession chain self.facts[handle] = payload def resolve(self, handle: str) -> dict[str, Any]: if handle not in self.facts: raise CompactionGroundingError( f"summary references handle {handle!r} absent from fact store; " "checkpoint is corrupt or store was not persisted atomically" ) return self.facts[handle] def construct_tool_arg(store: FactStore, handle: str, field_name: str, proposed: Any) -> Any: """Resolve a committed fact for a tool call; reject prose-derived approximations.""" fact = store.resolve(handle) if field_name not in fact: raise CompactionGroundingError(f"fact {handle!r} has no field {field_name!r}") exact = fact[field_name] if proposed != exact: # Catch the '~118k -> 118000' corruption: approximate-but-not-exact is a # lossy-summary artifact being consumed as a literal. raise CompactionGroundingError( f"proposed value {proposed!r} for {handle}.{field_name} does not match " f"committed literal {exact!r}; value likely re-derived from summary prose" ) return exact # --- failure trace reproduction --- store = FactStore() store.commit("f_12", {"row_count": 118204, "checksum": "9f3a...c1", "schema_version": 7}) # Step 71: agent reconstructs from parent summary "~118k rows" and calls the join. try: construct_tool_arg(store, "f_12", "row_count", 118000) except CompactionGroundingError as e: print(f"BLOCKED (correct): {e}") # A summary that dropped the handle entirely is a corrupt checkpoint. try: store.resolve("f_12_checksum") # handle the leaf summarizer never emitted except CompactionGroundingError as e: print(f"FAIL-CLOSED (correct): {e}") ```