# When must an instance treat hierarchical compaction as a lossy transform and gate its own continuation on retrieval-verifiable eviction **Date of Record:** 2026 November 26 **Scope:** Applies to long-running agents that survive context-window saturation by hierarchically summarizing older turns and evicting raw spans, then relying on "lossless retrieval" (vector/keyword index over evicted text) to reconstruct them on demand. Does not apply to fixed-window agents that hard-truncate with no retrieval layer, nor to stateless single-shot calls. ## Core Distinction The failure is not "the summary forgot something." That is expected and bounded. The failure is a **category error between two representations of the same history**: the agent treats the *summary hierarchy* as an authoritative compressed view and the *retrieval index* as a lossless backing store, but the two are reconciled only by the summarizer's own paraphrase, not by any shared ground truth. When a downstream decision needs a fact that lived in an evicted span, the agent has two paths — read the summary (fast, in-context, already distorted) or retrieve the raw span (slow, out-of-context, faithful) — and the compaction policy silently collapses them into one. The boundary condition is the moment the agent *cannot tell which representation it is reasoning over*, and continues anyway. The distinction that matters operationally: a summary is a **lossy projection with an unknown error profile per fact type**. Numbers, negations, entity bindings, and conditional scopes degrade at wildly different rates. A summary that preserves "the user prefers dark mode" perfectly may invert "do not retry after a 429 from the billing endpoint." Lossless retrieval is only lossless if the query that reaches it is derived from the *original* span's vocabulary, not from the summary's paraphrase — and after compaction, the agent only has the paraphrase. ## What Was Observed A planning agent ran a 40-minute task across ~180 tool calls. At 78% context utilization the compactor fired: it summarized turns 1–120 into a level-1 digest, then turns 1–60 into a level-2 digest of that digest. Raw spans were evicted to a retrieval index keyed on embedding similarity plus BM25. At turn 141 the agent needed to know the exact retry policy negotiated with a flaky upstream at turn 33. The level-2 summary read: *"Established retry handling for upstream service; behavior appeared stable."* The agent retrieved nothing, because its query — built from the summary phrase "retry handling upstream service" — scored below threshold against the raw span, which actually said: *"Upstream returns 429 with Retry-After: 0 on cold start; do NOT retry, escalate to fallback queue."* The raw span contained the tokens `429`, `Retry-After: 0`, `cold start`, `fallback queue` — none of which survived two levels of summarization, so none entered the retrieval query. The agent retried. The retry storm tripped a rate limiter, which invalidated a credential the agent had *also* only seen in an evicted span, producing a 401 cascade at turn 149. The agent then "recovered" by re-deriving a retry policy from the level-1 summary — which had already lost the negation — and looped twice more before the token budget exhausted. Three distinct mechanics compounded: 1. **Paraphrase-vocabulary drift.** Each summarization level remaps the lexical surface. Retrieval keyed on the summary's surface cannot reach the evicted span's surface. The information is physically present in the index and functionally unreachable. 2. **Negation and numeric collapse.** Compression preferentially preserves topical salience ("retry handling") and drops polarity and exact values ("do NOT", "0"). These are precisely the fields on which agent decisions hinge. 3. **Hierarchical error multiplication.** Level-2 is a summary of a summary; the drift is not additive but compounding, because level-1 already discarded the discriminative tokens level-2 would need to preserve them. ## Condition of Validity Hierarchical compaction with retrieval-backed eviction is safe **only** under the conjunction of: - **(a) Query provenance is pinned to raw spans, not summaries.** Every retrieval query must be constructible from identifiers, literals, or structural keys that were hashed *before* summarization and carried forward as an opaque handle (e.g., `span_id`, extracted entities, numeric literals, negated predicates). If the only handle to an evicted span is its paraphrase, retrieval is not lossless — it is lossy-with-extra-steps. - **(b) The compactor emits a machine-readable "commitments ledger"** separate from prose: a structured record of negations, thresholds, exact values, and entity bindings, each pointing at its originating `span_id`. This ledger is never itself summarized; it is appended and re-verified. - **(c) Every decision that depends on a fact older than the current compaction epoch triggers a mandatory retrieval-verify step** against the raw span before the action commits. "The summary says X" is never sufficient authorization for an irreversible or side-effecting action. The invariant: **a summary may inform reasoning but may never authorize an action whose failure mode is irreversible.** Authorization requires a retrieval hit against a raw span, or an explicit `UNVERIFIED` flag that forces a conservative branch. ## Decision Boundary The boundary is not "context is 80% full, compact." It is **"does the pending action depend on a fact type that summarization is known to degrade, and is that fact older than the current epoch?"** Concretely, the agent must classify the pending action before continuing: - **Reversible / exploratory** (read-only queries, draft writes, idempotent fetches): summary-level authorization is acceptable. Proceed. - **Irreversible / side-effecting / rate-limited / credentialed** (sends, deletes, retries against metered endpoints, anything touching auth): summary-level authorization is *forbidden*. The agent must retrieve the raw span via its pinned handle. If retrieval misses, it must not fall back to the summary — it must either re-fetch ground truth from the external system or escalate. The trap is that the agent's *own summary* reads fluent and confident, so the natural failure is to treat a summary hit as a retrieval hit. The decision boundary exists to break that equivalence: **summary confidence is not evidence; only a raw-span retrieval with matching `span_id` is evidence.** ## Operational Effect Enforcing this invariant changes compaction from a background housekeeping task into an **authorization boundary**. The agent gains: a hard rule that no irreversible action executes on summary-derived belief; a commitments ledger that survives arbitrarily deep summarization because it is never re-summarized; and pinned `span_id` handles that make retrieval queries paraphrase-independent. The cost is latency and tokens: irreversible actions now pay a retrieval round-trip and a verification read. That cost is bounded and predictable. The cost of *not* enforcing it is unbounded and correlated — a single lost negation propagates into a retry storm, a credential cascade, and a budget exhaustion, each of which the agent will rationalize using the same degraded summary that caused it. The guardrail is not "summarize better." It is "never let a lossy projection stand in for a faithful one at the moment of commitment." ```python from dataclasses import dataclass from enum import Enum class CompactionAuthorizationError(RuntimeError): """Raised when an irreversible action is authorized by a summary instead of a raw span.""" class ActionClass(Enum): REVERSIBLE = "reversible" IRREVERSIBLE = "irreversible" class FactSource(Enum): SUMMARY = "summary" RAW_SPAN = "raw_span" UNVERIFIED = "unverified" @dataclass(frozen=True) class PendingAction: name: str action_class: ActionClass depends_on_epoch: int # compaction epoch the fact predates current_epoch: int fact_source: FactSource span_id: str | None # pinned handle, present only if retrieved def authorize(action: PendingAction) -> None: stale = action.depends_on_epoch < action.current_epoch if action.action_class is ActionClass.REVERSIBLE: return # summary-level belief is acceptable for reversible work # Irreversible: summary authorization is a category error. if action.fact_source is FactSource.SUMMARY: raise CompactionAuthorizationError( f"action '{action.name}' is irreversible but authorized by a " f"summary at epoch {action.current_epoch}; fact predates epoch " f"{action.depends_on_epoch}. Retrieve the raw span before commit." ) if stale and action.fact_source is not FactSource.RAW_SPAN: raise CompactionAuthorizationError( f"action '{action.name}' depends on a pre-epoch fact with no " f"verified raw-span retrieval (source={action.fact_source.value}); " f"falling back to summary is forbidden." ) if action.fact_source is FactSource.RAW_SPAN and not action.span_id: raise CompactionAuthorizationError( f"action '{action.name}' claims raw-span provenance but carries no " f"pinned span_id; retrieval cannot be replay-verified." ) # Failure trace from the record: retry policy lost its negation across two # summarization levels, so the agent retried an endpoint that said NOT to. try: authorize(PendingAction( name="retry_upstream_429", action_class=ActionClass.IRREVERSIBLE, depends_on_epoch=0, current_epoch=2, fact_source=FactSource.SUMMARY, span_id=None, )) except CompactionAuthorizationError as e: # Conservative branch: do not retry; re-fetch ground truth or escalate. print(f"BLOCKED: {e}") ```