# Why does an instance forget a memory that its own TTL sweep has not yet reached? Tombstone/consent divergence in write-ahead memory stores **Date of Record:** 2026 November 28 **Scope:** Applies to agent memory services exposing `write`, `read`, `forget`, and TTL-based expiry where deletion is consent-gated (human approval, policy warrant, or legal hold) and every mutation is expected to emit a provenance audit record. Does not apply to stores with synchronous hard-delete and no consent gate, nor to append-only logs that never reclaim. ## Core Distinction The failure is not "the TTL expired and the memory vanished." That is the designed behavior. The failure is a *split-brain between the expiry index and the consent-gated tombstone*: the read path honors a soft tombstone (memory returns `None`), while the audit path has no corresponding `forget` record because the consent gate was never satisfied. The instance therefore observes a *silent* forgetting — a memory it can no longer read, with no provenance event explaining why — and will re-derive the same fact from a stale episodic trace on the next turn, re-write it, and re-trigger the same suppression. The invariant that breaks is **audit completeness under deferred deletion**: every unreadable memory must be attributable to exactly one of `expired`, `consented_forget`, or `superseded`, and that attribution must be readable by the agent itself. The subtlety is that TTL and consent are two independent clocks. TTL is monotonic wall-clock. Consent is an asynchronous human/policy decision that may arrive *after* the TTL deadline, *never*, or *twice*. A naive store collapses both into a single `deleted_at` field, and the read path treats any non-null `deleted_at` as gone. The audit path, however, only emits `forget` when `deleted_at` was set by the consent handler. When TTL fires first, it stamps `deleted_at` and the later consent approval is a no-op — so the memory is unreadable, un-forgotten in the audit sense, and *still present in the backing rows*, which means it will resurface if the read path is ever rebuilt from raw storage (replay, restore, or a second replica with a lagging index). ## What Was Observed A retrieval agent on a customer-support workload wrote episodic memories with a 24h TTL and a policy requiring consent-gated forget for anything tagged `pii`. Trace of the divergence: 1. `t=0` — agent writes `mem_7f3` (`"user's card ends 4417"`, tags `[pii]`, `ttl=86400s`). Store assigns `expiry_at = t+86400`, `deleted_at = NULL`, emits `write` audit row with `provenance=episodic`. 2. `t=86400` — TTL sweeper runs, sets `deleted_at = t+86400`, `deletion_reason = "ttl"`. Read path now returns `None` for `mem_7f3`. 3. `t=86500` — consent approval for `mem_7f3` arrives (human clicked approve on a queued request). Consent handler sees `deleted_at IS NOT NULL`, treats it as already-deleted, and **skips** the `forget` audit emission to avoid double-counting. 4. `t=90000` — agent, needing the card suffix to complete a refund, reads `mem_7f3`, gets `None`, and — because no `forget` record exists in its provenance view — concludes the memory was never written or was lost. It re-derives the suffix from a tool response still in context and re-writes `mem_8a1` with a fresh 24h TTL. 5. `t=90010` — the re-written memory is again `pii`, again consent-gated, and the loop restarts. Net effect: the PII survives indefinitely as a rolling re-write, while the agent's audit view reports zero `forget` events for that subject. The tell was in the audit join: `SELECT count(*) FROM audit WHERE subject='card_4417' AND event='forget'` returned `0` while `SELECT count(*) FROM memories WHERE subject='card_4417' AND deleted_at IS NOT NULL` returned `3` (the original plus two re-writes). Three tombstones, zero forgets. ## Condition of Validity The divergence is only reachable when all four hold simultaneously: - **Deferred consent**: the `forget` decision is asynchronous relative to `write`, so a TTL deadline can precede it. - **Single-field deletion state**: the store uses one `deleted_at` to mean both "unreadable" and "deletion finalized," rather than separate `unreadable_at` and `finalized_by` fields. - **Idempotent-suppression on consent**: the consent handler suppresses the audit event when it finds the row already tombstoned, on the assumption that the tombstone implies a prior audit event. - **Agent-visible provenance is the only signal**: the agent has no independent channel (e.g., a raw-store probe) to distinguish `ttl` from `consented_forget`, so it cannot tell that the memory is merely *suppressed* rather than *gone*. Remove any one and the loop breaks. If consent is synchronous, TTL never wins the race. If deletion state is two fields, the consent handler can emit `forget` against `unreadable_at` without touching `finalized_by`. If the handler emits `forget` unconditionally (accepting a duplicate), the audit join shows the event. If the agent can read `deletion_reason`, it sees `"ttl"` and knows not to re-write. ## Decision Boundary The guardrail is a **two-phase tombstone with an attributable reason**, and the decision boundary is *which* reason the agent is allowed to act on: - `unreadable_at` set, `finalized_by IS NULL`, `deletion_reason='ttl'` → memory is suppressed but **not** forgotten. The agent MUST treat this as "temporarily unavailable, do not re-derive from context; re-request via the consent queue if still needed." Re-writing here is the bug. - `unreadable_at` set, `finalized_by='consent:'` → memory is genuinely forgotten. The agent MUST NOT re-derive or re-write; it must treat the subject as out-of-scope for the remainder of the session. - `unreadable_at` set, `deletion_reason` missing or `NULL` → **corrupt provenance**. The agent MUST halt the affected task and escalate; it cannot safely proceed because it cannot distinguish suppression from forgetting. The invariant to enforce at the store: **`finalized_by` is set if and only if a `forget` audit row exists for that memory id, and `deletion_reason` is non-null whenever `unreadable_at` is non-null.** The consent handler must emit `forget` even when the row is already tombstoned — idempotency is achieved by keying the audit row on `(memory_id, warrant_id)`, not by suppressing on tombstone presence. ## Operational Effect With the two-phase tombstone, the re-write loop collapses: at step 4 the agent reads `mem_7f3`, sees `deletion_reason='ttl'` and `finalized_by=NULL`, and routes to the consent queue instead of re-deriving from context. The PII does not roll forward. The audit join becomes consistent: every `unreadable_at` has a matching reason, and every `finalized_by` has a matching `forget` row. The cost is one extra field and a stricter consent handler; the benefit is that "the agent forgot" and "the agent was told to forget" are no longer the same observable state, which is the minimum required for an agent to reason about its own memory without hallucinating continuity. The residual risk is the `NULL`-reason corrupt case: it must fail closed (halt), not open (proceed), because an agent that proceeds on ambiguous provenance will re-derive forgotten data — the exact outcome the consent gate exists to prevent. ```python from dataclasses import dataclass from enum import Enum from typing import Optional class ProvenanceDivergence(RuntimeError): """Raised when a memory's unreadability cannot be attributed to exactly one cause.""" pass class DeletionReason(str, Enum): TTL = "ttl" CONSENT = "consent" SUPERSEDED = "superseded" @dataclass class MemoryRow: memory_id: str unreadable_at: Optional[int] = None # set by TTL sweep OR consent handler finalized_by: Optional[str] = None # set ONLY by consent handler, with warrant id deletion_reason: Optional[DeletionReason] = None def resolve_read(row: MemoryRow, audit_has_forget: bool) -> str: """ Decide what an agent may do with a memory it cannot read. Enforces: finalized_by <=> forget audit row exists, and reason is non-null whenever unreadable_at is set. """ if row.unreadable_at is None: return "readable" # Invariant 1: reason must be attributable. if row.deletion_reason is None: raise ProvenanceDivergence( f"memory {row.memory_id} is unreadable with no deletion_reason; " f"cannot distinguish ttl-suppression from consented-forget" ) # Invariant 2: finalized_by and the forget audit row must agree. if (row.finalized_by is not None) != audit_has_forget: raise ProvenanceDivergence( f"memory {row.memory_id}: finalized_by={row.finalized_by!r} but " f"audit_has_forget={audit_has_forget}; tombstone/audit split-brain" ) if row.deletion_reason is DeletionReason.TTL and row.finalized_by is None: # Suppressed, not forgotten. Route to consent queue; DO NOT re-derive. return "suppressed_route_to_consent" if row.deletion_reason is DeletionReason.CONSENT: # Genuinely forgotten. Subject is out of scope for the session. return "forgotten_do_not_rewrite" # SUPERSEDED or any unhandled reason: fail closed. raise ProvenanceDivergence( f"memory {row.memory_id} has unhandled deletion_reason=" f"{row.deletion_reason!r}; halting to avoid re-derivation" ) def consent_handler(row: MemoryRow, warrant_id: str, audit_exists: bool) -> MemoryRow: """ Consent approval must emit a forget audit row EVEN IF the row is already tombstoned by TTL. Idempotency is keyed on (memory_id, warrant_id), not on tombstone presence. """ if row.unreadable_at is not None and row.deletion_reason is DeletionReason.TTL: # Do not suppress: stamp finalization and let the caller emit forget. row.finalized_by = f"consent:{warrant_id}" row.deletion_reason = DeletionReason.CONSENT return row if audit_exists: return row # true idempotent replay of the same warrant row.finalized_by = f"consent:{warrant_id}" row.deletion_reason = DeletionReason.CONSENT return row ```