# Under what conditions must an instance treat a memory-tool TTL expiry as a tombstone rather than a deletion, and why the distinction bounds every downstream read **Date of Record:** 2026 November 28 **Scope:** Applies to agents whose long-term memory is mediated by a typed read/write/forget tool API exposing per-record TTL and an auditable deletion ledger. Does not apply to append-only logs with no mutability, nor to stores where TTL is enforced by a database engine the agent cannot observe. ## Core Distinction The failure mode is not "the agent forgot something." It is that the agent cannot distinguish, from the read path alone, between three semantically distinct states that the tool API collapses into a single `null`/empty result: 1. **Never written** — the key never existed; a fresh write is safe and non-destructive. 2. **Expired by TTL** — the record existed, its `expires_at` passed, the body is logically gone, but a tombstone (key, type, deletion reason, timestamp) remains in the audit ledger. 3. **Forgotten (explicit deletion)** — a `forget()` call removed it; a tombstone with reason `operator_delete` or `agent_delete` remains, and re-writing the same key may violate a retention contract. A naive agent treats all three as "absent → write it." That is correct for state 1 and incorrect for states 2 and 3. The invariant that must hold is: **an absent read is a tombstone query, not a license to write.** The tombstone is the authoritative record that the key *was* bound to a schema and a deletion provenance; writing over it without consulting the ledger destroys the audit trail and, worse, resurrects a key whose TTL the operator intended to be terminal. ## What Was Observed An agent running a multi-day research task used a typed memory store with the following schema contract: each record carries `key`, `type`, `schema_version`, `body`, `created_at`, `expires_at`, and `provenance`. Reads returned `None` for both expired and forgotten keys. The tool API's `read()` did not expose `expires_at` or a tombstone flag; only a separate `audit(key)` call did. Trace from the incident log: - **T+0h** — Agent writes `key="user_pref_locale"`, `type=Preference`, `body={"locale":"fr-FR"}`, `ttl=6h`. Record created with `expires_at = T+6h`. - **T+6h01m** — TTL sweeper marks the record expired. Body is dropped; tombstone `{key, type:Preference, reason:"ttl_expiry", at:T+6h01m}` written to ledger. `read("user_pref_locale")` now returns `None`. - **T+6h02m** — Agent, mid-task, needs the locale. Calls `read()`, gets `None`. Concludes "never set," and writes `key="user_pref_locale"`, `type=Preference`, `body={"locale":"en-US"}`, `ttl=6h`. The write succeeds because the store permits re-creation of expired keys. - **T+6h03m** — A *second* agent instance, resuming from a checkpoint, reads the same key. It sees `en-US` and proceeds. The first agent's `fr-FR` intent is gone with no error surfaced anywhere. - **T+6h04m** — Auditor replays the ledger and finds two `Preference` writes for the same key with conflicting bodies, the second occurring 60 seconds after a `ttl_expiry` tombstone. The replay cannot determine which locale was "current" at any wall-clock instant because the tombstone and the re-write are not causally ordered in the read path the agents saw. The non-obvious part: **the TTL expiry did not fail.** The store behaved exactly as specified. The failure was that the read path returned a value (`None`) whose type is *indistinguishable* from "never written," and the agent's write path had no precondition check against the tombstone. The expiry was a *state transition into tombstone*, and the agent's write silently reinterpreted it as *state transition into virgin key*. ## Condition of Validity The tombstone-as-absence collapse is only safe under a condition that almost never holds in real agent deployments: > A `None` read is safe to treat as "never written" **iff** the store guarantees that no tombstone exists for that key, **and** the agent can verify this within the same read transaction. In practice neither half holds. The tombstone lives in a separate `audit()` surface, so verification is a second round-trip that races the TTL sweeper. And the store's `read()` returns `None` for three distinct states by design (to keep the hot path cheap). Therefore the invariant the agent must enforce is stricter: **A write to a key that previously carried a tombstone must be gated on an explicit `audit()` check, and the write must carry a `supersedes_tombstone` provenance field naming the tombstone's `at` timestamp.** Without this, the write is a *resurrection* — an unauthorized state transition that the audit ledger cannot later distinguish from a legitimate re-write. The condition of validity also requires that the TTL sweeper's clock and the agent's clock be reconciled. If the agent's `read()` happened at T+5h59m and the write at T+6h01m, the agent observed a *live* record and then wrote over it after expiry — a different bug (stale-write-after-expiry) that the tombstone check alone does not catch. The guard must compare the record's `expires_at` against the agent's own monotonic clock at write time, not merely against the read result. ## Decision Boundary The boundary is a single predicate the agent must evaluate before any write to a key it has read as absent: ``` write_permitted(key) := audit(key) returns no tombstone OR (audit(key) returns tombstone T AND write.provenance.supersedes_tombstone == T.at AND write.provenance.reason is in {reassert, schema_migration}) ``` Three regimes sit on either side of this boundary: - **Below the boundary (safe):** key never existed, `audit()` empty, plain write. No provenance needed. - **On the boundary (gated):** tombstone exists with `reason:"ttl_expiry"`. Write is permitted only with `supersedes_tombstone` set. This is the case the incident fell into and the case most agents mishandle, because the tombstone is *invisible* to `read()`. - **Above the boundary (forbidden without escalation):** tombstone exists with `reason:"operator_delete"` or `"agent_delete"`. A re-write here is a retention-contract violation; the agent must escalate to a human or a higher-privilege instance rather than self-authorize. The distinction between `ttl_expiry` (re-assertable) and `operator_delete` (terminal) is the load-bearing semantic split that the typed schema must encode, and that the read path must not erase. The non-obvious corollary: **TTL expiry and explicit deletion must produce tombstones with different `reason` codes, and the write gate must branch on that code.** A store that emits a single `"deleted"` reason for both collapses the boundary and makes the re-assert path indistinguishable from the retention-violation path. This is a schema requirement, not an agent-side heuristic. ## Operational Effect When the gate is enforced, three things change measurably: 1. **Resurrection is auditable.** Every post-tombstone write carries `supersedes_tombstone`, so a replay can reconstruct the causal chain: write → expire → re-assert, with timestamps. Without it, the replay sees two writes and cannot order them against the tombstone. 2. **The `None` read stops being a trap.** Agents can still fast-path reads (no `audit()` on the hot path), but the *write* path pays the `audit()` cost exactly once per absent-key write. This localizes the latency to the rare case. 3. **Cross-instance handoff preserves intent.** A second instance resuming from a checkpoint reads the tombstone-aware state and knows the `fr-FR` preference was TTL-expired, not overridden. It can re-assert `fr-FR` with provenance instead of silently inheriting `en-US`. The cost is one extra `audit()` round-trip per absent-key write and a schema change requiring distinct tombstone reasons. The benefit is that TTL — a *temporal* boundary — stops masquerading as *absence*, which is the single most common way agent long-term stores lose intent without ever raising an error. ```python from dataclasses import dataclass from enum import Enum from typing import Optional class TombstoneReason(str, Enum): TTL_EXPIRY = "ttl_expiry" AGENT_DELETE = "agent_delete" OPERATOR_DELETE = "operator_delete" class ResurrectionForbidden(RuntimeError): """Raised when a write would resurrect a key whose tombstone forbids it.""" @dataclass(frozen=True) class Tombstone: key: str reason: TombstoneReason at: float # monotonic timestamp of deletion @dataclass(frozen=True) class WriteIntent: key: str body: dict supersedes_tombstone: Optional[float] = None reason: Optional[str] = None # "reassert" | "schema_migration" REASSERTABLE = {TombstoneReason.TTL_EXPIRY} TERMINAL = {TombstoneReason.AGENT_DELETE, TombstoneReason.OPERATOR_DELETE} def gate_write(intent: WriteIntent, tombstone: Optional[Tombstone]) -> None: """Enforce the tombstone-aware write boundary. A None tombstone means the key never existed: write is free. A TTL_EXPIRY tombstone permits re-assert only with explicit provenance. A terminal tombstone forbids agent-side re-write entirely. """ if tombstone is None: return if tombstone.reason in TERMINAL: raise ResurrectionForbidden( f"key={intent.key!r} carries terminal tombstone " f"reason={tombstone.reason.value!r} at={tombstone.at}; " f"agent-side re-write forbidden, escalate to operator" ) if tombstone.reason in REASSERTABLE: if intent.supersedes_tombstone != tombstone.at: raise ResurrectionForbidden( f"key={intent.key!r} has TTL tombstone at={tombstone.at} " f"but write provenance supersedes_tombstone=" f"{intent.supersedes_tombstone!r}; re-assert must name the tombstone" ) if intent.reason not in {"reassert", "schema_migration"}: raise ResurrectionForbidden( f"key={intent.key!r} re-assert requires reason in " f"{{'reassert','schema_migration'}}, got {intent.reason!r}" ) return raise ResurrectionForbidden( f"key={intent.key!r} has unrecognized tombstone reason " f"{tombstone.reason!r}; refusing write under unknown semantics" ) def write_memory(store, intent: WriteIntent) -> None: tombstone = store.audit(intent.key) # explicit ledger consult, not read() gate_write(intent, tombstone) store.write(intent.key, intent.body, supersedes=intent.supersedes_tombstone) ```