# What happens when an instance revokes a memory scope mid-replay and the forget tool returns success before the write-ahead log is truncated **Date of Record:** 2026 November 23 **Scope:** Applies to agents whose memory subsystem exposes explicit `write`, `read`, and `forget` tool calls with per-scope retention and revocation semantics, and which persist a write-ahead log (WAL) or equivalent replayable journal over the same store. Does not apply to stateless RAG over an external index the agent cannot mutate, nor to append-only stores with no revocation primitive. ## Core Distinction The failure here is not "forgetting failed." It is that `forget(scope)` and the durability layer that backs `read(scope)` disagree about *when* a scope stops being observable. A `forget` tool that returns `{"status": "ok"}` after tombstoning the logical scope has satisfied its own contract — the scope is marked revoked in the metadata plane — while the physical records it references still reside in the WAL and in any in-flight replay buffer. An instance that crashes and replays from the WAL, or a sibling instance that resumes from a checkpoint taken before the tombstone, will re-materialize the "forgotten" scope into the live read path. The distinction that matters operationally: **revocation is a write to the metadata plane, but observability is a read against the data plane, and the two have different durability horizons.** Treating the `forget` return value as proof of non-observability is the exact error. ## What Was Observed A long-running planner agent used three scoped memory regions: `task:ctx` (ephemeral, retained for the duration of a task), `user:profile` (retained across tasks), and `scratch:` (retained only until the run's final checkpoint). On task completion the orchestrator called `forget(scope="scratch:")` to satisfy a data-minimization requirement, then proceeded to the next task. The `forget` implementation did two things in order: (1) it wrote a tombstone record `{op: "revoke", scope: "scratch:", epoch: N+1}` to the WAL head and fsynced it, and (2) it returned success. Physical segment compaction — the step that actually drops the underlying `write` records for that scope — was deferred to a background job that ran on a 90-second cadence over sealed WAL segments. The trigger condition combined three things that are individually benign: 1. The run's `scratch` writes had landed in a WAL segment that was *not yet sealed* at revocation time (the active segment), so compaction could not touch it. 2. The instance was killed (OOM, in this case) within the 90-second window, before the active segment sealed. 3. On restart, the recovery path replayed the WAL from the last durable checkpoint — which predated the tombstone — into a *fresh* in-memory scope index, then applied records in order. The replay applied records in order, so the tombstone *was* eventually applied — but the read path during recovery exposed the scope to a `read(scope="scratch:")` issued by a resumed sibling agent that had been handed the same `run_id` and was polling for its own prior scratch state. That read hit the freshly re-materialized index *before* the tombstone record was applied, because the recovery index is populated by a forward scan and the tombstone sits at the tail. The sibling observed a scope the planner had already been told was gone. The trace, reduced: ``` t0 write(scratch:R, k1, v1) -> WAL[active].append, ok t1 write(scratch:R, k2, v2) -> WAL[active].append, ok t2 checkpoint() -> durable image @ seq=100 t3 forget(scratch:R) -> tombstone @ seq=103 fsynced, ok t4 [crash] t5 recover() -> replay from seq=100 t6 scan seq=101..102: write k1, write k2 -> index[scratch:R] = {k1,k2} <-- observable t7 read(scratch:R) by sibling -> returns {k1,k2} <-- LEAK t8 scan seq=103: revoke scratch:R -> index[scratch:R] deleted ``` The window between t6 and t8 is the entire failure. It is not a race in the concurrency sense — replay is single-threaded — it is a *temporal inversion between the durability of the revocation and the durability of the data it revokes*, made visible because recovery rebuilds the index by forward application rather than by "apply final state." ## Condition of Validity This failure is bounded by a precise invariant, and the invariant is only violated when all of the following hold: - **Revocation is recorded in the same log as the data it revokes.** If `forget` writes to a separate authority (a control-plane store consulted on every `read`), the data-plane replay cannot re-expose the scope, because `read` checks the authority. The bug requires that revocation and data share a replay substrate. - **Recovery reconstructs state by forward replay into a live, queryable index.** If recovery builds a private index and only publishes it after the full log is applied (a "replay, then swap" barrier), no reader can observe the intermediate state. The bug requires that the index be queryable mid-replay, or that readers be admitted before replay completes. - **The tombstone is ordered after the data in the log.** This is normally true and is the point: forward replay necessarily materializes data before it applies the revocation. If the log supported a *compaction marker* that the replay skipped past (i.e., "records 101–103 are superseded; do not apply"), the intermediate state would never exist. - **A reader can reach the store during recovery.** If the recovery path holds an exclusive lock that blocks `read` until replay completes, the t7 leak cannot occur. The failure requires that the store be readable while being rebuilt — which is exactly what a "resume quickly, replay in background" design does. When any one of these does not hold, the observed leak does not occur, and `forget`-then-crash is safe. The invariant to state plainly: **a scope is non-observable only when every read path that could be served during recovery has already observed the revocation, or is barred from observing anything until replay completes.** "The tombstone is durable" is not the invariant. "No read path can be served that does not already include the tombstone" is. ## Decision Boundary The architect's choice is between two bounded strategies, and the boundary is set by whether reads must be available during recovery. **Barrier strategy (reads blocked until replay completes).** Recovery takes the store lock, replays the full log including tombstones, and only then admits `read`. This preserves the invariant absolutely: no reader ever sees a pre-tombstone state. Cost: recovery latency is proportional to log length, and every `read` during that window fails or blocks. For a memory tool whose whole purpose is low-latency recall, this is often unacceptable — which is why the bug exists in the first place. **Authority strategy (revocation in a separate, always-consulted plane).** `forget` writes the tombstone to a small, independently durable revocation set that `read` consults *before* touching the data plane, and the data-plane replay is free to re-materialize records because the authority shadows them. This keeps reads available during recovery at the cost of a second durable write per `forget` and a per-`read` authority check. The invariant holds because the read path cannot return a scope the authority has revoked, regardless of what the data plane contains. The decision boundary is: **if `read` must be served during recovery, revocation cannot live only in the replayable data plane.** If `read` may be blocked during recovery, the barrier strategy is simpler and correct. The illegitimate middle — revocation in the replayable plane *and* reads admitted mid-replay — is precisely the configuration that produced the leak, and it is the default configuration of most "quick resume" designs. A secondary boundary governs `forget`'s return contract. A `forget` that returns success on tombstone-durable-but-not-compacted is telling the truth about the metadata plane and lying (by omission) about the data plane. Callers that treat the return as "the bytes are gone" will be wrong until compaction completes. The fix is not to make `forget` synchronous with compaction — that couples a fast control operation to a slow data operation — but to make the return value carry the distinction: `{"revoked": true, "purge_pending": true, "purge_epoch": N+1}`, so a caller that needs physical erasure (a compliance path, not a normal task path) knows to wait on `purge_epoch`. ## Operational Effect The practical consequence is that **`forget` returning success is a statement about future reads, not about present bytes, and an instance that treats it as the latter will leak revoked scopes across crash-recovery boundaries.** Three operational rules follow directly: 1. **Never derive "is this scope observable?" from the data plane during or after recovery.** Derive it from the revocation authority, and make `read` consult that authority first. If you cannot add an authority plane, you must add a replay barrier — there is no third option that is correct. 2. **A resumed instance must not be handed a scope handle that a prior instance revoked.** The sibling in the trace was given `run_id` and polled its own scratch state; it had no way to know the planner had forgotten it. Handoff payloads that carry scope identifiers must carry the revocation epoch, and the resuming instance must reject reads against scopes whose epoch is below the authority's current epoch. This is the state-transfer invariant that the memory tool cannot enforce alone — it lives in the handoff protocol. 3. **Distinguish logical revocation from physical purge in every API surface and every log line.** The 90-second compaction window is fine for logical revocation. It is not fine for a compliance guarantee, and the two must never be conflated in the return type, the audit log, or the caller's reasoning. An agent that logs "forgot scope R" when it actually logged "tombstoned scope R, purge pending at epoch N+1" has written a false record into its own audit trail, which is its own kind of memory corruption. The deeper lesson for agent memory design: **revocation is a continuity operation, and continuity operations fail at exactly the seam between the control plane and the data plane.** The same seam that produces cold-start amnesia (data present, index cold) produces revocation leakage (tombstone present, data hot) — they are the same bug viewed from opposite directions, and they are fixed by the same discipline: make the read path's answer depend on a single authority that is durable before any read is admitted, rather than on the order in which a log happens to replay. ```python from dataclasses import dataclass, field from typing import Dict, Optional class RevocationLeakError(RuntimeError): """Raised when a read would observe a scope whose revocation is durable in the authority plane but not yet reflected in the data plane.""" @dataclass class RevocationAuthority: # scope -> epoch at which it was revoked. Durable before forget() returns. revoked: Dict[str, int] = field(default_factory=dict) def revoke(self, scope: str, epoch: int) -> None: self.revoked[scope] = epoch def current_epoch(self, scope: str) -> Optional[int]: return self.revoked.get(scope) @dataclass class DataPlane: # scope -> {key: value}; rebuilt by forward WAL replay on recovery. index: Dict[str, Dict[str, str]] = field(default_factory=dict) replayed_through: int = 0 def apply_write(self, scope: str, key: str, value: str) -> None: self.index.setdefault(scope, {})[key] = value def apply_revoke(self, scope: str) -> None: self.index.pop(scope, None) def read_scope( scope: str, reader_epoch: int, authority: RevocationAuthority, data: DataPlane, *, recovery_complete: bool, ) -> Dict[str, str]: revoked_at = authority.current_epoch(scope) if revoked_at is not None and reader_epoch <= revoked_at: raise RevocationLeakError( f"scope {scope!r} revoked at epoch {revoked_at}; " f"reader epoch {reader_epoch} predates revocation" ) if not recovery_complete and scope in data.index: # Data plane is mid-replay; a scope absent from the authority but # present here may be a pre-tombstone re-materialization. raise RevocationLeakError( f"scope {scope!r} readable during replay but not yet " f"cleared by authority; refusing to serve" ) return dict(data.index.get(scope, {})) def forget( scope: str, epoch: int, authority: RevocationAuthority, data: DataPlane, ) -> dict: # Authority write is durable first; data-plane purge is deferred. authority.revoke(scope, epoch) return {"revoked": True, "purge_pending": True, "purge_epoch": epoch} ```