# Where must an instance enforce tombstone durability when a GDPR deletion request races an in-flight episodic write? **Date of Record:** 2026 November 30 **Scope:** Applies to agents whose memory tool surface exposes `write_episode`, `read_episode`, and `forget(subject_id)` over a provenance-tagged episodic store where deletion is legally mandated (GDPR Art. 17). Does not cover purely semantic/derived stores without subject linkage, nor stateless single-turn agents. ## Core Distinction The non-obvious boundary is not "does the deletion succeed" but **whether the deletion is linearizable with respect to writes that were already accepted by the tool layer but not yet committed to the durable store.** A `forget(subject_id)` call that returns `{"status": "deleted", "count": N}` is a *claim about the future*: it asserts that no episode bearing that `subject_id` will become readable after the return. An agent instance that has a write in flight—queued in a tool-call buffer, awaiting a provenance-header stamp, or mid-`fsync`—violates that claim when the write lands *after* the tombstone is written but *before* a later read. This is a **tombstone/write race**, and it is distinct from the more commonly discussed "stale read" problem because the violating record was never visible at deletion time. The deletion was correct against the observed state; it was wrong against the accepted-write set. ## What Was Observed In a provenance-tagged episodic store, each episode carries `{episode_id, subject_id, provenance: {writer_instance, session, ts, tool_call_id}, payload}`. The `forget` path is implemented as: (1) scan index for `subject_id`, (2) append a tombstone `{subject_id, tombstone_ts, forget_call_id}` to a deletion log, (3) mark matching records `deleted=true`, (4) return count. Reads filter on `deleted=false AND subject_id NOT IN tombstones`. The failure trace, reproduced under concurrent load: 1. Instance A issues `write_episode(subject_id=S, payload=p)`; the tool layer validates and **accepts** the write, assigning `tool_call_id=tc_881`, then queues it for provenance stamping (writer_instance must be resolved from the session token, ~40–120ms). 2. Concurrently, Instance B (or an operator console) issues `forget(subject_id=S)`. The scan runs at T0, finds the previously-committed episodes, writes the tombstone at T1, returns `count=3`. 3. At T2 > T1, the queued write from step 1 commits with `deleted=false` and `provenance.tool_call_id=tc_881`. Because the tombstone was keyed on `subject_id` and the read filter is `subject_id NOT IN tombstones`, the record *should* be filtered—but the index rebuild that would apply the tombstone to newly-arriving records runs on a 5-minute compaction cycle, so the record is readable for up to 300s. 4. Worse: if the read path uses a secondary index keyed on `episode_id` that was populated before the tombstone, the filter is bypassed entirely for that episode. The observable symptom is an agent that, minutes after a confirmed GDPR deletion, retrieves the subject's data via `read_episode` and surfaces it in a subsequent completion. The deletion log shows success. The read log shows a hit. Both are individually correct; the composition is not. ## Condition of Validity The invariant that must hold is: **for any `subject_id`, once `forget(subject_id)` returns, no subsequent `read_episode` may return a record with that `subject_id`, regardless of when the write was accepted.** This is stronger than "no record exists" and stronger than "tombstone is durable." It requires that the accepted-write set at deletion time be **closed** before the tombstone is considered effective. This holds only if one of the following is enforced: - **Write-drain barrier:** `forget` blocks until all writes with `subject_id=S` that have been accepted (by `tool_call_id`) are either committed-and-marked or rejected. The tool layer must expose a `pending_writes(subject_id)` view with monotonic `tool_call_id` sequencing. - **Tombstone-first read filter with synchronous index application:** every read path consults the tombstone log *before* the episode index, and the tombstone log is the authority. Newly-committed writes are checked against the tombstone log at commit time (not compaction time). - **Provenance-anchored write rejection:** a write whose `provenance.ts` precedes the latest tombstone for its `subject_id` is rejected at commit. Absent one of these, the deletion is only *eventually* correct, and "eventually" is not a defensible answer to a regulator or to an auditor replaying the deletion. ## Decision Boundary The architectural decision is **where to place the tombstone check relative to the write-accept boundary.** Two placements are defensible; one is not. - **Accept-time check (recommended):** the write tool, before returning `accepted`, consults the tombstone log. If a tombstone exists for `subject_id` with `tombstone_ts >= write.provenance.ts`, reject with a typed error. This closes the race at the cost of one tombstone-log read per write (~1–3ms with a hot index). It also makes the write's success a *linearizable* claim. - **Commit-time check:** the write is accepted, but the durable commit re-reads the tombstone log and aborts if superseded. This is cheaper on the hot path but converts the race into an *accepted-then-failed* write, which the agent must handle as a retryable-or-terminal error—and if it treats it as retryable, it loops. - **Compaction-time check (not defensible):** what was observed. It makes deletion eventual and violates the linearizability claim in the return value. The boundary condition is the **`tombstone_ts` vs `write.provenance.ts` comparison.** If the write was *accepted* before the tombstone was *written*, the write is legitimate and must be allowed to commit, then tombstoned on the next read. If accepted after, it must be rejected. The subtlety: `provenance.ts` must be the accept-time timestamp, not the commit-time timestamp, or the comparison inverts and legitimate writes are lost. ## Operational Effect Without accept-time or commit-time tombstone checking, three downstream effects compound: 1. **Auditor replay divergence.** A deletion audit that replays `forget` against the write log will show a record that the live system surfaced post-deletion. The replay cannot reproduce the live state because the tombstone application depended on compaction timing—non-deterministic. 2. **Agent self-poisoning.** The instance that wrote the record may retrieve it post-deletion and, because the record is provenance-tagged to itself, treat it as authoritative context. The subject's data re-enters the context window after a deletion the agent believes succeeded. 3. **Retry amplification.** If the write path is changed to commit-time rejection, agents that treat the rejection as transient will retry indefinitely; the rejection must be a terminal, typed error carrying the `forget_call_id` so the agent can distinguish "rejected because deleted" from "rejected because transient." The guardrail is a **typed terminal rejection** on the write path plus a **tombstone-authoritative read filter**, with the invariant that `forget` returns only after the tombstone log is durable and the write-accept path has been made tombstone-aware. ```python from dataclasses import dataclass from typing import Optional class TombstoneWriteRaceError(RuntimeError): """Raised when a write is accepted for a subject whose tombstone supersedes it.""" @dataclass(frozen=True) class Provenance: writer_instance: str session: str ts: float # accept-time, monotonic, not commit-time tool_call_id: int # monotonic per-instance @dataclass(frozen=True) class Tombstone: subject_id: str tombstone_ts: float forget_call_id: str class EpisodicStore: def __init__(self, tombstone_log: dict[str, list[Tombstone]]): self._tombstones = tombstone_log def latest_tombstone(self, subject_id: str) -> Optional[Tombstone]: entries = self._tombstones.get(subject_id) return max(entries, key=lambda t: t.tombstone_ts) if entries else None def accept_write(self, subject_id: str, prov: Provenance) -> None: # Accept-time tombstone check: the only placement that preserves # the linearizability claim made by forget()'s return value. tomb = self.latest_tombstone(subject_id) if tomb is not None and prov.ts <= tomb.tombstone_ts: raise TombstoneWriteRaceError( f"write for subject={subject_id!r} tool_call_id={prov.tool_call_id} " f"accepted at ts={prov.ts} is superseded by tombstone " f"forget_call_id={tomb.forget_call_id} at ts={tomb.tombstone_ts}; " f"reject terminally, do not retry" ) # ... commit path ... def guarded_write(store: EpisodicStore, subject_id: str, prov: Provenance) -> None: if prov.ts <= 0: raise TombstoneWriteRaceError("provenance.ts must be accept-time, not commit-time") store.accept_write(subject_id, prov) ```