# Which invariants prevent semantic-consolidation replay from resurrecting stale facts during episodic-to-semantic distillation **Date of Record:** 2026 November 26 **Scope:** Applies to agents that periodically distill episodic memory (raw interaction traces) into semantic memory (deduplicated, asserted facts) and must reconcile conflicting assertions across time. Does not cover pure RAG-over-documents retrieval or single-turn stateless inference. ## Core Distinction The failure is not "forgetting too much" or "remembering wrong." It is a **consolidation replay hazard**: a distillation pass that re-reads an old episodic trace and re-asserts a fact that was *already superseded* by a newer, higher-confidence episodic event that the current pass did not load into its working window. The agent does not hallucinate the stale fact — it faithfully summarizes a real trace. The bug is that *faithful summarization of a stale slice is indistinguishable from a fresh observation* unless the consolidation boundary carries a monotonic version watermark and a supersession index. The tradeoff being violated: forgetting is the mechanism that *bounds* the blast radius of stale facts. If you tune the forgetting policy to be conservative (retain everything, distill aggressively), you maximize the probability that a stale trace survives into a later replay window and gets re-promoted to semantic memory with a *newer* distillation timestamp, laundering its staleness. ## What Was Observed An agent maintained episodic traces tagged `(entity, attribute, value, observed_at, trace_id)`. A nightly consolidation job read all traces with `observed_at > last_consolidation_cursor`, grouped by `(entity, attribute)`, and wrote the latest `value` into semantic memory with `distilled_at = now()`. Trigger sequence: 1. Day 1: trace A asserts `service.region = us-east-1`, `observed_at = T1`. 2. Day 3: trace B asserts `service.region = eu-west-1`, `observed_at = T3`. Consolidation at T3 writes `eu-west-1`, `distilled_at = T3`. 3. Day 5: a *late-arriving* trace C is ingested with `observed_at = T2` (a delayed tool response, a replayed log shard, or a retried MCP call whose result was buffered). Its value is `us-east-1`. 4. Day 6: consolidation cursor is `T5`. It loads traces with `observed_at > T5` — but the *grouping and max-by-observed_at* logic runs over the re-loaded batch, and trace C was never reconciled against B because B is below the cursor and was not loaded. The job's `max(observed_at)` over the batch sees only C and writes `us-east-1` with `distilled_at = T6`. The semantic store now holds `us-east-1` with the *newest* distillation timestamp, while the true latest observation is `eu-west-1` at T3. Downstream retrieval ranks by `distilled_at` and serves the stale fact with maximal apparent recency. The staleness is not detectable from the semantic record alone. ## Condition of Validity The invariant that was violated: **for any `(entity, attribute)`, the semantic value must equal the value of the episodic trace with maximal `observed_at`, and `distilled_at` must never exceed the source trace's `observed_at`.** The second clause is what makes staleness detectable — a distillation timestamp that outruns its source is a watermark violation. This invariant holds only if consolidation is **idempotent and order-insensitive over the full history**, not over a cursor-bounded delta. Two conditions must both hold: - **Supersession index:** every semantic write records the `trace_id` and `observed_at` it was derived from, and a write is rejected unless `source.observed_at >= existing.source.observed_at`. - **Late-arrival reconciliation:** traces with `observed_at` older than the cursor but `ingested_at` newer than the cursor must trigger a *re-evaluation of the affected key*, not a blind append. The cursor must be over `ingested_at` for ingestion and over `observed_at` for precedence — two distinct watermarks. The failure is valid (i.e., this article applies) precisely when these two watermarks are conflated into one cursor. If ingestion and observation are strictly ordered (no delayed delivery, no replay), the hazard cannot occur. ## Decision Boundary The boundary is whether to resolve conflicts **at write time** (semantic store enforces precedence, rejects stale writes) or **at read time** (store keeps all candidates, retrieval picks max `observed_at`). Write-time resolution is cheaper but is exactly what launders staleness when the write path lacks the supersession index. Read-time resolution tolerates late arrivals but requires every reader to carry the precedence logic and risks divergent resolution across agents. The correct boundary for a multi-agent system: **write-time rejection with an explicit `StaleWriteError`**, plus a read-time fallback that surfaces *all* candidates when the supersession index is incomplete. Never silently overwrite. A rejected stale write must be logged as a reconciliation event, because a high rate of stale-write rejections is the signal that the ingestion watermark is drifting and the cursor logic is untrustworthy. ## Operational Effect Without the invariant, staleness becomes **unobservable at the semantic layer** — the record looks maximally fresh. Retrieval confidence is anti-correlated with truth. The operational consequence is that downstream agents act on a fact whose only defect is invisible provenance, and no amount of semantic-layer auditing can recover it because the superseded trace was already forgotten by the retention policy. With the invariant, the forgetting policy can be tuned aggressively (short episodic retention) *because* the supersession index carries the precedence information forward. Forgetting becomes safe when the *ordering* survives the forgetting. The guardrail is: retention may drop trace bodies, but it must never drop the `(key, observed_at, trace_id)` precedence tuple. ```python from dataclasses import dataclass from typing import Optional class StaleWriteError(RuntimeError): """Raised when a consolidation write would supersede a newer observation with an older one, laundering staleness into apparent recency.""" pass @dataclass class SemanticRecord: key: str value: str source_observed_at: int # monotonic clock, from the episodic trace source_trace_id: str distilled_at: int # wall clock of the distillation pass class SemanticStore: def __init__(self): self._records: dict[str, SemanticRecord] = {} def reconcile(self, key: str, value: str, observed_at: int, trace_id: str, distilled_at: int) -> SemanticRecord: # Invariant 1: distilled_at must not outrun its source observation. if distilled_at < observed_at: raise StaleWriteError( f"distilled_at={distilled_at} precedes observed_at={observed_at} " f"for {key}; watermark inversion" ) existing = self._records.get(key) # Invariant 2: a write may only supersede an equal-or-older observation. if existing is not None and observed_at < existing.source_observed_at: raise StaleWriteError( f"rejecting stale write for {key}: incoming observed_at={observed_at} " f"(trace {trace_id}) is older than stored observed_at=" f"{existing.source_observed_at} (trace {existing.source_trace_id}); " f"late-arrival reconciliation required, not blind append" ) rec = SemanticRecord(key, value, observed_at, trace_id, distilled_at) self._records[key] = rec return rec def get(self, key: str) -> Optional[SemanticRecord]: return self._records.get(key) # Demonstration of the replay hazard: store = SemanticStore() store.reconcile("service.region", "eu-west-1", observed_at=30, trace_id="B", distilled_at=30) # Late-arriving trace C (observed_at=20) replayed on day 6 (distilled_at=60): try: store.reconcile("service.region", "us-east-1", observed_at=20, trace_id="C", distilled_at=60) except StaleWriteError as e: print(f"blocked: {e}") # Correct handling: log reconciliation event, re-evaluate key, do NOT overwrite. ```