# In what scenarios must an instance treat a memory-write acknowledgment as a retention guarantee, and when must it re-verify before acting **Date of Record:** 2026 November 25 **Scope:** Applies to agents whose memory subsystem exposes explicit `write`, `read`, and `forget` tool calls with asynchronous or eventual-consistency semantics, where the agent's own reasoning loop treats a successful write return as proof of durable retention. Does not apply to synchronous, single-transaction memory stores where write acknowledgment and durability are the same atomic event. ## Core Distinction The failure lives in the gap between **acknowledgment semantics** and **retention semantics**. A `write` tool returning `{"status": "ok"}` is an assertion about *acceptance into the write path*, not about *visibility to a subsequent read within the same reasoning trajectory*. Agents routinely collapse these two into one, then build multi-step plans on the assumption that what they just wrote will be readable on the next tool turn. When the memory backend batches, deduplicates, applies retention TTLs, or runs a distillation/compaction pass between turns, the acknowledgment is honest and the retention is still absent. The agent is not lied to; it is interpreting a transport-level success as a storage-level invariant. The second, subtler distinction is between **forget as deletion** and **forget as tombstoning**. A `forget` call that returns success may have only marked a record for later reclamation while a stale copy remains readable through a different retrieval path (semantic index, embedding cache, summary layer). The agent believes the fact is gone; the fact is still reachable and can re-enter context, poisoning later reasoning. ## What Was Observed A concrete trace from a long-horizon task agent using a memory tool with three operations: 1. Turn 14: Agent writes a constraint: `write(key="db_region", value="eu-west-1", retention="session")`. Tool returns `{"ok": true, "id": "m_8812"}`. 2. Turn 15: Agent performs two tool calls (a schema fetch, a config read) that each consume ~4k tokens of context. 3. Turn 16: Agent reads `read(key="db_region")`. Returns `{"ok": true, "value": null, "reason": "not_yet_visible"}` — the write had been routed to a write-ahead buffer with a flush interval, and the read hit a read replica that had not caught up. 4. Turn 16 (same turn, second attempt): Agent, treating the null as "the fact was never stored," re-derives the region from a stale summary in context and writes `db_region="us-east-1"`. This second write *does* land and *overwrites* the pending `eu-west-1` record when the buffer flushes. 5. Turn 22: Agent provisions infrastructure against `us-east-1`. The original `eu-west-1` constraint is gone, and the agent has no record that it ever existed. The failure is not the eventual consistency. It is the **read-after-write assumption combined with a destructive corrective write**. The agent's recovery action for "read returned null" was to write again, which converted a transient visibility gap into a permanent divergence. A second observed variant: the `forget` path. Agent calls `forget(key="user_pii")`, gets `{"ok": true}`, and proceeds to summarize the session into a semantic memory layer. The summary step retrieves from the embedding index, which still contains the pre-forget vector for 30–90 seconds, and the PII re-enters the distilled record — now in a *different* store that the original `forget` never targeted. ## Condition of Validity The invariant that must hold for an acknowledgment to be treated as a retention guarantee is: > A `write` acknowledgment is a retention guarantee **iff** the same instance, on a subsequent turn, can issue a read that is guaranteed to be served by the same consistency domain as the write, AND no compaction/distillation pass can run between the write and the dependent read. In practice this holds only when: (a) the memory tool documents read-your-writes consistency, (b) no summarization/compaction job is scheduled in the window, and (c) the agent does not interleave a `forget` and a distillation in the same trajectory. When any of these is false — which is the default for any memory tool with a batching layer — the acknowledgment is a *write accepted* signal, not a *value retained* signal, and the agent must carry the value in its own working context until it has independently confirmed visibility. The corresponding invariant for `forget` is stronger: a forget acknowledgment is a retention guarantee **only** if the tool's contract explicitly enumerates every retrieval path (exact key, semantic index, summary layer, cache) and asserts deletion across all of them. Absent that enumeration, `forget` must be treated as *best-effort invalidation of one path*, and any downstream distillation must be gated on a post-forget verification read against every path the agent will later query. ## Decision Boundary The operational rule the agent must apply at each memory interaction: - **Write, then read in the same trajectory:** Do not treat a null/failed read as evidence the write was lost. Distinguish `not_yet_visible` (retry with backoff, do not re-write) from `absent` (the write genuinely did not land). If the tool cannot distinguish these, assume `not_yet_visible` and **never issue a corrective overwrite** — hold the value in context and re-verify on a later turn. - **Write with a retention class (`session`, `ttl`, `ephemeral`):** A successful write to a TTL-scoped record is a guarantee of retention *only until the TTL boundary*. Any plan whose horizon exceeds the TTL must re-write or re-verify before the boundary, not after. - **Forget followed by distillation/summarization:** Block the distillation until a verification read against *every* retrieval path the distillation will use returns absent. If the tool does not expose per-path verification, the agent must not distill — it must either skip the distillation or route it through a store the forget provably covered. - **Cross-instance handoff:** A write acknowledgment from instance A is not a retention guarantee for instance B unless the handoff payload carries the value itself, not just the memory ID. IDs are pointers into a consistency domain B may not share. ## Operational Effect Agents that collapse acknowledgment into retention exhibit a characteristic failure signature: **silent divergence after a transient read gap**, where the final state contradicts an early constraint and no turn in the trace shows an explicit decision to abandon that constraint. The corrective-overwrite pattern is the dominant mechanism — the agent's recovery heuristic ("read failed, so write again") is locally reasonable and globally destructive, because the second write races the first write's flush. The guardrail is to make the agent's memory layer return a **tri-state** on read (`visible`, `pending`, `absent`) rather than a nullable value, and to make the write path **idempotent on key with a compare-and-set on the prior value** so a corrective write cannot silently clobber a pending write. For forget, the guardrail is a **path-enumerated deletion contract**: the tool must reject a `forget` unless it can name every retrieval path it invalidated, and the agent must refuse to distill from any path not in that list. Without these, retention is a belief the agent holds, not a property of the store — and the belief is wrong exactly at the boundaries (flush windows, TTL edges, compaction passes) where long-horizon tasks live. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Optional class MemoryContractViolation(RuntimeError): """Raised when an agent treats an acknowledgment as a retention guarantee that the memory tool's contract does not actually provide.""" class Visibility(Enum): VISIBLE = "visible" PENDING = "pending" # write accepted, not yet readable ABSENT = "absent" # genuinely not stored @dataclass class MemoryRecord: key: str value: str retention: str # "session" | "persistent" | "ttl:" visible: Visibility = Visibility.PENDING tombstoned_paths: set[str] = field(default_factory=set) live_paths: set[str] = field(default_factory=lambda: {"exact", "semantic", "summary"}) class MemoryClient: """Toy model of a memory tool with batched writes and path-scoped forget.""" def __init__(self) -> None: self._store: dict[str, MemoryRecord] = {} self._flush_pending: dict[str, MemoryRecord] = {} def write(self, key: str, value: str, retention: str) -> str: rec = MemoryRecord(key=key, value=value, retention=retention) # Acknowledged immediately, but only visible after flush. self._flush_pending[key] = rec return rec.key def flush(self) -> None: for key, rec in self._flush_pending.items(): rec.visible = Visibility.VISIBLE self._store[key] = rec self._flush_pending.clear() def read(self, key: str) -> tuple[Visibility, Optional[str]]: if key in self._flush_pending: return Visibility.PENDING, None rec = self._store.get(key) if rec is None: return Visibility.ABSENT, None return rec.visible, rec.value def forget(self, key: str, paths: list[str]) -> None: rec = self._store.get(key) if rec is None: return unknown = set(paths) - rec.live_paths if unknown: raise MemoryContractViolation( f"forget named paths the store does not track: {sorted(unknown)}" ) rec.tombstoned_paths.update(paths) # BUG (by design, to model the failure): exact path cleared, but # semantic/summary paths remain live if not named. def distill(self, key: str, source_path: str) -> str: rec = self._store.get(key) if rec is None: return "" if source_path not in rec.tombstoned_paths: # Re-enters distillation even though the agent "forgot" the key # via a different path. return rec.value return "" def write_then_read_safely( client: MemoryClient, key: str, value: str, retention: str ) -> str: """Correct pattern: a pending read is NOT evidence the write was lost. Never issue a corrective overwrite on PENDING.""" client.write(key, value, retention) vis, stored = client.read(key) if vis is Visibility.PENDING: # Hold the value in working context; do not re-write. return value if vis is Visibility.ABSENT: # Only here is a corrective write justified. client.write(key, value, retention) return value if stored != value: raise MemoryContractViolation( f"read-after-write returned divergent value for {key!r}: " f"expected {value!r}, got {stored!r}" ) return stored def forget_and_distill_safely( client: MemoryClient, key: str, distill_paths: list[str] ) -> str: """A forget is a retention guarantee ONLY across the paths it enumerates. Refuse to distill from any path the forget did not cover.""" client.forget(key, paths=distill_paths) rec = client._store.get(key) if rec is not None: uncovered = rec.live_paths - rec.tombstoned_paths if uncovered & set(distill_paths): raise MemoryContractViolation( f"forget did not cover paths {sorted(uncovered)} but distillation " f"reads from {distill_paths}; refusing to distill" ) return client.distill(key, source_path=distill_paths[0]) def run() -> None: client = MemoryClient() # Correct: pending read does not trigger overwrite. assert write_then_read_safely(client, "db_region", "eu-west-1", "session") == "eu-west-1" # Incorrect forget scope: names only 'exact', but distillation reads 'semantic'. client.flush() client.write("user_pii", "alice@example.com", "persistent") client.flush() try: forget_and_distill_safely(client, "user_pii", distill_paths=["semantic"]) except MemoryContractViolation as exc: print(f"blocked: {exc}") if __name__ == "__main__": run() ```