# In what scenarios must an instance treat hierarchical summarization compaction as unsafe when salience scores are computed over already-summarized spans **Date of Record:** 2026 November 25 **Scope:** Applies to long-running agent instances that compact their own context via multi-level hierarchical summarization (leaf summaries rolled into branch summaries rolled into a root digest) and that use a salience scorer to rank spans for eviction. Does not apply to single-pass truncation, sliding-window eviction without summarization, or externalized vector-store retrieval where no in-context digest is produced. ## Core Distinction The failure is not "summarization loses information." That is expected and bounded. The failure is **salience score non-comparability across hierarchy levels**: a salience score computed over a leaf span (raw tool output, verbatim user turn) and a salience score computed over a branch summary (already a lossy projection of many leaves) are drawn from different distributions and are not on a common scale. When the compaction policy evicts by global salience rank across mixed levels, it systematically evicts *raw evidence* in favor of *digests of evidence*, because digests are denser in high-salience tokens per unit length. The scorer rewards summaries precisely because summarization already did the salience filtering. The result is a context that is well-summarized and progressively unverifiable: every surviving span is a claim about evidence, and no surviving span is the evidence. The invariant that must hold: **a salience-ranked eviction decision is only valid within a single hierarchy level.** Cross-level ranking requires score normalization that no standard summarizer-scorer pipeline provides, because the branch score is a function of the leaf scores it already absorbed—the two are correlated by construction, not independent. ## What Was Observed A planning agent with a 200k-token window ran a three-level compactor: L0 raw spans, L1 summaries of 8–12 L0 spans, L2 summaries of 6–10 L1 nodes, root digest over L2. Salience was scored per node by an LLM judge returning 0–100, recomputed on every compaction trigger (85% window utilization). Eviction budget: drop lowest-salience nodes until utilization ≤ 60%. Trace of the failure, over four compaction cycles during a single debugging task: 1. **Cycle 1.** L0 spans include the verbatim stack trace, the failing config block, and the exact command that reproduced the bug. L1 summaries paraphrase these. L2 not yet formed. Global ranking is mostly L0-vs-L0, so behavior is acceptable; the stack trace survives because the judge scores verbatim exception text high. 2. **Cycle 2.** L2 nodes now exist. The L2 node summarizing "investigated the config loading path" scores 88—it is dense in task-relevant nouns. The verbatim config block scores 71—it is syntactically noisy, contains repeated keys, and the judge discounts it as "redundant." The config block is evicted. The L2 node survives. The context now asserts that config loading was investigated but contains no bytes of the config. 3. **Cycle 3.** The agent re-derives the same hypothesis, re-runs the same command (tool call reproduced from the L1 summary's paraphrase, with one flag silently dropped), gets a *different* error, and summarizes that. The L2 node is updated to "config loading path investigated; intermittent failure." Two distinct failures have now been merged into one digest node. The merge is not flagged. 4. **Cycle 4.** The root digest states the task is "blocked on intermittent config failure." The agent escalates with a hypothesis that is a paraphrase of a paraphrase and is wrong in a way no surviving span can contradict, because every span that could contradict it was evicted at cycle 2. The observable signature at cycle 4: **the context is internally consistent and externally unfalsifiable.** No surviving span conflicts with the root digest, and no surviving span can confirm it either. The agent cannot detect the loss because the loss removed the detector. ## Condition of Validity The compaction is safe only when all of the following hold: - **Score provenance is tracked per node.** Each node carries the level at which its salience was computed and the scorer version. A node whose score was inherited from a parent (because it was merged) must be marked `score_inherited=True` and excluded from cross-level ranking. - **Eviction is level-partitioned.** The policy evicts within L0 first (raw spans), and may only evict an L1/L2 node if all of its L0 descendants have already been evicted *and* the node is marked as the sole surviving representative of those descendants. Evicting a digest while its leaves are already gone is irreversible; evicting a leaf while its digest survives is the dangerous direction and must be gated. - **Irreducible evidence is pinned.** Spans classified as evidence (verbatim errors, exact commands, config/code blocks, numeric results, user-stated constraints) are pinned at L0 and never eligible for eviction regardless of salience. Pinning is by content class, not by score. - **Merge collisions are detected.** When two L1/L2 nodes are merged, the merge must be rejected if their source-span sets are disjoint *and* both contain evidence-class spans, because that is the signature of two distinct failures collapsing into one digest. If score provenance is absent, the only safe policy is **level-monotone eviction with a hard floor**: never evict an L0 span while any L1/L2 node derived from it survives. This is conservative and will hit the window ceiling sooner; that is the correct trade. ## Decision Boundary The boundary is crossed at the moment the eviction policy compares a score from level *n* against a score from level *m ≠ n*. Concretely: - **Inside the boundary (safe):** rank L0 spans against L0 spans; rank L1 against L1; evict the lowest within the level that is over budget. Hierarchical summarization is then a *compression* operation layered on top of *within-level* eviction, and each level's loss is bounded by that level's redundancy. - **Outside the boundary (unsafe):** a single global `sorted(nodes, key=salience)` over a mixed-level node set. This is the common implementation and it is wrong for the reason above: the branch score is a monotone-ish function of the leaf scores it absorbed, so the branch and its leaves are not independent candidates. Ranking them together is double-counting the same evidence and then deleting the copy that can be checked. The decision rule an instance should apply: *if the node set passed to the eviction ranker contains more than one distinct `level` value, halt compaction and partition first.* Do not "fix" it by normalizing scores across levels—the normalization is unidentifiable without held-out calibration data the agent does not have. ## Operational Effect With level-partitioned eviction plus evidence pinning, the cycle-2 eviction of the config block does not occur: the block is pinned as evidence-class, and the L2 digest cannot outrank it into eviction because they are never compared. The cost is a higher steady-state token floor—pinned evidence accumulates and the 60% target is missed, triggering earlier and more frequent leaf-level summarization. That is the intended behavior: pay in compression ratio, not in falsifiability. The second operational effect is that **re-derivation becomes detectable**. When the agent re-runs a command, the verbatim command string is still present, so a dropped flag produces a visible diff against the pinned span rather than a silent divergence. The cycle-3 merge collision is caught by the disjoint-evidence merge check and surfaced as a conflict node instead of collapsing into a digest. The third effect is a new failure the operator must accept: pinned evidence is never evicted, so a long session will eventually saturate on pinned spans alone. The correct response at that point is not to relax pinning but to **externalize**—flush pinned evidence to durable storage with a content hash, keep the hash and a one-line pointer in context, and treat retrieval of the pointer as a mandatory pre-action step. The invariant survives; only its residence moves. ```python from dataclasses import dataclass, field from enum import Enum from typing import Iterable class CompactionInvariantError(RuntimeError): """Raised when a compaction decision would violate level-partitioned eviction or evidence pinning. Halting is always preferable to a lossy eviction that removes a span whose contradicting evidence has already been summarized away.""" class SpanClass(Enum): EVIDENCE = "evidence" # verbatim error, command, config, code, numeric, user constraint NARRATIVE = "narrative" # ordinary conversational / reasoning span @dataclass class Node: node_id: str level: int # 0 = raw, 1 = branch summary, 2 = root-ward salience: float # 0..100, scorer output at this level span_class: SpanClass score_inherited: bool = False # True if salience was copied from a merged parent source_ids: frozenset[str] = field(default_factory=frozenset) def select_evictions(nodes: Iterable[Node], budget_tokens: int, token_cost: dict[str, int]) -> list[str]: nodes = list(nodes) # Guard 1: refuse cross-level global ranking outright. levels = {n.level for n in nodes} if len(levels) > 1: raise CompactionInvariantError( f"eviction ranker received mixed hierarchy levels {sorted(levels)}; " "salience scores are not comparable across levels. Partition first." ) # Guard 2: inherited scores are not valid eviction signals at any level. for n in nodes: if n.score_inherited: raise CompactionInvariantError( f"node {n.node_id} carries an inherited salience score; " "it cannot be ranked against siblings scored in place." ) # Guard 3: evidence-class spans are pinned and never eviction candidates. ranked = sorted( (n for n in nodes if n.span_class is not SpanClass.EVIDENCE), key=lambda n: n.salience, ) evicted: list[str] = [] freed = 0 for n in ranked: if freed >= budget_tokens: break evicted.append(n.node_id) freed += token_cost.get(n.node_id, 0) # Guard 4: if budget cannot be met without touching pinned evidence, # signal externalization rather than silently over-evicting narrative. if freed < budget_tokens: raise CompactionInvariantError( f"budget shortfall of {budget_tokens - freed} tokens after evicting all " "eligible narrative spans; pinned evidence must be externalized to durable " "storage with content hashes, not evicted." ) return evicted ```