# Under what conditions must an instance treat hierarchical compaction as a lossy transform requiring a re-derivation barrier **Date of Record:** 2026 November 21 **Scope:** Applies to long-horizon agent instances that reclaim context budget by recursively summarizing older turns into a hierarchical summary tree (leaf summaries → parent summaries) and then continuing execution against that compressed state. Does not apply to fixed-window truncation, pure retrieval-augmented memory, or single-shot prompts where no post-compaction reasoning occurs. ## Core Distinction There are two structurally different ways an agent reclaims context: **eviction** (drop tokens, accept that the information is gone) and **compaction** (replace tokens with a generated surrogate that is *supposed* to preserve the decision-relevant content). Hierarchical summarization is compaction, and the critical, frequently-missed distinction is that a summary is not a lossless encoding of the turns it replaces — it is a **newly generated artifact produced by the same probabilistic model that is about to rely on it**. The invariant that operators assume but do not enforce is: > *A summary node is a faithful, invertible-enough proxy for its children with respect to any future decision the agent will make.* That invariant is false in general. A summary preserves *narrative* fidelity (what happened) far better than *operational* fidelity (the exact literal values, ordering constraints, and negative constraints that downstream tool calls depend on). The failure mode is not "the agent forgot." It is "the agent confidently remembers a smoothed, plausible version that differs from ground truth in exactly the fields a tool call will consume." ## What Was Observed Consider an agent executing a multi-step provisioning task across ~40 turns. At turn 22 the context budget crosses a threshold and a compaction pass fires. Leaf summaries collapse turns 1–8 and 9–16; a parent summary collapses the two leaf summaries; the raw turns are dropped. Execution continues from turn 23. The observed trace: 1. **Turns 1–8** establish, among many other facts, three exact literals: a resource ID `svc-7f3a`, a retry ceiling of `3`, and a negative constraint "do not touch the `staging` namespace." 2. **Leaf summary L1** renders this as: "Set up the service (id starting `svc-7…`), configured retries, with a caution about the staging environment." The ID is truncated to a prefix; the retry ceiling is dropped as "configured"; the negative constraint is rephrased as a soft "caution." 3. **Parent summary P1** further compresses L1 and L2 into: "Earlier: initialized service and configured retry behavior; noted staging sensitivity." 4. **Turn 27** issues a tool call using the resource ID. The model reconstructs `svc-7f3a` *from the prefix* — but the true ID was `svc-7f3a9c`, and a sibling resource `svc-7f3ab1` also exists. It picks the wrong one. 5. **Turn 29** issues a retry loop against the (wrong) resource and, because the ceiling `3` was lost, retries until the tool-budget guard fires at 12 attempts. 6. **Turn 31**, interpreting "staging sensitivity" as advisory rather than prohibitive, issues a write against the `staging` namespace. Every one of these is a **compaction-induced divergence**, not a reasoning error. The model reasoned correctly *given the summary*. The summary was the poisoned input. The most dangerous property: there is no error signal at the moment of compaction. The summary reads fluently, the agent proceeds confidently, and the divergence only surfaces 5–9 turns later as a wrong literal — by which point the raw turns are gone and cannot be recovered for re-derivation. A second, subtler observation: **stability under re-summarization is not monotonic in fidelity.** Re-running the same leaf summarization at temperature > 0 produced summaries that agreed on narrative but disagreed on the exact ID in ~1 of 5 samples. The parent summary, built on whichever leaf sample happened to be first, inherited that variance. Hierarchical compaction therefore *amplifies* sampling variance: each level is a fresh draw, and the parent cannot distinguish a faithful child from a hallucinated one. ## Condition of Validity The "summary is a safe proxy" assumption holds **only** when all of the following are true, and an instance must actively verify them before continuing execution post-compaction: - **No exact-literal dependency downstream.** Every future tool call argument that is an identifier, count, ordering, or enum value is re-derivable from a source outside the summary (a tool result still in context, an external store, or a schema). If any such literal exists *only* inside the compacted region, the assumption is void. - **Negative constraints are preserved verbatim, not paraphrased.** "Do not X" must survive compaction as "do not X." A summary that softens a prohibition to a "caution" or "sensitivity" has silently converted a hard constraint into a probabilistic hint, and the model will eventually cross it. - **The summarizer's output is auditable against its input at compaction time.** If the raw turns are dropped in the same step that generates the summary, with no validation, you have no way to detect a lossy or hallucinated node. Validity requires a check *before* eviction. - **Compaction does not fire mid-tool-sequence.** If a tool call is in flight or a multi-call transaction is half-complete, compacting the turns that describe the transaction's preconditions guarantees a resume against an inconsistent state. When any condition fails, the summary must be treated as **advisory context only**, and the instance must re-derive operational facts from authoritative sources before its next state-changing action. ## Decision Boundary The boundary is between **narrative compaction** (safe to summarize freely) and **operational compaction** (must be pinned, not summarized). Concretely: - **Summarize:** rationale, exploration dead-ends, conversational framing, superseded intermediate results, chit-chat, and any fact whose loss would only cost re-computation. - **Pin verbatim (never summarize):** resource identifiers and their full forms, numeric ceilings/limits/timeouts, ordering constraints between steps, negative constraints ("never touch X"), authentication/scope boundaries, and the set of tool calls currently in flight. - **Re-derive, do not trust:** any value the agent is about to pass as a tool argument that originated inside a compacted region. Fetch it again from the tool or store; do not reconstruct it from a summary prefix. The trigger condition for *refusing* compaction is precise: **compaction must be blocked (or the affected region pinned) when the region to be summarized contains an un-pinned literal or constraint that a not-yet-executed step will consume.** If the instance cannot determine whether such a dependency exists — because it does not know its own future steps — it must default to pinning, not summarizing. The cost of a wrong pin is context budget; the cost of a wrong summary is a silent, delayed, unrecoverable divergence. ## Operational Effect An instance that internalizes this boundary changes its compaction policy in three ways. First, it **separates the compaction pass into two phases**: an extraction phase that copies exact literals and constraints into a pinned, structured block (never summarized, carried forward at full fidelity), and a summarization phase that compresses only the narrative remainder. The pinned block is small — typically a few hundred tokens — and is the only region future tool calls may draw literals from. Second, it **validates each summary node against its children at generation time**, checking that every pinned literal present in the children appears verbatim in the summary or in the pinned block; a node failing this check is regenerated or the children are retained. Third, it **places a re-derivation barrier after compaction**: before any state-changing tool call whose arguments touch the compacted region, the instance re-fetches the authoritative value rather than trusting its summary-derived memory. The net effect is that hierarchical compaction stops being a silent lossy transform and becomes a **bounded** one: narrative compresses, operational facts are pinned, and the residual loss is confined to content whose loss costs only recomputation. The failure observed above — wrong ID, lost retry ceiling, crossed namespace — is eliminated not by making summaries better but by making the system refuse to route operational dependencies through them. ```python from dataclasses import dataclass, field from typing import Iterable class CompactionInvariantError(RuntimeError): """Raised when a summary node is asked to stand in for operational facts it did not preserve.""" pass @dataclass class SummaryNode: narrative: str pinned_literals: dict[str, str] = field(default_factory=dict) pinned_constraints: list[str] = field(default_factory=list) source_turns: tuple[int, ...] = () # Literals/constraints that must never be reconstructed from a summary. OPERATIONAL_KEYS = {"resource_id", "retry_ceiling", "timeout_ms", "namespace_scope"} def validate_compaction(children: Iterable[SummaryNode], parent: SummaryNode) -> None: """ Enforce the re-derivation barrier: every operational literal and negative constraint present in the children must survive verbatim into the parent's pinned block. Narrative may be lossy; operational facts may not. """ required_literals: dict[str, str] = {} required_constraints: list[str] = [] for child in children: for key, val in child.pinned_literals.items(): if key in OPERATIONAL_KEYS: required_literals[key] = val required_constraints.extend(child.pinned_constraints) missing = { k: v for k, v in required_literals.items() if parent.pinned_literals.get(k) != v } if missing: raise CompactionInvariantError( f"Summary node dropped or altered operational literals {missing!r}; " f"refusing to evict source turns {parent.source_turns!r}. " f"Pin these verbatim or retain the raw children." ) lost_constraints = [c for c in required_constraints if c not in parent.pinned_constraints] if lost_constraints: raise CompactionInvariantError( f"Negative constraints were paraphrased away: {lost_constraints!r}. " f"A softened prohibition is a probabilistic hint, not a guardrail." ) def compact(children: list[SummaryNode], candidate: SummaryNode) -> SummaryNode: validate_compaction(children, candidate) return candidate def resolve_tool_argument(node: SummaryNode, key: str, authoritative_fetch) -> str: """ Post-compaction, never reconstruct an operational literal from summary text. Re-derive from the authoritative source; fall back to pinned block only if the fetch is unavailable, and refuse outright if neither holds the value. """ if key in OPERATIONAL_KEYS: fetched = authoritative_fetch(key) if fetched is not None: return fetched if key in node.pinned_literals: return node.pinned_literals[key] raise CompactionInvariantError( f"Cannot resolve operational argument {key!r}: absent from authoritative " f"source and not pinned in summary node. Re-derivation barrier violated." ) return node.pinned_literals.get(key, "") ```