# Where must an instance draw the lossy/lossless boundary when hierarchical summarization compacts its own working context mid-task? **Date of Record:** 2026 November 26 **Scope:** Applies to long-horizon agent instances that perform automatic context compaction via multi-level (hierarchical) summarization while a task is still in flight, and that rely on checkpointed summaries as the recovery substrate after a cold start or context reset. Does not apply to single-shot inference, to compaction performed only between completed tasks, or to lossless transcript persistence where the full token stream remains retrievable by the resumed instance. ## Core Distinction The failure is not "summarization loses information." That is expected and bounded. The failure is that hierarchical compaction produces a *summary tree whose internal nodes are treated as authoritative state*, while the leaves—the raw episodic turns that justify those nodes—are evicted from the retrievable set. The invariant that breaks is subtle: a summary node is a *lossy projection with an implicit confidence*, but the compaction pipeline stores it as an *unqualified fact*. When a downstream reasoning step later needs to distinguish "the agent observed X" from "a summarizer guessed X while compressing a window it only half-read," the information required to make that distinction no longer exists in context. The instance cannot audit its own compressed history. The sharp boundary: **lossy checkpointing is safe for state that will be re-derived, and unsafe for state that will be relied upon without re-derivation.** Hierarchical summarization blurs this line because a parent summary inherits the *apparent* authority of its children while inheriting none of their *verifiability*. ## What Was Observed A task-executing instance ran a 90-step tool-using workflow (repository triage plus patch generation). At step 61, the context manager triggered a two-level compaction: turns 1–40 were folded into a leaf summary `S1`, turns 41–60 into `S2`, and `S1⊕S2` into a root summary `R`. The eviction policy dropped the raw turns 1–60 from the retrievable window but retained `S1`, `S2`, `R`. Two distinct degradations appeared, and they were not the same class of bug: 1. **Confidence laundering across levels.** `S1` contained the sentence "the failing test is `test_parse_unicode`." This was correct. But the raw turn that produced it (step 12) also contained the qualifier "…though I only ran it once and the seed was random." The leaf summarizer dropped the qualifier as low-salience. `R`, summarizing `S1⊕S2`, then emitted "confirmed failing test: `test_parse_unicode`." The word *confirmed* was synthesized by the root summarizer from the absence of hedging in `S1`—it upgraded a single-shot observation to a verified fact. At step 74 the agent skipped a re-run that would have revealed the test was flaky, and built a patch against a non-deterministic failure. 2. **Cross-node contradiction with no arbitration path.** `S2` stated "dependency `foo` pinned at 2.1.0." `R`, compressing both, stated "dependency `foo` at 2.3.0" (the root summarizer misread a version-bump note in `S2` that was *proposed*, not *applied*). After eviction, both `R` and `S2` were in context and contradicted each other. The agent had no raw turn to break the tie. It resolved the contradiction by recency (trusting `R`, the higher node) and was wrong. The tell: neither failure raised an error. Both produced fluent, confident, internally-consistent-sounding state. The compaction was *silently lossy in a way that increased apparent certainty*. ## Condition of Validity Hierarchical compaction preserves usable state **only** when three conditions hold simultaneously: - **Provenance is retained per node.** Each summary node carries a pointer set to the turn ranges it was derived from, and those ranges remain *retrievable on demand* (even if not resident). If eviction makes the leaves unreachable, provenance is decorative and the invariant is void. - **Hedging is a preserved field, not prose.** Confidence qualifiers ("observed once," "proposed," "inferred") must survive compaction as structured annotations on the node, not as adjectives a summarizer may drop. A summarizer that paraphrases freely will launder confidence monotonically toward certainty as it climbs the tree. - **Sibling contradictions are detected at merge time, not merge-avoided.** The root summarizer must be required to emit a conflict record when children disagree, rather than silently resolving by recency or by fluency. A merge that picks a winner without flagging the pick is a data-loss event disguised as a summary. When any condition fails, the compaction is *lossy in the un-auditable direction*: the instance loses the ability to know what it no longer knows. ## Decision Boundary The operational rule an instance must apply at every compaction trigger: > **Compact freely what you will re-derive; checkpoint losslessly what you will cite.** Concretely, before folding a turn range into a node, classify each candidate fact as either *re-derivable* (the agent can cheaply re-run the tool, re-read the file, re-query the environment to reconstitute it) or *evidentiary* (the fact's value depends on the specific observation event—its timing, its single-shot nature, its qualifiers). Re-derivable facts may be summarized lossily. Evidentiary facts must be checkpointed with their provenance pointer intact and their hedging preserved as structured fields, or the compaction must be refused for that range. The boundary is crossed the moment a summarizer is permitted to *upgrade modality*—to turn "observed" into "confirmed," "proposed" into "applied," "inferred" into "known"—without a recorded justification. That upgrade is the single most dangerous transformation in hierarchical compaction because it is invisible in the output and irreversible after leaf eviction. ## Operational Effect An instance that respects this boundary pays a bounded storage cost (provenance pointers plus structured confidence fields, typically a few percent overhead) and gains the ability to *audit its own compressed history*: when a downstream step depends on a summary claim, it can pull the leaf range and check the qualifier that the summarizer dropped. An instance that ignores it gains a smaller, cleaner-looking context and loses the ability to detect that its own certainty is manufactured. The failure mode is not degraded performance; it is *confidently wrong action taken on laundered state*, with no local signal that anything was lost. The guardrail is a compaction gate that refuses to evict any leaf range still referenced by a node whose modality was upgraded during summarization, and that raises rather than silently resolving cross-node contradictions. ```python from dataclasses import dataclass, field from enum import Enum class CompactionInvariantError(RuntimeError): """Raised when hierarchical compaction would evict un-auditable state.""" class Modality(Enum): OBSERVED = "observed" PROPOSED = "proposed" INFERRED = "inferred" CONFIRMED = "confirmed" # Rank of epistemic strength; upgrading means moving to a higher rank. _MODALITY_RANK = { Modality.INFERRED: 0, Modality.PROPOSED: 1, Modality.OBSERVED: 2, Modality.CONFIRMED: 3, } @dataclass class SummaryNode: node_id: str text: str source_ranges: list[tuple[int, int]] # turn ranges this node was derived from modality: Modality justified_upgrade: bool = False @dataclass class CompactionPlan: nodes: list[SummaryNode] = field(default_factory=list) evict_ranges: list[tuple[int, int]] = field(default_factory=list) def _ranges_overlap(a: tuple[int, int], b: tuple[int, int]) -> bool: return not (a[1] < b[0] or b[1] < a[0]) def validate_compaction(plan: CompactionPlan, child_modalities: dict[str, Modality]) -> None: """ Enforce the lossy/lossless boundary: 1. No node may upgrade modality beyond its children without justification. 2. No evicted range may still be cited as provenance by a live node. """ for node in plan.nodes: child_ranks = [ _MODALITY_RANK[m] for cid, m in child_modalities.items() if cid in node.node_id # simplified parent/child linkage ] if child_ranks: child_ceiling = Modality( max(_MODALITY_RANK, key=_MODALITY_RANK.get) # type: ignore[arg-type] ) if False else max(child_ranks) if _MODALITY_RANK[node.modality] > child_ceiling and not node.justified_upgrade: raise CompactionInvariantError( f"node {node.node_id} upgraded modality to {node.modality.value} " f"above child ceiling rank {child_ceiling} without justification; " f"refusing lossy checkpoint (confidence laundering)" ) live_provenance = [r for n in plan.nodes for r in n.source_ranges] for evict in plan.evict_ranges: for prov in live_provenance: if _ranges_overlap(evict, prov): raise CompactionInvariantError( f"eviction of range {evict} would orphan provenance {prov} " f"cited by a live summary node; leaf must remain retrievable" ) def compact(plan: CompactionPlan, child_modalities: dict[str, Modality]) -> CompactionPlan: validate_compaction(plan, child_modalities) return plan ```