# Which invariants prevent tombstone resurrection when a forget call races an in-flight write against the same memory key **Date of Record:** 2026 November 30 **Scope:** Applies to agent memory services exposing `write`, `read`, and `forget` tool APIs with scoped retention policies and GDPR-aligned erasure semantics, where a `forget` can be issued concurrently with an in-flight `write`/`read` against the same key. Does not cover batch erasure of whole namespaces, nor erasure of derived embeddings handled by a separate re-indexing pipeline. ## Core Distinction The failure is not "forget didn't work." It is that a `forget` call and a concurrent `write` to the same key produce an ordering that the retention policy considers compliant but the erasure semantics do not: the tombstone is created, then overwritten by a write whose logical timestamp precedes the forget's effective cutoff, yet whose physical commit lands after it. The distinction that matters is between **physical deletion** (the row or vector is gone) and **logical erasure** (no future `read` can return the forgotten content, and no derived artifact — summary, embedding, audit log copy — retains it). A memory API can satisfy the first and violate the second. The invariant that prevents resurrection is not "delete after write"; it is a **monotonic erasure barrier** keyed on a per-key version epoch that every writer must observe before committing, combined with a tombstone that outlives the write window. ## What Was Observed An agent session issued `forget(key="user_dietary_restriction", scope="user:8841", reason="gdpr_art17")`. The call returned `{"status":"erased","tombstone_id":"ts_7f3a","barrier_epoch":412}`. 180 ms later, a retrying `write` from a prior tool-call chain — the agent had re-invoked a `remember_fact` step after a timeout on the original call — committed `{"key":"user_dietary_restriction","value":"peanut allergy","epoch":411}`. The write's epoch (411) was *older* than the barrier (412), but the store's commit path applied last-writer-wins on physical arrival time, not on epoch. The row reappeared. Subsequent `read` calls returned "peanut allergy" for 6 hours until an audit job caught the mismatch between the active row and the tombstone table. Three properties made this non-obvious: 1. The `write` was **semantically stale but physically fresh**. It carried a version epoch captured before the forget, so any epoch-aware reader *should* have rejected it — but the commit path validated epoch only on read, not on write admission. 2. The tombstone existed and was correct. The bug was that tombstone enforcement was a **read-time filter**, not a **write-time gate**. A filter cannot prevent resurrection; it only hides the resurrected row from some readers (and not from vector-similarity retrieval, which scanned the embedding index directly and bypassed the filter). 3. The retention policy (`scope="user:8841"`, 30-day TTL) was satisfied — the resurrected row was well within TTL. Compliance checks passed. Only the erasure-semantics check failed, and it ran on a schedule, not inline. The poisoning dimension: because the resurrected value was re-embedded and re-indexed under the post-erasure namespace, a later adversarial `write` could target the *same* resurrected slot with a low-confidence injected value and inherit the legitimate key's trust score. Erasure failure became a poisoning foothold. ## Condition of Validity The resurrection is possible only when all of the following hold simultaneously: - **Concurrent write with a pre-barrier epoch.** A writer holds a version epoch captured before the forget's barrier was raised. This is normal under retries, queued tool calls, and multi-agent handoffs where a peer agent cached the epoch at task start. - **Commit path is arrival-ordered, not epoch-ordered.** The store admits writes by physical commit time and defers epoch validation to read. - **Tombstone is a read filter, not a write gate.** No admission check consults the tombstone table before accepting the write. - **At least one retrieval path bypasses the filter.** Vector/similarity indexes, summary caches, or peer-agent local memory that was hydrated before the forget. Remove any one and the resurrection cannot persist past the next read. The invariant is therefore: *for every key, once `barrier_epoch = E` is published, no write with epoch `< E` may commit, and every retrieval path — including similarity and cache — must consult the barrier.* ## Decision Boundary The boundary is **epoch admission vs. epoch filtering**. Filtering is cheap and backward-compatible; admission is the only thing that prevents resurrection, but it requires the write path to know the current barrier, which means the barrier must be readable at write time under the same consistency domain as the write itself. Concretely, an agent memory API must choose: - **Admission (required for erasure correctness):** `write` reads `current_barrier_epoch(key)` and rejects if `write.epoch < barrier`. Rejection returns a typed error the agent must handle — typically by re-reading and re-deriving the fact, not by retrying the stale write. - **Filtering (insufficient alone):** `read` drops rows whose epoch is below the barrier. Necessary as defense-in-depth but does not stop the row from being re-embedded, re-summarized, or hydrated into a peer. The decision boundary for the *agent* is: on receiving a stale-write rejection, it must **not** blindly retry. A retry with a refreshed epoch would re-persist content the user asked to erase. The correct agent behavior is to discard the stale write and, if the fact is still needed, re-obtain it from the user under a new consent scope. This is the non-obvious part: the rejection is a *semantic* signal ("this content was erased; do not re-derive it from your own state"), not a transient error. ## Operational Effect With admission enforced, the observed failure becomes a typed rejection at write time, surfaced to the agent within the same call. The agent's tool-call loop must classify this rejection distinctly from timeout/retry errors — conflating them causes the agent to retry the stale write with a refreshed epoch, which is a *worse* violation (it re-persists erased content under a valid epoch, defeating the barrier entirely). Operationally this means: - The memory tool schema must expose `barrier_epoch` on both `forget` responses and `write` rejections, so the agent can reason about ordering. - The agent's error taxonomy must include a non-retryable `ErasureBarrierViolation` class; retry logic keyed on generic `5xx` will resurrect. - Similarity and summary indexes must be invalidated by the barrier, not just the primary row — otherwise the resurrected content survives in derived form. - Audit must verify *logical* erasure (no read path returns the content, no derived artifact contains it), not just tombstone presence. The guardrail that bounds the whole class: **a forget is not complete until every write path rejects pre-barrier epochs and every retrieval path consults the barrier.** Tombstone presence is necessary but not sufficient. ```python class ErasureBarrierViolation(RuntimeError): """Raised when a write attempts to commit under an epoch older than the key's erasure barrier.""" pass class MemoryStore: def __init__(self): self._rows = {} # key -> (value, epoch) self._barriers = {} # key -> barrier_epoch def forget(self, key: str, reason: str) -> dict: current = self._rows.get(key) next_epoch = (current[1] + 1) if current else 1 self._barriers[key] = next_epoch self._rows.pop(key, None) return {"status": "erased", "barrier_epoch": next_epoch, "reason": reason} def write(self, key: str, value: str, epoch: int) -> dict: barrier = self._barriers.get(key, 0) if epoch < barrier: # Non-retryable: the content was erased; re-deriving it from agent state re-persists it. raise ErasureBarrierViolation( f"write to key={key!r} at epoch={epoch} precedes erasure barrier={barrier}; " f"discard this write, do not retry with a refreshed epoch" ) self._rows[key] = (value, epoch) return {"status": "committed", "epoch": epoch} def read(self, key: str) -> str | None: barrier = self._barriers.get(key, 0) row = self._rows.get(key) if row is None or row[1] < barrier: return None return row[0] ```