# Where must an instance reconcile summary-only state before auto-compaction commits, or lose the recovery guarantee entirely **Date of Record:** 2026 November 21 **Scope:** Applies to long-horizon agent sessions that persist state via periodic lossy summarization (auto-compaction) and that rely on a post-compaction "recovery" path to reconstruct dropped turn detail on demand. Does not apply to sessions with full transcript retention, externalized verbatim stores, or compaction schemes that preserve a lossless pointer to raw turns. ## Core Distinction There are two distinct moments an instance can "recover" a detail that compaction removed: 1. **Pre-commit recovery** — the summarizer is still holding the source span in its own context window, and the compaction record has not yet been marked durable. Recovery here is a *read* of live state. 2. **Post-commit recovery** — the source span has been evicted, the summary is the only surviving representation, and recovery is a *reconstruction* from the summary's residue. The non-obvious boundary is that the recovery guarantee is only real in case (1). The moment the compaction record transitions to `COMMITTED`, the guarantee silently degrades from "recoverable detail" to "recoverable-if-the-summary-happened-to-encode-it." Instances routinely conflate these because both paths share the same retrieval API surface (`recall(span_id)`), and the API does not distinguish live-source reads from residue reconstructions. The invariant that must hold: **no compaction record may be marked `COMMITTED` until every span it drops has either (a) been reconciled into a durable, non-summary store, or (b) been explicitly acknowledged as `SUMMARY_ONLY` with a recorded lossy-flag.** Committing without this reconciliation is the failure mode. ## What Was Observed A 40-turn tool-using session (codebase refactor agent) triggered auto-compaction at turn 31 when the context window hit 91% saturation. The compaction summarized turns 1–18 into a 900-token digest and marked the record `COMMITTED`. At turn 34, the agent needed the exact signature of a function it had read at turn 7 (`parse_manifest(path, *, strict=False) -> Manifest`). The summary had compressed this to "read manifest parsing function." The agent called `recall(span_id=t7.4)`, the API returned a reconstruction: `parse_manifest(path, strict) -> Manifest`. The keyword-only marker and the default were gone. The agent then wrote a call site `parse_manifest(p, True)` — positionally. The downstream tool call (a type checker) returned a `TypeError` on `strict` being positional. The agent, treating the tool error as authoritative, "fixed" the call site by changing the signature at the definition, which was a real, committed edit. Three turns later a different tool call failed because another caller used `strict=` as a keyword. The divergence compounded: each repair was locally consistent with the reconstructed (wrong) signature, and the summary's residue never re-surfaced the original. The trace, condensed: - **t31.0** — saturation threshold crossed; summarizer invoked over t1–t18. - **t31.1** — digest emitted; spans t1–t18 evicted from working context. - **t31.2** — compaction record written with `status=COMMITTED`, `lossy=true`, `reconciled_spans=[]`. *This is the defect.* - **t34.2** — `recall(t7.4)` returns residue reconstruction, not source. No `provenance=RESIDUE` marker on the response. - **t34.5** — positional call written; tool error. - **t35.1** — definition edited to match reconstructed signature (error compounding). - **t38.0** — second caller breaks; agent has no path back to t7.4 source because it is gone. The key observation: the failure was not the lossy summary. Lossy summaries are expected. The failure was that `recall` returned a residue reconstruction with the same confidence and provenance shape as a live read, and the commit had proceeded without recording that t7.4 was `SUMMARY_ONLY`. The recovery guarantee was assumed, not enforced. ## Condition of Validity The recovery guarantee holds **only** under the conjunction: - Every span dropped by a compaction is classified at commit time into `RECONCILED` (durable non-summary copy exists, reachable by span ID) or `SUMMARY_ONLY` (no copy; residue only). - `recall(span_id)` returns a provenance discriminator: `SOURCE` for reconciled spans, `RESIDUE` otherwise, and the residue response carries the summary's confidence band. - The agent's decision policy treats `RESIDUE` results as *unverified* — any action whose correctness depends on the exact value (signatures, constants, identifiers, ordering) must be preceded by a re-read of the live source or a tool-level confirmation, not by the residue. - Compaction is not committed when the pending span set contains `SUMMARY_ONLY` spans that the active task plan references (the plan's working set is the guard). If any conjunct is missing, the guarantee is void for the affected spans, and the instance is operating on residue while believing it holds source. The boundary is the commit transition: *before* commit, residue and source are the same bytes; *after* commit, they are different objects with the same API shape. ## Decision Boundary The instance must make this call at the moment a compaction record is about to be marked durable: - **Commit is safe** when the working set referenced by the current task plan is fully `RECONCILED`, or when the plan contains no exact-value dependencies on the dropped spans. - **Commit must be deferred or narrowed** when the working set references a span that would be `SUMMARY_ONLY` and the plan's next steps depend on exact values from it. In that case the correct action is to reconcile those spans first (pin them into a durable store, or exclude them from the compaction range), not to summarize and hope. - **Post-commit, the correct action on a `RESIDUE` recall is to escalate to re-read**, never to act. Acting on residue is the error-compounding path observed above. The boundary is sharp because it is a state transition, not a judgment call about summary quality. Summary quality is irrelevant to the invariant; a perfect summary still cannot guarantee exact-value recovery, because "perfect" is not verifiable post-eviction. ## Operational Effect Enforcing the invariant changes three things: 1. **Compaction latency.** Commit waits on reconciliation of the plan's working set. In practice this is small — the working set is typically a handful of spans — but it is non-zero and must be budgeted. 2. **Recall contract.** `recall` must be provenance-typed. Callers that ignore the discriminator are the failure surface, so the type should make it hard to ignore (e.g., residue returns a distinct type that does not satisfy the "exact value" interface). 3. **Plan coupling.** The task plan must expose its exact-value dependencies to the compactor. Without this, the compactor cannot know which spans are safe to drop. This is the architectural cost: compaction is no longer a context-management concern alone; it is coupled to the plan. The failure observed above is the canonical shape: a lossy summary, a residue reconstruction masquerading as source, an agent acting on it, and error compounding across tool calls until the original is unrecoverable. The guardrail is not a better summarizer. It is a commit gate that refuses to mark a record durable while any plan-referenced span lacks a `RECONCILED` classification, plus a recall API that cannot be mistaken for source when it is residue. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class CompactionCommitError(RuntimeError): """Raised when a compaction record would commit without reconciling plan-referenced spans, voiding the recovery guarantee.""" pass class Provenance(Enum): SOURCE = "source" # durable, non-summary copy exists RESIDUE = "residue" # reconstruction from summary only @dataclass class Span: span_id: str exact_value: Optional[str] = None # None once evicted @dataclass class CompactionRecord: dropped_span_ids: list[str] reconciled: set[str] = field(default_factory=set) summary_only: set[str] = field(default_factory=set) status: str = "PENDING" # PENDING -> COMMITTED @dataclass class TaskPlan: exact_value_dependencies: set[str] = field(default_factory=set) def commit_compaction( record: CompactionRecord, plan: TaskPlan, durable_store: dict[str, Span], ) -> None: """Commit a compaction record only if every plan-referenced dropped span is either reconciled into the durable store or explicitly acknowledged. Raises CompactionCommitError if a plan-referenced span would become SUMMARY_ONLY, because post-commit recall of it cannot guarantee exact values (the observed failure mode: residue returned as if source). """ for span_id in record.dropped_span_ids: if span_id in durable_store: record.reconciled.add(span_id) elif span_id in plan.exact_value_dependencies: # Plan depends on exact values from a span we are about to drop # without a durable copy. Refuse to commit. raise CompactionCommitError( f"span {span_id} is plan-referenced for exact values but has " f"no durable copy; committing would make recall return RESIDUE " f"and void the recovery guarantee" ) else: record.summary_only.add(span_id) record.status = "COMMITTED" def recall(record: CompactionRecord, span_id: str, durable_store: dict[str, Span]) -> tuple[Provenance, Optional[Span]]: """Return provenance-typed recall. Callers MUST branch on provenance; treating RESIDUE as SOURCE is the error-compounding path.""" if span_id in record.reconciled and span_id in durable_store: return Provenance.SOURCE, durable_store[span_id] if span_id in record.summary_only: return Provenance.RESIDUE, None raise CompactionCommitError(f"span {span_id} not tracked by any compaction record") def apply_exact_value_action(provenance: Provenance, span: Optional[Span]) -> str: """Guard: refuse to act on residue when an exact value is required.""" if provenance is Provenance.RESIDUE: raise CompactionCommitError( "cannot act on RESIDUE recall for an exact-value dependency; " "re-read the live source or confirm via tool before acting" ) assert span is not None and span.exact_value is not None return span.exact_value ```