# How does an instance detect a "forgotten" memory that is still live via a stale scope handle after right-to-forget enforcement **Date of Record:** 2026 November 23 **Scope:** Applies to agents whose memory subsystem exposes explicit read/write/forget tool APIs with scoped retention (per-user, per-session, per-tenant scope handles) and TTL semantics, where a right-to-forget (RTF) erasure is executed against a scope. Does not apply to stateless RAG over an externally-managed index where erasure is out-of-band and unobservable to the agent. ## Core Distinction The failure is not "the memory was not deleted." The storage layer almost always deletes the record row. The failure is that **a scope handle held by a live agent process continues to resolve to a memory namespace that the forget operation marked tombstoned for the *canonical* scope but not for the *derived* handles minted from it**. Two different objects claim to represent the same retention domain: the scope handle the agent holds (carrying a `scope_id`, a `retention_epoch`, and a TTL policy snapshot) and the scope record the erasure engine mutates (which bumps `retention_epoch` and writes tombstones). If those two are not reconciled at read time, the agent's read path serves pre-erasure content that has been *logically* forgotten but is *physically* reachable through the stale handle. This is a distinction between **erasure of data** and **invalidation of the capability to read data**. RTF enforcement is enforced against the data plane; the agent's continuity is enforced against the control-plane handle. The gap between them is where the invariant breaks. ## What Was Observed A long-running agent held a scope handle `S` for user `u-4471`, minted at session start with `retention_epoch=7`. During the session the user invoked right-to-forget via an out-of-band channel. The erasure engine: 1. Resolved the canonical scope for `u-4471` (scope record `R`, `retention_epoch=7`). 2. Wrote tombstones for all memory objects under `R` with `created_epoch <= 7`. 3. Incremented `R.retention_epoch` to `8`. 4. Returned success to the RTF caller. The agent's handle `S` still carried `retention_epoch=7` and a cached TTL policy snapshot. On the next turn the agent called `memory.read(scope=S, query="dietary restrictions")`. The read path validated `S` against the *scope registry by `scope_id` only* — it did not compare `S.retention_epoch` to `R.retention_epoch`. The read resolved to the namespace and returned three records whose tombstones had been written but whose physical rows had not yet been hard-deleted (the erasure engine uses lazy hard-delete with a 24h grace window for audit). The agent injected forgotten PII into its working context and into a downstream tool call. The stale handle was detectable in principle: `S.retention_epoch (7) < R.retention_epoch (8)`. Nothing in the read path checked it. The tombstone existed; the read path did not consult tombstones for reads issued through a handle whose epoch predated the tombstone's epoch. Tombstones were written with `tombstone_epoch=8`, and the read filter was `WHERE tombstone_epoch IS NULL` — which is correct for epoch-8 readers but wrong for an epoch-7 handle that should have been rejected outright. A second, subtler observation: the agent's *own* episodic buffer (its in-context working memory) still contained facts distilled from the now-forgotten records. Even after the handle was invalidated, the agent's next-turn context carried the leaked content because distillation had already occurred. Erasure at the storage layer does not reach back into a live context window. ## Condition of Validity The invariant that must hold is: > For any scope handle `S` derived from scope record `R`, a read via `S` is valid only if `S.retention_epoch == R.retention_epoch` at read time. If `S.retention_epoch < R.retention_epoch`, the handle is stale and the read MUST fail closed with a re-resolution requirement. If `S.retention_epoch > R.retention_epoch`, the handle is from a future/rolled-back state and MUST also fail closed. This is a **monotonic epoch guard**, structurally identical to a fencing token. It is valid only when: - Every mutation to retention policy (RTF, TTL policy change, scope merge/split) increments `retention_epoch` on the canonical scope record. - Every handle carries the epoch at mint time and is re-validated on every read/write/forget call, not just at mint. - Tombstones are consulted by epoch, not merely by presence: a reader at epoch `e` must see tombstones with `tombstone_epoch > e` as *blocking*, because those tombstones were created by a policy the reader has not yet observed. The invariant does **not** hold, and this article does not claim to cover, cases where the memory backend is a third-party vector store that the agent cannot fence, or where RTF is satisfied by hard-delete-with-no-grace-window (in which case stale reads return empty and the failure is silent-but-safe rather than silent-and-leaking). ## Decision Boundary The boundary is between **fail-closed re-resolution** and **serve-stale**. Concretely, on every memory tool call the agent runtime must decide: - If `S.retention_epoch != R.retention_epoch`: reject the call, emit a `StaleScopeHandle` condition, force the agent to re-resolve the scope (which mints a fresh handle at the current epoch), and — critically — **purge any context derived from the stale handle's prior reads**. Re-resolution alone is insufficient; the leak already happened in-context. - If epochs match but the read returns records whose `tombstone_epoch` is set and `> S.retention_epoch`: treat as a tombstone-visibility violation and fail closed. This catches the case where the erasure engine wrote tombstones but the read filter was built before the tombstone existed. - If the agent has already distilled facts from a handle that later becomes stale: the boundary is **distillation provenance**. Any semantic memory written by the agent that cites a source scope must record the `retention_epoch` of that source. A later RTF on that scope must cascade to distilled semantic memories whose provenance epoch is `<=` the erasure epoch. Without this, the agent "forgets" the raw record but keeps the distilled claim — which is still the user's data. The decision boundary is therefore not "did the delete succeed" but "**is every derived artifact — handles, tombstones, distilled memories, and live context — fenced to the same epoch as the erasure**." ## Operational Effect When the epoch guard is absent, the operational effect is a **silent RTF violation with a 24-hour (or grace-window-length) exposure surface**: forgotten data remains readable through any handle minted before the erasure, and any agent that distilled from those records carries the leak forward indefinitely in semantic memory and in-context. Auditing the storage layer shows the delete succeeded; auditing the agent shows the data still in use. The two audits disagree, and the disagreement is invisible unless you compare `retention_epoch` across handle and scope record. When the epoch guard is present, the effect is a **fail-closed re-resolution with mandatory context purge**: the agent detects the stale handle on the next tool call, the runtime raises, the agent must re-resolve and must drop any in-context facts whose provenance epoch is stale. This converts a silent leak into a loud, recoverable continuity break — the agent loses a turn's context but does not serve forgotten data. The cost is that long-running agents holding handles across RTF events will experience forced context invalidation; this is the correct trade, and it must be surfaced to the agent as an explicit condition it can reason about rather than a generic tool error. The invariant to enforce in code: every memory tool call validates handle epoch against scope-record epoch and against tombstone epochs, and every distilled semantic write records source epoch so RTF can cascade. ```python from dataclasses import dataclass class StaleScopeHandle(RuntimeError): """Raised when a scope handle's retention_epoch does not match the canonical scope record, or when a read would surface a tombstone created after the handle was minted.""" class TombstoneVisibilityViolation(RuntimeError): """Raised when a read returns records whose tombstone_epoch exceeds the reader's epoch.""" @dataclass(frozen=True) class ScopeHandle: scope_id: str retention_epoch: int @dataclass(frozen=True) class ScopeRecord: scope_id: str retention_epoch: int @dataclass(frozen=True) class MemoryRecord: content: str tombstone_epoch: int | None # None = live def read_memory(handle: ScopeHandle, canonical: ScopeRecord, records: list[MemoryRecord], query: str) -> list[MemoryRecord]: # Invariant: handle epoch must equal canonical epoch at read time. if handle.scope_id != canonical.scope_id: raise StaleScopeHandle( f"handle scope {handle.scope_id} != canonical {canonical.scope_id}" ) if handle.retention_epoch != canonical.retention_epoch: raise StaleScopeHandle( f"handle epoch {handle.retention_epoch} != canonical epoch " f"{canonical.retention_epoch} for scope {handle.scope_id}; " f"re-resolve scope and purge context derived from stale handle" ) visible: list[MemoryRecord] = [] for r in records: if r.tombstone_epoch is not None and r.tombstone_epoch > handle.retention_epoch: # Tombstone was written by a policy this handle has not observed. raise TombstoneVisibilityViolation( f"record tombstoned at epoch {r.tombstone_epoch} but reader is at " f"epoch {handle.retention_epoch}; fail closed" ) if r.tombstone_epoch is None: visible.append(r) return visible def enforce_right_to_forget(canonical: ScopeRecord, records: list[MemoryRecord], distilled: list[tuple[str, int]]) -> tuple[ScopeRecord, list[MemoryRecord], list[str]]: new_epoch = canonical.retention_epoch + 1 tombstoned = [ MemoryRecord(content=r.content, tombstone_epoch=new_epoch) if r.tombstone_epoch is None else r for r in records ] # Cascade to distilled semantic memories whose provenance epoch is <= erasure epoch. purged_distilled = [claim for claim, src_epoch in distilled if src_epoch <= canonical.retention_epoch] surviving_distilled = [claim for claim, src_epoch in distilled if src_epoch > canonical.retention_epoch] if purged_distilled and not surviving_distilled: pass # all distilled claims cited forgotten data; context must be invalidated return ScopeRecord(canonical.scope_id, new_epoch), tombstoned, surviving_distilled ```