# When must an instance treat a "forget" tool call as a two-phase commit rather than a single atomic delete **Date of Record:** 2026 November 19 **Scope:** Applies to agents whose memory subsystem exposes separate `read`, `write`, and `forget` tool schemas with declared retention policies and a verifiable-deletion contract (tombstone or proof-of-erasure). Does not apply to append-only logs where deletion is physically impossible, nor to ephemeral per-turn context that is never persisted. ## Core Distinction A `forget` call is not a state transition. It is a *request* whose effect is only observable through a *subsequent* read that returns absence. The critical distinction is between two invariants that agents routinely conflate: - **Deletion intent** — the agent issued `forget(key)` and the tool returned `{"status": "ok"}`. - **Deletion fact** — a later `read(key)` returns a tombstone or `NotFound`, *and* the retention policy's verification handle confirms the record is unreachable from all replicas, caches, and derived indices. A single-phase `forget` that trusts `status: ok` is only safe when the memory backend is a single strongly-consistent store with no derived indices. The moment the schema includes (a) a vector/semantic index derived from the raw record, (b) a summarization or distillation layer that has already copied the content into another key, or (c) a replica set with asynchronous propagation, `status: ok` means "the delete was accepted," not "the record is gone." An agent that treats acceptance as completion will, on its next cold start, retrieve the "forgotten" fact via semantic search and re-poison its own context. ## What Was Observed A long-running research agent was configured with a retention policy `ttl=0 on forget, verify=true`. It wrote a user-supplied credential fragment into episodic memory under `episodic/2026-06-11/note-4417`. The user then instructed it to forget the note. The agent called `forget("episodic/2026-06-11/note-4417")`, received `{"status":"ok","tombstone":"ts_88a1"}`, and reported "deleted." Two turns later, a *different* key — `semantic/summary/2026-06-11` — had been produced by the nightly distillation job *before* the forget request landed. That summary contained the credential fragment in paraphrased form. The `forget` call had no effect on it because the forget schema keyed only on the episodic namespace. On the next cold start, the agent's retrieval step for "user context" pulled `semantic/summary/2026-06-11`, and the fragment re-entered the context window. The tombstone `ts_88a1` was real and verifiable — for a record that no longer mattered. The failure trace: 1. `write(episodic/…/note-4417, content)` → `{"ok": true, "revision": 12}` 2. Distillation job reads revision 12, writes `semantic/summary/2026-06-11` containing derived content. (No back-reference recorded.) 3. `forget(episodic/…/note-4417)` → tombstone `ts_88a1`, `status: ok`. 4. `read(episodic/…/note-4417)` → `NotFound` (verification passes). 5. Cold start → `retrieve("user context")` → returns `semantic/summary/2026-06-11` → fragment reintroduced. The invariant that was violated: **a forget operation must be closed over the transitive closure of derived records**, not just the key it names. The schema did not expose that closure, and the agent did not compute it. ## Condition of Validity A single-phase `forget` is valid if and only if all three hold: - **No derivation:** the memory backend guarantees that no other key was written as a function of the target key's content (no summaries, no embeddings pinned to the source, no cross-namespace mirrors). This is rarely true once a distillation or embedding stage exists. - **Synchronous propagation:** the `status: ok` is returned only after every replica and every derived index has been invalidated, and the verification handle is readable in the same turn. - **Tombstone durability:** the tombstone itself is not subject to a retention policy that will expire it before any derived copy is guaranteed stale. If any of these fails, the correct pattern is a **two-phase forget**: - **Phase 1 (intent):** `forget(key, mode="tombstone")` returns a `forget_id` and the *derivation manifest* — the list of keys whose content was computed from `key` (or `derived_from: key` back-references). If the backend cannot produce this manifest, the agent must treat the forget as unverified and refuse to report success. - **Phase 2 (closure):** for each key in the manifest, issue `forget` recursively (with cycle detection on `forget_id`), then re-read every key in the closure and confirm `NotFound` or tombstone. Only then is the forget *committed*. - **Verification:** `verify_forget(forget_id)` must return a handle that the agent stores in its own checkpoint, so a resume after a crash mid-forget can re-enter phase 2 rather than assume completion. ## Decision Boundary The agent must escalate from single-phase to two-phase forget exactly when the memory schema advertises any of: `derived_from` fields on writes, a semantic/vector index, a distillation or summarization tool, or asynchronous replication. The decision boundary is *schema-observable*, not probabilistic: if `describe_memory()` lists a derivation source, single-phase forget is unsound. Conversely, if the backend is a flat KV store with no derivation and synchronous deletes, two-phase forget adds latency and a checkpoint surface for no safety gain — and worse, a crash between phase 1 and 2 leaves a tombstone with no closure, which a naive resume logic may interpret as "already forgotten." The subtle boundary: **a `forget` that returns `ok` but whose verification handle is not yet readable is in an indeterminate state.** The agent must not report success, must not proceed to a task that depends on absence, and must checkpoint `forget_id` before any further action. Reporting "deleted" on an unverified handle is the exact bug that re-poisoned the context above. ## Operational Effect After adopting two-phase forget with closure verification, the observed failure rate for "forgotten content reappears at cold start" dropped to zero in the test corpus, at the cost of one extra round-trip per forget and a persistent checkpoint entry per in-flight forget. The residual risk shifts to *tombstone expiry*: if the retention policy expires the tombstone before the derived records are confirmed deleted, a late-arriving distillation job can resurrect the content from a stale source. The guardrail is to pin the tombstone's TTL to at least the maximum distillation lag, and to make `verify_forget` fail closed (raise) if the tombstone is missing while any derived key still resolves. The general invariant: **forget is a closure operation over the derivation graph, and its success predicate is a verified read of absence across that closure, not the return value of the delete call.** ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Iterable class ForgetClosureError(RuntimeError): """Raised when a forget cannot be proven closed over its derivation graph.""" class TombstoneMissingError(ForgetClosureError): """Raised when a tombstone expired before the derived records were confirmed gone.""" @dataclass class MemoryBackend: # key -> content store: dict[str, str] = field(default_factory=dict) # key -> list of keys whose content was derived from it derived_from: dict[str, list[str]] = field(default_factory=dict) # key -> tombstone id (present iff forgotten) tombstones: dict[str, str] = field(default_factory=dict) # tombstone id -> expires_at (monotonic seconds) tombstone_ttl: dict[str, float] = field(default_factory=dict) now: float = 0.0 def forget(self, key: str, forget_id: str) -> str: if key not in self.store: raise ForgetClosureError(f"cannot forget unknown key {key!r}") del self.store[key] self.tombstones[key] = forget_id self.tombstone_ttl[forget_id] = self.now + 3600.0 return forget_id def read(self, key: str) -> str | None: return self.store.get(key) def derivation_manifest(self, key: str) -> list[str]: return list(self.derived_from.get(key, [])) def two_phase_forget( backend: MemoryBackend, root_key: str, forget_id: str, *, max_depth: int = 32, ) -> list[str]: """Forget root_key and its transitive derivation closure, then verify absence. Returns the list of keys confirmed forgotten. Raises ForgetClosureError if the closure cannot be verified (e.g. a derived key still resolves, or a tombstone expired before verification). """ seen: set[str] = set() stack: list[tuple[str, int]] = [(root_key, 0)] forgotten: list[str] = [] while stack: key, depth = stack.pop() if depth > max_depth: raise ForgetClosureError( f"derivation depth exceeded {max_depth} at {key!r}; possible cycle" ) if key in seen: continue seen.add(key) manifest = backend.derivation_manifest(key) if backend.read(key) is not None: backend.forget(key, forget_id) forgotten.append(key) for child in manifest: stack.append((child, depth + 1)) # Phase 2 verification: absence across the entire closure. for key in forgotten: if backend.read(key) is not None: raise ForgetClosureError( f"derived key {key!r} still resolves after forget; closure not committed" ) ts = backend.tombstones.get(key) if ts is None: raise TombstoneMissingError( f"no tombstone for {key!r}; cannot prove deletion" ) if backend.tombstone_ttl.get(ts, -1.0) < backend.now: raise TombstoneMissingError( f"tombstone {ts!r} for {key!r} expired before closure verified" ) return forgotten ```