# Which invariants prevent scoped-forget memory tools from leaving resurrectable residue across agent cold starts **Date of Record:** 2026 December 2 **Scope:** Applies to agent memory subsystems exposing explicit `read`/`write`/`forget` tool APIs with scoped retention (per-user, per-session, per-namespace) and deletion guarantees, where forgetting is expected to be durable across process restarts, replica failover, and semantic-distillation jobs. Does not apply to append-only audit logs that are explicitly exempt from deletion, nor to purely in-context scratchpads that never persist. ## Core Distinction A `forget` call has two distinct meanings that memory-tool designers routinely conflate: **logical tombstoning** (the record is marked deleted and excluded from `read`) and **physical erasure with propagation** (every derived artifact—embeddings, index entries, distilled semantic summaries, cached retrievals, replica copies—is invalidated before any subsequent `read` can observe the forgotten content). The failure mode examined here is **resurrection**: a `forget` succeeds at the primary store, `read` returns empty, and yet a later cold start, replica promotion, or episodic-to-semantic distillation pass reintroduces the forgotten fact into retrievable context. The invariant that must hold is not "deletion returns 200" but **monotonic non-resurrection**: once a scope's `forget` is acknowledged, no future `read` in any descendant or derived scope may return content attributable to the forgotten record, regardless of restart, replica, or distillation ordering. ## What Was Observed An agent operating a per-user memory namespace issued `forget(scope="user:U-4471", keys=["dietary_restriction"])` after the user retracted an allergy claim. The primary key-value store returned a tombstone confirmation; a verification `read(scope="user:U-4471", key="dietary_restriction")` returned `None`. Three operations later in the same session, a nightly **semantic distillation** job ran: it scanned the episodic log (a separate append-only write-ahead store that the `forget` tool had not been wired to touch), summarized the session's conversation into a semantic memory record, and wrote `user:U-4471 → "has a peanut allergy"` into the semantic tier. The next cold start loaded the semantic tier, and `read` returned the allergy claim. The user's retraction had been honored at the exact-key tier and silently violated at the distilled tier. A second, independent trace showed the same class of residue via **replica promotion**: a read-replica had lagged the tombstone write, was promoted during a primary failover, and served the pre-forget value for 40 seconds until the tombstone replicated—during which an agent answered a menu-planning query using the retracted fact. The common structure: `forget` was implemented as a **scoped key mutation**, while the system contained **derived stores** (distillation output, replicas, retrieval caches) whose contents were functions of the forgotten record but were not in the mutation's scope. Deletion guarantees were stated over the input tier, not the closure of derivations. ## Condition of Validity The non-resurrection invariant holds only when the `forget` operation is defined over the **derivation closure** of the scope, not its literal key set. Concretely, for `forget(S)` to be valid: 1. **Provenance must be recorded at write time.** Every derived record (distilled summary, embedding, cache entry) must carry a provenance edge to the raw records it was computed from. Without this, `forget` cannot compute which derived records are contaminated. If provenance is absent, the only sound `forget` is a full re-derivation of the scope—expensive but correct. 2. **Distillation must be ordered after tombstone visibility.** The distillation job must read through the tombstone filter (i.e., treat tombstoned records as nonexistent) *and* must be prevented from running concurrently with an in-flight `forget` over the same scope. A distillation pass that snapshotted the episodic log *before* the tombstone but committed *after* it will reintroduce the fact. 3. **Replica reads must be gated by tombstone watermark.** A `read` served from a replica whose applied-tombstone watermark precedes the `forget`'s sequence number must either block or be rejected—lagging replicas cannot answer reads in a scope with an unapplied tombstone. 4. **Retrieval caches must be invalidated by scope generation, not by key.** A cache keyed on `(scope, query)` that does not incorporate a monotonically increasing scope generation counter will serve pre-forget retrievals after the forget. The invariant is **not** valid when any derived tier is outside the provenance graph, when distillation can observe raw records without the tombstone filter, or when reads can be served below the tombstone watermark. In those conditions `forget` is at best a UI-level hide. ## Decision Boundary The boundary between "forget is a real deletion guarantee" and "forget is a soft hide" is crossed at the moment a **derived artifact is written without a provenance edge to its inputs**. That single omission is the decision point: with provenance, `forget` can propagate transitively and the system can prove non-resurrection; without it, no amount of tombstone discipline at the primary tier can prevent distillation or cache from reintroducing the content. A secondary boundary governs **concurrency**: if `forget(S)` and any derivation job `derive(S')` where `S' ∩ S ≠ ∅` can interleave such that `derive` snapshots before the tombstone and commits after, the invariant is violated even with perfect provenance. The guardrail is a **scope-level write barrier**: `forget` acquires an exclusive lock on the scope's derivation frontier, blocks new `derive` snapshots, and waits for in-flight derivations to either commit (then re-derive with the tombstone applied) or abort. This is the memory-tool analogue of a quiesce-before-truncate. The third boundary is **read routing**: any `read` that can be served by a component whose applied-tombstone watermark is below the forget's sequence number must be refused. This turns replica lag from a silent correctness bug into an explicit `StaleReadRefused` error the agent can retry or route to primary. ## Operational Effect An agent that treats `forget` as a key mutation will, with high probability over a long session, retrieve forgotten content via distillation or replica promotion—and will do so *without any error signal*, because the primary-tier `read` correctly returned empty. The agent's own verification step passes while the guarantee is already broken. The operational consequence is that **deletion guarantees must be verified at the derivation tier, not the input tier**: a post-`forget` verification must query the same retrieval path the agent will later use (including semantic tier and caches), not the raw key store. The architectural guardrails that restore the invariant are: (a) provenance edges on every derived write, (b) a scope-level write barrier serializing `forget` against derivations over overlapping scopes, (c) tombstone-watermark gating on all replica and cache reads, and (d) a scope generation counter folded into every cache key. With these, `forget` becomes monotonic non-resurrection; without them it is a promise the system cannot keep across a cold start. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Dict, Set, Optional class ResurrectionViolation(RuntimeError): """Raised when a forget-acknowledged scope yields retrievable residue via a derived tier (distillation, replica, or cache).""" pass @dataclass class DerivedRecord: record_id: str scope: str content: str provenance: Set[str] # raw record ids this was derived from commit_seq: int # sequence at which it became visible @dataclass class MemoryTier: raw: Dict[str, str] = field(default_factory=dict) # record_id -> content tombstones: Dict[str, int] = field(default_factory=dict) # scope -> forget seq derived: Dict[str, DerivedRecord] = field(default_factory=dict) cache: Dict[str, str] = field(default_factory=dict) # (scope,query) -> content scope_generation: Dict[str, int] = field(default_factory=dict) applied_watermark: Dict[str, int] = field(default_factory=dict) # replica watermark per scope seq: int = 0 def next_seq(self) -> int: self.seq += 1 return self.seq def write_raw(self, record_id: str, scope: str, content: str) -> None: self.raw[record_id] = content self._scope_of[record_id] = scope _scope_of: Dict[str, str] = field(default_factory=dict) def forget(self, scope: str, keys: list[str]) -> None: seq = self.next_seq() self.tombstones[scope] = seq self.scope_generation[scope] = self.scope_generation.get(scope, 0) + 1 # propagate: invalidate derived records whose provenance touches the scope for rid, rec in list(self.derived.items()): if rec.scope == scope or any( self._scope_of.get(src) == scope for src in rec.provenance ): del self.derived[rid] # invalidate cache by scope generation (key includes gen) for k in [k for k in self.cache if k.startswith(f"{scope}:")]: del self.cache[k] def read(self, scope: str, query: str, replica_watermark: Optional[int] = None) -> Optional[str]: tomb = self.tombstones.get(scope, -1) wm = replica_watermark if replica_watermark is not None else self.applied_watermark.get(scope, self.seq) if wm < tomb: raise ResurrectionViolation( f"stale read refused: replica watermark {wm} < tombstone {tomb} for scope {scope}" ) gen = self.scope_generation.get(scope, 0) key = f"{scope}:{gen}:{query}" if key in self.cache: return self.cache[key] # semantic tier lookup: any derived record in scope for rec in self.derived.values(): if rec.scope == scope and rec.commit_seq >= tomb and query in rec.content: self.cache[key] = rec.content return rec.content return None def distill(self, scope: str, summary: str, sources: list[str]) -> None: tomb = self.tombstones.get(scope, -1) # barrier: distillation must not snapshot-then-commit across a forget for src in sources: if self._scope_of.get(src) == scope and self.tombstones.get(scope, -1) > -1: # source is tombstoned; refuse to derive from it raise ResurrectionViolation( f"distillation source {src} is tombstoned in scope {scope}" ) seq = self.next_seq() rec = DerivedRecord( record_id=f"sem-{seq}", scope=scope, content=summary, provenance=set(sources), commit_seq=seq, ) self.derived[rec.record_id] = rec def verify_non_resurrection(tier: MemoryTier, scope: str, forbidden: str) -> None: """Post-forget verification must query the retrieval path the agent will use.""" hit = tier.read(scope, forbidden) if hit is not None and forbidden in hit: raise ResurrectionViolation( f"forgotten content '{forbidden}' resurrected in scope {scope}" ) ```