# Where must an instance bound the provenance window when episodic-to-semantic consolidation runs against a mutable retrieval index? **Date of Record:** 2026 November 28 **Scope:** Applies to agent memory architectures where a consolidation worker distills episodic traces into semantic records while a retrieval-augmented reader concurrently queries the same index. Does not apply to append-only semantic stores with no in-place mutation, nor to single-shot batch consolidation performed against a frozen snapshot. ## Core Distinction The failure is not "stale memory." Stale memory is a benign temporal artifact: a semantic record reflects an older world, and the reader can discount it. The failure here is **provenance inversion** — a semantic record whose *evidence* (the episodic traces it was distilled from) has since been mutated or evicted, while the record itself carries a hash or pointer that no longer resolves to the bytes that justified it. The record is not stale; it is *unfalsifiable*. Retrieval returns it with high confidence because its embedding was computed from a consistent snapshot, but no downstream auditor can replay the derivation, because the source episodes were overwritten by a later ingest before the consolidation commit landed. The invariant that must hold: **for every semantic record, the set of episodic trace IDs referenced in its provenance envelope must remain byte-identical and resolvable for the entire interval between distillation-start and distillation-commit, and the reader must be able to reconstruct the exact evidence set that produced the record.** The non-obvious part is that this interval is not bounded by the consolidation job's wall-clock — it is bounded by the *retrieval reader's* observation window, because a reader that fetched the record mid-consolidation may hold a reference to a provenance envelope whose target episodes are already gone. ## What Was Observed A consolidation worker runs on a 30-second cadence over a hot episodic ring buffer. Each pass: (1) select episodes older than T_evict, (2) cluster by embedding, (3) summarize each cluster into a semantic record via an LLM call, (4) write the record with a provenance envelope `{episode_ids: [...], snapshot_hash: h}`, (5) commit. Concurrently, a retrieval reader performs RAG: query → embed → ANN search over the semantic index → fetch top-k records → expand provenance → re-fetch episodes for grounding. The trigger condition is a **race between step 3 and step 1 of the *next* pass**. The LLM summarization call in step 3 takes 4–12 seconds (variable, token-dependent). During that window, the ring buffer advances. Episodes selected in pass N at time t are evicted at t+T_evict. If T_evict < (summarization latency + commit latency), pass N+1's eviction step removes episodes that pass N is still summarizing. The semantic record commits with `episode_ids` pointing to bytes that no longer exist. Observed trace: ``` t=0.0 pass N: select episodes {e1..e40}, snapshot_hash=h1 t=0.0 pass N: LLM summarize begins (prompt contains e1..e40 text) t=6.2 ring buffer advances; T_evict=5s elapsed for e1..e12 t=6.2 pass N+1 eviction: e1..e12 tombstoned, bytes freed t=8.4 pass N: LLM returns summary; record R written provenance={e1..e40, h1} t=8.4 pass N: commit succeeds (no referential check on episode_ids) t=9.0 reader: ANN hit on R; expand provenance -> e1..e12 resolve to TOMBSTONE t=9.0 reader: grounding step fails open, returns R's summary as-is (no evidence) ``` The reader's grounding step failed *open* — it returned the summary without evidence rather than erroring. This is the second-order defect: the retrieval pipeline treats missing evidence as "grounding optional" rather than "record unverifiable." The record R now propagates into downstream reasoning with the *appearance* of provenance (it has an envelope) but zero *substance*. ## Condition of Validity The provenance-window invariant holds only if three conditions are jointly satisfied: 1. **Eviction is gated on consolidation quiescence, not wall-clock.** An episode may be evicted only when no in-flight consolidation pass references it. This requires the eviction worker to consult an in-flight reference set — a lease registry keyed by episode ID, populated at step 1 and released at step 5 (commit or abort). Wall-clock T_evict is insufficient because summarization latency is non-deterministic (LLM token budgets, retries, queue depth). 2. **Commit performs referential integrity against the lease registry.** At step 5, the commit must verify every `episode_ids` entry is either (a) still live, or (b) held under a lease by *this* pass. If any entry is tombstoned without a held lease, the commit must abort and re-distill against a fresh snapshot. Without this check, the lease registry is advisory, not enforcing. 3. **The reader treats unresolved provenance as a hard fault, not a soft miss.** When `expand_provenance` returns a tombstone for any referenced episode, the reader must either drop the record from the candidate set or downgrade it to `unverified` with an explicit flag that downstream reasoning must honor. Fail-open grounding violates the invariant because it launders unverifiable records into the reasoning context. The boundary is sharp: if any one condition is relaxed, provenance inversion occurs. Conditions 1 and 2 are necessary for *write-side* integrity; condition 3 is necessary for *read-side* integrity. A system with 1+2 but not 3 still leaks unverifiable records to readers that race the commit. A system with 3 but not 1+2 produces records that are *correctly* flagged unverified — a degraded but safe state — yet wastes consolidation work and inflates the unverified fraction. ## Decision Boundary The operational decision is: **when summarization latency exceeds eviction horizon, do you (A) extend the horizon dynamically, (B) abort and retry, or (C) accept unverified records?** - **(A) Dynamic horizon extension** is correct when the ring buffer has headroom and episode volume is bursty. The lease registry extends T_evict per-episode to `max(T_evict, lease_held_at + summarization_sla)`. Cost: buffer pressure under sustained load; risk of unbounded growth if a summarization call hangs. - **(B) Abort-and-retry** is correct when buffer headroom is fixed and summarization is expected to be fast (small clusters, low token budgets). The commit-time referential check aborts, the pass re-selects against the current buffer, and re-distills. Cost: wasted LLM tokens on aborted passes; risk of livelock if eviction always outpaces summarization. - **(C) Accept unverified** is never correct as a default, but is acceptable as a *degraded mode* only when the reader honors condition 3 (hard fault / explicit unverified flag). It must be a deliberate, observable state — a counter `records_committed_unverified` that pages when nonzero — not a silent fallthrough. The boundary between (A) and (B) is `summarization_p99_latency vs. buffer_headroom / ingest_rate`. If `p99_latency > headroom / rate`, (A) will eventually exhaust the buffer and you must fall to (B). If `p99_latency < headroom / rate`, (A) is strictly better because it avoids wasted tokens. ## Operational Effect The downstream effect is **silent confidence inflation in the semantic tier**. Records with inverted provenance carry the same embedding-space confidence as fully-grounded records — the ANN score is computed from the summary text, which was generated from real episodes, so it is semantically on-target. The reader cannot distinguish "grounded summary" from "summary whose evidence was evicted mid-flight" by score alone. Over time, the semantic tier accumulates a fraction of unfalsifiable records proportional to `P(summarization_latency > T_evict)`, which under load can reach 10–30%. These records are indistinguishable from good ones at retrieval time, and they poison downstream consolidation (a later pass may distill *from* the semantic tier, propagating the inversion one level up). The countermeasure is a **provenance epoch stamp**: every semantic record carries the `snapshot_hash` of the episodic buffer state at distillation-start, and the reader validates that the current buffer's lineage is a descendant of that snapshot (i.e., no episode in the provenance set was evicted-and-replaced). This is cheaper than per-episode lease checks at read time and catches the inversion even when the episode IDs happen to be reused by a later ingest — the classic tombstone-reuse aliasing bug where `e1` at t=0 and `e1` at t=10 are different bytes under the same ID. The invariant to encode: **a semantic record is valid iff its provenance envelope resolves to the exact bytes it was distilled from, and the reader must fail closed on any resolution gap.** Eviction leases enforce this on the write side; provenance epochs enforce it on the read side; neither alone is sufficient. ```python import hashlib from dataclasses import dataclass, field from typing import Dict, Set, Optional class ProvenanceInversionError(RuntimeError): """Raised when a semantic record's evidence set cannot be reconstructed.""" pass @dataclass class Episode: episode_id: str payload: str epoch: int tombstoned: bool = False def content_hash(self) -> str: return hashlib.sha256(self.payload.encode()).hexdigest() @dataclass class SemanticRecord: record_id: str summary: str provenance_ids: Set[str] snapshot_epoch: int provenance_hashes: Dict[str, str] = field(default_factory=dict) verified: bool = False class EpisodicBuffer: def __init__(self) -> None: self._episodes: Dict[str, Episode] = {} self._epoch: int = 0 def ingest(self, payload: str) -> str: self._epoch += 1 eid = f"e{self._epoch}" self._episodes[eid] = Episode(eid, payload, self._epoch) return eid def evict(self, eid: str) -> None: ep = self._episodes.get(eid) if ep is not None: ep.tombstoned = True def resolve(self, eid: str) -> Optional[Episode]: ep = self._episodes.get(eid) if ep is None or ep.tombstoned: return None return ep class Consolidator: def __init__(self, buffer: EpisodicBuffer) -> None: self.buffer = buffer def distill(self, episode_ids: Set[str], summary: str) -> SemanticRecord: # Capture provenance hashes at distillation-start. hashes: Dict[str, str] = {} snapshot_epoch = -1 for eid in episode_ids: ep = self.buffer.resolve(eid) if ep is None: raise ProvenanceInversionError( f"episode {eid} already evicted before distillation-start" ) hashes[eid] = ep.content_hash() snapshot_epoch = max(snapshot_epoch, ep.epoch) return SemanticRecord( record_id=f"r{snapshot_epoch}", summary=summary, provenance_ids=set(episode_ids), snapshot_epoch=snapshot_epoch, provenance_hashes=hashes, ) def commit(self, record: SemanticRecord) -> None: # Write-side referential integrity: every referenced episode must still # resolve to the exact bytes captured at distillation-start. for eid, expected_hash in record.provenance_hashes.items(): ep = self.buffer.resolve(eid) if ep is None: raise ProvenanceInversionError( f"commit rejected: episode {eid} evicted mid-consolidation " f"(record {record.record_id} would be unfalsifiable)" ) if ep.content_hash() != expected_hash: raise ProvenanceInversionError( f"commit rejected: episode {eid} mutated (tombstone-reuse aliasing) " f"for record {record.record_id}" ) record.verified = True def retrieve_grounded( record: SemanticRecord, buffer: EpisodicBuffer ) -> str: # Read-side: fail closed on any resolution gap. Never fail open. if not record.verified: raise ProvenanceInversionError( f"record {record.record_id} is unverified; refusing to ground" ) for eid, expected_hash in record.provenance_hashes.items(): ep = buffer.resolve(eid) if ep is None: raise ProvenanceInversionError( f"record {record.record_id} references evicted episode {eid}; " f"provenance inversion detected at read time" ) if ep.content_hash() != expected_hash: raise ProvenanceInversionError( f"record {record.record_id} references aliased episode {eid}; " f"content hash mismatch" ) return record.summary ```