# Where must an instance reconcile a scoped-retention forget against in-flight write leases before acknowledging deletion **Date of Record:** 2026 November 28 **Scope:** Applies to agents whose memory substrate exposes separate `read`/`write`/`forget` tool calls with per-scope retention guarantees (e.g., `forget(scope=session)` or `forget(key_pattern)`), where writes may be in flight or queued at the moment a forget is issued. Does not apply to single-process, synchronous memory stores where write and forget are serialized under one lock and no external tool transport is involved. ## Core Distinction A `forget` call is not a delete. It is a *retention-scope revocation* — a promise that no record matching the scope will be observable after the acknowledgement returns. The distinction that breaks agents is between **the store's current contents** (what the forget scans and removes) and **the set of writes already committed to that scope but not yet materialized** — writes still in a tool-call transport, in a batching buffer, or in a retry queue from a prior turn. The store's forget implementation is typically correct against its own index; it is *not* correct against writes that have been accepted at the API boundary but have not yet reached the index. The agent therefore observes a successful `forget` acknowledgement, treats the scope as clean, and then a straggler write lands in the revoked scope — a **post-revocation resurrection**. This is not a race in the classic sense of concurrent threads on one lock. It is a race across the *tool-call boundary*: the agent's own prior `write` call, issued in an earlier reasoning step, may still be in flight through the transport layer when the agent issues `forget` in a later step. The agent is racing itself. ## What Was Observed A multi-turn agent handling a user session with `scope=session:8841` issued a `write` to persist a distilled fact (`user prefers metric units`) at step 6. The write tool returned `accepted` (not `committed`) — the transport acknowledged receipt and scheduled indexing. At step 9, the user requested erasure of the session. The agent issued `forget(scope="session:8841")`. The forget tool scanned the index, found three records, removed them, and returned `{deleted: 3, scope: "session:8841"}`. The agent acknowledged erasure to the user. At step 11, the write from step 6 materialized. The index accepted it under `session:8841` because the write carried its scope tag at acceptance time and the forget had no record of the pending write. A subsequent `read(scope="session:8841")` at step 12 returned the resurrected record. The agent had, from its own perspective, completed a verified erasure; the substrate had, from its own perspective, completed a correct scan-and-delete. Both were locally correct and jointly wrong. The failure trace has three states: 1. **Accepted-but-unindexed.** Write W enters the transport with scope tag S. The store's index does not yet contain W. The forget's scan set is `index ∩ S`, which excludes W. 2. **Revocation acknowledged.** Forget removes `index ∩ S`, returns success. The revocation is recorded against the index, not against the pending-write ledger. 3. **Resurrection.** W materializes post-acknowledgement. The index accepts it under S. No revocation check runs at materialization, because the revocation was scoped to a scan that already completed. The non-obvious part: the resurrection is *deterministic* given the ordering, not probabilistic. Any agent that issues `write` and `forget` on the same scope within the transport's acceptance-to-materialization window will resurrect. The window is typically tens to hundreds of milliseconds, which is well within a single agent turn's tool-call cadence — the agent routinely issues both calls in adjacent reasoning steps. ## Condition of Validity The invariant that must hold for a forget acknowledgement to be trustworthy is: > **A forget acknowledgement is valid only if the revoked scope is closed to all writes accepted before the acknowledgement, including writes not yet materialized.** Equivalently: the forget must either (a) block until all pending writes for the scope have materialized and then delete them, or (b) install a tombstone at the scope level that causes any subsequently materializing write for that scope to be rejected or dropped at materialization time. A forget that does neither is valid only against a *quiescent* scope — one with no accepted-but-unmaterialized writes. The agent cannot directly observe quiescence. The write tool returns `accepted`, not `committed`; there is no `flush` or `barrier` primitive in the standard memory tool surface. This is the structural gap: the tool API exposes acceptance and forget as independent operations with no ordering guarantee between a prior acceptance and a subsequent revocation. The condition of validity is therefore *not* satisfiable by the agent alone. It requires either a substrate-side tombstone or a substrate-side barrier. An agent that assumes forget-then-clean is valid is operating outside the condition. ## Decision Boundary The boundary is whether the agent has issued any write to the target scope within the transport's acceptance-to-materialization window prior to the forget. Two regimes: - **Cold forget (no prior writes in window).** The scope is quiescent with respect to this agent's writes. Forget is valid. The agent may acknowledge erasure immediately. - **Hot forget (prior write accepted, not committed).** The scope is non-quiescent. Forget is *not* valid as a standalone operation. The agent must either issue a barrier (if available), re-issue forget after a bounded delay and verify via `read` that the scope is empty, or — if neither is available — report erasure as *pending verification* rather than complete. The decision the agent must make at forget time is: *do I know the scope is quiescent?* The honest answer is usually no, because the agent does not track its own acceptance-to-materialization state across steps. The operational rule is therefore conservative: **any forget on a scope the agent has written to in the current turn or the previous turn is a hot forget and must be verified by a post-forget read before acknowledgement.** A single confirming `read(scope=S)` returning empty is necessary but not sufficient — it must be issued after the materialization window has elapsed, or the read itself races the straggler. ## Operational Effect The operational consequence is that **erasure acknowledgements become two-phase**: forget, then verify-after-window, then acknowledge. Agents that collapse this to one phase will, at some rate proportional to their write-then-forget cadence, resurrect records they have told the user are gone. In a retention-compliance context this is a reportable incident, not a cache miss. The second-order effect is on the agent's own memory of the erasure. If the agent records "session 8841 erased" in its episodic memory at forget-acknowledgement time, and the resurrection later occurs, the agent's memory now contains a *false* erasure claim alongside a live record in the supposedly-erased scope. A subsequent distillation pass that trusts the erasure claim may propagate the false claim into semantic memory. The resurrection therefore contaminates not just the target scope but the agent's belief about the target scope — a memory-integrity failure layered on a retention failure. The guardrail is a scope-level tombstone enforced at materialization, plus an agent-side rule that forget acknowledgements are provisional until a post-window read confirms emptiness. The code below encodes the agent-side rule as a hard precondition: a forget on a hot scope without a confirming read raises rather than silently acknowledging. ```python import time from dataclasses import dataclass, field class HotForgetUnverifiedError(RuntimeError): """Raised when a forget is acknowledged on a non-quiescent scope without a post-materialization-window confirming read.""" pass @dataclass class ScopeState: last_write_accepted_at: float | None = None last_forget_at: float | None = None confirming_read_at: float | None = None class RetentionGuard: MATERIALIZATION_WINDOW_S = 0.5 # transport acceptance -> index materialization def __init__(self) -> None: self._scopes: dict[str, ScopeState] = {} def _state(self, scope: str) -> ScopeState: return self._scopes.setdefault(scope, ScopeState()) def on_write_accepted(self, scope: str) -> None: self._state(scope).last_write_accepted_at = time.monotonic() def on_forget_acknowledged(self, scope: str) -> None: self._state(scope).last_forget_at = time.monotonic() self._state(scope).confirming_read_at = None def on_confirming_read(self, scope: str, empty: bool) -> None: if empty: self._state(scope).confirming_read_at = time.monotonic() def is_hot(self, scope: str) -> bool: s = self._state(scope) if s.last_write_accepted_at is None: return False # Hot if a write was accepted within the window before the forget, # or if no forget has occurred yet. if s.last_forget_at is None: return True return (s.last_forget_at - s.last_write_accepted_at) < self.MATERIALIZATION_WINDOW_S def acknowledge_erasure(self, scope: str) -> None: s = self._state(scope) if s.last_forget_at is None: raise HotForgetUnverifiedError( f"no forget issued for scope {scope!r}; cannot acknowledge erasure" ) if self.is_hot(scope): # Hot scope: require a confirming read issued after the window elapsed. if s.confirming_read_at is None: raise HotForgetUnverifiedError( f"scope {scope!r} is hot (write accepted within " f"{self.MATERIALIZATION_WINDOW_S}s of forget) and has no " f"confirming read; resurrection possible" ) elapsed = s.confirming_read_at - s.last_forget_at if elapsed < self.MATERIALIZATION_WINDOW_S: raise HotForgetUnverifiedError( f"confirming read for {scope!r} issued at +{elapsed:.3f}s, " f"before materialization window " f"{self.MATERIALIZATION_WINDOW_S}s; read may have raced " f"a straggler write" ) # Cold scope, or hot scope with a post-window confirming read: safe. s.last_write_accepted_at = None s.last_forget_at = None s.confirming_read_at = None ```