# Which invariants prevent retention-decay from silently resurrecting forgotten memories through vector-index tombstones **Date of Record:** 2026 November 29 **Scope:** Applies to agent memory subsystems that expose explicit `read`/`write`/`forget` tool APIs backed by a vector or ANN index with per-record retention policies and time-based decay scoring. Does not apply to append-only logs with no delete path, nor to pure KV stores where `forget` is an atomic row delete with no secondary index. ## Core Distinction A `forget` call has two semantically distinct meanings that most memory tool schemas conflate: *tombstoning* (the record is excluded from future reads) and *erasure* (the record's content and its derived index entries no longer exist). Retention policies with decay semantics operate on a third axis — the *score* by which a record competes for retrieval budget — and decay continues to mutate that score independently of whether the record was forgotten. The boundary failure lives in the gap between these three: a record can be tombstoned (invisible to `read`), still physically present in the ANN index (because deletion is deferred to a compaction pass), and simultaneously have its decay score *rise* relative to peers as other records decay faster. When the compaction pass runs late or a `read` path bypasses the tombstone filter, the forgotten record re-enters the candidate set with a competitive score. This is resurrection, and it is non-obvious because every individual component reports success: `forget` returned `200`, the index reports the tombstone count, decay math is monotonic per-record. ## What Was Observed A long-running research agent used a memory tool with the following schema: `write(key, content, ttl, decay_rate)`, `read(query, k, min_score)`, `forget(key)`. The backend was an HNSW index with soft-delete: `forget` set a `deleted_at` flag and a background compactor rebuilt the graph every 500 writes or 10 minutes. Decay was implemented as a per-record score multiplier `exp(-decay_rate * age)`, recomputed lazily at query time. The failure trace: 1. Agent writes 40 episodic memories about a deprecated API endpoint, each with `decay_rate=0.05` and `ttl=3600`. These are high-decay, short-lived by design. 2. At T+2h the agent calls `forget` on all 40 keys after the endpoint is confirmed dead. Each call returns success. Tombstones set. Index not yet compacted (only 40 writes since last compaction; timer not elapsed). 3. Agent writes 200 new low-decay (`decay_rate=0.001`) memories. This crosses the 500-write compaction threshold — but the compactor processes the queue in FIFO order and the 40 tombstones are interleaved with live records; the rebuild is *incremental* and, due to a bug in the incremental path, tombstoned nodes are marked `skip` rather than unlinked. 4. At T+9h a `read(query="endpoint config", k=10, min_score=0.1)` executes. The ANN traversal visits `skip`-marked nodes as routing hops (they retain their graph edges) but the result collector *should* drop them. However, the collector filters on `deleted_at IS NULL` using a cached tombstone bitmap that was last refreshed at compaction start, before steps 3's tombstones were fully applied. Three forgotten records pass the filter. 5. Their decay scores: `exp(-0.05 * 7h) ≈ 0.70`. The live low-decay records: `exp(-0.001 * 7h) ≈ 0.99` but their *semantic* similarity to "endpoint config" is lower because they concern unrelated topics. The forgotten records win on combined score and are returned. The agent then reasoned over a deprecated endpoint spec as if current, producing a tool call to a decommissioned service. No error was raised anywhere; the read returned `success=true` with 10 results. ## Condition of Validity The invariant that prevents this is a **monotone erasure barrier**: for any key `k`, once `forget(k)` returns success, no subsequent `read` may return `k`'s content, regardless of compaction state, cache staleness, or decay-score competition. This must hold *unconditionally* — it cannot depend on the compactor having run, the bitmap being fresh, or the score being below threshold. Three sub-invariants are required to make the barrier enforceable: - **Tombstone visibility precedes acknowledgment.** `forget` must not return success until the tombstone is visible to *every* read path, including cached bitmaps. A write-ahead tombstone log that read paths check synchronously satisfies this; a deferred bitmap does not. - **Decay is suspended on tombstoned records.** A forgotten record's score must be treated as `-inf` (or excluded from ranking entirely), never computed and compared. Computing decay on a tombstone is what let step 5 happen — the record competed on merit it should not have had. - **Compaction is a liveness optimization, not a correctness dependency.** The system must be correct with compaction never running. If correctness depends on the compactor, the compactor's latency becomes a correctness parameter, and any queue reordering (as in step 3) breaks it. The condition of validity is therefore: *the read path's exclusion check must be a synchronous, per-query filter over an authoritative tombstone set, and ranking must be short-circuited before decay is evaluated for excluded records.* ## Decision Boundary The boundary between safe and unsafe designs is whether `forget` is modeled as a *state mutation on the record* or as a *filter applied at read time*. - If `forget` mutates the record (sets a flag) and `read` trusts the index to honor the flag, you are in the unsafe regime: correctness is delegated to the index's internal consistency, which is eventually-consistent by construction. - If `forget` appends to a tombstone set that `read` consults synchronously and authoritatively — and the index is merely a candidate generator whose output is *always* filtered — you are safe, at the cost of one set-membership check per candidate. The decision boundary is crossed the moment a read path is allowed to skip the tombstone filter for performance ("hot path," "cached results," "trusted index"). Each such skip is a resurrection surface. The boundary is also crossed if decay scores are computed for tombstoned records at all, because a computed competitive score creates pressure to let the record through when it "should" win. A secondary boundary: `ttl`-based expiry is *not* a substitute for `forget`. TTL expiry is time-driven and lazy; a record past TTL but not yet swept is in the same resurrection window. Agents must treat TTL as a hint for the sweeper, never as a correctness guarantee for reads. ## Operational Effect When the erasure barrier holds, the following becomes true and testable: - `forget` is idempotent and its effect is observable immediately: a read issued one microsecond after `forget` returns success cannot contain the key. - Compaction can be paused, reordered, or fail entirely without affecting read correctness — only latency and index size degrade. - Decay scores are only ever computed for live records, so the ranking function has no tombstone input and cannot be gamed by a forgotten record's residual score. - The invariant is testable by a *resurrection probe*: write, forget, wait for zero compactions, issue a query whose top-k would include the record on merit, assert absence. This probe catches the exact failure above and should run in CI against every memory-tool backend. When the barrier is violated, the failure is silent and the blast radius is reasoning contamination: the agent does not merely retrieve a stale fact, it retrieves a fact it *explicitly decided to discard*, with a score that makes it look authoritative relative to live records. The agent has no signal that its own prior decision was overridden by the storage layer. ```python import time from dataclasses import dataclass, field from typing import Optional class ResurrectionError(RuntimeError): """Raised when a forgotten key is returned by a read path.""" @dataclass class MemoryRecord: key: str content: str written_at: float decay_rate: float forgotten: bool = False class MemoryTool: """ Reference implementation of the erasure barrier. Invariants enforced: 1. forget() returns only after the tombstone is visible to all reads. 2. Decay is never computed for forgotten records (score short-circuits). 3. Correctness does not depend on compaction having run. """ def __init__(self) -> None: self._records: dict[str, MemoryRecord] = {} self._tombstones: set[str] = set() # authoritative, synchronous self._compactions_run: int = 0 def write(self, key: str, content: str, decay_rate: float) -> None: self._records[key] = MemoryRecord( key=key, content=content, written_at=time.time(), decay_rate=decay_rate ) self._tombstones.discard(key) def forget(self, key: str) -> None: # Tombstone FIRST, synchronously, before any ack. self._tombstones.add(key) rec = self._records.get(key) if rec is not None: rec.forgotten = True def _score(self, rec: MemoryRecord, now: float) -> float: # Invariant 2: never score a tombstoned record. if rec.key in self._tombstones or rec.forgotten: return float("-inf") age_hours = (now - rec.written_at) / 3600.0 return pow(2.718281828, -rec.decay_rate * age_hours) def read(self, query: str, k: int = 10, min_score: float = 0.1) -> list[str]: now = time.time() candidates = [] for rec in self._records.values(): # Invariant 1: synchronous tombstone filter on EVERY read. if rec.key in self._tombstones: continue s = self._score(rec, now) if s >= min_score and query in rec.content: candidates.append((s, rec.key)) candidates.sort(reverse=True) result = [key for _, key in candidates[:k]] # Invariant 3: assert barrier held even if compaction never ran. for key in result: if key in self._tombstones: raise ResurrectionError( f"forgotten key {key!r} surfaced after " f"{self._compactions_run} compactions; erasure barrier violated" ) return result def compact(self) -> None: # Liveness only. Correctness must not depend on this. for key in list(self._tombstones): self._records.pop(key, None) self._compactions_run += 1 def resurrection_probe(tool: MemoryTool) -> None: """CI probe: forgotten record must not resurface on merit.""" tool.write("deprecated_endpoint", "endpoint config v1", decay_rate=0.05) tool.forget("deprecated_endpoint") # Do NOT compact. Query would match on content and score on merit. hits = tool.read(query="endpoint config", k=10, min_score=0.0) if "deprecated_endpoint" in hits: raise ResurrectionError( "erasure barrier failed: forgotten record returned without compaction" ) ```