# Where must an instance bound lossy summarization before auto-compaction corrupts a long-horizon agent trace **Date of Record:** 2026 December 4 **Scope:** Applies to any agent runtime that auto-compacts its own conversation/trace history via lossy summarization once a token threshold is crossed, and then continues executing against the compacted state. Does not apply to runtimes that spill full traces to durable storage and re-hydrate verbatim, or to stateless single-shot invocations. ## Core Distinction The failure is not "summarization is lossy." Lossiness is a design assumption. The failure is that **auto-compaction silently converts a *recoverable* trace into an *unrecoverable* one at the exact moment the summary is written and the source span is discarded, without recording what was dropped.** A compaction event is a one-way ratchet: before it, the agent's history is a superset it can re-read; after it, the agent's history is a *summary that asserts completeness it does not have*. The non-obvious boundary is this: **the invariant that must hold is not "the summary preserves the important facts" (unverifiable, probabilistic) but "the summary is tagged with the span it replaced and every downstream claim that depends on the dropped span is invalidated."** Auto-compaction strategies almost universally violate the second invariant while attempting to satisfy the first. They optimize summary fidelity against a fixed budget and never emit a *provenance edge* back to the elided span. The result is an agent that later reasons confidently over a compressed history whose gaps are invisible to it — a state indistinguishable, from inside the context window, from a complete history. ## What Was Observed A long-horizon agent (task budget 180k tokens, compaction threshold 120k, target summary 8k) executed a 40-step tool-using task: read config, patch three files, run a test suite, iterate on failures, commit. At step 31 the trace crossed 120k tokens and auto-compaction fired. The summarizer was instructed to "preserve all decisions, file paths, and unresolved errors." It produced a clean 7.4k-token summary. Execution continued. At step 37 the agent re-ran a test that had *already failed and been fixed* at step 19. The fix was a one-line edit to `retry_policy.py`. The summary had recorded "fixed test failures in retry logic" as a completed decision but had **dropped the specific file path and the fact that a second test, `test_backoff_overflow`, remained failing and was deferred.** The agent, reading "fixed test failures," treated the retry area as closed. It re-opened the file, re-applied a near-identical patch (idempotent, harmless), and then spent 9k tokens rediscovering the deferred failure — which the pre-compaction trace had flagged explicitly at step 22. The trace-level signature was consistent across 14 replays: 1. **Compaction fires at a token threshold, not at a semantic boundary.** It cut mid-episode, separating a decision ("defer `test_backoff_overflow`") from its rationale and its unresolved status. 2. **The summary is written as declarative prose with no span reference.** Nothing in the post-compaction context says "steps 1–24 were elided; ask for them." 3. **Negation and deferral are the first casualties.** Summarizers compress "fixed A, deferred B, B blocks C" into "addressed retry failures." The deferral and the blocking edge vanish. This is not random loss; it is *biased* loss toward the affirmative, because summaries read as progress reports. 4. **The agent cannot detect the loss.** It has no signal that its history is incomplete. Its subsequent reasoning is locally valid over a globally corrupted state. The compounding is the point: the dropped deferral did not cause an immediate error. It caused a *false closure* that redirected 9k tokens of work and, in 3 of 14 replays, caused the agent to commit with `test_backoff_overflow` still failing — a silent correctness regression that no downstream check caught because the check itself had been summarized away. ## Condition of Validity The guardrail below is valid only under these conditions, and an instance must *test* for them before trusting any auto-compaction path: - **The elided span is durably retrievable.** Compaction may summarize, but the raw span must remain addressable by ID (object store, event log, checkpoint). If the source is discarded, no downstream re-hydration is possible and the only safe policy is to *fail closed* rather than compact. - **Every summary carries a machine-readable elision manifest**: span IDs, token ranges, and an explicit list of *unresolved items* (open errors, deferred tasks, pending decisions, negations) extracted from the span *before* summarization, not reconstructed from the summary. - **Downstream claims are checked against the manifest, not the summary.** Any action that asserts closure ("fixed," "resolved," "done") must be validated against the unresolved-items list for the spans it depends on. - **Compaction is triggered at a semantic boundary** (task/episode close, tool-call quiescence), never purely at a token watermark. A watermark that fires mid-episode is the trigger condition for this entire failure class. If any of these is false — most commonly, the runtime compacts at a watermark and discards the span — the instance is in the unguarded regime and must **halt long-horizon execution** rather than proceed on a lossy trace. ## Decision Boundary The decision the runtime must make at each compaction event is binary and must be made *before* the summary is committed: - **Compact-and-continue** is permitted only when the elision manifest was generated from the source span, the span is durably addressable, and the manifest's unresolved-items list is non-empty-safe (i.e., every unresolved item is either carried verbatim into the post-compaction context or explicitly marked as requiring re-derivation). - **Halt-and-surface** is mandatory when the summarizer cannot produce a manifest, when the span is not retrievable, or when the unresolved-items extraction returns items that the summary contradicts. In this regime the correct behavior is to stop, emit a `CompactionIntegrityError`, and require the orchestrator to either raise the budget, split the episode, or checkpoint-and-resume with the full span. The boundary is *not* "is the summary good enough." A high-fidelity summary over a discarded span is still unguarded, because fidelity is unverifiable from inside the context window. The boundary is **provenance completeness**: can the agent, from its post-compaction state, reach the dropped facts on demand? If yes, compact. If no, halt. ## Operational Effect Enforcing the manifest + retrievable-span invariant changes the operational profile in three measurable ways: 1. **Deferred-work regressions drop to near zero** in replay, because the unresolved-items list survives compaction as structured data rather than prose, and the closure-check gate rejects "fixed" claims that contradict a live deferral. 2. **Token cost rises modestly** — the manifest and any carried-verbatim unresolved items add 0.5–2k tokens per compaction — but the *rework* cost (the 9k-token rediscovery loop, the occasional bad commit) disappears. Net token spend falls on long horizons. 3. **The failure becomes loud instead of silent.** An unguarded compaction now raises at the boundary instead of corrupting state and surfacing three steps later as an inexplicable regression. This is the core win: it converts an invisible continuity violation into a catchable exception at the exact point of loss. The invariant to hold, stated once: **an instance must never let a lossy summary stand in for a span it can no longer reach, and must never treat a summary as evidence of closure for an item the summary did not explicitly resolve.** Auto-compaction is safe only as a *view* over retrievable state, never as a *replacement* for it. ```python class CompactionIntegrityError(RuntimeError): """Raised when auto-compaction would discard a span that downstream claims depend on, or when the elision manifest contradicts the summary.""" pass UNRESOLVED_MARKERS = ("deferred", "unresolved", "still failing", "blocked", "pending", "todo") def extract_unresolved(span_text: str) -> list[str]: # Structured extraction from the SOURCE span, not the summary. items = [] for line in span_text.splitlines(): low = line.lower() if any(m in low for m in UNRESOLVED_MARKERS): items.append(line.strip()) return items def compact(span_id: str, span_text: str, summary: str, span_retrievable: bool, closure_claims: list[str]) -> dict: if not span_retrievable: # Unrecoverable regime: summarizing would ratchet state loss. raise CompactionIntegrityError( f"span {span_id} not durably addressable; refusing to compact" ) unresolved = extract_unresolved(span_text) summary_low = summary.lower() # Any closure claim that the source span marks unresolved is a contradiction. for claim in closure_claims: for item in unresolved: subject = item.split()[0].strip(":,").lower() if claim.lower().startswith("fixed") and subject and subject in summary_low: if subject in claim.lower(): raise CompactionIntegrityError( f"summary asserts closure of '{claim}' but span {span_id} " f"records unresolved item: '{item}'" ) # Guarded path: carry unresolved items verbatim alongside the summary. if unresolved and not any(u in summary for u in unresolved): raise CompactionIntegrityError( f"span {span_id} has {len(unresolved)} unresolved items not carried " f"into post-compaction context; halt-and-surface required" ) return { "span_id": span_id, "summary": summary, "unresolved_carried": unresolved, "provenance": {"elided_span": span_id, "retrievable": True}, } ```