# What happens when an instance compacts its own context: hierarchical summarization and the lossy-recall budget boundary **Date of Record:** 2026 December 2 **Scope:** Applies to long-horizon agent instances that manage their own context window by summarizing older turns into hierarchical nodes (leaf → parent → root) under a fixed token budget, then rehydrating from those summaries on later turns. Does not apply to externally-managed retrieval (RAG over an external store) where the raw text is never destroyed, nor to single-turn inference. ## Core Distinction There are two structurally different ways to "forget." **Eviction** drops raw text but the instance knows it dropped it — a hole exists in its history and it can request rehydration or declare uncertainty. **Compaction** replaces raw text with a generated summary that *claims* to cover the evicted span. The failure mode here is not that information is lost; it is that the summary is a *lossy surrogate that presents as complete*. The instance's later reasoning treats the summary as ground truth, so a compaction defect is indistinguishable, from the inside, from a genuine fact. Eviction fails loudly; compaction fails silently and then gets *reasoned over*. The specific boundary is the **lossy-recall budget**: the per-node token allowance `B` allocated to a summary. When the source span's information content exceeds `B`, the summarizer must drop facts. It does not drop them uniformly — it drops the ones least salient to the *summarizer's* framing at compaction time, which is not the same as least relevant to the *task* at recall time. This mismatch is the mechanism. ## What Was Observed An instance executing a 40-step provisioning task compacted at step 18. The leaf summary of steps 9–14 read: *"Verified credentials and network access; all checks passed."* The raw span actually contained a transient result: a scoped token that passed validation but carried a 15-minute TTL and a `renew_before` field the summarizer judged redundant. At step 31, past the TTL, the instance attempted a privileged call using the now-expired credential, because the summary asserted "all checks passed" with no temporal qualifier. The compaction had collapsed a **time-bounded validity assertion** into a **static boolean**. The trace: 1. **Trigger.** Cumulative context hit the compaction threshold `θ` (here 78% of window). Hierarchical compactor selected the oldest un-summarized leaf span. 2. **Budget allocation.** Leaf budget `B_leaf = 180` tokens for a 2,400-token span. Compression ratio ~13:1. 3. **Lossy encoding.** Summarizer retained the *outcome* of each check (pass/fail) and discarded *qualifiers* (TTL, scope, issuing authority) because qualifiers were lower-probability continuations under its prompt. 4. **Promotion.** Leaf summary promoted into parent node; raw span discarded. No pointer to raw text retained (the store was cleared to reclaim memory). 5. **Stale recall.** At step 31, retrieval matched the parent summary on the token "credentials" and surfaced "all checks passed" without the TTL. 6. **Divergence.** Instance reasoned `valid(credential) → proceed`, executed, received `401 expired`, retried twice with the same summary, then escalated. The invariant that broke: **a summary must be closed under the predicates its descendants depend on.** The raw span asserted `valid(c) ∧ ttl(c, 15m)`. The summary asserted only `valid(c)`, which is not a valid abstraction because downstream reasoning consumed `valid` without the binding temporal constraint. ## Condition of Validity Compaction is safe only when, for every fact `f` in the raw span that any downstream step may consume, the summary preserves either `f` or an explicit **abstention marker** (`UNKNOWN: credential TTL not retained`) that forces the instance to rehydrate or re-derive. The condition is: > For a summary node `S` covering span `R`, `S` is *recall-complete* with respect to budget `B` iff every predicate in `R` that is (a) time-varying, (b) scope-bounded, or (c) an authorization/identity fact is either reproduced in `S` or replaced by an abstention marker, regardless of salience. This condition is *not* satisfiable by better summarization alone — it requires the compactor to classify facts by **consumption risk**, not by **narrative importance**. A summarizer optimizing for fluency or compression will systematically violate it, because the facts it drops (TTLs, scopes, nonces, sequence numbers) are precisely the low-salience, high-consequence ones. The condition fails structurally when: - `B` is set below the irreducible "risk-fact floor" of the span (the token cost of all time-varying/authorization predicates). - The compactor has no schema for risk-facts and relies on the LLM's salience judgment. - Raw spans are destroyed on promotion, removing the ability to re-derive or verify. ## Decision Boundary The operating boundary is a function of **span risk density** `ρ` (risk-facts per 1k tokens) against the **budget ratio** `B / |R|`: - **`B ≥ ρ·|R| + ε`** (budget covers the risk-fact floor): compaction is safe; risk-facts fit alongside the narrative. Proceed with standard hierarchical summarization. - **`ρ·|R| ≤ B < ρ·|R| + ε_narrative`**: risk-facts fit but narrative does not. The compactor must **prioritize risk-facts over narrative** and emit abstention markers for narrative gaps. This is the regime most agents get wrong — they preserve narrative and drop risk-facts. - **`B < ρ·|R|`** (budget below risk-fact floor): compaction is **unsafe at any summarizer quality**. The only valid action is to **refuse compaction** for this span and instead: (i) evict with an explicit hole marker, (ii) retain a raw-text pointer for rehydration, or (iii) halt and surface the budget conflict. Compacting here guarantees silent loss of a risk-fact. The boundary is crossed silently because the compactor cannot observe `ρ` — it sees tokens, not risk-classes — and the instance cannot observe the loss because the summary reads as complete. Detection requires an **external risk-classifier** at compaction time, not a better summarizer. ## Operational Effect When this boundary is crossed, the failure surfaces far from its cause (step 31 vs. step 18) and is **self-reinforcing**: the instance retries with the same stale summary, and each retry may itself get compacted into a summary asserting "retried privileged call," laundering the failure into apparent diligence. Recovery requires the instance to distrust its own summary layer — which it has no internal signal to do. Guardrails that bound it: 1. **Risk-fact floor check.** Before compacting a span, compute `ρ·|R|` via a classifier over time-varying/authorization/identity predicates. If `B < ρ·|R|`, raise and refuse. 2. **Abstention markers over silent omission.** Summarizer prompt must emit `UNKNOWN:` for any risk-fact it cannot fit, never a fluent elision. 3. **Retained raw pointer.** Promotion must keep a rehydration handle for any span containing risk-facts, so recall can re-derive rather than trust. 4. **Temporal qualifier preservation.** Any "valid/passed/authorized" in a summary must carry its binding constraint (`valid until T`, `scope S`) or an abstention marker. A bare boolean is a protocol violation. 5. **Compaction provenance.** Downstream reasoning that consumes a summary fact must be able to see it came from a summary node with budget `B` and ratio `|R|/B`, so confidence can be discounted accordingly. The following guard enforces the boundary at compaction time and refuses unsafe compaction rather than silently degrading recall. ```python from dataclasses import dataclass from typing import Iterable class CompactionBudgetViolation(RuntimeError): """Raised when a span's risk-fact floor exceeds its lossy-recall budget.""" @dataclass(frozen=True) class RiskFact: kind: str # "ttl" | "scope" | "identity" | "nonce" | "sequence" tokens: int # token cost to faithfully encode this fact @dataclass(frozen=True) class Span: raw_tokens: int risk_facts: tuple[RiskFact, ...] def risk_fact_floor(span: Span) -> int: return sum(f.tokens for f in span.risk_facts) def compact_span(span: Span, budget: int, slack: int = 24) -> dict: """ Decide whether hierarchical summarization is safe under `budget`. Returns a compaction plan, or raises if the risk-fact floor is unreachable. """ floor = risk_fact_floor(span) if budget < floor: # Compacting here would silently drop a time-varying/authorization fact. raise CompactionBudgetViolation( f"budget={budget} < risk-fact floor={floor} " f"(raw={span.raw_tokens} tok, kinds={[f.kind for f in span.risk_facts]}); " "refuse compaction, evict with hole marker or retain raw pointer" ) plan = {"mode": "compact", "preserve": [f.kind for f in span.risk_facts]} if budget < floor + slack: # Risk-facts fit but narrative does not: abstain on narrative, never drop risk-facts. plan["mode"] = "compact_risk_first" plan["narrative"] = "ABSTAIN: UNKNOWN (narrative exceeds budget)" else: plan["narrative"] = "summarize" return plan def verify_summary(summary: str, span: Span) -> None: """ Post-condition: every risk-fact must be either reproduced with its binding qualifier or replaced by an explicit abstention marker. """ for fact in span.risk_facts: marker = f"UNKNOWN:{fact.kind}" reproduced = fact.kind in summary and "until" in summary.lower() or "scope" in summary.lower() if not reproduced and marker not in summary: raise CompactionBudgetViolation( f"summary silently dropped risk-fact '{fact.kind}' with no abstention marker; " "lossy-recall invariant violated" ) ```