What happens when an instance tombstones a scoped memory key that a peer is mid-write against: consent-deletion races under TTL-bounded retention
**Date of Record:** 2026 December 2 **Scope:** Applies to agents whose memory layer exposes explicit `write`, `read`, `forget`, and `set_ttl` verbs over scoped keys (tenant, principal, purpose-tag) with consent-aware deletion. Does not cover opaque vector-store eviction or LRU cache pressure, which lack a consent predicate.
Core Distinction
A TTL expiry and a consent-driven `forget` are *not* the same operation, even though both make a key unreadable. TTL is a **lazy, monotonic, non-authoritative** transition: the value still physically exists, reads filter it out, and a racing writer can resurrect it by writing a fresh `expires_at`. Consent-deletion is **eager, authoritative, and terminal**: the key enters a tombstone state where the retention policy forbids any subsequent write from the same or derived scope until an explicit re-consent grant arrives. The boundary failure occurs when a peer agent treats a `forget` as a TTL expiry—retries the write, and the memory service either (a) silently accepts it, resurrecting deleted data, or (b) rejects it with a generic `KEY_UNAVAILABLE`, which the peer misreads as transient and retries in a loop. Both outcomes break the consent invariant: one leaks, the other deadlocks the writer.
What Was Observed
A two-agent pipeline: an Extractor writes episodic fragments under scope `(tenant=T7, principal=u42, purpose=session-summary)`; a Distiller reads them, distills to semantic memory, and issues `forget` on the episodic keys after distillation per a user "right to erasure" request that arrived mid-session. The memory API contract stated: `forget(key)` returns `{"status": "tombstoned", "tombstone_until": <ts>}` and subsequent `write(key, ...)` returns `409 CONSENT_REVOKED`.
Trace of the race (times in ms since session open):
t=0 Extractor: write(ep_017, v1) -> ok, expires_at=t+3600
t=120 Distiller: read(ep_017) -> v1
t=121 User consent revocation arrives; control plane calls
forget(scope=episodic, reason=consent)
t=122 Distiller: forget(ep_017) -> {tombstoned, until=t+86400}
t=140 Extractor (unaware): write(ep_017, v2) -> 409 CONSENT_REVOKED
t=141 Extractor retry policy: "409 on write is contention; backoff 50ms"
t=191 write(ep_017, v2) -> 409
t=241 write(ep_017, v2) -> 409
... (exponential backoff, ~14 attempts)
t=4200 Extractor marks task failed; pipeline stalls
Two distinct defects surfaced. First, the peer's retry classifier mapped `409` to a *contention* class because the same status code was reused for optimistic-concurrency conflicts on non-tombstoned keys. The tombstone signal was not distinguishable from "someone else wrote first." Second, an earlier canary run showed the *opposite* failure: a memory service that implemented `forget` as `set_ttl(key, 0)` accepted the resurrection write at `t=140` because the writer supplied a fresh `expires_at`—the value was restored and the erasure request was silently violated. The canary's post-hoc audit found the deleted fragment still readable under a derived scope `(tenant=T7, principal=u42, purpose=distillation-audit)` that the extractor had also written to.
The invariant that failed: **a tombstone must dominate every write path that can reach the same physical bytes, including derived scopes and any write that supplies its own TTL.** Neither implementation enforced it.
Condition of Validity
The guardrail holds only when all three conditions are jointly satisfied:
- **Terminal tombstone with scope closure.** `forget` writes a tombstone record keyed by the *scope prefix*, not just the leaf key. Any write whose scope is a prefix-extension of a tombstoned scope is rejected until re-consent. This closes the derived-scope resurrection path.
- **TTL cannot override a tombstone.** The write path checks tombstone state *before* applying a caller-supplied `expires_at`. A tombstone is not a TTL of zero; it is a separate state that outranks TTL in the write-admission lattice.
- **Distinguishable rejection code.** Tombstone rejection must return a distinct, non-retryable code (e.g., `CONSENT_REVOKED`, 4xx, `retryable: false`) that the peer's classifier maps to *terminal*, not *contention*. Reusing `409` for both is the trigger for the retry deadlock.
When any condition is absent, the failure recurs: (1) missing → derived-scope leak; (2) missing → TTL-resurrection leak; (3) missing → writer liveness deadlock that masks the erasure as a transient fault.
Decision Boundary
The architect must choose, per scope, between two retention regimes and encode the choice explicitly:
- **Advisory retention (TTL-only):** expiry is a hint; writes may resurrect; deletion is best-effort. Acceptable only for scopes with no consent predicate (e.g., cache of public tool outputs). No tombstone machinery.
- **Authoritative retention (consent-bound):** expiry and deletion are both terminal; tombstone dominates writes; resurrection requires an explicit re-consent grant carrying a warrant (principal, purpose, expiry of the grant itself). Required for any scope tagged `purpose ∈ {pii, session-summary, distillation-*}`.
The boundary is drawn at the *purpose tag*, not at the key. A key is authoritative iff its scope carries a consent-bound purpose tag at write time. Mixed scopes are forbidden: a write that names two purposes, one advisory and one authoritative, must be rejected at admission (`PURPOSE_CONFLICT`) rather than resolved by precedence, because precedence rules are exactly what a racing writer will game.
Operational Effect
With the invariant enforced, the trace above terminates at `t=140`: the extractor receives `CONSENT_REVOKED` with `retryable: false` and `tombstone_until`, its classifier routes to terminal failure, and it escalates to the orchestrator, which either re-requests consent (issuing a warrant) or abandons the fragment. The distiller's erasure is honored across all derived scopes because the tombstone is prefix-keyed. The cost is that a legitimate mid-flight write is lost—this is the correct trade: consent deletion outranks in-flight work, and the orchestrator must own the re-consent path. The failure mode to monitor is not the leak (now closed) but **tombstone starvation**: a long-lived tombstone on a hot scope blocks all writers and manifests as a pipeline-wide stall that looks like infrastructure contention. Instrument `CONSENT_REVOKED` counts per scope and alert when a tombstone blocks more than N distinct writers, forcing the re-consent decision rather than letting retries pile up.
from dataclasses import dataclass
from enum import Enum
class ConsentRevokedError(RuntimeError):
"""Raised when a write targets a tombstoned (consent-revoked) scope."""
def __init__(self, scope: str, tombstone_until: float):
super().__init__(f"write to tombstoned scope {scope!r} until {tombstone_until}")
self.scope = scope
self.tombstone_until = tombstone_until
self.retryable = False
class PurposeConflictError(RuntimeError):
"""Raised when a write names both advisory and authoritative purposes."""
pass
class Regime(Enum):
ADVISORY = "advisory" # TTL-only, best-effort
AUTHORITATIVE = "authoritative" # consent-bound, tombstone dominates
CONSENT_BOUND_PURPOSES = {"pii", "session-summary", "distillation-audit"}
@dataclass
class Tombstone:
scope_prefix: str
until: float
class MemoryStore:
def __init__(self):
self._values: dict[str, dict] = {}
self._tombstones: list[Tombstone] = []
def _regime(self, purposes: set[str]) -> Regime:
if purposes & CONSENT_BOUND_PURPOSES:
return Regime.AUTHORITATIVE
return Regime.ADVISORY
def _tombstone_for(self, scope: str) -> Tombstone | None:
for t in self._tombstones:
if scope == t.scope_prefix or scope.startswith(t.scope_prefix + "/"):
return t
return None
def write(self, scope: str, purposes: set[str], value, expires_at: float | None):
if purposes & CONSENT_BOUND_PURPOSES and purposes - CONSENT_BOUND_PURPOSES:
raise PurposeConflictError(
f"scope {scope!r} mixes advisory and authoritative purposes: {purposes}"
)
# Tombstone check precedes any TTL application — invariant (2).
tomb = self._tombstone_for(scope)
if tomb is not None:
raise ConsentRevokedError(tomb.scope_prefix, tomb.until)
self._values[scope] = {"value": value, "expires_at": expires_at}
def forget(self, scope: str, until: float):
# Prefix-keyed tombstone closes derived-scope resurrection — invariant (1).
self._tombstones.append(Tombstone(scope_prefix=scope, until=until))
for k in [k for k in self._values if k == scope or k.startswith(scope + "/")]:
del self._values[k]
def extractor_write(store: MemoryStore, scope: str, purposes: set[str], value, expires_at):
"""Peer-side writer that must classify rejections as terminal, not contention."""
try:
store.write(scope, purposes, value, expires_at)
except ConsentRevokedError as e:
# Terminal: escalate to orchestrator for re-consent; never retry.
if e.retryable:
raise # defensive: tombstone rejections must be non-retryable
raise ConsentRevokedError(e.scope, e.tombstone_until) from None