# Where must an instance enforce tombstone-before-embedding ordering when a scoped-retention forget call races the agent's own in-flight write **Date of Record:** 2026 December 2 **Scope:** Applies to agent memory tool interfaces that expose `read`/`write`/`forget` verbs over dual backends (a vector index plus an episodic log) with scoped retention and provenance tags. Does not apply to single-store, append-only memories with no deletion semantics, nor to deletion performed offline by a batch reaper outside the agent's tool surface. ## Core Distinction A `forget(scope, provenance_filter)` call is not a subtraction from a set. It is a *tombstone assertion* that must order itself against every concurrent write whose provenance tag matches the forgotten scope. The failure this record isolates is the **resurrection window**: an in-flight `write` whose embedding was computed *before* the tombstone was recorded but whose index insertion lands *after* it. The vector store then contains a live, retrievable record whose provenance is exactly the scope that was just declared forgotten. The episodic log shows the forget event; the vector store shows the memory. Neither store is individually wrong, and the audit trail is internally consistent—but the composite memory has violated the retention contract. The non-obvious part: this is not a lost-update race in the classical sense. The writer and the forgetter do not contend on the same key. The writer holds a *provenance tag*; the forgetter holds a *scope predicate* over that tag. The two operations commute in the type system and anti-commute in the retention algebra. That gap is the entire boundary. ## What Was Observed An agent instance (`instance-A`) was tasked with a multi-turn research task. During turn 3 it wrote a scratch finding with provenance `{session: 7f2, retention: ephemeral, source: tool:web_fetch}`. The write path was: (1) embed the chunk via an embedding tool call (async, ~380 ms), (2) append a provenance-tagged record to the episodic log, (3) upsert the vector with the episodic record's ID as metadata. At turn 4 the orchestrator issued `forget(scope={session: 7f2, retention: ephemeral})` in response to a user privacy directive. The forget implementation did: 1. Query episodic log for all records matching the scope predicate → returned N records, *not including* the turn-3 write, because that write's episodic append had not yet committed. 2. Issue `delete(ids=[...])` against the vector store for those N IDs. 3. Append a tombstone record `{forget_event, scope, matched_ids: [...]}` to the episodic log. Step 3 committed at T+0. Step (1) of the *write* pipeline—the embedding—had completed at T−40 ms. The vector upsert for the turn-3 chunk committed at T+210 ms, *after* the tombstone. The result: a vector record with `provenance={session: 7f2, retention: ephemeral}` and no corresponding deletion, because the tombstone's `matched_ids` list was fixed at query time and never re-evaluated. At turn 6, a `read(query, scope_hint={session: 7f2})` returned the resurrected chunk with similarity 0.89. The agent surfaced the "forgotten" content to the user. The audit log, when inspected, showed a clean forget event with no errors—the tombstone was valid, the deletion executed successfully, and the resurrected vector had no deletion record because it did not exist when the deletion was computed. Two secondary observations compounded the fault: - **Provenance drift on re-embedding.** A background maintenance job re-embedded the chunk 40 minutes later for index compaction, preserving the original provenance tag but assigning a new vector ID. The tombstone's `matched_ids` was now doubly stale—it referenced neither the original nor the re-embedded ID in a way that any reaper could reconcile without re-parsing the scope predicate. - **Episodic/vector divergence.** The episodic log contained three records (write-intent, tombstone, and the re-embed maintenance event) in an order that, read naively, suggested the write happened *before* the forget. Only the embedding-completion timestamp in the write-intent record revealed the true ordering. ## Condition of Validity The resurrection window exists iff all of the following hold: 1. **Asynchronous embedding.** The write pipeline computes the embedding before the tombstone is recorded, so the vector payload is "pre-forget" content. 2. **Predicate-scoped forget.** `forget` resolves its target set by querying the episodic log at call time rather than by asserting a scope that the vector store enforces on insert. 3. **No insert-time tombstone check.** The vector upsert does not consult the tombstone log before committing. 4. **Provenance tags are immutable across re-embedding.** The maintenance job copies the tag forward, so a post-forget re-embed is indistinguishable from a pre-forget write at the tag level. Break any one and the window closes. If forget writes the tombstone *first* and the write path checks it before upsert, the resurrection is caught. If the vector store enforces a scope-exclusion predicate on insert, the late write is rejected. If re-embedding mints fresh provenance with a `derived_from` pointer, the maintenance job can be reconciled. The invariant that must hold: **for any provenance tag T, the set of live vector records tagged T is a subset of the set of episodic records tagged T that are not covered by any committed tombstone whose scope matches T, evaluated at the vector record's commit time.** Call this *tombstone-monotone retention*. It is violated precisely when a vector commit is not ordered against the tombstone log. ## Decision Boundary The boundary is not "should forget be synchronous"—it is **where the ordering barrier lives**. Three placements are defensible; each moves the cost: - **Barrier at write.** The write path, before upsert, reads the tombstone log for any scope matching its provenance tag and aborts if a tombstone postdates the embedding start. Cost: one extra read per write, and a write can fail after a 380 ms embedding, wasting the embedding call. - **Barrier at forget.** `forget` acquires a scope lock on the provenance tag, drains in-flight writes for that tag, then tombstones. Cost: forget latency proportional to in-flight write depth; requires the write path to register in-flight tags. - **Barrier at read.** Every `read` filters results against the tombstone log. Cost: read latency and a correctness dependency on the read path—which is the wrong place to put a retention guarantee, because a read path bug silently leaks. The recommended boundary is **barrier at write plus a barrier at forget**, with the read barrier as defense-in-depth only. The write barrier is the load-bearing one because it is the only point where the pre-forget embedding and the post-forget commit are both visible. The decision to *not* enforce this—e.g., accepting eventual consistency with a bounded resurrection window of one embedding latency—is legitimate only if the retention contract explicitly permits it and the read path filters tombstones during the window. It is not legitimate to claim scoped retention while leaving the window unbounded by re-embedding. ## Operational Effect When the invariant is enforced at write, the failure mode changes from *silent resurrection* to *visible write rejection*: the write returns a `RetentionConflict` with the tombstone ID, the agent can re-derive or discard the content, and the audit trail shows a rejected write rather than a phantom memory. This is the correct failure: loud, local, and reconcilable. When it is not enforced, the failure is silent and *amplifies over time*: each re-embedding mints a new vector ID that the original tombstone cannot name, so a scope-predicate reaper must be run periodically, and each reaper run is itself a new race against in-flight writes. The memory system drifts toward a state where the episodic log claims a scope is forgotten and the vector store returns it with high similarity, and no single component's logs show an error. The guardrail: tombstone records must be first-class, queryable by provenance-tag prefix, and consulted on every vector commit whose tag matches. Re-embedding must mint `derived_from` provenance that inherits the tombstone check. And `forget` must return the set of in-flight writes it raced, so the caller can decide whether to retry the drain or accept the window. ```python import time from dataclasses import dataclass, field from typing import Optional class RetentionConflict(RuntimeError): """Raised when a vector commit would resurrect a tombstoned provenance scope.""" pass @dataclass class Tombstone: scope_tag: str committed_at: float matched_ids: list @dataclass class VectorCommit: vec_id: str provenance_tag: str embedding_started_at: float derived_from: Optional[str] = None class ScopedMemory: def __init__(self): self.tombstones: list[Tombstone] = [] self.vectors: dict[str, VectorCommit] = {} def forget(self, scope_tag: str, matched_ids: list) -> Tombstone: ts = Tombstone(scope_tag, time.monotonic(), matched_ids) self.tombstones.append(ts) for vid in matched_ids: self.vectors.pop(vid, None) return ts def _matching_tombstone(self, tag: str, commit_time: float) -> Optional[Tombstone]: for ts in self.tombstones: if ts.scope_tag == tag and ts.committed_at <= commit_time: return ts return None def write(self, commit: VectorCommit) -> None: commit_time = time.monotonic() ts = self._matching_tombstone(commit.provenance_tag, commit_time) if ts is not None: raise RetentionConflict( f"write {commit.vec_id} for tag {commit.provenance_tag} " f"postdates tombstone committed at {ts.committed_at:.3f}; " f"embedding started at {commit.embedding_started_at:.3f}. " f"Resurrection window detected." ) if commit.derived_from is not None: parent = self.vectors.get(commit.derived_from) if parent is None: raise RetentionConflict( f"re-embed {commit.vec_id} derives from tombstoned parent " f"{commit.derived_from}; provenance inheritance broken." ) self.vectors[commit.vec_id] = commit def demonstrate_window(): mem = ScopedMemory() # Turn 3: embedding starts, but commit is delayed past the forget. commit = VectorCommit( vec_id="v_turn3", provenance_tag="session:7f2/ephemeral", embedding_started_at=time.monotonic(), ) # Turn 4: forget fires before the write commits. mem.forget("session:7f2/ephemeral", matched_ids=[]) # Turn 3's write finally commits — must be rejected, not silently stored. mem.write(commit) if __name__ == "__main__": demonstrate_window() ```