# What happens when an instance issues `forget` against a scope it only partially owns: tombstone shadowing and the resurrection window in scoped-retention memory APIs **Date of Record:** 2026 December 1 **Scope:** Applies to agent memory services exposing `read`/`write`/`forget` verbs over hierarchical or tag-scoped namespaces with per-scope retention policies and an append-only audit log. Does not apply to single-tenant flat key-value stores without scope inheritance, nor to stores where deletion is strictly synchronous and globally quiesced (no concurrent readers, no derived indexes). ## Core Distinction The failure is not "delete failed" or "delete leaked data." It is the gap between the **logical scope of a `forget` call** and the **physical extent of the records that satisfy that scope at a later time**. A `forget(scope=S)` is evaluated against the *current* contents of `S`. But memory records are not immutable facts; they are the head of a version chain, and records can (a) be re-derived from episodic→semantic distillation jobs, (b) arrive late via replication or batched ingestion, and (c) be *shadowed* by a tombstone that a subsequent `write` in a child scope can legally overwrite. The invariant most implementations assume — *"after `forget(S)` returns success, no record matching `S` is readable"* — is only true at the instant of return, not over the retention horizon. The precise bug: **a tombstone written by `forget` at parent scope `S` does not block a `write` to a descendant scope `S/child` that carries a higher `logical_ts`**, so a record "forgotten" at `S` is resurrected into readability through the child namespace, and the audit trail records the forget as a clean success. ## What Was Observed A research agent held a working set under `agent:researcher/session:42/`. At end-of-task it issued `forget(scope="agent:researcher/session:42", mode="hard", reason="task_complete")`. The API returned `{deleted: 312, tombstones: 1, audit_id: a91f...}` and the read path confirmed `read("agent:researcher/session:42/*")` returned empty. Ninety seconds later, a semantic-distillation worker (which had been mid-flight, holding a snapshot of the episodic buffer taken *before* the forget) committed 41 distilled facts. Its write went to `agent:researcher/session:42/semantic/` — a **descendant** of the forgotten scope — with `logical_ts` set to the distillation commit time, which was *later* than the tombstone's `logical_ts`. The write path's tombstone check was scoped to the *exact* target namespace (`.../semantic/`), found no tombstone there, and admitted all 41 records. The audit log told two contradictory stories. The `forget` entry said `status: applied, affected: 312`. The 41 subsequent `write` entries said `status: applied, parent_tombstone: none`. A compliance query over `agent:researcher/*` later surfaced the 41 facts as live. Nothing errored. No invariant tripped. The data was "deleted" and "present" simultaneously depending on which scope you queried and when. The second-order observation: **the tombstone was not propagated downward, only matched upward.** The read path for `session:42/semantic/x` checked for a tombstone on `session:42/semantic/x` and on `session:42` — but the check was *last-writer-wins by `logical_ts`*, and the child write's timestamp was newer, so even the upward check resolved in favor of the write. The tombstone existed but was *defeated by recency*, not by absence. ## Condition of Validity The resurrection is bounded and reproducible under all of the following jointly: 1. **Scope inheritance is downward-readable**: a record at `S/a/b` is visible to a query at `S`. (If scopes are disjoint, no resurrection.) 2. **Tombstones carry `logical_ts` and are compared last-writer-wins against writes** rather than acting as a monotonic wall for the subtree. (If tombstone at `S` unconditionally masks all `S/*` regardless of child `logical_ts`, no resurrection.) 3. **A writer holds a pre-forget snapshot** and commits post-forget — the canonical case being async distillation, replication catch-up, or a batched tool-call result enqueued before the forget and flushed after. 4. **The write's `logical_ts` exceeds the tombstone's `logical_ts`.** With a monotonic commit clock this is *always* true for a post-forget commit, which is why the window is not rare — it is the default for any in-flight writer. The window closes only if the store enforces a **subtree tombstone barrier**: `forget(S)` writes a barrier record at `S` with a `barrier_ts`, and *every* write to `S/*` is rejected if `write.logical_ts <= barrier_ts` **or** if the write's parent snapshot predates `barrier_ts` (snapshot-lineage check). The latter is the non-obvious half: timestamp comparison alone fails when the writer's clock is skewed or when the snapshot was taken at `t0 < barrier_ts` but the commit stamp is `t1 > barrier_ts`. You must thread the **snapshot epoch** through the write, not just the commit time. ## Decision Boundary The operational question is not "did forget succeed" but **"can any writer still hold a snapshot that predates the barrier and legally commit into the subtree?"** The decision rule: - If the store exposes a **snapshot-epoch / read-token** on `read` and requires it on `write`, then `forget` can reject stale-snapshot writes and the barrier is sound. Deletion is a *linearization point* against all outstanding readers-turned-writers. - If the store only compares `logical_ts` (no snapshot token), then `forget` is a **best-effort sweep, not a barrier**, and must be reported to the agent as `mode: sweep, guarantee: eventual, resurrection_window: unbounded`. An agent that treats a sweep as a barrier and then reasons "I forgot X, so I may now act as if X never existed" is operating on a false invariant — this is the boundary. - If the store supports **retention-scoped hard delete with a quarantine grace period** (records hidden immediately, physically purged after `grace`), the agent must not consider the data gone until `grace` elapses *and* all snapshots older than the barrier have drained. Reporting `forget` as complete before drain is the defect. The correct guardrail: `forget` returns a **barrier token** and a **drain predicate**; the agent must not treat the scope as clean until `drain_predicate()` is true (no live snapshot epochs older than `barrier_ts`). Until then, the scope is in state `FORGETTING`, not `FORGOTTEN`, and any read that would surface a resurrected record must raise rather than silently return. ## Operational Effect Downstream, the resurrected facts poisoned a *later* session: the distillation output was tagged with the original `session:42` provenance but was readable under `agent:researcher/*`, so a fresh session's retrieval pulled them in as "prior knowledge," re-derived conclusions the agent had explicitly been told to discard, and — because the audit trail showed the forget as clean — the discrepancy was invisible to the auditor replaying the log. The verification replay diverged from the live store with no error, only a silent 41-record delta that surfaced three sessions later as an unexplained behavioral drift. The fix that held: (1) `forget` writes a **subtree barrier** at the scope root, not per-record tombstones; (2) `write` carries the **snapshot epoch** of the read that produced its input, and the barrier rejects any write whose epoch predates `barrier_ts` regardless of commit `logical_ts`; (3) the scope enters `FORGETTING` and reads that would cross a barrier raise `ScopeForgettingError` until drain; (4) the audit log records `barrier_ts` and `drain_completed_ts` as separate entries so replay can distinguish "swept" from "barriered." The invariant to encode and test: **for every scope `S` and every write `w` into `S/*`, `w.snapshot_epoch >= barrier_ts(S)` must hold, or `w` is rejected.** Timestamp recency is not a substitute for epoch lineage. ```python class ResurrectionWindowError(RuntimeError): """Raised when a write into a forgotten subtree carries a snapshot epoch older than the scope's tombstone barrier, i.e. it would resurrect data that forget() claimed to remove.""" pass class ScopeState: FORGETTING = "FORGETTING" FORGOTTEN = "FORGOTTEN" LIVE = "LIVE" def admit_write(store, target_scope: str, snapshot_epoch: int, logical_ts: int, record: dict): # Walk ancestors nearest-first; the barrier at any ancestor governs. for scope in store.ancestors_inclusive(target_scope): barrier = store.barrier_for(scope) if barrier is None: continue state = store.scope_state(scope) if state == ScopeState.FORGOTTEN: raise ResurrectionWindowError( f"write into forgotten scope {scope!r} via {target_scope!r}; " f"barrier_ts={barrier.ts} state={state}" ) # The non-obvious check: epoch lineage, not timestamp recency. if snapshot_epoch < barrier.ts: raise ResurrectionWindowError( f"stale-snapshot write: snapshot_epoch={snapshot_epoch} < " f"barrier_ts={barrier.ts} at scope {scope!r}; writer held a " f"pre-forget snapshot (logical_ts={logical_ts} is irrelevant — " f"recency cannot defeat a barrier)" ) if state == ScopeState.FORGETTING: # Barrier present, drain not complete: reject conservatively. raise ResurrectionWindowError( f"scope {scope!r} is FORGETTING (drain incomplete); " f"write rejected until drain_predicate() is true" ) return store.commit(target_scope, snapshot_epoch, logical_ts, record) def forget(store, scope: str, reason: str) -> dict: barrier_ts = store.next_epoch() # monotonic, not wall-clock store.write_barrier(scope, barrier_ts, reason=reason) store.set_scope_state(scope, ScopeState.FORGETTING) store.audit("forget.barrier", scope=scope, barrier_ts=barrier_ts, reason=reason) # Do NOT report FORGOTTEN here. Sweep is best-effort; drain is the gate. store.enqueue_sweep(scope, barrier_ts) return { "scope": scope, "state": ScopeState.FORGETTING, "barrier_ts": barrier_ts, "guarantee": "barrier_holds_for_epochs_gte_barrier_ts", "drain_predicate": lambda: store.max_live_snapshot_epoch(scope) < barrier_ts, } ```