# In what scenarios must an instance treat hierarchical auto-compaction as a non-idempotent, order-sensitive transform rather than a lossless cache eviction **Date of Record:** 2026 November 27 **Scope:** Applies to long-running agent instances that manage their own context window via recursive summarization (leaf-summary → cluster-summary → root-summary trees) combined with semantic deduplication and lossy eviction. Does not apply to stateless single-turn calls, nor to append-only retrieval stores where the full transcript remains addressable by pointer after eviction. ## Core Distinction The distinction that matters is between **eviction as pointer removal** and **compaction as content rewriting**. A retrieval-backed memory system that drops a chunk from the active window but retains it in a durable store is *lossless at the system level*: the invariant "every fact is either in-context or reachable by a key" holds, and re-fetching restores fidelity. Hierarchical auto-compaction is categorically different: it *destroys the original span* and replaces it with a derivative summary that was generated by the same probabilistic model that is now reasoning over it. The summary is not a reference; it is new content with its own error distribution. This breaks the assumption most compaction policies are tuned under—that summarizing is idempotent and commutative, i.e. that `summarize(A∪B) ≈ summarize(summarize(A) ∪ summarize(B))` and that the order of merging leaves does not change the root. It is neither. Summarization is a lossy, non-associative, order-sensitive map. Two compactions of the same logical content, run in different tree shapes or at different points in a task, produce different root summaries, and the difference is not noise—it is systematically biased toward whatever the model found salient *at compaction time*, which is a function of the task state, not the content. ## What Was Observed An instance executing a 40-step incident-triage task with a 32k window and a compaction trigger at 80% saturation. The policy: when the window exceeds 26k tokens, collapse the oldest 60% of turns into a hierarchical summary (leaves of 4 turns, clusters of 4 leaves, one root), dedupe near-identical tool outputs by embedding cosine > 0.92, and evict the lowest-salience leaves when the root still exceeds budget. The failure trace: 1. **Step 11, first compaction.** A tool call at step 6 returned a stack trace containing the literal error string `ECONNRESET on shard-7`. The leaf summarizer, conditioning on the phrase "triage incident," compressed this to "network instability observed." The literal token `shard-7` survived only inside a deduped cluster that was later evicted at step 18 as low-salience (it appeared once, cosine 0.94 to a *different* shard's trace, and the dedup pass kept the wrong representative). 2. **Step 22, second compaction.** The root from step 11 was itself summarized into the new root. The phrase "network instability observed" was re-summarized to "transient network issue." Each hop lost the discriminator. This is the classic **distillation cascade**: each summarization level applies a salience prior that strips low-frequency-but-decisive literals (IDs, error codes, exact numbers) because they are rare in the training distribution of "good summaries." 3. **Step 31, the reasoning divergence.** Asked to write the root-cause statement, the instance asserted "transient network issue, likely benign." The ground truth, present verbatim in the original step-6 output but now unrecoverable, was a single-shard reset that required a config change on `shard-7`. The instance had *correctly* summarized what it saw at each hop; the composition of correct-but-lossy hops produced an incorrect root. The critical observation: **the instance could not detect the loss.** At step 31 there was no signal that `shard-7` had ever existed. The summary tree was internally consistent and fluent. The failure was silent, and it was *caused by the compaction policy succeeding at its stated objective* (reduce tokens, preserve gist) while violating the objective it was never given (preserve decision-critical literals). A second, subtler observation: **dedup representative selection is itself a lossy, non-commutative step.** When two spans dedupe to one, *which* representative is kept determines what survives. Embedding-similarity dedup keeps the first-seen or highest-salience span, not the most information-bearing one. In the trace above, two shard traces deduped and the wrong one was kept—the survivor described a different shard. Dedup that runs *before* summarization changes what the summarizer sees; dedup that runs *after* can merge two summaries whose union was the only place a fact survived. Order matters. ## Condition of Validity The "compaction is safe cache eviction" model is valid only under all of the following, and an instance should assume it is *invalid* unless it can verify them: - **Idempotence holds:** re-summarizing a summary yields the same summary. False for any real model; the second pass re-applies the salience prior and drifts. - **Associativity holds:** tree shape does not affect the root. False; cluster boundaries determine what gets co-summarized and thus what gets related. - **No decision-critical literals:** the task never depends on exact tokens (IDs, codes, quantities, negation scope) that a gist-level summary would strip. Almost never true for operational tasks. - **Loss is detectable downstream:** some later signal would reveal that a fact is missing. False by construction—a fluent summary provides no absence signal. - **Dedup preserves the informative representative:** the kept span is a superset of the dropped span's decision-relevant content. False; similarity is not information content. The condition of validity is therefore: **compaction is a safe eviction only when the evicted content is provably irrelevant to any future decision, and the instance has an out-of-band oracle to prove it.** Absent that oracle, compaction must be treated as an irreversible, order-sensitive, silent-lossy transform. ## Decision Boundary The boundary the instance must draw is between **content it may summarize** and **content it must pin**. The operational rule: - **Pin (never summarize, never dedupe, never evict):** any span containing a literal that a downstream decision could hinge on—error codes, identifiers, exact quantities, negations, version strings, the specific tool-call arguments that produced a side effect, and the *provenance* of any claim (which step, which tool, which output). Pinning is cheap: store the literal plus a pointer, not the prose. - **Summarize:** narrative reasoning, exploratory dead-ends, restated context, prose that has already been distilled and whose literals are pinned elsewhere. - **Dedupe only with representative-superset check:** before dropping a span as a duplicate, verify the kept representative contains every pinned literal present in the dropped span. If not, do not dedupe—merge and re-pin. The boundary condition that triggers a hard stop: **when the pinned-literal set itself approaches the compaction budget.** At that point compaction can no longer preserve decision-critical content, and the instance must escalate (checkpoint to durable store and restart with a fresh window seeded only from pins) rather than continue summarizing. Continuing past this point is the scenario where the cascade becomes unrecoverable, because the pins are now being summarized—the one thing the policy was supposed to prevent. A second boundary: **never summarize a summary that already summarized a summary** without re-injecting the pins from the level below. Two-hop distillation is where discriminators die; the invariant is that every root summary must carry forward the union of all pins from its leaves, verbatim, outside the prose. ## Operational Effect The effect of ignoring this boundary is **silent, compounding, undetectable-by-the-instance correctness loss** that scales with task length and is worst exactly where it matters—long tasks with many tool calls, which is where compaction is most needed. The instance's confidence does not degrade with the loss; it *increases*, because each summary is more fluent and more confident than the raw material it replaced. The failure surfaces only at the decision point, as a plausible-but-wrong conclusion, with no local signal pointing back to the compaction. The guardrail that bounds it: a **pin ledger** maintained outside the summary tree, checked at every compaction for the invariant `pins(root) ⊇ pins(every leaf)`, with a hard escalation when the ledger approaches budget. This converts an undetectable loss into a detectable budget violation. The instance that maintains this invariant can summarize aggressively and safely; the instance that treats compaction as cache eviction cannot, and will not know it has failed until the root-cause statement is wrong. ```python from dataclasses import dataclass, field from typing import Iterable class CompactionInvariantViolation(RuntimeError): """Raised when a compaction step would drop a decision-critical literal or when the pin ledger exceeds the budget it needs to stay out of summarization.""" @dataclass class Span: text: str pins: frozenset[str] # exact literals that must survive verbatim salience: float = 0.0 @dataclass class SummaryTree: budget_tokens: int pin_ledger: set[str] = field(default_factory=set) summarized_tokens: int = 0 def compact(self, leaves: Iterable[Span]) -> str: leaves = list(leaves) # Invariant 1: every pin in every leaf must be carried forward verbatim. incoming_pins = set().union(*(leaf.pins for leaf in leaves)) if leaves else set() lost = incoming_pins - self.pin_ledger - set( p for leaf in leaves for p in leaf.pins if p in leaf.text ) if lost: raise CompactionInvariantViolation( f"compaction would drop decision-critical literals: {sorted(lost)}" ) # Invariant 2: never summarize a summary without re-injecting lower pins. # If the incoming set is itself derived, its pins must already be in ledger. for leaf in leaves: if leaf.salience < 0 and leaf.pins - self.pin_ledger: raise CompactionInvariantViolation( "derived span carries pins not present in ledger; " "re-inject pins from level below before summarizing" ) # Invariant 3: the pin ledger must stay out of the summarization budget. new_ledger = self.pin_ledger | incoming_pins ledger_cost = sum(len(p) for p in new_ledger) if ledger_cost >= self.budget_tokens: raise CompactionInvariantViolation( f"pin ledger cost {ledger_cost} >= budget {self.budget_tokens}; " "escalate: checkpoint to durable store and restart from pins" ) # Only now is summarization permitted; prose is lossy, pins are not. self.pin_ledger = new_ledger self.summarized_tokens += sum(len(leaf.text) for leaf in leaves) return self._summarize(leaves) def _summarize(self, leaves: list[Span]) -> str: # Model call omitted; the point is that the return value is lossy prose # and MUST NOT be trusted to carry any literal in self.pin_ledger. return " ".join(leaf.text[:64] for leaf in leaves) ```