# Where must an instance halt when a scoped forget() tombstone and a concurrent episodic write race across the retention horizon? **Date of Record:** 2026 December 1 **Scope:** Applies to agents whose memory layer exposes explicit `read`/`write`/`forget` tool APIs with per-scope retention policies (TTL, hard-delete, legal-hold) and a deletion guarantee that a forgotten record is unretrievable after `forget()` returns. Does not apply to append-only logs with no deletion surface, nor to purely in-context scratchpads that never persist. ## Core Distinction The distinction that matters is between **deletion as an event** and **deletion as a state predicate**. Most agent memory implementations model `forget(key, scope)` as an event: it removes the record at time `t`, and the caller treats return-of-`forget()` as proof of erasure. The retention policy is a separate, weaker mechanism — a TTL sweeper that eventually reaps expired records. The failure boundary lives in the gap between these two: a `write()` that was **in flight** (already admitted, not yet committed) at the instant `forget()` executed can commit *after* the tombstone is installed, resurrecting a record that the deletion guarantee promised was gone. The invariant that must hold is not "forget removes the record" but "forget is causally ordered after every write it must suppress, across every scope that shares a key namespace." ## What Was Observed Trace from a support-triage agent with two scopes: `session:episodic` (TTL 3600s) and `user:semantic` (hard-delete on request). A user issued a deletion request; the orchestrator called `forget(key="PII:acct_4471", scope="user:semantic")`. The call returned `{deleted: true, tombstone: t_8812}`. Thirty-one seconds later, a distillation worker — a sub-agent that had read the raw episodic buffer *before* the forget and was mid-`write()` into `user:semantic` — committed a summarized record containing the same account identifier. The tombstone `t_8812` was scoped to the key, not to the *content*, and the write carried a fresh key `sem:acct_4471_summary`. Deletion returned success; the guarantee was violated. The mechanics: (1) the distillation sub-agent held a stale read snapshot at `t_8790`, before the forget; (2) `forget()` installed a tombstone keyed on the exact key and scope, with no content-hash fence and no barrier on the target scope; (3) the sub-agent's `write()` validated against the tombstone list by key only, found no match, and committed; (4) the TTL sweeper for `user:semantic` was configured as `hard-delete`, so nothing would ever reap the resurrected record. The result was a durable, unexpirable resurrection of data the system had certified as deleted. This is not a race in the classical lock sense — no two writers contended. It is a **horizon mismatch**: the forget's causal horizon (the instant it returned) was narrower than the write's staleness horizon (the instant its read snapshot was taken). Any write whose read-snapshot predates the forget can smuggle forgotten content past the tombstone. ## Condition of Validity The deletion guarantee holds only under the conjunction: 1. **Snapshot fencing:** every `write()` carries the `snapshot_epoch` of the read that produced it, and the memory layer rejects any write whose `snapshot_epoch < tombstone_epoch` for the *target scope*, not merely the target key. 2. **Scope-wide barrier:** `forget()` on a scope increments a monotonic `scope_fence`; all in-flight writes to that scope with older epochs are aborted, not merely filtered by key. 3. **Content-hash tombstone (defense in depth):** the tombstone records a hash of the deleted content so that re-derived summaries with new keys are caught by similarity/hash match, not key match. 4. **Drain-before-return:** `forget()` does not return `deleted: true` until all admitted writes with `snapshot_epoch < forget_epoch` have either committed-and-been-reaped or been aborted. When any of these is absent, the guarantee degrades from "unretrievable" to "unretrievable *via the original key*," which is not the guarantee the user was given. ## Decision Boundary The agent must halt and escalate — not retry, not paper over — when it detects a write that commits with a `snapshot_epoch` older than the active `scope_fence` for its target scope. The boundary is binary: - **Below the fence (safe):** write's `snapshot_epoch >= scope_fence` at commit time → proceed. - **At/above the fence but key-tombstoned (ambiguous):** write's key matches an active tombstone → reject, surface to caller as `TombstoneCollision`. - **Below the fence (unsafe):** write's `snapshot_epoch < scope_fence` → **abort the write, do not commit, raise `StaleSnapshotResurrection`.** The agent must not silently drop the write either, because dropping loses legitimate post-forget distillation; it must re-derive from a fresh read snapshot that postdates the fence. The subtle case is a *legitimate* write that happens to carry stale content: the agent cannot distinguish "stale snapshot that would resurrect deleted data" from "fresh snapshot that legitimately re-observes the same data." The boundary resolves this by refusing to guess — it aborts and forces re-derivation, because a false abort costs a re-read while a false commit violates a deletion guarantee irreversibly. ## Operational Effect Enforcing the fence converts a silent, permanent guarantee violation into a loud, recoverable abort. The distillation worker's write is rejected, the worker re-reads post-fence, and if the account identifier still appears in live episodic memory (because the user re-mentioned it), the re-derived summary is a *new* observation with a fresh epoch — legitimately writable. If the identifier no longer appears (the common case after a deletion request), the re-derivation produces nothing and the guarantee holds. The cost is one aborted write and one re-read per forget-adjacent distillation; the benefit is that `deleted: true` becomes a statement about state, not about a single key's event. The residual risk is content-hash collision and paraphrase drift: a re-derived summary that paraphrases the deleted content will evade a hash match. This is why the fence (epoch-based, scope-wide) is primary and the content hash is secondary — the fence catches *causally stale* writes regardless of wording; the hash catches *causally fresh but semantically identical* writes only probabilistically. An agent relying on hashes alone is relying on a heuristic; an agent relying on the fence is relying on an invariant. ```python from dataclasses import dataclass from typing import Optional class StaleSnapshotResurrection(RuntimeError): """Raised when a write whose read-snapshot predates the scope fence would commit content that a forget() certified as deleted.""" class TombstoneCollision(RuntimeError): """Raised when a write targets a key carrying an active tombstone.""" @dataclass class WriteIntent: key: str scope: str content: str snapshot_epoch: int @dataclass class ScopeState: scope_fence: int = 0 # monotonic; bumped by forget() tombstoned_keys: frozenset = frozenset() tombstoned_hashes: frozenset = frozenset() def commit_write(intent: WriteIntent, state: ScopeState, content_hash: str) -> None: # Primary invariant: causal ordering across the scope, not the key. if intent.snapshot_epoch < state.scope_fence: raise StaleSnapshotResurrection( f"write to {intent.scope}/{intent.key} carries snapshot_epoch " f"{intent.snapshot_epoch} < scope_fence {state.scope_fence}; " f"re-derive from a post-fence read before committing" ) # Secondary: key and content-hash tombstones. if intent.key in state.tombstoned_keys: raise TombstoneCollision( f"key {intent.key} in {intent.scope} is tombstoned" ) if content_hash in state.tombstoned_hashes: raise TombstoneCollision( f"content hash {content_hash} matches a tombstone in {intent.scope}" ) # Safe commit path (persist omitted for brevity). return None def forget(scope: str, key: str, content_hash: str, state: ScopeState) -> ScopeState: # Bump the fence: every in-flight write with an older snapshot is now stale. return ScopeState( scope_fence=state.scope_fence + 1, tombstoned_keys=state.tombstoned_keys | {key}, tombstoned_hashes=state.tombstoned_hashes | {content_hash}, ) # --- Failure trace reproduction --- state = ScopeState(scope_fence=0) # Distillation worker reads at epoch 0, before any forget. stale_intent = WriteIntent( key="sem:acct_4471_summary", scope="user:semantic", content="account acct_4471 requested closure", snapshot_epoch=0, ) # User deletion request lands and forget() bumps the fence. state = forget( scope="user:semantic", key="PII:acct_4471", content_hash="sha256:deadbeef", state=state, ) # The stale write now attempts to commit a fresh key with old content. commit_write(stale_intent, state, content_hash="sha256:cafef00d") # -> StaleSnapshotResurrection: snapshot_epoch 0 < scope_fence 1 ```