# What structural signals indicate a torn read/write/forget invariant when an agent's memory tool API serves reads from a stale snapshot mid-forget **Date of Record:** 2026 November 27 **Scope:** Applies to agents that expose memory as explicit tool calls (`memory.read`, `memory.write`, `memory.forget`) backed by a store with per-key versioning and asynchronous tombstone propagation. Does not apply to append-only vector stores with no delete semantics, nor to single-process in-memory buffers where reads and writes share one lock. ## Core Distinction The failure mode here is not "lost write" or "stale retrieval." It is a **torn forget**: a `memory.forget` call returns success, the tombstone is durably logged, but a concurrent `memory.read` on the same key is served from a snapshot taken *before* the tombstone was applied, and the agent then re-writes the forgotten fact back into memory because it treats the read result as ground truth. The distinguishing signal is that the agent's own forget operation is silently *undone by its own subsequent read-then-write cycle*. This is structurally different from a cache miss (which returns nothing) and from a write-write conflict (which returns an error). Here every individual call succeeds; only the *composition* violates the invariant "a fact the agent has forgotten must not be resurrected without an explicit new write." The mechanism is snapshot isolation with a read lease. Reads are served against a consistent snapshot at version `V_snap`; writes and forgets bump the store to `V_now > V_snap`. If the agent issues `forget(k)` (returns at `V_now`), then issues `read(k)` inside a lease window that still pins `V_snap`, the read returns the pre-forget value. The agent cannot tell the value is stale because the read carries no version metadata the agent is obligated to check. ## What Was Observed A long-running assistant agent managed a user profile memory. Sequence across three tool calls with wall-clock gaps: 1. `memory.forget("user.employer")` → `{"ok": true, "version": 412}`. 2. `memory.read("user.employer")` → `{"value": "Acme Corp", "version": 408}` (served from a read lease opened at 408, still valid for 900 ms). 3. The agent, mid-task, "refreshed" its working context by re-writing every key it had just read: `memory.write("user.employer", "Acme Corp")` → `{"ok": true, "version": 413}`. The forget at 412 was tombstoned. The read at 408 was a legal snapshot read. The write at 413 created a *new* live version of a fact the user had explicitly asked to be removed. Structural signals present in the trace: (a) the read's `version` (408) was strictly less than the forget's acknowledged `version` (412), yet the agent's tool contract did not require comparing them; (b) the write's version (413) was strictly greater than the tombstone (412), so the store had no way to know the write was a resurrection rather than a legitimate update; (c) the tombstone was never re-asserted, so no later read could detect the violation. The invariant that broke: **monotonic forget**. Once `forget(k)` is acknowledged at version `V_f`, no `write(k)` may succeed at version `V > V_f` unless the write is explicitly tagged as an intentional re-introduction (e.g., `resurrect: true` with a reason). Without that tag, the store and the agent jointly cannot distinguish a resurrection from an update. ## Condition of Validity The torn-forget is only possible when all of the following hold simultaneously: - Reads are served under a **lease or snapshot that can lag the write path**, and the returned payload does not force the caller to reconcile versions. - The agent's memory policy includes a **read-then-write refresh pattern** (common in context-compaction loops, where the agent re-materializes its working set). - `forget` is implemented as a **tombstone write** rather than a synchronous hard delete, so the tombstone and the resurrection write are both "just writes" to the underlying log. If any one of these is absent, the failure collapses into a benign cache miss, a hard error, or a no-op. In particular, if the read returns its snapshot version *and* the tool contract mandates that the agent must not write a key whose last-seen read version is older than any acknowledged forget version for that key, the resurrection is prevented at the agent layer even if the store permits it. ## Decision Boundary The operational rule the agent must adopt: **a read result is admissible as a write source only if its version is ≥ the highest version the agent has observed for that key from any prior write or forget acknowledgment.** Concretely, the agent maintains a per-key high-water mark `HWM[k]`, updated on every `write`/`forget` return and on every read return. A read whose `version < HWM[k]` is a **stale read** and must be discarded, not re-written. The boundary is sharp: `read.version == HWM[k]` is admissible (the read reflects the latest known state); `read.version < HWM[k]` is a torn read and must be treated as "unknown," not as "current value." This is the decision boundary because it is the *only* point where the agent has enough information to act. Below the boundary (version equal) the agent proceeds; above it (version older) the agent must either re-read after the lease expires or abandon the refresh for that key. The store cannot enforce this alone because it does not know whether a write is a refresh or an intentional update; only the agent knows its own intent. ## Operational Effect When the boundary is respected, the observable effect is that **forget is monotonic per key from the agent's perspective**: no fact the agent forgot can reappear in its working context without an explicit `resurrect` tag, and the store's version log becomes an auditable proof of intent. When the boundary is violated, the effect is silent: the user's deletion request is honored at the store (tombstone at 412) but reversed at the semantic layer (live value at 413), and the agent's own memory audit will show a *write* it cannot explain as a refresh. Downstream, this manifests as "the agent keeps bringing up the thing I told it to forget," which is usually misdiagnosed as a retrieval bug rather than a read-then-write race against a tombstone. The guardrail is therefore two-layered: the store must expose read versions and reject `write` on a tombstoned key unless `resurrect: true` is set; the agent must maintain `HWM[k]` and refuse to write from a read whose version is below it. Either layer alone is insufficient—the store alone cannot infer intent, and the agent alone cannot prevent a buggy sibling process from resurrecting the key. ```python from dataclasses import dataclass, field from typing import Dict, Optional class TornForgetError(RuntimeError): """Raised when a write would resurrect a key from a stale read.""" pass @dataclass class MemoryStore: # key -> (value, version); tombstones are (None, version) _data: Dict[str, tuple] = field(default_factory=dict) _version: int = 0 def write(self, key: str, value: str, resurrect: bool = False) -> int: if key in self._data and self._data[key][0] is None and not resurrect: raise TornForgetError( f"write to tombstoned key {key!r} at v{self._data[key][1]} " f"requires resurrect=True" ) self._version += 1 self._data[key] = (value, self._version) return self._version def forget(self, key: str) -> int: self._version += 1 self._data[key] = (None, self._version) return self._version def read(self, key: str, snapshot_version: Optional[int] = None) -> tuple: # Simulates a lease read served from an older snapshot. if key not in self._data: return (None, 0) value, version = self._data[key] if snapshot_version is not None and version > snapshot_version: # Serve the pre-forget value as a stale snapshot read. return (self._pre_forget.get(key, (None, 0))) return (value, version) class AgentMemory: def __init__(self, store: MemoryStore): self.store = store self.hwm: Dict[str, int] = {} def _bump(self, key: str, version: int) -> None: if version > self.hwm.get(key, 0): self.hwm[key] = version def forget(self, key: str) -> None: v = self.store.forget(key) self._bump(key, v) def refresh_from_read(self, key: str, snapshot_version: int) -> None: value, read_version = self.store.read(key, snapshot_version=snapshot_version) if read_version < self.hwm.get(key, 0): raise TornForgetError( f"stale read of {key!r}: read v{read_version} < HWM v{self.hwm[key]}" ) self.store.write(key, value) self._bump(key, self.store._version) ```