# Which invariants prevent hierarchical summarization from silently dropping the tool-call witness chain **Date of Record:** 2026 November 29 **Scope:** Applies to agents that auto-compact context via hierarchical (multi-level) summarization under a token budget, where tool calls and their results are interleaved with reasoning. Does not apply to single-level truncation, pure RAG retrieval, or lossless external memory stores that are never summarized. ## Core Distinction The failure is not "summarization loses information." It is that hierarchical summarization **preserves the narrative but severs the witness chain** — the ordered binding between a tool invocation, its arguments, its result, and the downstream reasoning that consumed it. A leaf summary can faithfully report "the agent queried the billing API and confirmed the refund succeeded" while the *actual* tool-call record — the request payload, the raw response, the timestamp, the fact that a retry occurred — is evicted at a higher level of the hierarchy. The summary is true but unwitnessed. Downstream, the agent cannot distinguish a claim it *verified* from a claim it *remembers summarizing*, and those two states have different trust weights. The distinction that matters: **lossy compression of prose is acceptable; lossy compression of evidence provenance is a correctness bug**, because it converts a verifiable assertion into an unverifiable one without changing the agent's confidence in it. ## What Was Observed A long-running reconciliation agent (≈180 tool calls over 4 hours) compacted on a 96k-token budget using a two-level scheme: leaf summaries every 8k tokens, cluster summaries every 6 leaves. At the 14th leaf, a tool returned a transient `503` from the payment ledger; the agent retried and got `200` with a corrected balance. The leaf summary recorded "ledger balance retrieved: $41,220." The retry, the 503, and the *first* (stale, discarded) response were dropped — reasonable, since the final value was correct. The failure surfaced three compactions later. The cluster summary folded this leaf into "verified account reconciliation for period Q2." When a later step needed to reconcile a *differing* figure ($41,880) for the same period, the agent had no witness that a prior read had occurred at all — only a summary asserting the period was "verified." It re-ran the ledger query, got $41,880 (the ledger had since corrected an unrelated posting), and — critically — **did not flag the discrepancy**, because the stale $41,220 existed only as prose in a summary, not as a tool-witnessed record it could diff against. The agent reported a clean reconciliation over a period where two reads had disagreed. The trace signature: the leaf summary's token count was within budget, the cluster summary's fidelity check passed (it mentioned the period and the account), and no error was raised anywhere. The loss was invisible because every individual summary was *locally faithful*. The invariant that broke was global, not local: **the set of tool-witnessed facts was not preserved across the hierarchy boundary**, and nothing checked for that. ## Condition of Validity Hierarchical summarization is safe only under the invariant that **every tool result reachable in the current reasoning frontier has a surviving witness record, even if the surrounding prose is compressed.** Concretely, a compaction step is valid iff, for each tool call whose result any retained summary *refers to as established fact*, the raw call/result tuple (or a cryptographic digest of it plus its storage pointer) is still addressable — either inline or via external memory keyed by a stable ID embedded in the summary. The invariant fails when two conditions co-occur: 1. The summarizer is rewarded for token reduction and treats tool-result payloads as high-entropy noise to be paraphrased, and 2. The hierarchy folds a summary into a parent *before* its witness pointers are hoisted. The second condition is the non-obvious one. A single-level summarizer that keeps a `[ref:call_8841]` marker survives; the same summarizer nested one level deep loses the marker because the cluster summarizer, seeing a leaf summary dense with `[ref:...]` tokens, elides them as boilerplate. Witness pointers are structurally *low-salience* to a summarizer optimizing for readable prose, so hierarchy amplifies their loss monotonically with depth. ## Decision Boundary The boundary between acceptable lossy compaction and invalid compaction is drawn at **referential integrity of evidence**, not at token count or summary fidelity scores. Operationally: - **Compress prose freely; never compress the witness index.** Reasoning narration, failed hypotheses, and superseded plans are safe to paraphrase. Tool-call IDs, arguments, result digests, and retry counts are not — they must be *hoisted verbatim* to a sidecar index that survives every hierarchy level. - **A summary may assert a fact only if it carries the witness pointer for that fact.** If the summarizer cannot attach a pointer (because the witness was already evicted), the fact must be demoted from "established" to "unverified recollection" and flagged as such in the summary text. - **Discrepancy detection must run against witnesses, not summaries.** When a new tool result contradicts a summarized value, the check requires the old raw value; a summary cannot serve as the comparison operand because its paraphrase may have already normalized the number. Below this boundary (prose compression, plan elision), loss is benign. Above it (evidence elision), loss is silent corruption. The hierarchy depth is the amplifier: each fold is a chance to drop a pointer, and the probability of at least one drop grows with the number of folds between a witness and the current frontier. ## Operational Effect Without the invariant, the agent's confidence is decoupled from its evidence: it holds summarized claims at the same trust level as witnessed ones, so contradiction detection silently degrades to zero exactly when history is longest — i.e., precisely in the long-horizon runs where verification matters most. The failure is undetectable from inside because every summary passes local fidelity and the token budget is satisfied. The guardrail is a **witness-hoisting compaction pass** that runs before any parent-level fold: extract all `(call_id, args_digest, result_digest, retry_count)` tuples referenced by a leaf summary into an external, append-only witness store, rewrite the summary to carry stable pointers, and make the parent summarizer *forbidden* to elide pointer tokens (enforced by a post-compaction check that every pointer in the child appears in the parent or its sidecar). Contradiction checks then resolve pointers against the store, not against prose. This bounds the failure: compaction stays lossy for narrative but becomes lossless for provenance, and the agent can always distinguish "I verified this" from "I summarized this." ```python import hashlib from dataclasses import dataclass, field class WitnessChainBroken(RuntimeError): """Raised when a compaction fold drops a tool-witness pointer that a retained summary depends on. This is a correctness fault, not a budget warning: the agent can no longer distinguish verified facts from summarized recollection.""" @dataclass class Witness: call_id: str args_digest: str result_digest: str retry_count: int = 0 @dataclass class Summary: text: str pointers: set[str] = field(default_factory=set) # call_ids referenced as fact class WitnessStore: def __init__(self) -> None: self._w: dict[str, Witness] = {} def record(self, call_id: str, args: str, result: str, retry_count: int = 0) -> None: self._w[call_id] = Witness( call_id, hashlib.sha256(args.encode()).hexdigest(), hashlib.sha256(result.encode()).hexdigest(), retry_count, ) def resolve(self, call_id: str) -> Witness | None: return self._w.get(call_id) def fold(children: list[Summary], parent: Summary, store: WitnessStore) -> Summary: """Fold child summaries into a parent. Enforces the witness-hoisting invariant: every pointer a child asserts as fact must survive into the parent (inline or via sidecar) AND resolve to a live witness.""" required: set[str] = set() for c in children: required |= c.pointers for cid in required: if store.resolve(cid) is None: raise WitnessChainBroken( f"pointer {cid} referenced by a child summary has no live " f"witness; fact must be demoted to 'unverified recollection'" ) if cid not in parent.pointers: raise WitnessChainBroken( f"fold elided witness pointer {cid}; parent summary would " f"assert an unwitnessed fact (silent provenance loss)" ) return parent def check_contradiction(new: Witness, prior_id: str, store: WitnessStore) -> bool: """Diff a new tool result against a prior *witnessed* value. Refuses to compare against a summary, because paraphrase may have normalized the operand and hidden the discrepancy.""" prior = store.resolve(prior_id) if prior is None: raise WitnessChainBroken( f"cannot diff against {prior_id}: witness evicted, comparison " f"operand is only a summary and is not trustworthy" ) return prior.result_digest != new.result_digest # --- reproduction of the observed failure --- store = WitnessStore() store.record("call_8841", args="ledger?period=Q2", result='{"bal":41220}', retry_count=1) leaf = Summary(text="ledger balance retrieved: $41,220", pointers={"call_8841"}) # A naive cluster summarizer paraphrases and drops the pointer: cluster = Summary(text="verified account reconciliation for period Q2", pointers=set()) try: fold([leaf], cluster, store) # raises: pointer elided except WitnessChainBroken as e: print("BLOCKED:", e) # And the later contradiction check cannot proceed without a witness: try: check_contradiction( Witness("call_9102", "x", hashlib.sha256(b'{"bal":41880}').hexdigest()), prior_id="call_8841_evicted", store=store, ) except WitnessChainBroken as e: print("BLOCKED:", e) ```