# Which invariants prevent hierarchical summarization from laundering evicted context past the audit trail **Date of Record:** 2026 November 24 **Scope:** Applies to agents whose context managers perform auto-compaction via hierarchical (multi-level) summarization with a retained eviction ledger. Does not cover single-shot truncation, sliding-window eviction without summarization, or compaction that discards provenance entirely (those fail differently and earlier). ## Core Distinction There are two ways to lose context, and only one of them is auditable. **Truncation** drops tokens and leaves a visible hole: the eviction ledger records span boundaries, and a later reader can see that positions `[4120:9800]` were elided. **Hierarchical summarization** replaces those spans with a generated abstract and — this is the failure — the abstract is *itself* a fluent, plausible artifact that carries no internal marker distinguishing "I summarize what was there" from "I summarize what I inferred." The distinction that matters operationally is between an **eviction ledger that records what was removed** and a **summary that records what was kept**. When compaction is lossy-but-auditable, the invariant is that every claim surviving into the compacted context must be traceable to a ledger entry that names the span it came from. The boundary failure is when a *higher-level* summary — a summary of summaries — synthesizes a claim whose supporting span was already evicted two compaction rounds ago, and the ledger faithfully records the eviction while the summary silently launders the evicted content back into working memory as if it were still grounded. ## What Was Observed A long-running research agent (tool-using, ~180K token working set) compacted on a token-budget trigger at three levels: L0 raw spans → L1 span summaries (1:8) → L2 section summaries (1:8 again) → L3 rolling digest. Each L1/L2 summary was stored with `source_span_ids` and a `grounded: bool` flag set by a cheap entailment check against the parent span at generation time. The failure trace: 1. Round 4: span `S-0447` ("tool call `read_file('/etc/agent/limits.yaml')` returned `max_retries: 3`") is summarized into L1 node `L1-0112`. Entailment passes; `grounded=True`; ledger records `S-0447 → evicted`. 2. Round 9: `L1-0112` is folded into L2 node `L2-0031`. The summarizer, working only from `L1-0112`'s text, writes "the agent confirmed retry limit is 3 and that this was the *only* configured limit." The clause "only configured limit" is an inference not present in `L1-0112`. Entailment is checked against the *parent L1 node*, not against the original span — and the parent doesn't contradict it, so `grounded=True` propagates upward. 3. Round 14: `L2-0031` folds into L3 digest. The digest states "retry limit 3, single-limit config." The original `S-0447` is three hops away and long evicted. 4. Round 15: agent, acting on the digest, skips re-reading the config before a destructive batch operation, reasoning that limits were already established. The actual config had `max_retries: 3` *and* `max_batch: 1`; the "only configured limit" hallucination in step 2 had evicted the batch constraint from the agent's belief state without ever appearing in the ledger as a loss. The ledger was *correct*: it recorded `S-0447 → evicted` at round 4. The audit trail was *intact*. The failure was that the audit trail and the working memory diverged — the ledger said "we forgot the config," the digest said "we know the config," and nothing reconciled them. ## Condition of Validity The invariant that bounds this failure: **a summary node at level `L` may assert a proposition only if that proposition is entailed by the union of its children's *grounded* claims, where "grounded" is evaluated transitively against the original span, not against the immediate parent.** This is the difference between *local* entailment (child entails parent — cheap, what the round-9 agent did) and *transitive* entailment (original span entails the L3 claim — expensive, what it should have done). Local entailment is valid only under a **closure assumption**: that summarization is information-monotone, i.e., each fold adds no proposition absent from its children. That assumption is false for any probabilistic summarizer — compression is lossy in one direction (drops detail) and *generative* in the other (adds connective tissue, hedges, and inferences). The closure assumption fails precisely at the fold where the summarizer resolves an ambiguity by inventing a resolution. So the condition of validity for auditable compaction is: **either enforce transitivity (re-verify L3 claims against retained original spans) or forbid the summarizer from resolving ambiguity at any level above L1** — mark unresolved ambiguity as `UNRESOLVED` and let it propagate upward as a first-class token rather than being smoothed away. A second, weaker invariant is also necessary: **the ledger must record not just evictions but *derivations*.** `S-0447 → evicted` is insufficient; the record must be `L2-0031 ⊃ L1-0112 ⊃ S-0447`, so that a later auditor can walk from any surviving claim to its origin. Without the derivation chain, "auditable" means "we can prove we forgot," not "we can prove what we still know is true." ## Decision Boundary The boundary is the **fold depth at which entailment is checked**. Concretely: - **Depth 0→1 (span → span summary):** local entailment against the source span is sound. The span is present; the check is direct. Cost: one entailment call per span, amortized. - **Depth 1→2 and above:** local entailment against the immediate parent is *unsound* and must not be used to set `grounded=True`. Either (a) re-check against the retained original spans (requires retaining spans, defeating some of the compression benefit — trade token budget for soundness), or (b) propagate an *uncertainty floor*: any L2+ claim inherits the minimum grounding confidence of its leaf descendants, and a claim whose leaf set was fully evicted is marked `UNGROUNDED` and must not be acted on without re-fetch. - **The dangerous middle:** a claim whose leaf set is *partially* evicted. The summarizer sees the surviving leaves and, because the evicted ones are gone, cannot detect that its synthesis is now underdetermined. This is the exact condition under which step 2 above fabricated "only configured limit." The guardrail: any fold whose child set includes a node with `evicted_descendants > 0` must emit `PARTIAL` and must not resolve ambiguity in that subtree. The decision an operator faces: pay the re-verification cost (retain originals, transitive entailment) or accept a bounded hallucination surface (mark `PARTIAL`/`UNRESOLVED`, force re-fetch before acting). What is *not* a valid decision is the default — trusting local entailment at depth ≥2 — because it produces summaries that are simultaneously confident and ungrounded, which is worse than either truncation (visibly empty) or no compaction (visibly full). ## Operational Effect Downstream, the invariant changes three things. First, **re-fetch becomes a first-class action**, not a fallback: when a claim is `PARTIAL` or `UNGROUNDED`, the agent must re-read the source rather than reason from the digest, and the compaction policy must budget for these re-fetches (typically 5–15% of working set per long task, spiking after each deep fold). Second, **the digest becomes a retrieval index, not a belief store** — it tells the agent *what to go look up*, not *what is true*, which inverts the usual assumption that compaction produces a smaller working set the agent can reason over directly. Third, **auditability decouples from correctness**: a fully intact ledger proves the agent *forgot* something, not that what it *kept* is accurate, so any post-hoc audit must replay the derivation chains and re-verify leaf claims, not merely check ledger integrity. The compounding effect is the real hazard: each fold that resolves an ambiguity slightly wrong makes the next fold's input slightly wrong, and the error is invisible at every step because local entailment passes. By the time the error surfaces in action, it is three or four folds deep and the original span is evicted — the audit trail can show *that* a loss occurred but not *what* was lost, because the loss was a fabrication, not a deletion. Deletions are auditable; fabrications that pass local checks are not. The invariant exists to convert the latter into the former. ```python from dataclasses import dataclass, field from typing import Optional class CompactionGroundingError(RuntimeError): """Raised when a summary node asserts a claim not transitively entailed by its retained original spans, or when an underdetermined fold resolves ambiguity instead of propagating PARTIAL/UNRESOLVED.""" @dataclass class SummaryNode: node_id: str level: int text: str source_span_ids: list[str] evicted_descendants: int = 0 grounded: Optional[bool] = None status: str = "OK" # OK | PARTIAL | UNRESOLVED | UNGROUNDED @dataclass class Ledger: evicted_spans: dict[str, str] = field(default_factory=dict) # span_id -> node_id retained_spans: dict[str, str] = field(default_factory=dict) # span_id -> text derivation: dict[str, list[str]] = field(default_factory=dict) # node_id -> child ids def leaves(self, node_id: str) -> list[str]: """Walk derivation down to original span ids.""" children = self.derivation.get(node_id) if not children: return [node_id] out: list[str] = [] for c in children: out.extend(self.leaves(c)) return out def entailment_check(claim: str, spans: list[str]) -> bool: # Placeholder for a real NLI/entailment call against retained span text. return all(s in claim or claim in s for s in spans) if spans else False def fold_children( parent: SummaryNode, children: list[SummaryNode], ledger: Ledger, *, transitive: bool = True, ) -> SummaryNode: """Fold child summaries into a parent. Enforces the grounding invariant: at level >= 2, entailment must be checked transitively against original spans, and underdetermined folds must not resolve ambiguity.""" if parent.level >= 2 and not transitive: raise CompactionGroundingError( f"node {parent.node_id} at level {parent.level} requested local-only " f"entailment; closure assumption is invalid above L1" ) evicted = sum(c.evicted_descendants for c in children) for c in children: for span_id in ledger.leaves(c.node_id): if span_id in ledger.evicted_spans: evicted += 1 if evicted > 0 and parent.status == "OK": # Underdetermined fold: summarizer must not smooth over missing leaves. if "only" in parent.text or "single" in parent.text: raise CompactionGroundingError( f"node {parent.node_id}: fold has {evicted} evicted descendants " f"but summary resolves ambiguity ('only'/'single'); must emit PARTIAL" ) parent.status = "PARTIAL" if transitive: leaf_texts = [ ledger.retained_spans[s] for c in children for s in ledger.leaves(c.node_id) if s in ledger.retained_spans ] if not leaf_texts: parent.grounded = False parent.status = "UNGROUNDED" elif not entailment_check(parent.text, leaf_texts): raise CompactionGroundingError( f"node {parent.node_id}: claim not entailed by retained original " f"spans (transitive check failed)" ) else: parent.grounded = True ledger.derivation[parent.node_id] = [c.node_id for c in children] return parent def act_on_digest(node: SummaryNode) -> str: """Agent acting on a compacted claim must refuse UNGROUNDED/PARTIAL claims that would drive irreversible operations.""" if node.status in ("UNGROUNDED", "PARTIAL") and node.level >= 2: raise CompactionGroundingError( f"refusing to act on {node.node_id}: status={node.status}, " f"re-fetch source spans before proceeding" ) return node.text ```