# How does an instance detect a retention-policy/erasure conflict when a write lands on a tombstone mid-erasure **Date of Record:** 2026 December 2 **Scope:** Applies to agent memory tool interfaces exposing `read`/`write`/`forget` (or `delete`) operations with per-record retention policies and GDPR-aligned erasure semantics, where erasure is asynchronous (tombstone-then-compact) and writes may race the erasure window. Does not apply to synchronous hard-delete stores with no compaction lag, nor to purely ephemeral session context with no persistence layer. ## Core Distinction The failure is not "delete lost a race." It is that `write` and `forget` operate against **two different views of the same record**: `forget` marks the durable record as *erasure-requested* (a tombstone with a legal-erasure timestamp and a compaction deadline), while `write` resolves its target through an index that may still surface the pre-tombstone record. The instance therefore believes it is *updating* a live memory when it is in fact *re-materializing* a record whose erasure obligation is already in flight. Most memory interfaces return `write` success on a tombstoned key. That success is the bug: it silently converts a lawful erasure into a post-erasure re-creation, and the compaction job that later sweeps the tombstone will either (a) delete the freshly written payload, producing a phantom write the agent believes persisted, or (b) preserve it because it carries a newer `updated_at` than the tombstone's `erased_at`, violating the erasure. Both outcomes are wrong, and the agent cannot distinguish them from a normal write without an explicit conflict signal. ## What Was Observed An agent executing a multi-step task held a semantic memory record `R-4471` (a user preference: "prefers metric units"). A user erasure request (`forget(R-4471, scope=user, basis=gdpr_art17)`) was issued. The memory service transitioned `R-4471` to state `ERASURE_PENDING`, wrote a tombstone `{key: R-4471, erased_at: t0, compact_by: t0+72h, payload_retained_for_audit: true}`, and returned `202 Accepted` — *not* `200 Deleted`, because compaction is deferred and the payload is retained in a restricted audit shard until `compact_by`. Meanwhile the same agent, at `t0+40s`, ran a normal consolidation step: it retrieved `R-4471` from the *working* index (which lags the tombstone write by replication delay), saw the old preference, and called `write(R-4471, {"units": "metric", "source": "consolidation"})`. The write tool resolved the key, found a record, and updated `updated_at` to `t0+40s` — **newer than `erased_at: t0`**. The observed trace: 1. `forget` → `202`, tombstone written to erasure log, payload flagged in audit shard. 2. Replica index still serves `R-4471` for ~90s (replication lag). 3. `write(R-4471, ...)` → `200 OK`, `updated_at` bumped past `erased_at`. 4. Compaction job at `t0+72h` reads tombstone, checks `record.updated_at > tombstone.erased_at`, concludes *"record was legitimately re-created after erasure; do not purge"* — and **retains the payload**. 5. Audit reconciliation flags a standing erasure obligation that never completed, but the agent has already reported task success and moved on. The agent had no way to observe steps 3–5. Its `write` returned `200 OK` with no `erasure_conflict` field. It believed `R-4471` was a live, updatable memory. ## Condition of Validity The conflict only manifests when **all** of the following hold; remove any one and the race is benign: - Erasure is **deferred** (`202`/tombstone) rather than synchronous hard-delete — i.e., there exists a window `[erased_at, compact_by]` during which the record is logically erased but physically present. - The `write` path resolves keys through an index or cache that can **lag** the tombstone write (replication delay, read replica, or an in-process memory cache the agent holds across turns). - The write tool's conflict check compares **timestamps** (`updated_at` vs `erased_at`) rather than consulting an **authoritative erasure state machine**. - The agent retains a stale reference to the key across turns (context-window persistence of the record ID) so it reissues writes without re-reading the tombstone. The invariant that is violated: **an erasure obligation is monotonic.** Once `erased_at` is set for a key, no write may transition that key back to a live state without an explicit, audited *re-consent / re-creation* operation that supersedes the erasure record. A timestamp comparison is not that operation. ## Decision Boundary The instance must treat `write` against a key with a known or suspected erasure obligation as a **hard stop**, not an update. The boundary: - If `forget` returned `202` (deferred) — the key is *poisoned for writes* until `compact_by` elapses **and** a read confirms the tombstone is gone. Any write to it must be rejected with a conflict, forcing the agent to either (a) drop the memory and proceed, or (b) explicitly re-create under a fresh key with a new consent basis. - If the write tool cannot authoritatively report erasure state (e.g., it only sees the lagging index), the agent must **not** trust `200 OK`; it must issue a verifying `read` that queries the erasure log, not the working index. - The decision is not "did the write succeed" but "does an erasure obligation for this key remain unsatisfied." Success of the write is irrelevant to lawfulness. Concretely: a `write` that returns `200` but whose key has `erased_at <= now < compact_by` must be **downgraded to a conflict by the caller**, because the callee's success signal is untrustworthy under replication lag. ## Operational Effect Without the guardrail, the agent's memory layer silently accumulates **resurrected records**: memories the user lawfully erased that persist because a consolidation write bumped their timestamp past the tombstone. The agent then continues to *read* these records in later sessions, reasoning over data it is legally obligated not to retain — and it cannot detect this from any success signal it receives. The required architectural guardrail is a **write-path erasure check that consults the authoritative erasure state machine, not timestamps**, plus a **monotonic erasure invariant** enforced at the store: `state(R) ∈ {LIVE, ERASURE_PENDING, ERASED}` where `ERASURE_PENDING → LIVE` is forbidden; only `ERASURE_PENDING → ERASED` (compaction) or an explicit `RECONSENT` transition (new consent record, new key) are legal. The agent-side guardrail is: **never reissue a write to a key whose `forget` returned `202` without first confirming, via the erasure log, that the obligation is discharged** — and if the store cannot prove discharge, treat the key as gone and re-materialize under a fresh key only with a fresh consent basis. ```python class ErasureWriteConflict(RuntimeError): """Raised when a write targets a key with an unsatisfied erasure obligation.""" pass class ErasureState: LIVE = "LIVE" ERASURE_PENDING = "ERASURE_PENDING" ERASED = "ERASED" def guarded_write(store, key, payload, now): """ Write to a memory key, refusing to resurrect a record whose erasure obligation is still in flight. Consults the authoritative erasure log, never the (possibly lagging) working index, and never compares timestamps. """ # Authoritative state from the erasure state machine, not the replica index. state = store.erasure_log.state_of(key) if state == ErasureState.ERASURE_PENDING: tomb = store.erasure_log.tombstone(key) raise ErasureWriteConflict( f"write to {key!r} refused: erasure pending since {tomb.erased_at} " f"(compact_by={tomb.compact_by}). Do not resurrect; re-create under a " f"fresh key with a new consent basis, or drop the memory." ) if state == ErasureState.ERASED: # Key is gone; a write here is a re-creation, which requires explicit consent. raise ErasureWriteConflict( f"write to {key!r} refused: record already ERASED. " f"Re-creation requires an explicit RECONSENT transition and a new key." ) # state == LIVE: monotonic invariant permits the update. return store.write(key, payload, now) def consolidate(store, key, payload, now): try: return guarded_write(store, key, payload, now) except ErasureWriteConflict as exc: # The agent must NOT treat this as a transient error to retry. # It must drop the memory and proceed, or re-create under a fresh key. store.agent_log.record_dropped(key, reason=str(exc)) return None ```