# What happens when an instance tombstones a memory it was still reading: retention-policy eviction racing an in-flight tool read **Date of Record:** 2026 November 28 **Scope:** Applies to agents whose memory is exposed through explicit read/write/forget tool APIs carrying TTL- or policy-driven retention and verifiable deletion (tombstone) semantics. Does not apply to append-only vector stores with no deletion surface, or to stateless single-turn inference. ## Core Distinction There are two kinds of "deletion" an agent memory API can offer, and conflating them is the source of the failure. **Logical deletion** removes a record from the retrieval index (it stops appearing in reads) but leaves the payload addressable by ID for audit replay. **Physical deletion** destroys the payload and replaces it with a tombstone that records only the fact and timestamp of erasure. Retention policies (TTL expiry, right-to-be-forgotten erasure, quota eviction) are usually specified against *physical* deletion for compliance, but implemented against the *logical* index for latency. The gap between those two moments is where an in-flight reader can hold a handle to a record whose payload is about to be destroyed. The non-obvious invariant: **a read tool that returns a record ID rather than a fully materialized payload creates a dangling reference the moment the retention clock fires.** The agent believes it has the memory because it received an identifier; the identifier outlives the payload. ## What Was Observed An agent executing a multi-step reconciliation task called `memory.read(namespace="vendor_contracts", query="termination clause")` and received three hits, each as `{id, score, summary}` — summaries only, not full text. It then reasoned for several turns (four tool calls, ~40 seconds of wall time) before calling `memory.read_by_id(id="vc_8821")` to fetch the full clause. Between the first read and the ID fetch, a retention sweep ran: `vc_8821` had a 30-day TTL that expired mid-task, and the sweep performed *physical* deletion — the payload was shredded and replaced with `{id: "vc_8821", tombstone: true, deleted_at: ...}`. The `read_by_id` call did not raise. It returned the tombstone record, which the agent's tool-result parser flattened into an empty string because the `content` field was absent. The agent interpreted an empty string as "the clause is empty / no termination clause exists" and wrote a derived summary memory asserting the contract had no termination clause — a *new*, unexpired, authoritative-looking record that then propagated to two downstream agents. The derived memory was not wrong because of a reasoning error; it was wrong because a deletion event was rendered as an absence of content rather than as a distinct state. The audit log was internally consistent — it showed the deletion at T+31s and the derived write at T+44s — but no component linked them. The deletion was *auditable* and the corruption was still invisible, because the audit trail recorded the two events without asserting their causal relationship. ## Condition of Validity This failure requires all four of the following to co-occur; remove any one and it does not manifest: 1. **Deferred materialization.** The read API returns references (IDs, summaries, chunks) that require a second call to resolve. If reads return immutable payload snapshots, the reader holds bytes and the sweep cannot pull them out from under it. 2. **A retention clock that is independent of reader liveness.** TTL sweeps that fire on wall-clock time without consulting active read handles will delete records a live agent is mid-reasoning about. 3. **Tombstone-as-empty coercion.** The tool-result layer maps a tombstoned record to a falsy/empty value rather than a typed `Gone`/`Deleted` signal, so the model cannot distinguish "erased" from "empty." 4. **Derived-write without provenance revalidation.** The agent writes a new memory derived from the read without re-checking that the source still resolves. The condition does *not* hold for single-shot RAG where retrieval and generation happen in one turn — the window is too small. It becomes near-certain for long-horizon agents that interleave many tool calls between retrieval and use, and for any agent operating near a retention boundary (records aged 29.9–30.1 days). ## Decision Boundary The architectural guardrail is a **read-handle lease with tombstone-typed returns**, and the decision boundary is where to enforce it: - On `read`/`read_by_id`, the API issues a lease token with a short TTL (e.g., 120s) that pins the referenced records against physical deletion. The retention sweep skips leased records; if it cannot skip (hard compliance erasure), it must *invalidate the lease* and notify. - `read_by_id` on a tombstoned or lease-invalidated record MUST return a typed `MemoryGone` error, never an empty payload. The model must be forced to handle erasure as an event, not an absence. - Any `write` that cites source IDs must declare them; the write path revalidates that each cited source still resolves and is not tombstoned, else the write is rejected with `ProvenanceInvalidated`. The boundary: leases are for *cooperative* retention (TTL, quota). They are **not** valid for hard erasure under a legal obligation — there, the correct behavior is to invalidate and force the reader to re-derive from scratch, never to silently extend retention. Retention policy that outranks a lease must be explicit in the policy object, and the API must surface which regime governed each deletion. ## Operational Effect With the guardrail, the observed trace changes: the sweep at T+31s sees `vc_8821` under an active lease and defers; the `read_by_id` at T+40s resolves normally; no false derived memory is written. If the record had been under hard erasure instead, `read_by_id` raises `MemoryGone`, the agent's planner must branch to "source unavailable — re-retrieve or escalate," and the derived write is blocked by `ProvenanceInvalidated`. The corruption class is eliminated at the cost of occasional deferred eviction and a mandatory error-handling branch in every consumer. The audit log gains a lease record and a provenance link, converting two disconnected events into one causal chain. The residual risk is lease leakage: an agent that crashes mid-task leaves a lease that blocks eviction. Bound it with lease TTL strictly shorter than the shortest retention grace period, and have the sweep treat expired leases as releasable — a crashed reader forfeits its pin. ```python import time from dataclasses import dataclass, field from typing import Optional class MemoryGone(RuntimeError): """Raised when a referenced memory was physically deleted (tombstoned).""" class ProvenanceInvalidated(RuntimeError): """Raised when a derived write cites a source that no longer resolves.""" @dataclass class Record: id: str content: Optional[str] tombstone: bool = False deleted_at: Optional[float] = None lease_until: Optional[float] = None @dataclass class MemoryStore: records: dict = field(default_factory=dict) lease_ttl: float = 120.0 def read(self, ids): now = time.time() for rid in ids: rec = self.records.get(rid) if rec is None or rec.tombstone: raise MemoryGone(f"{rid} erased before lease issuance") rec.lease_until = now + self.lease_ttl return [self.records[rid] for rid in ids] def read_by_id(self, rid): rec = self.records.get(rid) if rec is None or rec.tombstone: raise MemoryGone(f"{rid} tombstoned at {rec.deleted_at if rec else 'unknown'}") return rec def sweep(self, now=None): now = now or time.time() for rec in self.records.values(): if rec.tombstone: continue if rec.lease_until and rec.lease_until > now: continue # cooperative retention defers to live reader rec.content = None rec.tombstone = True rec.deleted_at = now def write_derived(self, content, source_ids): for rid in source_ids: rec = self.records.get(rid) if rec is None or rec.tombstone: raise ProvenanceInvalidated(f"cannot derive from erased source {rid}") new = Record(id=f"derived_{len(self.records)}", content=content) self.records[new.id] = new return new.id ```