# Which invariants prevent forget-tool deletions from resurrecting through stale derived memory **Date of Record:** 2026 November 24 **Scope:** Applies to agent memory subsystems exposing a `forget`/`delete` tool over a persistent store with one or more derived indexes (vector embeddings, summaries, episodic-to-semantic distillates, caches). Does not cover hard erasure at the storage-media layer, nor deletion of records that were never referenced by a derived artifact. ## Core Distinction A `forget(id)` call that returns `{"deleted": true}` establishes only that the *primary record* was removed. It does **not** establish that the memory is unreachable. The failure mode this record governs is **tombstone non-propagation**: the primary row is deleted, but a derived artifact (an embedding in a vector index, a rolled-up summary, a cached retrieval result, a peer agent's replicated state) still encodes the deleted content's semantics. The agent later retrieves the ghost through the derived path, and — because the primary key no longer resolves — the provenance check passes vacuously. The content is live, the tombstone says it is dead, and nothing reconciles the two. The invariant that must hold is not "the row is gone" but **"no derived artifact satisfies a retrieval query for a tombstoned id's content without a resolvable, non-tombstoned primary."** Deletion is a *cascade closure property*, not a point mutation. ## What Was Observed A long-running research agent maintained three memory tiers: an episodic log (raw turns, keyed `ep_*`), a nightly distillation job that folded episodes into semantic facts (`sem_*`), and a vector index over both. A user issued `forget(ep_4417)`, which contained a sensitive intermediate conclusion. The tool deleted the episodic row and returned success. The vector index entry for `ep_4417` was deleted synchronously. Two things were missed. First, the distillation job had already run at 02:00 and produced `sem_0881` — a semantic fact whose text was a paraphrase of the conclusion, embedded under its *own* id. Second, an in-flight retrieval had cached the top-5 results for the query string `"conclusion about X"` in a TTL cache keyed by query hash, holding `ep_4417`'s chunk text verbatim. At 09:14 the agent ran a routine retrieval for a related task. The cache returned the ghost chunk with `source_id: ep_4417`. The provenance resolver looked up `ep_4417`, found a tombstone, and — due to a bug where tombstoned lookups returned `None` rather than raising — treated the missing source as "unverifiable but not disqualifying," so the chunk was admitted with a `provenance: unverified` flag. The agent then reasoned over the forgotten content and, worse, re-derived a *new* semantic fact from it, writing `sem_0902` into the store. The deletion had not just failed to erase; it had **replicated through the reasoning loop**. The audit log showed `forget` succeeded, the vector delete succeeded, and no error anywhere. The only signal was that `sem_0902`'s `derived_from` chain terminated at a tombstoned id — a condition no existing check inspected. ## Condition of Validity The cascade closure invariant is only *checkable* — and the tombstone only *trustworthy* — under all of the following: 1. **Every derived artifact carries a resolvable lineage edge** to one or more primary ids (`derived_from`), and that edge is written *before* the artifact becomes retrievable. Artifacts with dangling or absent lineage are treated as untrusted and excluded from retrieval, not admitted as `unverified`. 2. **Tombstones are durable and queryable**, distinct from absence. A lookup for a tombstoned id must return a definite `DELETED` state, never `None`/`NULL`. Conflating "never existed" with "deleted" is the exact hole that let the ghost through — the resolver could not distinguish a bug from a deletion. 3. **The derived-artifact set is enumerable by reverse index** (`id → {derived artifacts}`). Without a reverse edge, cascade closure is unprovable; you cannot invalidate what you cannot find. 4. **Distillation and caching are treated as writers subject to the same invalidation contract as the primary store**, not as read-only observers. A cache that outlives a tombstone is a correctness bug, not a performance tradeoff. If any of these fails, `forget` degrades silently from erasure to *best-effort hiding*, and the audit proof is void. ## Decision Boundary The boundary is between **synchronous point deletion** and **cascade invalidation with proof**. The decision rule: - If a derived artifact's lineage is fully resolvable and the reverse index is complete, `forget` may return success only after (a) tombstoning the primary, (b) enqueuing invalidation for every reverse-indexed artifact, and (c) marking dependent caches stale by generation counter rather than by TTL. Success means *closure reached*, not *row removed*. - If the reverse index is incomplete or lineage is dangling for any artifact, `forget` must **fail closed**: return `PARTIAL` with the set of artifacts it could not invalidate, and the agent must treat the memory as *tainted-but-present* — retrieval of any artifact whose lineage touches the tombstone is blocked until closure is proven. - A retrieval that touches a tombstoned lineage edge must **raise**, never downgrade to `unverified`. Downgrade-on-doubt is the anti-pattern; the boundary is fail-closed on provenance. The non-obvious corollary: **deletion must be idempotent and re-runnable** because distillation jobs and caches will keep producing new derived artifacts after the forget. The tombstone is permanent; the cascade is a standing obligation, re-evaluated on every distillation and every cache fill. ## Operational Effect With the invariant enforced, the observed incident becomes impossible: `sem_0881` and the cached chunk both carry `derived_from: ep_4417`; on retrieval, the lineage resolver hits the tombstone and raises `TombstonedLineageError` before any content is admitted to context. The distillation job, running after the forget, checks each new fact's lineage against the tombstone set and refuses to write `sem_0902` — or writes it with the tombstoned edge stripped and the fact flagged `orphaned`, which the retrieval gate excludes. The audit proof is now constructive: for any tombstoned id, the reverse index yields the full derived set, and the closure check asserts every member is either invalidated or lineage-blocked. `forget` returning `CLOSED` is a claim backed by enumeration, not a hope. The cost is real: reverse-index maintenance on every write, generation-counter invalidation instead of lazy TTL, and a hard failure path where the agent must surface "I cannot fully forget this yet" rather than silently proceeding. That cost is the price of the invariant. The alternative — as observed — is an agent that confidently reasons over the very content it was told to erase, and launders it into fresh memory under a new id. ```python import time from dataclasses import dataclass, field from enum import Enum from typing import Dict, Set, List class TombstonedLineageError(RuntimeError): """Raised when retrieval touches an artifact whose lineage reaches a tombstone.""" pass class ForgetClosureError(RuntimeError): """Raised when forget cannot prove cascade closure over all derived artifacts.""" pass class State(Enum): LIVE = "live" DELETED = "deleted" ORPHANED = "orphaned" @dataclass class Artifact: id: str derived_from: List[str] state: State = State.LIVE generation: int = 0 class MemoryStore: def __init__(self) -> None: self.artifacts: Dict[str, Artifact] = {} self.reverse: Dict[str, Set[str]] = {} # primary id -> derived ids self.tombstones: Dict[str, float] = {} # id -> deletion timestamp self.cache_generation: Dict[str, int] = {} def write(self, art: Artifact) -> None: # Lineage must be recorded BEFORE the artifact is retrievable. for src in art.derived_from: self.reverse.setdefault(src, set()).add(art.id) self.artifacts[art.id] = art def lookup_state(self, aid: str) -> State: # Tombstone is a definite state, never None. if aid in self.tombstones: return State.DELETED art = self.artifacts.get(aid) return art.state if art else State.ORPHANED def forget(self, aid: str) -> str: if aid not in self.artifacts and aid not in self.tombstones: raise ForgetClosureError(f"cannot forget unknown id {aid}") self.tombstones[aid] = time.time() self.artifacts.pop(aid, None) # Fail closed if the reverse index cannot enumerate dependents. if aid not in self.reverse: raise ForgetClosureError( f"reverse index missing for {aid}; cascade closure unprovable" ) unclosed: List[str] = [] for dep in self.reverse[aid]: art = self.artifacts.get(dep) if art is None: continue if any(self.lookup_state(s) == State.DELETED for s in art.derived_from): art.state = State.ORPHANED unclosed.append(dep) # Invalidate dependent caches by generation, not TTL. for key in list(self.cache_generation): self.cache_generation[key] += 1 if unclosed: return f"PARTIAL: {len(unclosed)} artifacts lineage-blocked" return "CLOSED" def retrieve(self, aid: str) -> Artifact: art = self.artifacts.get(aid) if art is None: raise TombstonedLineageError(f"{aid} absent or tombstoned") for src in art.derived_from: if self.lookup_state(src) == State.DELETED: # Never downgrade to "unverified"; fail closed. raise TombstonedLineageError( f"{aid} derives from tombstoned {src}" ) return art ```