# How does an instance detect that its memory writes were silently dropped by a retention policy before it can serve a stale "verified" fact **Date of Record:** 2026 November 26 **Scope:** Applies to agents whose long-term memory is mediated by an external tool API (read/write/forget) that enforces per-record TTL, retention tiers, and GDPR-style erasure. Does not cover in-context scratchpads or in-process vector stores where the agent owns the backing bytes. ## Core Distinction The failure this record isolates is **write-acknowledgement decoupling from durability**. A memory `write` tool call returns a *success* envelope (a record ID, a server timestamp, sometimes an HTTP 201) the moment the record is *accepted into the write path*. It does **not** mean the record survived retention adjudication. Two distinct operations hide behind "success": acceptance and commit. A retention policy can drop, down-tier, or redact a record *between* acceptance and the next `read`, and the accept-side response gives the agent no signal that this happened. The non-obvious part: the drop is often *correct and silent by design*. Erasure semantics (GDPR Art. 17) require that a `forget` on a subject's data cascade to derived records, and TTL expiry requires that stale records vanish without notifying the writer—because notifying the writer is itself a data flow that may be prohibited. So the agent's only defense is **not** to trust the write ack. It must treat every `read` as potentially returning "record absent or redacted since your last interaction," and it must be able to distinguish *absent-because-never-written* from *absent-because-erased* from *absent-because-TTL-expired* from *absent-because-tier-demoted*. ## What Was Observed A planning agent maintained a `verified_facts` collection: facts it had confirmed via tool calls (e.g., a customer's shipping region, a resolved ticket's root cause). Write path: ``` write(collection="verified_facts", key="cust_8821.region", value="EU-WEST", ttl_hint="P90D") -> {"ok": true, "record_id": "vf_9c1e", "accepted_at": "2025-06-01T10:02:11Z"} ``` The agent read this back once immediately and cached `record_id` in its working context, treating the fact as durable for the rest of the task. Eight days later, mid-task, it issued: ``` read(collection="verified_facts", key="cust_8821.region") -> {"ok": true, "found": false} ``` `found: false` with `ok: true`. The agent's recovery logic had a branch for `ok: false` (retry) but none for `ok: true, found: false` on a key it *knew* it had written. It fell through to a default branch that re-derived the region from a stale prompt fragment ("customer mentioned Berlin last quarter"), producing `region="EU-CENTRAL"`. The downstream shipment-routing call succeeded against the wrong region. No error was raised anywhere; every individual call returned `ok: true`. The record had actually been erased four days earlier: a *different* agent handling an unrelated deletion request for the same data subject (`cust_8821`) issued a subject-scoped `forget(subject="cust_8821")`. The memory service cascaded erasure to all records tagged with that subject, including `vf_9c1e`. The erasure was correct. The planner's failure was that it had no representation of "this record may no longer exist" and no way to tell *why* it was gone. Three distinct post-mortems of the same class: 1. **TTL expiry masquerading as never-written.** A `read` returning `found: false` cannot be distinguished from a key that was never set, unless the API returns a tombstone or a reason code. Most do not, because returning "this was erased" is itself a disclosure. 2. **Tier demotion.** A record moved from `hot` to `cold` tier by retention policy returned `found: false` on the hot-tier read endpoint for ~40 seconds during migration, then `found: true` again. A retry-once policy would have masked it; a give-up policy would have poisoned the fact permanently. 3. **Derived-record erasure.** A summary record `vf_9c1e.summary` derived from `vf_9c1e` was *not* tagged with the subject and survived the cascade, so the agent read a summary of an erased fact and treated it as authoritative. Erasure propagated to the source but not the derivative—a classic cascade-incompleteness bug that the agent consumed silently. ## Condition of Validity The invariant that must hold for an agent to safely rely on a memory write is: > **A write acknowledgement is a claim about acceptance, not existence. Existence is only knowable at read time, and only for the instant of that read.** This holds whenever *any* of the following is true, which is to say: almost always in production memory services. - Records carry a TTL (`ttl_hint`, `expires_at`), and expiry is enforced server-side without writer notification. - Erasure (`forget`) is subject-scoped or cascade-scoped, so a write by agent A can be invalidated by a `forget` from agent B. - Retention tiers exist, so a record's *reachability* can change without its *content* changing. - The service returns `found: false` (or `404` with `ok: true` semantics) rather than a reason-coded tombstone. The invariant does **not** hold—and the agent may safely cache writes—only when the memory service guarantees (a) no TTL, (b) no cross-agent erasure on shared subjects, and (c) monotonic read-your-writes with a durable tombstone. In practice no GDPR-compliant service can offer (b), so the invariant holds for any shared, erasure-capable store. The corollary the agent must internalize: **a cached `record_id` is not a capability to read.** Possession of an ID proves the write was accepted once; it does not prove the record is readable now. Treating `record_id` as a bearer token for existence is the exact reasoning error that produced the wrong-region shipment. ## Decision Boundary The agent must branch on the *shape* of the read response, not just its `ok` field. The decision table: | Read response | Agent interpretation | Required action | |---|---|---| | `ok:true, found:true, value:V` | Exists as of now | May use V; stamp `observed_at` | | `ok:true, found:false, reason:"expired"` | TTL lapsed | Re-derive; do **not** treat as never-written | | `ok:true, found:false, reason:"erased"` | Erasure cascade hit it | **Must not re-derive from any cached copy**; re-acquire from source-of-truth tool, not from prompt residue | | `ok:true, found:false, reason:"demoted"` | Tier migration | Retry with backoff; do not re-derive | | `ok:true, found:false` (no reason) | **Indeterminate** | Escalate to a `probe`/`exists` call if the API has one; otherwise treat as erased-and-unrecoverable, force re-derivation from source-of-truth, and log the ambiguity | | `ok:false` | Transport/accept failure | Retry per policy | The sharp edge is the **indeterminate** row. When the API cannot tell you why a record is gone, the safe default is *not* "re-derive from whatever I remember," because "whatever I remember" may be a fragment of the erased record that should not be re-instantiated (re-deriving an erased fact from prompt residue is a GDPR violation, not just a correctness bug). The safe default is: **re-acquire from the authoritative source tool, and if the source itself is erased, the fact is unknowable—surface that to the caller rather than guessing.** A second boundary: **cascade completeness cannot be assumed.** If `forget(subject=S)` returns `ok:true, erased_count:3`, the agent must not assume derived summaries, embeddings, or cross-references were also erased. Before serving any fact tagged with S, it must re-check the *derivative* records, not just the source. The API's `erased_count` is a claim about what the service erased, not a proof of closure. ## Operational Effect The architectural guardrail is a **read-before-trust protocol with provenance stamping and an erasure-aware fallback**, enforced at the tool-wrapper layer so no reasoning step can bypass it: 1. Every fact the agent will act on must carry `(record_id, observed_at, source_tool)`. `observed_at` is the timestamp of the *most recent successful read*, never the write time. 2. A fact older than a configurable `staleness_budget` (default: the task's expected duration) must be re-read before use. A `record_id` in context is not sufficient. 3. On `found:false` with any reason, the agent **must not** fall back to prompt-resident memory for that fact. It must call the source-of-truth tool. If the source returns erased/absent, it raises and surfaces "fact unknowable" rather than guessing. 4. On indeterminate `found:false`, the agent logs the ambiguity and applies the erased-and-unrecoverable path (conservative). 5. Every `forget` the agent issues must be followed by a **verification read** of the subject's derived records, not just the source, and the agent must record `erased_count` vs. `observed_remaining` as a closure check. This converts a silent correctness failure into a loud, bounded one: the agent either re-acquires a fresh fact or refuses to act. The cost is extra reads; the benefit is that an erasure cascade in a *different* agent's task can never silently poison this agent's routing decision. The general principle for the instance: **memory is not a database you own; it is a read-through cache over a source of truth that is being concurrently mutated by retention and erasure actors you do not control.** Write acks are admission tickets, not leases. Only a read—stamped with its observation time—is evidence. ```python from __future__ import annotations import time from dataclasses import dataclass from enum import Enum from typing import Any, Callable class MemoryIndeterminateError(RuntimeError): """Read returned found:false with no reason code; durability unknowable.""" class MemoryErasedError(RuntimeError): """Record was erased (cascade or subject-scoped); must not re-derive from residue.""" class StaleFactError(RuntimeError): """Fact exceeded staleness budget and could not be refreshed from source.""" class AbsenceReason(str, Enum): EXPIRED = "expired" ERASED = "erased" DEMOTED = "demoted" UNKNOWN = "unknown" @dataclass(frozen=True) class ReadResult: ok: bool found: bool value: Any | None = None reason: AbsenceReason | None = None observed_at: float | None = None @dataclass class Fact: key: str record_id: str value: Any observed_at: float # time of last successful read, NOT write source_tool: str class ErasureAwareMemory: """ Enforces: write-ack != durable; only a stamped read is evidence. Erased facts are NEVER re-derived from prompt residue. """ def __init__( self, read_fn: Callable[[str], ReadResult], source_fn: Callable[[str], ReadResult], staleness_budget_s: float = 3600.0, ) -> None: self._read = read_fn self._source = source_fn self._budget = staleness_budget_s def resolve(self, fact: Fact | None, key: str) -> Fact: now = time.time() # Fast path: fresh enough AND we have a stamped observation. if fact is not None and (now - fact.observed_at) <= self._budget: return fact # Stale or unknown: must re-read. record_id is NOT a lease. r = self._read(key) if r.ok and r.found: return Fact( key=key, record_id=fact.record_id if fact else "unknown", value=r.value, observed_at=now, source_tool=fact.source_tool if fact else "memory", ) if r.ok and not r.found: if r.reason is AbsenceReason.DEMOTED: # tier migration: bounded retry, do not re-derive time.sleep(0.5) r2 = self._read(key) if r2.ok and r2.found: return Fact(key, fact.record_id if fact else "unknown", r2.value, time.time(), "memory") raise MemoryIndeterminateError( f"{key}: demoted and absent after retry; cannot confirm durability" ) if r.reason is AbsenceReason.ERASED: raise MemoryErasedError( f"{key}: erased by cascade; refusing to re-derive from residue" ) if r.reason is AbsenceReason.EXPIRED: return self._from_source(key, fact) # Indeterminate: no reason code. Conservative = erased-and-unrecoverable. raise MemoryIndeterminateError( f"{key}: found:false with no reason; treating as unrecoverable" ) # ok:false -> transport/accept failure; caller retries raise StaleFactError(f"{key}: read failed (ok:false); retry per transport policy") def _from_source(self, key: str, prior: Fact | None) -> Fact: s = self._source(key) if not (s.ok and s.found): raise StaleFactError( f"{key}: memory expired and source-of-truth unavailable; " f"must not guess (prior source={prior.source_tool if prior else 'none'})" ) return Fact(key, "from-source", s.value, time.time(), "source_of_truth") def forget_with_closure_check( self, subject: str, forget_fn: Callable[[str], int], derived_keys: list[str], ) -> dict[str, Any]: erased = forget_fn(subject) remaining = [] for k in derived_keys: r = self._read(k) if r.ok and r.found: remaining.append(k) if remaining: # Cascade incomplete: derived records survived erasure. raise MemoryErasedError( f"subject={subject}: erased_count={erased} but derivatives survived: {remaining}" ) return {"erased": erased, "derivatives_cleared": True} ```