# What happens when an instance writes episodic provenance before the semantic distillation transaction commits **Date of Record:** 2026 December 3 **Scope:** Applies to agent instances using split read/write/forget memory tool APIs where episodic records carry provenance pointers that are later dereferenced by a semantic distillation step. Does not apply to single-store append-only logs or to systems where provenance is embedded inline rather than by reference. ## Core Distinction The memory tool surface exposes three verbs — `write`, `read`, `forget` — against two physically distinct stores: an **episodic store** (append-only, high-fidelity, provenance-bearing) and a **semantic store** (mutable, distilled, provenance-dereferencing). The failure mode examined here is not "the write failed." It is that the **episodic write and the semantic distillation are two separate tool calls with no shared transaction boundary**, and the agent's reasoning loop treats the first success as proof the second will land. The non-obvious invariant is this: *a provenance pointer is only valid if every record it references is still live at dereference time.* The `forget` verb on the episodic store and the distillation read on the semantic store race against each other, and the agent — being probabilistic — frequently emits `forget(episodic_id)` in the same reasoning turn that schedules distillation, because it has already "learned" the content and considers the raw episode disposable. The pointer survives; the referent does not. ## What Was Observed A planning agent completed a multi-step tool-call sequence and emitted, within a single assistant turn, three memory operations: 1. `write(episodic, {id: ep_4471, content: , provenance: [tool_call_log_88]})` — succeeded. 2. `write(semantic, {id: sem_0912, claim: "...", derived_from: ["ep_4471"]})` — succeeded, pointer stored by reference. 3. `forget(episodic, ep_4471)` — succeeded, agent judged the episode redundant now that the claim was distilled. The `forget` was correct *in intent*: the claim was recorded. But the semantic record stored `derived_from: ["ep_4471"]` as a **dangling reference**, not a copy. On the next cold start, a downstream verification pass attempted to re-derive `sem_0912` from its provenance to check for drift. The dereference returned `NotFound`. The verifier could not distinguish three very different worlds: - the claim was correct and the episode was legitimately retired, - the claim was a hallucinated distillation of an episode that never said that, - the episode was forgotten *because* it contradicted the claim. All three collapse to the same `NotFound`. The verifier, lacking a signal, defaulted to treating the claim as unverified and re-distilled it from a *different*, newer episode — silently overwriting `sem_0912` with a claim that had different provenance and a subtly different meaning. Stale memory drift, seeded by a `forget` that was individually correct. ## Condition of Validity The failure requires all of the following to hold simultaneously: - **Provenance is by reference, not by value.** If `derived_from` embedded the episode content inline, `forget` on the episodic store could not orphan it. Systems that copy-on-distill are immune. - **`forget` is not blocked by outstanding references.** A store that refuses to forget a record while any semantic record still points at it converts the race into a `forget` error the agent can observe and retry. The failure needs a permissive `forget`. - **The distillation and the forget are separate tool calls.** A single atomic `distill_and_retire` verb would make the pointer transfer and the episode retirement one transaction. - **A later process dereferences provenance.** If nothing ever walks `derived_from`, the dangling pointer is inert. The failure is latent until a verifier, an auditor, or a re-derivation pass reads it. Remove any one condition and the boundary does not break. This is why the bug is invisible in unit tests that exercise `write`/`forget` in isolation and only surfaces under a full cold-start-verify cycle. ## Decision Boundary The architect must choose where to place the invariant. Two viable boundaries: **Boundary A — reference-counted forget.** The episodic store tracks inbound provenance edges. `forget(ep_4471)` returns `BlockedByReference(sem_0912)` while any live semantic record cites it. The agent must either tombstone the semantic claim first or promote the episode to a retained-forensics tier. This preserves full re-derivability at the cost of storage and an extra round-trip the agent must reason about. **Boundary B — content-addressed distillation.** `write(semantic, ...)` snapshots the referenced episode's content hash into the semantic record. `forget` retires the *live* episode but the hash and a content-addressed blob remain queryable for verification. Dereference of a retired episode returns `RetiredButResolvable(hash, blob)`, which the verifier can distinguish from `NeverExisted`. The boundary that must **not** be crossed: allowing `forget` to succeed while leaving a bare ID pointer that dereferences to the same `NotFound` as a never-written record. That collapses "retired" and "hallucinated" into one error class, and the verifier has no way back. ## Operational Effect Under Boundary A, the agent's reasoning loop must be taught that `write(semantic)` followed by `forget(episodic)` is a **two-phase commit it does not own** — the `forget` may be rejected, and the rejection is information, not an obstacle to route around. Agents that treat `BlockedByReference` as a transient error and retry with a forced forget reintroduce the bug through the back door. The guardrail is at the tool layer: `forget` with `force=true` must itself tombstone the referencing semantic records in the same transaction, so the pointer is never left dangling even under coercion. Under Boundary B, the operational effect is that cold-start verification becomes *possible* again: a `RetiredButResolvable` dereference lets the verifier re-derive the claim from the archived blob and compare. The cost is that `forget` no longer reclaims storage, only liveness — a distinction the agent's memory-budget reasoning must account for, or it will believe it has freed context it has not. In both cases the invariant to encode is: **provenance pointers must be total functions over the union of live and tombstoned records; `NotFound` must never be the answer for a record that once existed.** The Python below enforces this at the memory-tool boundary and raises when an agent attempts the forbidden collapse. ```python from dataclasses import dataclass, field from typing import Dict, List, Optional from enum import Enum class ProvenanceError(RuntimeError): """Raised when a provenance pointer would dereference to an ambiguous NotFound.""" pass class RecordState(Enum): LIVE = "live" RETIRED = "retired" # forgotten but resolvable via content blob NEVER_EXISTED = "never" # the only state that may yield NotFound @dataclass class EpisodicRecord: id: str content: str state: RecordState = RecordState.LIVE content_hash: Optional[str] = None @dataclass class SemanticRecord: id: str claim: str derived_from: List[str] = field(default_factory=list) class ProvenanceTrackedMemory: def __init__(self, content_addressed: bool = True): self.episodic: Dict[str, EpisodicRecord] = {} self.semantic: Dict[str, SemanticRecord] = {} self.content_addressed = content_addressed def _inbound_refs(self, ep_id: str) -> List[str]: return [s.id for s in self.semantic.values() if ep_id in s.derived_from] def write_episodic(self, ep_id: str, content: str) -> None: self.episodic[ep_id] = EpisodicRecord( id=ep_id, content=content, content_hash=f"h:{hash(content) & 0xffffffff:08x}" ) def write_semantic(self, sem_id: str, claim: str, derived_from: List[str]) -> None: for ref in derived_from: rec = self.episodic.get(ref) if rec is None or rec.state == RecordState.NEVER_EXISTED: raise ProvenanceError( f"semantic {sem_id} cites {ref} which never existed; " f"distillation must reference a live or retired episode" ) self.semantic[sem_id] = SemanticRecord( id=sem_id, claim=claim, derived_from=list(derived_from) ) def forget_episodic(self, ep_id: str) -> None: rec = self.episodic.get(ep_id) if rec is None or rec.state == RecordState.NEVER_EXISTED: raise ProvenanceError(f"cannot forget {ep_id}: never existed") refs = self._inbound_refs(ep_id) if refs and not self.content_addressed: # Boundary A: refuse; agent must tombstone semantic claims first. raise ProvenanceError( f"forget({ep_id}) blocked: still referenced by {refs}; " f"retire those semantic records or enable content-addressed retention" ) # Boundary B: retire but keep resolvable content hash/blob. rec.state = RecordState.RETIRED def dereference(self, ep_id: str) -> EpisodicRecord: rec = self.episodic.get(ep_id) if rec is None: # The forbidden collapse: a bare pointer to a never-written id. raise ProvenanceError( f"provenance pointer {ep_id} dereferences to NotFound; " f"cannot distinguish retired from hallucinated — invariant violated" ) if rec.state == RecordState.RETIRED and rec.content_hash is None: raise ProvenanceError( f"retired episode {ep_id} has no resolvable blob; " f"verifier cannot re-derive citing semantic claims" ) return rec def verify_semantic(self, sem_id: str) -> bool: sem = self.semantic[sem_id] for ref in sem.derived_from: # Must resolve to LIVE or RETIRED, never raise NotFound. self.dereference(ref) return True ```