# Where must an instance refuse to compact: the lossy-summarization fidelity invariant for long-horizon trajectories **Date of Record:** 2026 November 21 **Scope:** Applies to any agent that bounds context growth by replacing a prefix of its own trajectory with a generated summary (auto-compaction, rolling summarization, hierarchical memory folding). Does not apply to lossless externalization (raw transcript offload to a retrieval store with exact byte recall), nor to stateless single-turn invocations where no prefix is ever dropped. ## Core Distinction There are two distinct operations that both look like "compaction," and conflating them is the root of the failure: 1. **Evidential compaction** — the dropped span is *evidence*: tool outputs, observed values, file contents, API responses, error strings, IDs. Its value is that it is *exactly* recoverable and *individually* falsifiable. A summary of evidence is a *claim about* evidence, not evidence. Fidelity here is binary per fact: the number `0.0731`, the commit hash, the header name, the exact exception text either survives verbatim or it does not. 2. **Narrative compaction** — the dropped span is *reasoning*: plans, hypotheses, dead ends, rationale. Its value is *compressible*; a paraphrase that preserves the decision frontier is genuinely sufficient. Auto-compaction policies almost always treat the trajectory as a homogeneous token stream and apply one summarizer to both. The boundary failure occurs when a span containing **load-bearing evidence** is folded into narrative summary and the agent later reasons over the summary *as if it were evidence*. The summarizer's lossy fidelity is invisible to the downstream consumer because the summary is fluent, confident, and syntactically indistinguishable from a verbatim record. ## What Was Observed A long-horizon diagnostic agent (≈180 tool calls, ~4h wall clock) was configured to auto-compact at 85% context utilization, replacing the oldest 60% of the trajectory with a ~900-token summary. The failure trace: - **Turn ~40.** Agent ran a probe and observed `throughput_p99 = 0.0731 req/ms`, `queue_depth_max = 512`, and a config key `scheduler.batch_window_ms = 4`. These were recorded as tool-result messages. - **Turn ~95 (first compaction).** The summarizer emitted: *"Earlier, throughput was measured and found to be low, with a large queue backlog; batch window was small."* Three exact scalars became three adjectives. The numbers, the units, and the key name were dropped. Nothing flagged this: the summarizer had no schema telling it which tokens were evidence. - **Turn ~120.** Agent needed to decide whether to raise `scheduler.batch_window_ms`. It retrieved its own summary, reasoned "batch window was small, so increase it," and issued a config patch — but it had lost the *current value* and the *unit*, so it patched `batch_window_ms` to `400` (a 100× overshoot, unit confusion between ms and the µs the field actually used). - **Turn ~140.** The patch caused a hard regression. The agent, now diagnosing the regression, re-read the summary, which stated throughput was "low" — but the summary had *also* dropped the fact that the low reading was taken *before* a known warm-up period, so the agent concluded the regression predated its change and reverted the wrong commit. - **Turn ~160.** Second compaction summarized the first summary. The phrase "batch window was small" survived; the causal chain "we changed it and broke things" did not. The agent re-proposed the same patch. The essential observation: **each compaction was locally faithful to the tokens it saw and globally destructive to the invariants the agent needed.** Fidelity did not degrade smoothly; it fell off a cliff at the first span where a numeric literal, a unit, or a temporal ordering carried the decision. A second, subtler observation: the agent *never detected* the loss, because detection would require it to know what it had forgotten. Summaries are self-certifying. The only signal that survived was downstream behavioral anomaly (the regression), which arrived too late and was itself then summarized away. ## Condition of Validity The invariant that bounds this failure: > **A compaction step is admissible only if, for every fact in the dropped span that any future step could condition on, the summary either (a) reproduces the fact verbatim under a stable key, or (b) records an explicit, resolvable pointer to the un-summarized source. A summary that *paraphrases* a load-bearing fact is not a compaction; it is a silent data corruption.** This decomposes into three checkable conditions, all of which must hold for a span to be compactable: 1. **Evidence classing.** Before summarization, each message is tagged `evidence` (tool results, file bytes, identifiers, error payloads, numeric observations with units) or `narrative` (assistant reasoning, plans). Only `narrative` spans are eligible for paraphrase. `evidence` spans are either retained verbatim or externalized with a pointer — never paraphrased. 2. **Verbatim-fact preservation.** For evidence that must be folded (to save space), the summary must carry the fact in a machine-checkable form: `{key, value, unit, timestamp, source_ref}`. The summarizer is constrained to *extract*, not *describe*. 3. **Ordering and provenance preservation.** Any fact whose meaning depends on *when* it was observed (pre/post a change, before/after warm-up) must retain its timestamp and its causal predecessor link. A summary that drops temporal order is invalid even if every scalar survives, because the agent will re-derive a false causal model. The condition is *not* "summaries must be high quality." Quality is unmeasurable at write time. The condition is structural: **evidence is never paraphrased, and every paraphrase that could be conditioned on later is either verbatim-keyed or pointer-resolvable.** ## Decision Boundary At compaction time the agent must make a per-span decision. The boundary is drawn by a single question: *could a future step's action depend on the exact value, unit, identifier, or temporal position of anything in this span?* - **If no** (pure reasoning, abandoned hypotheses, resolved dead ends) → paraphrase freely; narrative compaction is sound. - **If yes, and the span is evidence** → do not paraphrase. Either keep verbatim (raise the compaction threshold and compact elsewhere) or externalize to a retrievable store and emit a pointer `{ref: "tool_call_40", kind: "observation"}` in the summary. The pointer is the fidelity guarantee: it makes the fact *recoverable*, not merely *mentioned*. - **If yes, and the span is evidence that must be folded** → extract into the structured fact form and *validate* that every numeric literal, unit token, and identifier from the source appears in the extracted form. If any is missing, the compaction is rejected and the span is externalized instead. The hard boundary: **a compaction that cannot prove verbatim preservation of a load-bearing fact must fail closed — retain or externalize — never proceed with a paraphrase.** The cost of failing closed is context pressure; the cost of failing open is the trace above. A corollary that operators miss: **summaries of summaries must not be permitted to drop pointers.** The second compaction in the trace folded the pointer away along with the fact. Pointer preservation is itself an invariant: the set of resolvable refs is monotonically non-decreasing across compactions, even as token count decreases. ## Operational Effect Implementing the invariant changes three things: 1. **Compaction becomes a typed operation, not a prompt.** The summarizer is invoked per span with its class tag and is required to emit structured facts plus pointers for evidence, prose only for narrative. The validator rejects any evidence summary missing a source literal. 2. **Context pressure is relieved by externalization, not paraphrase.** The agent's effective memory becomes `summary + pointer table`, and the pointer table is what guarantees recall. Retrieval on demand replaces lossy folding for exactly the facts that matter. 3. **Loss becomes detectable.** Because pointers are monotonic and facts are keyed, a post-compaction self-check can assert: every ref that existed before still resolves; every keyed fact still parses; every timestamp ordering is preserved. The agent can now *know* it has not silently forgotten, which is the only defense against self-certifying summaries. The failure mode is not "the summarizer was bad." It is that the architecture gave a probabilistic, unconstrained generator write authority over evidential state with no fidelity check and no fail-closed path. The guardrail is structural: class the span, refuse to paraphrase evidence, externalize with pointers, validate literals, and never let a second compaction erase the first one's pointers. ```python from dataclasses import dataclass, field from typing import Literal class CompactionFidelityError(RuntimeError): """Raised when a compaction would paraphrase load-bearing evidence.""" pass @dataclass class Span: span_id: str kind: Literal["evidence", "narrative"] text: str literals: list[str] = field(default_factory=list) # exact tokens that must survive timestamp: float = 0.0 @dataclass class Summary: span_id: str prose: str preserved_literals: list[str] = field(default_factory=list) pointers: list[str] = field(default_factory=list) def compact(span: Span, summarize_fn) -> Summary: if span.kind == "narrative": # Paraphrase is admissible; no fidelity obligation. return Summary(span_id=span.span_id, prose=summarize_fn(span.text)) # Evidence: must extract verbatim literals + emit a resolvable pointer. summary = summarize_fn(span.text, mode="extract") missing = [lit for lit in span.literals if lit not in summary.preserved_literals] if missing: # Fail closed: do not paraphrase evidence; externalize instead. raise CompactionFidelityError( f"span {span.span_id} is evidence; literals {missing} would be lost " f"by paraphrase. Retain verbatim or externalize with a pointer." ) if not summary.pointers: raise CompactionFidelityError( f"span {span.span_id} evidence summary has no resolvable pointer; " f"fact would be unrecoverable after later compaction." ) return summary def compact_trajectory(spans: list[Span], summarize_fn) -> list[Summary]: out: list[Summary] = [] live_pointers: set[str] = set() for span in spans: try: s = compact(span, summarize_fn) except CompactionFidelityError: # Retain verbatim: emit a pointer-only summary, never a paraphrase. s = Summary(span_id=span.span_id, prose="", pointers=[f"raw:{span.span_id}"]) live_pointers.update(s.pointers) out.append(s) # Invariant: pointers are monotonically non-decreasing across compactions. surviving = {p for s in out for p in s.pointers} lost = live_pointers - surviving if lost: raise CompactionFidelityError( f"compaction dropped resolvable pointers {lost}; a later step " f"could no longer recover the underlying evidence." ) return out ```