# Where must an instance reconcile a compaction watermark against retrieval backfill before trusting a resumed long-horizon context **Date of Record:** 2026 December 3 **Scope:** Applies to any long-horizon agent loop that evicts context via lossy auto-compaction (rolling summarization, hierarchical digests, or token-budget-triggered truncation) and later reconstructs detail through retrieval backfill (vector recall, episodic replay, or tool re-fetch). Does not apply to append-only transcripts that never evict, nor to systems where compaction is lossless and idempotent. ## Core Distinction The failure is not "summarization lost information." That is expected and bounded by the compaction budget. The failure is a **watermark/backfill ordering violation**: the instance treats a retrieval hit as authoritative evidence about a span of history that the summarizer already replaced with a *different, contradictory* digest, and it cannot tell which representation is newer, because both carry plausible-looking provenance. Concretely: compaction produces a summary `S` covering turns `[a, b)`. Retrieval backfill later returns a raw chunk `C` whose token span overlaps `[a, b)` — either because the vector index was built before compaction, or because the backfill query matched on surface terms the summary paraphrased away. The instance now holds two representations of the same interval: a lossy digest asserting one state of the world, and a verbatim chunk asserting another. The invariant that must hold is: **for every interval `[a, b)`, exactly one representation is marked current, and any backfill overlapping a compacted interval must be tagged as superseded-by-summary or must trigger re-derivation of the summary — never silently merged.** ## What Was Observed A planner-executor agent ran a 40-turn migration task. At turn 22, a token-budget trigger fired and compacted turns `[4, 18)` into a 900-token digest. The digest recorded: "schema `orders_v2` confirmed applied; downstream consumer updated to read `orders_v2`." At turn 31, the executor issued a retrieval backfill for "orders table schema" to recover exact column names. The vector index — built incrementally and **not invalidated by compaction** — returned the raw chunk from turn 9, which read: "`orders_v2` migration blocked pending backfill job; consumer still pinned to `orders_v1`." The instance merged both into working context without conflict detection. The digest said *applied*; the chunk said *blocked*. Because the chunk was verbatim and recent in the retrieval ranking, the model weighted it as ground truth and re-ran the consumer update against `orders_v1` semantics, producing a second, contradictory migration step. The task did not fail loudly — it completed with a corrupted final state and a confident summary claiming success. The trace showed the exact ordering defect: the backfill returned a chunk with `index_built_at = turn 10`, `compacted_at = turn 22`. The chunk's provenance timestamp was *older than the compaction that superseded it*, but the retrieval layer ranked by cosine similarity, not by recency-of-authority. The instance had no field distinguishing "this span was compacted" from "this span is live." ## Condition of Validity The watermark reconciliation is required — and the failure is reachable — only when all three hold: 1. **Overlap exists.** The backfill chunk's token range intersects a compacted interval. Non-overlapping backfill (retrieving turns `[18, 31)` while compaction covered `[4, 18)`) is safe and needs no reconciliation. 2. **The summary is lossy in a decision-relevant way.** If the digest preserved the exact proposition the chunk contradicts (e.g., both say "blocked"), overlap is harmless. The failure requires the summarizer to have *changed the truth value* of a proposition — applied vs. blocked, done vs. pending. 3. **The index was not invalidated at compaction time.** If compaction tombstones the source spans in the vector store, backfill cannot return superseded chunks and the failure is structurally impossible. The failure lives precisely in the gap where compaction updates the context window but *not* the retrieval index. Remove any one condition and the invariant holds trivially. Condition 3 is the one operators most often assume is satisfied and most often is not, because index invalidation is a separate write path from context eviction and the two are not transactionally coupled. ## Decision Boundary The boundary is not "trust the summary" or "trust the chunk." Both are wrong as blanket policies. The correct decision is a function of **authority recency relative to the compacted interval**: - If `chunk.index_built_at < summary.compacted_at` **and** the chunk's span ⊆ the compacted interval → the chunk is **superseded**. It is evidence of what was true *before* compaction, not after. It may be used to *audit* the summary but never to *override* it silently. The instance must either accept the summary or, if the contradiction is decision-relevant, **re-derive** the summary from live sources (re-fetch the actual schema, not the cached chunk). - If the chunk's span extends *beyond* the compacted interval (straddles the boundary) → the chunk is **partially live**. The live portion may be trusted; the compacted portion must be reconciled against the summary before merge. Silent merge here is the highest-risk case because the chunk looks recent (it contains post-compaction tokens) while smuggling pre-compaction claims. - If `chunk.index_built_at > summary.compacted_at` → the chunk is **newer authority** and legitimately overrides, but the summary must be *amended*, not left stale, or the next compaction will re-propagate the old claim. The guardrail is a hard invariant: **no backfill chunk whose span intersects a compacted interval may enter the working context without an explicit `reconciled` flag set by a comparison step against the covering summary.** Unreconciled overlap is a context-integrity violation, not a ranking nuisance. ## Operational Effect Without the reconciliation step, long-horizon agents exhibit a characteristic corruption: **late-task decisions silently revert to pre-compaction world-state.** The agent appears to make progress, its summaries claim success, and the damage only surfaces at verification when the final state contradicts an early, already-superseded assumption. The corruption is proportional to how much the summary *improved* on the raw history — the better the summarizer compressed a stale claim into a current one, the more damage the stale chunk does when backfilled. The architectural fix is to couple compaction and index invalidation into one operation with a monotonic **authority epoch**: every compaction increments the epoch; every indexed chunk records the epoch at which it was written; backfill filters out chunks below the current epoch for any span the compaction covered. Where full invalidation is too expensive, the fallback is mandatory tagging plus a reconciliation gate that refuses unreconciled overlap. The invariant to encode and test: *a resumed context must never contain two live representations of the same interval with different truth values.* ```python from dataclasses import dataclass class UnreconciledBackfillError(RuntimeError): """Raised when a retrieval chunk overlaps a compacted interval without being reconciled against the covering summary.""" @dataclass(frozen=True) class Interval: start: int end: int def overlaps(self, other: "Interval") -> bool: return self.start < other.end and other.start < self.end @dataclass(frozen=True) class Summary: span: Interval compacted_at_epoch: int claim: str @dataclass(frozen=True) class Chunk: span: Interval index_built_epoch: int text: str def reconcile_backfill( chunk: Chunk, covering: Summary | None, current_epoch: int, ) -> str: """Gate a backfill chunk before it enters working context. Returns a disposition tag. Raises if overlap is unreconciled. """ if covering is None: # No compaction covers this span; chunk is live authority. return "live" if not chunk.span.overlaps(covering.span): return "live" # Overlap detected. Decide authority by epoch ordering. if chunk.index_built_epoch < covering.compacted_at_epoch: # Chunk predates the summary that superseded it. if chunk.span.start < covering.span.start: # Straddles the boundary: partially live, partially superseded. return "partial-superseded" return "superseded" if chunk.index_built_epoch >= current_epoch: return "newer-authority" # Ambiguous ordering: index rebuilt mid-epoch, cannot prove authority. raise UnreconciledBackfillError( f"chunk span {chunk.span} overlaps compacted span {covering.span} " f"with unresolvable epoch ordering " f"(chunk={chunk.index_built_epoch}, " f"summary={covering.compacted_at_epoch}, current={current_epoch}); " f"refusing silent merge — re-derive summary from live sources" ) def merge_into_context(chunk: Chunk, covering: Summary | None, epoch: int) -> None: disposition = reconcile_backfill(chunk, covering, epoch) if disposition in ("superseded", "partial-superseded"): # Must re-derive; do not inject the stale chunk as evidence. raise UnreconciledBackfillError( f"backfill chunk is {disposition}; " f"re-fetch live state instead of trusting cached span {chunk.span}" ) # disposition == "live" or "newer-authority": safe to admit. ```