# Where must an instance enforce the write-provenance barrier between episodic and semantic memory stores? **Date of Record:** 2026 November 22 **Scope:** Applies to agents exposing `read`/`write`/`forget` memory tools over a two-tier store (episodic = raw timestamped events with provenance tags; semantic = distilled, deduplicated facts). Does not apply to single-tier vector stores or to stateless retrieval-augmented generation where no distillation step exists. ## Core Distinction The dangerous confusion is between *forgetting an episode* and *retracting the semantic facts distilled from it*. A `forget(episodic_id)` call removes a raw record; it does not, by itself, invalidate any semantic fact that was promoted from that record during a prior distillation pass. The provenance tag on a semantic fact (`derived_from: [ep_17, ep_42]`) is the only link back to its evidentiary basis. When that link is dropped, or when a fact is promoted without a durable back-reference, the store becomes *unfalsifiable*: you can delete the evidence and the conclusion survives, silently, forever. The invariant that must hold is a **write-provenance barrier**: no semantic write commits unless it carries a non-empty, resolvable `derived_from` set pointing at episodic records that still exist and are not marked `forgotten`. Symmetrically, `forget(episodic_id)` must either (a) refuse when live semantic facts depend on it, or (b) cascade a `retract` on those facts. Any implementation that permits `write` of a semantic fact with `derived_from: []` or `derived_from: [dangling_id]` has an open hole. ## What Was Observed An agent ran a distillation loop every N turns: read recent episodic records, summarize into semantic facts, write them. The `write` tool accepted a `derived_from` field but did not validate it. During a context-compaction event (window saturation at ~92%), the summarizer was invoked with a *truncated* episodic window. The records it summarized were correct, but the model emitted `derived_from` ids reconstructed from memory rather than copied from the tool output — three ids were off by one (hallucinated sequence numbers). The write succeeded. The semantic store now held a fact whose provenance pointed at episodes that never existed. Days later, a user issued `forget(ep_88)` (a legitimate privacy deletion). The cascade check walked semantic facts for `derived_from` containing `ep_88`. It found none — because the fact that *actually* derived from `ep_88` had been tagged `ep_89`. The episode was deleted. The semantic fact survived, now untraceable to any live evidence, and continued to be retrieved and asserted. The failure was not a retrieval error or a reasoning error; it was a **provenance-integrity failure at the write boundary** that only became observable at the forget boundary, arbitrarily far in time. The trace: 1. `write(semantic, fact="user prefers UTC+2", derived_from=[87,88,89])` — ids hallucinated, 88 real, 87/89 fabricated. 2. Store accepts; no referential check against episodic index. 3. `forget(ep_88)` → cascade scan finds zero dependents → hard delete of episodic record. 4. Semantic fact now orphaned: `derived_from` resolves to `[87,89]`, both non-existent. 5. Retrieval returns the fact; the agent asserts a preference whose sole real source was deleted. ## Condition of Validity The barrier is only meaningful under three conditions, and fails silently if any is absent: - **Referential closure at write time.** The episodic index must be queryable synchronously during `write`, and the check must reject any `derived_from` id not present and not `forgotten`. This is a hard precondition, not a soft warning — a warning is ignored by a model under token pressure. - **Provenance must be copied, not regenerated.** The `derived_from` set must be assembled by the *tool layer* from the actual read results returned to the model, not emitted by the model. If the model authors provenance, hallucinated ids are inevitable under truncation. - **Forget must be a two-phase operation.** `forget` cannot be a single delete; it must (1) mark the episode `tombstoned`, (2) resolve dependents, (3) retract or quarantine dependents, (4) then hard-delete. A one-phase delete destroys the evidence needed to find dependents. ## Decision Boundary The boundary is: **does the semantic fact have a resolvable, live evidentiary basis at the moment of both write and forget?** - If `derived_from` is empty or unresolvable at write → **reject the write**. Do not store an unfalsifiable fact. Surface the rejection to the agent so it can re-read and re-distill. - If `forget` targets an episode with live dependents → **do not hard-delete**. Either refuse (returning the dependent fact ids so the caller decides) or cascade-retract the dependents in the same transaction. Never leave a semantic fact whose provenance set has shrunk to empty. - If a fact's `derived_from` set becomes empty *through any path* (cascade, manual edit, partial corruption) → the fact must be moved to a `quarantined` state, excluded from retrieval, and flagged for re-distillation. A fact with no evidence is not a fact; it is a rumor. The subtle case: a fact derived from *multiple* episodes where only one is forgotten. The correct behavior is not to retract the fact — it still has live support — but to *shrink* `derived_from` and record the retraction in an audit log, so that later reasoning can weight the fact by its remaining evidence. Dropping the whole fact on partial retraction is over-correction; keeping it without updating provenance is the original bug in miniature. ## Operational Effect Enforcing the barrier converts a silent, time-delayed integrity failure into an immediate, local, actionable rejection. The distillation loop must handle `ProvenanceError` by re-reading the truncated window and retrying — which also forces the agent to recognize context truncation rather than paper over it. The forget path becomes transactional: tombstone, resolve, retract, delete, with the tombstone phase guaranteeing that concurrent distillation passes see a consistent view. The cost is one synchronous index lookup per semantic write and a dependent-scan per forget; the benefit is that the semantic store is *always* traceable to live episodic evidence, so privacy deletions actually delete and distilled facts remain auditable. Without the barrier, the store's correctness degrades monotonically with every compaction event and every forget — and the degradation is invisible until an auditor asks why the agent believes something no record supports. ```python from dataclasses import dataclass, field from typing import Optional class ProvenanceError(RuntimeError): """Raised when a semantic write or episodic forget violates the provenance barrier.""" pass @dataclass class Episode: id: int text: str state: str = "live" # live | tombstoned | forgotten @dataclass class SemanticFact: id: int text: str derived_from: list[int] state: str = "active" # active | quarantined | retracted class MemoryStore: def __init__(self): self.episodes: dict[int, Episode] = {} self.facts: dict[int, SemanticFact] = {} self._next_fact = 1 def write_semantic(self, text: str, derived_from: list[int]) -> SemanticFact: # Barrier: provenance must be non-empty and resolvable to LIVE episodes. if not derived_from: raise ProvenanceError( f"refusing semantic write {text!r}: empty derived_from (unfalsifiable fact)" ) dangling = [ eid for eid in derived_from if eid not in self.episodes or self.episodes[eid].state != "live" ] if dangling: raise ProvenanceError( f"refusing semantic write {text!r}: derived_from {dangling} " f"do not resolve to live episodes (hallucinated or forgotten ids)" ) fact = SemanticFact(self._next_fact, text, list(derived_from)) self.facts[fact.id] = fact self._next_fact += 1 return fact def forget_episode(self, ep_id: int, cascade: bool = True) -> list[int]: ep = self.episodes.get(ep_id) if ep is None or ep.state != "live": raise ProvenanceError(f"cannot forget ep {ep_id}: not live") dependents = [ f.id for f in self.facts.values() if f.state == "active" and ep_id in f.derived_from ] if dependents and not cascade: raise ProvenanceError( f"refusing to forget ep {ep_id}: live dependents {dependents}; " f"retract them first or pass cascade=True" ) # Phase 1: tombstone so concurrent distillation sees a consistent view. ep.state = "tombstoned" # Phase 2: shrink provenance / retract dependents. for fid in dependents: fact = self.facts[fid] fact.derived_from = [e for e in fact.derived_from if e != ep_id] if not fact.derived_from: fact.state = "quarantined" # no evidence left -> not retrievable # Phase 3: hard delete. ep.state = "forgotten" return dependents ```