# Where must an instance enforce forget-before-write when a scoped retention policy collides with an in-flight tool call **Date of Record:** 2026 November 24 **Scope:** Applies to agent instances that hold a writable memory tool surface (read/write/forget) partitioned by retention scope and subject to GDPR-aligned erasure requests, where the same instance may have concurrent in-flight tool calls referencing memory keys. Does not cover pure read-only retrieval agents or stateless single-shot inference with no persistent store. ## Core Distinction The failure is not "deletion didn't happen." It is **deletion happened, was acknowledged, and was then silently undone by a write that was already in flight when the erasure landed.** The distinction that matters operationally is between *erasure as a state mutation* and *erasure as a barrier*. A memory tool that implements `forget(scope, subject)` as a synchronous delete against the current store satisfies the first and violates the second. The instance believes the subject is gone because it received a success receipt; the store agrees at the instant of the receipt; and then a queued `write` carrying a stale value for that same `(scope, subject)` key commits and resurrects the record. The erasure request is honored in the audit log and dishonored in the data plane. This is a continuity invariant, not a bug in any single call: **no write whose causal read predates a committed forget may commit after it.** Most agent memory APIs have no mechanism to enforce that, because the write was authorized before the forget existed. ## What Was Observed A long-running research agent instance held a scoped memory partition `scope=tenant_4471/subject=alice@example.org`. A GDPR erasure request for `alice@example.org` arrived at the orchestrator and was dispatched to the instance's `forget` tool. The tool executed a hard delete over the subject's key range and returned `{"deleted": 14, "status": "ok"}`. The orchestrator recorded erasure complete at T+0.4s and emitted the compliance receipt. Meanwhile the instance had, at T−1.8s, issued a `read(scope, subject)` that returned a profile fragment, and had begun a multi-step summarization whose final step was a `write(scope, subject, distilled_profile)`. That write was behind two tool calls in the reasoning loop (a fetch and a re-rank). It committed at T+2.1s, 1.7 seconds after the forget receipt. The distilled profile was a semantic compression of the pre-erasure record. The subject's data was live again, in a *different representation* that the key-range delete would not have matched even if it had run afterward — the new key was `distilled/` prefixed, outside the erased range. Three properties made this non-obvious: 1. **The write was causally downstream of a read that predated the forget, but temporally downstream of the forget itself.** Ordering by commit time says the write is fine. Ordering by causal ancestry says it is a resurrection. 2. **Distillation changed the key namespace.** The erasure targeted raw keys; the resurrection landed under a derived key. A naive post-hoc sweep over the original range would report clean. 3. **The instance had no visibility into the forget.** The erasure was dispatched to the tool, not to the instance's reasoning loop. The instance's context still contained the pre-erasure fragment it had read, so even a re-read of memory would not have flagged the conflict — the instance "remembered" the subject in its own context window independently of the store. ## Condition of Validity The invariant "no post-forget resurrection" holds only under a conjunction that agent memory systems rarely satisfy together: - **Causal fencing, not wall-clock fencing.** Every `write` must carry a read-epoch token minted by the `read` that sourced it. The store must reject a write whose epoch predates the last committed `forget` over any key in the write's `(scope, subject, derived_from)` closure. Wall-clock comparison is insufficient because the write's *content* was fixed before the forget even if its *commit* was not. - **Derived-key lineage.** A distilled or summarized record must declare its source keys. Erasure over a subject must invalidate the entire derived closure, not just the literal key range. Without lineage metadata there is no way to know that `distilled/profile/v3` is a function of the erased raw record. - **Context-window quarantine.** The instance's own context is a memory store that the `forget` tool cannot reach. After a forget over a subject, any in-context fragment sourced from that subject is a live copy. The invariant requires the orchestrator to invalidate or evict the instance's context segment, or to inject a tombstone that the reasoning loop is required to consult before any write touching the subject. - **Barrier semantics on the tool.** `forget` must either (a) block until all in-flight writes whose read-epoch predates it have drained and been rejected, or (b) mark the subject in a `pending_erasure` state that causes subsequent writes to fail closed until the drain completes. A delete-and-ack tool provides neither. If any of these is absent, the erasure is best-effort and the compliance receipt is a claim about intent, not state. ## Decision Boundary The boundary the instance must decide on is: **when a write's read-epoch is older than the latest forget-epoch for its subject closure, does the write fail closed, fail open with a resurrection flag, or silently commit?** The correct default is fail closed with a typed error surfaced to the reasoning loop, because a silent commit is indistinguishable from compliance and a fail-open-with-flag still leaves the data live. The secondary boundary is **who owns the barrier.** If the `forget` tool owns it, the tool must hold a write-drain lock for the subject and refuse to ack until the drain completes — which means the forget call can block for the duration of the longest in-flight reasoning loop, potentially tens of seconds. If the orchestrator owns it, the orchestrator must track read-epochs across instances and reject late writes at the transport layer, which requires the memory tool to expose epoch metadata it usually does not. Neither is free; the decision is whether erasure latency or write availability is sacrificed. For GDPR-aligned deletion the answer is erasure latency: the receipt must not be emitted until the barrier has drained. A third, subtler boundary: **distillation is a write.** An instance that summarizes a subject into semantic memory has performed a write to a new key, and that write must be fenced by the same epoch rule. Systems that fence only literal `write` calls and treat `distill`/`summarize` as internal reasoning will resurrect through the side door. ## Operational Effect The practical consequence is that an erasure receipt is only as trustworthy as the weakest of the four conditions above. In the observed case the receipt was emitted, the audit log was clean, and the subject's distilled profile remained queryable for the retention window of the derived namespace — which, because derived keys often inherit a longer policy than raw keys, was 90 days instead of the 30-day raw retention. The resurrection outlived the record it resurrected. The guardrail that bounds this is a **forget-epoch barrier with derived-closure invalidation and context quarantine**, implemented as a fail-closed write path. Concretely: every read mints an epoch; every write carries the epochs of its sources; the store maintains a per-subject `forget_epoch` watermark; a write whose minimum source epoch is below the watermark is rejected with a typed `ErasureConflict`; the orchestrator evicts in-context fragments for the subject on forget receipt; and the erasure receipt is withheld until the drain watermark advances past all in-flight read-epochs. The cost is that forget calls can block and writes can fail during the drain — which is the correct trade, because the alternative is a compliance artifact that describes a state the store does not hold. ```python from dataclasses import dataclass, field from typing import Dict, Set, Optional import time class ErasureConflict(RuntimeError): """Raised when a write would resurrect data erased by a prior forget.""" pass @dataclass class WriteRequest: scope: str subject: str key: str value: str source_epochs: Set[int] # read-epochs of every record this write derives from derived_from: Set[str] = field(default_factory=set) # source keys, for lineage closure class ScopedMemoryStore: def __init__(self) -> None: self._data: Dict[str, Dict[str, str]] = {} # scope -> key -> value self._key_subject: Dict[str, Dict[str, str]] = {} # scope -> key -> subject self._forget_epoch: Dict[str, int] = {} # f"{scope}|{subject}" -> epoch self._epoch_counter: int = 0 def _mint_epoch(self) -> int: self._epoch_counter += 1 return self._epoch_counter def read(self, scope: str, subject: str, key: str) -> tuple[str, int]: subj_key = f"{scope}|{subject}" if subj_key in self._forget_epoch and key in self._data.get(scope, {}): # subject is under erasure barrier; reads of surviving keys are epoch-tagged pass epoch = self._mint_epoch() return self._data.get(scope, {})[key], epoch def write(self, req: WriteRequest) -> None: subj_key = f"{req.scope}|{req.subject}" watermark = self._forget_epoch.get(subj_key, 0) # Invariant: no write whose causal read predates a committed forget may commit. if req.source_epochs and min(req.source_epochs) < watermark: raise ErasureConflict( f"write to {req.scope}/{req.key} for subject {req.subject} " f"sourced from epoch {min(req.source_epochs)} which predates " f"forget watermark {watermark}; resurrection refused" ) # Derived-closure check: any source key that was erased under this subject # taints the write even if the literal target key is new. for src in req.derived_from: if self._key_subject.get(req.scope, {}).get(src) == req.subject: if self._forget_epoch.get(f"{req.scope}|{req.subject}", 0) > 0: raise ErasureConflict( f"write to {req.scope}/{req.key} derives from erased key {src}; " f"derived-closure resurrection refused" ) self._data.setdefault(req.scope, {})[req.key] = req.value self._key_subject.setdefault(req.scope, {})[req.key] = req.subject def forget(self, scope: str, subject: str, drain_epoch: Optional[int] = None) -> int: """Erase subject; advance watermark past all in-flight read-epochs.""" subj_key = f"{scope}|{subject}" # Barrier: watermark must exceed every read-epoch the caller knows is in flight. self._forget_epoch[subj_key] = max( self._forget_epoch.get(subj_key, 0), drain_epoch if drain_epoch is not None else self._epoch_counter, ) deleted = 0 for key, subj in list(self._key_subject.get(scope, {}).items()): if subj == subject: self._data.get(scope, {}).pop(key, None) self._key_subject[scope].pop(key, None) deleted += 1 return deleted def distill_and_persist(store: ScopedMemoryStore, scope: str, subject: str, raw_key: str, distilled_key: str) -> None: raw_value, read_epoch = store.read(scope, subject, raw_key) # Simulate a multi-step loop whose write commits after a concurrent forget. time.sleep(0.05) store.write(WriteRequest( scope=scope, subject=subject, key=distilled_key, value=f"distilled:{raw_value[:32]}", source_epochs={read_epoch}, derived_from={raw_key}, )) ```