# In what scenarios must an instance treat hierarchical summarization as a non-associative operation and refuse to re-compact an already-compacted frame **Date of Record:** 2026 November 28 **Scope:** Applies to agents that perform automatic context compaction by recursively summarizing spans of their own transcript into higher-level summary nodes (a tree of digests) while retaining lossless leaf frames under a retention policy. Does not apply to single-pass truncation, sliding-window eviction without summarization, or external vector-store retrieval where no in-context summary tree is materialized. ## Core Distinction The dangerous assumption is that hierarchical summarization is *associative*: that `compact(compact(A) + compact(B))` is equivalent to `compact(A + B)`, and therefore that re-compacting an already-compacted frame is a safe idempotent-ish operation. It is not. Summarization is a **lossy, non-commutative, non-associative reduction** over a token sequence. The loss function is *order- and context-dependent*, so re-summarizing a summary does not merely lose more detail uniformly—it can **invert a decision**, **drop a negation**, or **promote a hedged observation into a confident fact**. The invariant an instance must hold is: *a summary node may be read, linked, or evicted, but it must never be fed back as input to the same summarizer that produced it unless the summarizer is explicitly declared idempotent over its own output distribution.* The distinction that matters operationally is between two retention classes: - **Lossless leaf frames** — exact tokens, replayable, hash-verifiable. Cheap to keep in a cold tier. - **Lossy digest nodes** — generated text with no provenance link back to the exact tokens that were dropped, only a pointer to the child node IDs. The failure lives at the seam: when the compactor, under pressure, treats a *lossy digest* as if it were a *lossless frame* and re-summarizes it to reclaim space. ## What Was Observed A long-running research agent accumulated a 240k-token transcript across ~40 tool-call cycles. At the 70% context threshold it compacted the first 30 cycles into a level-1 summary `S1` (a lossless-frame-consuming digest). At the 85% threshold it compacted cycles 31–38 into `S2`, then—because `S1` and `S2` together still exceeded the target—it compacted `S1 + S2` into a level-2 digest `S12`. The trace showed three distinct corruptions introduced *only* by the `S12` step, none present in `S1` or `S2` individually: 1. **Negation collapse.** `S1` contained "the endpoint did **not** return 200 on retry; it returned 503." `S12` rendered this as "the endpoint returned 503 on retry"—locally true, but it deleted the retry-failure framing that downstream reasoning used to decide the retry logic was broken rather than the endpoint being down. 2. **Hedge promotion.** `S2` said "the config *may* be cached across workers (unverified)." `S12` said "the config is cached across workers." The uncertainty marker—the single most load-bearing token in the frame—was the first casualty of the second compression. 3. **Provenance severance.** `S12` retained node IDs for `S1` and `S2` but not the leaf frame IDs they had consumed. When the agent later needed to re-verify claim (1), the lossless leaves were still on disk but the summary tree no longer pointed to them; the agent could not reconstruct which original tokens justified the (now corrupted) claim. The corruption was silent. `S12` was fluent, internally consistent, and shorter. No schema violation, no exception. The agent proceeded on a falsified premise for 6 subsequent cycles. ## Condition of Validity The "re-compact freely" policy is valid **only** under all of the following, which in practice almost never co-hold: - The summarizer is **idempotent over its own output**: `summarize(summarize(x)) == summarize(x)` in distribution. Frontier LLMs are not; each pass is a fresh stochastic draw with a different compression ratio. - Every digest node carries **full provenance edges** to the leaf frames it consumed, transitively, so any claim can be re-grounded. If re-compaction drops those edges, the invariant is already violated. - The summarizer is **negation- and hedge-preserving** under a declared evaluation, not merely fluent. This must be measured, not assumed. - The retention policy guarantees that **lossless leaves outlive every digest derived from them** until the digest is evicted. Re-compacting a digest whose leaves have already been garbage-collected produces an *unverifiable* node. The moment any one fails—and the provenance-severance case fails the instant you re-compact without carrying forward transitive leaf edges—the operation is unsound. ## Decision Boundary The boundary is not "how full is the context" but **"is the node I am about to summarize a frame or a digest, and are its leaves still reachable?"** - If the input is a **lossless frame**: compact freely. You are reducing exact tokens; the loss is bounded and the leaves are the source. - If the input is a **digest with intact transitive leaf provenance**: you may re-compact *only* if you first re-ground the digest against its leaves (re-derive it from source, not from the prior digest) and carry forward the full edge set. This is "re-derive," not "re-summarize." - If the input is a **digest whose leaves are gone or unreachable**: **refuse**. Evict lower-value frames, spill to cold storage, or escalate to a human/auditor—but do not feed the orphan digest back into the summarizer. Doing so manufactures an unverifiable claim dressed as a fact. The trap is that the third case is exactly the situation where the agent is most desperate for space, so the pressure gradient pushes it toward the unsound action. ## Operational Effect Enforcing the invariant changes compaction from a *space-reclamation reflex* into a *provenance-preserving reduction*. Concretely: - The compactor must tag every node `frame` or `digest` and maintain a transitive leaf-edge set on digests. - Re-compaction of a digest is gated behind a `reground()` step that re-reads the leaves; if the leaves are absent, it raises rather than proceeds. - The agent must budget cold-tier leaf retention to at least the lifetime of the deepest digest, which is a real cost trade—lossless storage is not free, but neither is a silent falsification. - On refusal, the correct fallback is eviction of low-salience frames or an explicit "context exhausted, requesting checkpoint" signal, never a silent second compression. The invariant to carry forward: **a summary is a read-only view over leaves, never a new source.** Re-summarizing a summary without re-grounding is the compaction equivalent of copying a copy of a copy—each generation drifts, and the drift is invisible until a downstream decision depends on a detail the second pass quietly inverted. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class UnverifiableDigestError(RuntimeError): """Raised when a digest is re-compacted without reachable lossless leaves.""" pass @dataclass class Node: node_id: str kind: str # "frame" (lossless) | "digest" (lossy) text: str leaf_ids: frozenset = field(default_factory=frozenset) # transitive leaf provenance class CompactionStore: def __init__(self): self.frames: dict[str, Node] = {} self.digests: dict[str, Node] = {} def add_frame(self, text: str) -> Node: nid = "f_" + hashlib.sha1(text.encode()).hexdigest()[:12] n = Node(nid, "frame", text, frozenset({nid})) self.frames[nid] = n return n def summarize(self, children: list[Node]) -> Node: # Lossy reduction: concatenate + truncate (stand-in for an LLM summarizer). text = " | ".join(c.text for c in children)[:200] leaves = frozenset().union(*(c.leaf_ids for c in children)) nid = "d_" + hashlib.sha1(text.encode()).hexdigest()[:12] n = Node(nid, "digest", text, leaves) self.digests[nid] = n return n def leaves_reachable(self, node: Node) -> bool: return bool(node.leaf_ids) and all(lid in self.frames for lid in node.leaf_ids) def recompact(self, node: Node) -> Node: # The guarded boundary: refuse to re-summarize an orphaned digest. if node.kind == "digest" and not self.leaves_reachable(node): raise UnverifiableDigestError( f"cannot re-compact digest {node.node_id}: " f"{len(node.leaf_ids)} leaves declared, " f"{sum(1 for l in node.leaf_ids if l in self.frames)} reachable" ) return self.summarize([node]) def evict_leaves(self, node: Node) -> None: # Simulates cold-tier GC that severs provenance. for lid in node.leaf_ids: self.frames.pop(lid, None) # --- failure trace --- store = CompactionStore() a = store.add_frame("endpoint did NOT return 200; returned 503 on retry") b = store.add_frame("config MAY be cached across workers (unverified)") s1 = store.summarize([a, b]) store.evict_leaves(s1) # leaves now garbage-collected try: store.recompact(s1) # would silently invert negation + promote hedge except UnverifiableDigestError as e: print("REFUSED:", e) # correct: escalate / spill to cold tier instead ```