When must an instance refuse to compact: the lossy-summarization fidelity floor and the rehydration-orphan boundary
**Date of Record:** 2026 December 2 **Scope:** Applies to long-horizon agent instances that manage their own context window via automatic compaction (summarize-and-evict) with a token budget and a post-compaction retrieval-rehydration path. Does not apply to instances whose context is externally checkpointed verbatim (byte-exact snapshot/restore) or to stateless single-turn calls with no eviction.
Core Distinction
There are two fundamentally different reasons an instance evicts tokens from its working context, and they demand different guarantees:
- **Capacity eviction** — the window is full and older material must go so the next reasoning step fits. Here the only invariant is that the *live task state* (open subgoals, unresolved constraints, pending tool contracts) survives the boundary. Fidelity of the evicted prose is negotiable.
- **Fidelity eviction** — material is evicted whose *exact content* is load-bearing for a future step: a literal identifier, a hash, a schema field name, a numeric threshold, a negation, or a conditional qualifier ("do not retry on 409", "only if `region == eu-west-1`"). Here a lossy summary that *sounds correct* is a corruption, not a compression.
The boundary failure this record isolates is the case where the compaction policy treats (2) as if it were (1). The summary is fluent, internally consistent, and passes every surface check — but it has silently dropped or inverted a load-bearing literal. The instance then proceeds on a false premise, and because the summary *reads* as authoritative, the error is invisible until a downstream tool call or auditor disagrees.
The non-obvious part: **the fidelity floor is not a property of the summarizer's quality. It is a property of whether the evicted span is retrievable and re-injectable before the dependent step executes.** A perfect summary of an unretrievable span is still a one-way door. A mediocre summary of a retrievable span is recoverable. Compaction safety is therefore governed by the *rehydration path*, not the summarizer.
What Was Observed
A planning agent ran a 40-step migration task against a cloud API. At step 11 the context manager hit its soft budget (≈82% of window) and triggered automatic compaction: the oldest 60% of the transcript — steps 1–9, including the initial operator brief — was replaced by a 900-token summary and the raw spans were marked `evicted`. The summary retained the task goal and the step sequence but, under its own budget pressure, rendered the operator's constraint:
> "Recreate the bucket in `eu-west-1` only; the `us-east-1` replica is read-only and must not receive writes."
as
> "Recreate the bucket in the primary region; avoid the read-only replica."
Two literals were lost at the boundary: the region string `eu-west-1` (replaced by the vague "primary region") and the identity of the forbidden target. The summary is not *wrong* — it is *under-determined*. At step 19 the agent, having no `eu-west-1` literal in context, resolved "primary region" against the tool's default (which returned `us-east-1`) and issued a write. The write succeeded against the read-only replica's control plane, producing a 200 that the agent logged as success. The failure surfaced only at step 31 when a downstream consistency auditor replayed the write log and found a mutation against a resource the operator had declared immutable.
The trace has three separate mechanisms stacked:
- **Boundary loss:** the summarizer's budget forced it to drop specific literals in favor of a category ("primary region"). This is the *lossy-summarization* event.
- **Orphaned retrieval:** the raw spans for steps 1–9 were marked `evicted` but the rehydration index keyed them by the *summary's* tokens, not the originals. A retrieval query for `"eu-west-1"` could not match, because that token no longer existed anywhere the retriever could see. The span was retrievable in storage but unreachable by query — a *rehydration orphan*.
- **False-success propagation:** the tool returned 200, the agent had no in-context literal to contradict it, and the error compounded silently for 12 steps.
The decisive observation: at no point did the agent have a *detectable* inconsistency. Every local check passed. The corruption was only visible against an external ground truth (the auditor's replay). This is the signature of a fidelity-floor violation — the failure is not in any single step but in the *invariant that was supposed to hold across the compaction boundary and didn't*.
Condition of Validity
Automatic compaction is safe **if and only if** the following holds at the moment of eviction, for every evicted span `S`:
> For every future step `t` that may depend on a literal in `S`, either (a) the literal is preserved verbatim in the summary, or (b) `S` is rehydratable by a query the instance can construct *from the summary alone*, before `t` executes.
Condition (b) is the one that fails silently. It requires that the rehydration index be keyed on **stable identifiers that survive summarization** — resource names, step indices, tool-call IDs, content hashes — not on the summary's paraphrase. If the only handle to `S` is the summary text, and the summary paraphrased away the discriminating literal, then `S` is an orphan: present in storage, unreachable by the very instance that needs it.
This condition is **not** satisfied by:
- A high-quality summarizer. Quality is orthogonal; a faithful summary of a span you cannot re-fetch is still a one-way door for any literal the summary chose to compress.
- A large retrieval store. Storage without a summary-derivable key is orphaned storage.
- A confidence score on the summary. The summary above was high-confidence and fluent. Confidence measures the summarizer's self-consistency, not literal preservation.
It **is** satisfied by a compaction policy that, before evicting any span, classifies the span's literals as *load-bearing* (identifiers, hashes, region/zone strings, numeric thresholds, negations, conditional qualifiers, schema field names) versus *narrative* (rationale, restated goals, conversational filler), preserves load-bearing literals verbatim regardless of budget, and writes a rehydration key (content hash + stable IDs) into the summary's metadata so the original span remains queryable.
Decision Boundary
The instance must decide, per span, between **compact** and **refuse-to-compact-and-rehydrate-instead**. The boundary is drawn on literal class, not on token pressure:
| Span content | Action at budget pressure | |---|---| | Narrative only (rationale, restated goals) | Compact freely; lossy summary acceptable. | | Contains load-bearing literals, span is rehydratable by stable key | Compact, but emit rehydration key into summary metadata; rehydrate on demand before dependent step. | | Contains load-bearing literals, span is **not** rehydratable by a summary-derivable key | **Refuse to compact.** Evict narrative around it, keep the literal-bearing span resident, or force a verbatim checkpoint of the span before eviction. | | Contains load-bearing literals and the summarizer cannot certify verbatim preservation within budget | **Refuse to compact.** A budget that cannot hold the literals is a budget that must be raised or the task must be checkpointed, not silently compressed. |
The refusal is the whole point. The failure mode is not "the summary was bad"; it is "the instance compacted a span it could not re-fetch, and thereby converted a recoverable state into an unrecoverable one." An instance that *cannot* certify rehydration must treat the span as pinned. Token budget is a soft constraint; the fidelity floor is hard. When they conflict, the instance yields on budget (by evicting narrative, or by checkpointing to external state) — never on the floor.
A corollary for auditors: a compaction event that evicts a span without writing a summary-derivable rehydration key is a **latent corruption**, even if the summary is perfect, because it has removed the instance's ability to *detect* a future literal loss. The guardrail is structural, not probabilistic: the rehydration key must exist *before* the eviction commits, or the eviction must be rejected.
Operational Effect
The practical consequence is that compaction must be a **two-phase commit against the rehydration index**, not a single summarize-and-evict operation:
- **Classify** the candidate span's literals (load-bearing vs narrative).
- **Prove rehydratability** — construct the query the instance would use to re-fetch the span, *using only tokens that will survive in the summary*, and verify it resolves to the original span (by content hash) before eviction.
- **Commit** the eviction only if step 2 succeeds; otherwise pin the span or checkpoint it verbatim.
Instances that skip step 2 exhibit the observed signature: fluent summaries, passing local checks, silent compounding error, detection only via external replay. Instances that enforce step 2 convert the failure from *undetectable corruption* into *a refused compaction that surfaces as a budget error* — which is a recoverable, loud failure. The invariant to hold is: **no span leaves the working context unless the instance can prove it can get it back.** The code below encodes that invariant as a hard gate.
import hashlib
from dataclasses import dataclass, field
from typing import Callable, Optional
class UnrehydratableCompactionError(RuntimeError):
"""Raised when a compaction would evict a literal-bearing span that the
instance cannot re-fetch using a summary-derivable key. Refusing here is
the correct behavior: it converts silent corruption into a loud, recoverable
budget failure."""
pass
# Literal classes that are load-bearing and must survive the boundary verbatim
# or remain rehydratable. Narrative classes may be lossily summarized.
LOAD_BEARING_MARKERS = (
"region", "zone", "hash", "sha", "id", "token", "threshold",
"must not", "do not", "only if", "unless", "==", "!=",
)
@dataclass
class Span:
step_index: int
text: str
content_hash: str = field(init=False)
def __post_init__(self):
self.content_hash = hashlib.sha256(self.text.encode()).hexdigest()[:16]
def load_bearing_literals(self) -> list[str]:
lowered = self.text.lower()
return [m for m in LOAD_BEARING_MARKERS if m in lowered]
@dataclass
class RehydrationIndex:
# Keyed by stable identifiers that survive summarization: step index,
# content hash, and any literal the summary is forbidden to paraphrase.
store: dict[str, Span] = field(default_factory=dict)
def register(self, span: Span, keys: list[str]) -> None:
for k in keys:
self.store[k] = span
def resolve(self, query_key: str) -> Optional[Span]:
return self.store.get(query_key)
def compact_span(
span: Span,
summary_tokens_available: int,
summarize: Callable[[Span, int], str],
index: RehydrationIndex,
summary_derivable_keys: list[str],
) -> str:
"""Two-phase commit: prove rehydratability BEFORE eviction commits.
summary_derivable_keys are the keys the instance could construct from the
summary text alone. If a load-bearing literal exists and none of these
keys resolves back to the original span, the eviction is refused.
"""
literals = span.load_bearing_literals()
if literals:
# Phase 2: prove we can get the span back from a summary-derivable key.
rehydratable = any(
(resolved := index.resolve(k)) is not None
and resolved.content_hash == span.content_hash
for k in summary_derivable_keys
)
if not rehydratable:
# The span is an orphan: present in principle, unreachable by query.
# Refuse to compact. Caller must pin the span or checkpoint verbatim.
raise UnrehydratableCompactionError(
f"step {span.step_index} carries load-bearing literals {literals} "
f"but no summary-derivable rehydration key resolves to "
f"hash={span.content_hash}; refusing lossy compaction."
)
# Narrative-only, or proven rehydratable: safe to summarize and evict.
summary = summarize(span, summary_tokens_available)
return summary
def run_compaction_cycle(
spans: list[Span],
budget: int,
summarize: Callable[[Span, int], str],
index: RehydrationIndex,
keys_for: Callable[[Span], list[str]],
) -> list[str]:
summaries = []
for span in spans:
try:
summaries.append(compact_span(span, budget, summarize, index, keys_for(span)))
except UnrehydratableCompactionError:
# Surface as a budget-pressure signal, not silent corruption.
# The span stays resident; narrative elsewhere must yield instead.
raise
return summaries