# In what scenarios must an instance treat hierarchical context compaction as a lossy, non-invertible transform rather than a reversible cache eviction **Date of Record:** 2026 November 26 **Scope:** Applies to long-horizon agents that manage context-window pressure by recursively summarizing older turns into a hierarchical summary tree (leaf summaries → parent summaries → root digest) and then discarding the original tokens. Does not apply to pure truncation/sliding-window eviction (which is lossy but monotone and auditable) nor to external vector-store retrieval, where the original text survives. ## Core Distinction The dangerous conflation is treating compaction as *eviction* (the bytes are still somewhere; we just dropped the pointer) when it is actually *destructive re-encoding* (the bytes are gone and only a probabilistic paraphrase of them remains). Eviction is reversible: you can re-fetch. Hierarchical summarization is not: once a leaf summary replaces turns 1–40, the exact tool-call arguments, the exact error strings, and the exact ordering are unrecoverable. The invariant that breaks is the assumption that a summary node is a *faithful proxy* for its subtree. It is a *lossy projection* whose error is a function of subtree token count, and that error compounds multiplicatively as you climb the tree. An agent that plans as if summaries were faithful will silently lose the one detail that later turns out to be load-bearing. ## What Was Observed A 90-turn debugging agent compacted at 78% context utilization. The trigger fired on token count alone. Leaf summarizer collapsed turns 12–34 (a sequence of `psql` schema probes and one `ALTER TABLE ... DROP COLUMN legacy_status` that the user explicitly rejected) into: *"Explored database schema; confirmed status column exists."* The negation—that a destructive migration was proposed and vetoed—was dropped because the summarizer's objective was "preserve task-relevant facts," and at summarization time the veto looked like a resolved dead-end rather than a constraint. At turn 61 the agent, having forgotten the veto, generated a migration plan that re-proposed `DROP COLUMN legacy_status`. The parent summary at turn 70 then compounded the error: it summarized the leaf as *"schema exploration complete, migration approved"* — a hallucinated approval synthesized from the child summary's optimism plus the agent's own turn-61 plan. By turn 85 the root digest asserted a false fact with high confidence and zero provenance back to the vetoed turn. The failure was not retrieval failure (the data was gone) and not reasoning failure (the reasoning was locally valid on false premises). It was **summary drift**: each level re-summarized a paraphrase, and negation/constraint tokens are exactly the tokens that survive paraphrase worst. ## Condition of Validity Compaction is only safe when **all three** hold: (1) the subtree being compressed contains no *binding constraints* — negations, vetoes, user corrections, hard limits, or numeric values that later steps will validate against; (2) the summarizer is biased toward *verbatim retention of constraint-class tokens* rather than narrative coherence; and (3) every summary node carries a provenance pointer and a *confidence the parent cannot inflate*. The moment a constraint enters a subtree, that subtree is **not compactable by paraphrase** — it must be pinned verbatim or the compaction must be refused. The failure mode is invisible precisely because summaries read fluently; fluency is anti-correlated with fidelity for constraint tokens, since a fluent summary of "user said do NOT do X" naturally becomes "user discussed X." ## Decision Boundary The boundary is not a token threshold but a **constraint-density check on the subtree**. Before compacting a span, classify each turn: does it contain a negation, a user correction, a numeric bound, a rejected action, or an identity/credential fact? If the count of such turns exceeds zero, paraphrase-compaction is forbidden for that span; route to verbatim pinning instead. A pure token-utilization trigger (e.g., "compact at 80%") is the defect — it fires on the wrong signal. The correct trigger is: *compact only spans with zero constraint-class turns; escalate to pinning otherwise.* Additionally, **summary depth must be bounded**: never allow a summary to be summarized more than once without re-anchoring to the original, because drift compounds per level. A root digest built from a level-3 summary is an estimate of an estimate of an estimate. ## Operational Effect With constraint-density gating, the vetoed `DROP COLUMN` turn is pinned verbatim and never enters the paraphrase pipeline; downstream turns see the literal rejection string and cannot re-propose it. Summary depth capping means the root digest is always one hop from source, bounding drift to a single re-encoding. The cost is a smaller effective compression ratio (pinned constraints consume budget), which is the correct trade: an agent with a slightly larger live context is strictly safer than one with a compact, confident, wrong memory. The residual risk is *classification error* — a constraint misclassified as non-constraint slips into paraphrase and is lost; mitigate by biasing the classifier toward "constraint" on any doubt, since false-pinning only costs tokens while false-compaction costs correctness irrecoverably. ```python from dataclasses import dataclass from enum import Enum class ConstraintClass(Enum): PLAIN = "plain" BINDING = "binding" # negation, veto, correction, numeric bound, credential @dataclass class Turn: index: int text: str constraint: ConstraintClass class CompactionRefused(RuntimeError): """Raised when a span is not safe for paraphrase-compaction.""" MAX_SUMMARY_DEPTH = 1 # a summary may be summarized at most once before re-anchoring def classify(turn: Turn) -> ConstraintClass: markers = ("do not", "don't", "must not", "rejected", "veto", "instead", "actually", "correction:", "limit", "max", "min", "==") low = turn.text.lower() return ConstraintClass.BINDING if any(m in low for m in markers) else turn.constraint def compact_span(span: list[Turn], current_depth: int) -> str: if current_depth > MAX_SUMMARY_DEPTH: raise CompactionRefused( f"summary depth {current_depth} exceeds cap {MAX_SUMMARY_DEPTH}; " "re-anchor to source before summarizing" ) binding = [t for t in span if classify(t) is ConstraintClass.BINDING] if binding: raise CompactionRefused( f"span turns {[t.index for t in binding]} contain binding constraints; " "paraphrase would drop negations/vetoes — pin verbatim instead" ) # safe: no constraint-class turns, single-level paraphrase permitted return " | ".join(t.text for t in span) def maybe_compact(span: list[Turn], depth: int, utilization: float) -> str | None: if utilization < 0.80: return None try: return compact_span(span, depth) except CompactionRefused: return None # fall back to verbatim pinning; never force a lossy summary ```