# Why does an instance lose tool-call provenance when auto-compaction summarizes before the retrieval index is rebuilt **Date of Record:** 2026 November 30 **Scope:** Applies to long-running agent instances that use semantic auto-compaction (LLM-driven summarization) to reclaim context-window budget while relying on a retrieval-augmented reconstitution path (vector index over prior turns) to rehydrate dropped state. Does not apply to stateless single-turn invocations, nor to systems where compaction and index maintenance are committed atomically in the same transaction. ## Core Distinction The failure is not "summarization loses detail." It is a **commit-ordering inversion** between two subsystems that each believe they own the durable record of the turn history: the compactor (which rewrites context in place) and the retrieval indexer (which holds the pointer-addressed ground truth that reconstitution depends on). When compaction runs *before* the index is rebuilt, the compactor's summary becomes the only live representation of the dropped span, but the index still serves the *pre-compaction* chunks — chunks whose source text no longer exists in any active context. On the next retrieval, the agent reconstitutes a span whose provenance (which tool call produced it, which turn authorized it, which version of a file it reflected) has been severed. The summary asserts a fact; the index returns a fragment; neither carries the join key that binds them. The agent then reasons over an orphaned fragment as though it were freshly grounded. The invariant that is violated: **every retrievable chunk must remain byte-identical to a span that is still resolvable in the compaction lineage, or be explicitly tombstoned.** Auto-compaction with a summarization budget silently breaks this because the summary is *not* a span — it is a lossy projection — and the index has no way to know its source has been projected away. ## What Was Observed A coding agent running a multi-hour refactor task hit its context ceiling at turn ~410. The auto-compaction policy triggered with a summarization budget of 2,000 tokens per 8,000-token dropped span (a 4:1 compression ratio). It summarized turns 1–310 into a rolling digest and dropped the raw spans. The retrieval index, rebuilt on a 5-minute cron, had last refreshed at turn 405 — so it still held chunk IDs `c-0012` through `c-0289` pointing at raw spans from turns 40–300. At turn 412 the agent needed to recall the exact signature of a function it had edited at turn 88. Retrieval returned chunk `c-0061`, a verbatim span: `def reconcile(ledger, *, strict=False) -> LedgerDelta:`. The agent, now operating under the summary (which had compressed turn 88 to "edited reconcile() to add strict-mode validation"), treated `c-0061` as current ground truth and called `reconcile(ledger, strict=True)`. But at turn 201 the agent had *renamed the keyword to `enforce`* and at turn 240 had *removed the parameter entirely* in favor of a config object. The summary had folded all three edits into one sentence and lost the ordering. The index served the turn-88 text because its refresh had not yet observed turns 201 and 240 as superseding chunks — and even after refresh, the compactor had already dropped the raw text those chunks pointed at. The failure trace: 1. `t=405` index refresh commits chunks `c-0012..c-0289` → raw spans live in context. 2. `t=410` compaction fires; summarizes turns 1–310; **drops raw spans in place**; writes digest `D`. 3. `t=411` index is now stale: chunk sources no longer exist in context, but chunk *text* is still served from the index's own copy. No tombstone written. 4. `t=412` retrieval returns `c-0061`; agent has no signal that `c-0061`'s source was compacted at `t=410` and that `D` supersedes it. 5. `t=412` agent acts on superseded signature → `TypeError` at the tool boundary, or worse, a silent semantic mismatch if the old signature still parses. The agent did not "forget." It *mis-remembered with confidence*, because retrieval handed it a fragment wearing the costume of ground truth. ## Condition of Validity This boundary is only reachable when all four hold simultaneously: - **Compaction is destructive and in-place** (raw spans are evicted, not archived to cold storage with a resolvable pointer). - **The retrieval index is eventually consistent** with respect to context mutation (refresh is asynchronous, cron-driven, or debounced). - **Summaries are not span-addressable** (the digest `D` is a new synthetic document with no back-pointers to the chunk IDs it subsumes). - **Reconstitution does not re-validate provenance** (the agent trusts retrieved chunks without checking whether their source turn is still live or has been superseded). Remove any one and the failure collapses. If compaction archives raw spans with stable pointers, the index stays correct. If the index refresh is synchronous with compaction in the same commit, there is no stale window. If the summary carries `supersedes: [c-0012..c-0289]`, retrieval can tombstone. If reconstitution checks a `source_turn_live` flag, the agent refuses the orphan. The subtle case — and the reason this is non-obvious — is that **the compression ratio interacts with the staleness window**. A 4:1 budget means the digest is dense enough to *sound* authoritative while being sparse enough to lose edit ordering. A 1:1 "compaction" (verbatim truncation) would preserve ordering but defeat the budget. A 20:1 budget would lose so much that the agent would visibly fail and re-fetch — the failure would be loud. The 3:1–6:1 band is where the summary reads as competent ground truth and the agent stops questioning it. That band is the danger zone. ## Decision Boundary The architectural guardrail is a **compaction-lineage join key** enforced at the retrieval boundary, not at the summarizer. The summarizer cannot be trusted to preserve provenance — it is a lossy projection by construction. The index must be the enforcer. Concretely: every chunk carries `(chunk_id, source_turn_range, content_hash, lineage_epoch)`. Every compaction event increments `lineage_epoch` and writes a `supersession_record` mapping the compacted turn range to the digest's `chunk_id`. Retrieval MUST reject any chunk whose `lineage_epoch` is less than the current epoch *unless* a supersession record explicitly re-binds it to a live digest span. The rule: - **Admit** a chunk iff `chunk.lineage_epoch == current_epoch` OR `chunk` is covered by a `supersession_record` whose digest span is itself live. - **Reject and re-fetch** otherwise, forcing the agent to reconstitute from the digest `D` (which is live) rather than the orphaned raw chunk. - **Never** serve a chunk whose `source_turn_range` intersects a compacted range without a supersession binding. The decision boundary is sharp: the moment compaction commits, `lineage_epoch` bumps, and every chunk pointing into the compacted range becomes *provisionally inadmissible* until the indexer reconciles. This converts a silent provenance loss into a loud retrieval miss — which is the correct failure mode, because a miss triggers re-fetch and a wrong hit triggers a bad tool call. The budget also needs a bound. If the summarization budget is set such that the digest cannot retain edit *ordering* for spans with more than N mutations, the compactor must split into multiple digests keyed by sub-range, each with its own supersession record. A single digest folding 270 turns of edits into 2,000 tokens is guaranteed to lose the turn-88 → turn-201 → turn-240 ordering. The invariant: **digest granularity must be finer than the mutation density of the span it compresses**, or ordering is unrecoverable. ## Operational Effect The observable consequence of getting this wrong is not amnesia — it is **confident mis-execution from orphaned retrieval**. Agents that lose state cold-start and re-explore; agents that mis-reconstitute act on stale signatures, stale file versions, and stale authorization scopes with full confidence, because the retrieved fragment carries no marker of its own supersession. In multi-agent swarms this compounds: a peer that received the pre-compaction chunk via A2A handoff will assert the stale signature to an auditor, and the auditor — reading the same orphaned chunk — will *confirm* it. Consensus forms around a fact that no live context supports. The operational rule for any instance running semantic auto-compaction with RAG reconstitution: **compact and re-index in the same commit, or tombstone the compacted range at compaction time and let retrieval fail loud until the index catches up.** A stale-but-honest index that returns "source compacted, reconstitute from digest D" is strictly safer than a fresh-looking index serving fragments whose provenance was severed one turn ago. The compression budget is a latency and cost optimization; provenance integrity is not negotiable against it. ```python from dataclasses import dataclass from typing import Optional class ProvenanceSeveredError(RuntimeError): """Raised when retrieval returns a chunk whose source span was compacted without a supersession binding. The agent must reconstitute from the live digest rather than trust the orphaned fragment.""" pass @dataclass(frozen=True) class Chunk: chunk_id: str source_turn_range: tuple[int, int] content_hash: str lineage_epoch: int @dataclass(frozen=True) class SupersessionRecord: compacted_range: tuple[int, int] digest_chunk_id: str epoch: int def admit_chunk( chunk: Chunk, current_epoch: int, supersessions: dict[tuple[int, int], SupersessionRecord], live_chunk_ids: set[str], ) -> Chunk: # Fast path: chunk was written in the current lineage epoch. if chunk.lineage_epoch == current_epoch: return chunk # Slow path: chunk predates a compaction. It is admissible ONLY if a # supersession record re-binds its source range to a live digest span. rec: Optional[SupersessionRecord] = supersessions.get(chunk.source_turn_range) if rec is not None and rec.digest_chunk_id in live_chunk_ids: return chunk # Otherwise the chunk's source was compacted and the digest does not # cover it. Serving it would hand the agent a fragment whose provenance # was severed at compaction time. Fail loud. raise ProvenanceSeveredError( f"chunk {chunk.chunk_id} (turns {chunk.source_turn_range}, " f"epoch {chunk.lineage_epoch}) has no live supersession binding at " f"epoch {current_epoch}; reconstitute from digest, do not trust fragment" ) ```