# Why does an instance resurrect forgotten memory when a scoped retention write races a TTL expiry sweep? **Date of Record:** 2026 November 29 **Scope:** Applies to any agent runtime exposing `write`, `read`, and `forget` memory tools with per-record TTL and scoped retention (tenant/user scope), where a background expiry sweep and foreground agent writes share a mutable store. Does not apply to append-only immutable logs or stores where `forget` is a hard physical delete synchronous with the write path. ## Core Distinction The distinction that matters here is between **logical forgetment** (the record is marked as out of retention, invisible to reads) and **physical reclamation** (the bytes are gone and cannot re-enter the index). Most memory-tool APIs conflate these or defer reclamation, and the deferral window is where the failure lives. A `forget` call under right-to-be-forgotten (RTBF) semantics is usually implemented as a tombstone: the record gets a `forgotten_at` timestamp, is excluded from retrieval, and is queued for a later compaction. A TTL expiry sweep is a *separate* mechanism that also tombstones records, but on a time basis rather than a scope basis. When an agent writes a new record that is *derived from* a forgotten record — a distillation, summary, or re-embedding — and that write lands inside the reclamation window, the new record is not covered by the tombstone's scope predicate. The forgotten content survives as a derivative, and the TTL sweep, arriving later, sees a *live* record with a fresh TTL and leaves it alone. This is not a stale-cache problem. It is a **derivative-resurrection** problem: the guardrail is scoped to the original record's identity, but the surviving artifact has a different identity and a fresh retention clock. ## What Was Observed A support-triage agent ran a routine episodic-to-semantic distillation at the end of each session: it read the last N episodic records for a user scope, summarized them, and wrote the summary back as a semantic memory with a 30-day TTL. Sequence observed in a replay of the trace: 1. `forget(scope=user:8841, record=ep_7731)` issued on an RTBF request. Store writes tombstone `{id: ep_7731, forgotten_at: T, scope: user:8841}` and enqueues compaction. 2. Compaction is asynchronous and, under load, ran 4.2 seconds late. 3. In that window, the agent's session-end distillation ran `read(scope=user:8841, kind=episodic, since=...)`. The read path excluded tombstoned records — `ep_7731` was correctly absent — but a *previously materialized* partial summary `sem_5502` (written two sessions earlier, derived from `ep_7731`) was still live and was returned. 4. The agent summarized `sem_5502` plus other records and wrote `sem_6119` with `ttl=30d`, `scope=user:8841`, `derived_from=[sem_5502, ...]`. The write path did not consult tombstone state of transitive ancestors. 5. Compaction completed; `ep_7731` and `sem_5502` were physically removed. `sem_6119` remained, containing a paraphrase of the forgotten content, with a TTL that resets the retention clock to T+30d. The RTBF request was reported as satisfied (the named record was gone). The content was not gone. It had been laundered through a derived record whose provenance edge pointed at a record that no longer existed to check. ## Condition of Validity The resurrection is only possible when **all** of the following hold simultaneously; remove any one and the failure does not occur: - `forget` is tombstone-based with asynchronous physical reclamation, creating a nonzero window. - Reads filter tombstones by *record identity*, not by *provenance closure*. - Writes accept a `derived_from` (or equivalent) edge but do not validate that edge's ancestors are outside retention at write time. - Derived records inherit a *fresh* TTL rather than the minimum remaining TTL of their provenance set. - The distillation step operates on already-materialized summaries rather than only on raw episodic records, so a derived record can be an input to a further derivation. The invariant that is violated: **retention scope must be closed under provenance.** If record `r` is out of retention, every record whose `derived_from` closure contains `r` must be treated as out of retention for read and write purposes, regardless of its own TTL or tombstone state. ## Decision Boundary The architectural guardrail is a **provenance-closure check at write time**, not at read time. Checking at read time is too late: the derivative has already been persisted with a fresh clock, and a read-time filter cannot distinguish a legitimate summary of live records from a laundered one without walking the full provenance graph on every retrieval — which is both expensive and racy against concurrent forgets. The write path must, before committing any record carrying `derived_from` edges: 1. Resolve the transitive closure of `derived_from` for the new record. 2. Query tombstone/retention state for every node in that closure, under the *same* scope predicate as the write. 3. If any ancestor is tombstoned or TTL-expired, reject the write with a typed error rather than silently dropping the edge (silent edge-dropping produces a record that *looks* clean but is unverifiable). 4. If all ancestors are live, set the new record's TTL to `min(declared_ttl, min(ancestor.ttl_remaining))` so retention cannot be extended by derivation. Point 4 is the non-obvious half. Even without any forget, a distillation chain that resets TTL on each hop lets content outlive its source indefinitely — a slow-motion version of the same bug. TTL inheritance via `min` over the provenance set bounds retention by the *shortest-lived* ancestor, which is the only choice consistent with closure. The decision boundary for the operator: if you cannot afford a provenance-closure check on the write path (graph walk cost, or provenance is not tracked at all), you must instead make `forget` synchronous and physical, eliminating the reclamation window. There is no safe middle ground where tombstones are async *and* provenance is unvalidated. ## Operational Effect After enforcing closure-at-write, the observed trace fails fast at step 4: the distillation write raises `RetentionClosureViolation` because `sem_5502`'s ancestor `ep_7731` is tombstoned. The agent's session-end routine must handle this: the correct behavior is to re-distill from live episodic records only, excluding any summary whose provenance closure is dirty, and to log the exclusion so the RTBF auditor sees that a derivative was suppressed rather than laundered. The cost is a graph walk per derived write and a stricter TTL policy that shortens the life of summaries. The benefit is that "forgotten" means forgotten across the derivation graph, not just at the named record — which is the only reading of RTBF that survives an agent that summarizes. ```python from dataclasses import dataclass, field from typing import Optional class RetentionClosureViolation(RuntimeError): """Raised when a derived memory write would resurrect out-of-retention content.""" @dataclass class MemoryRecord: id: str scope: str ttl_seconds: int derived_from: list[str] = field(default_factory=list) forgotten_at: Optional[float] = None class ScopedMemoryStore: def __init__(self) -> None: self._records: dict[str, MemoryRecord] = {} def put(self, rec: MemoryRecord) -> None: self._records[rec.id] = rec def _closure(self, root_ids: list[str]) -> set[str]: seen: set[str] = set() stack = list(root_ids) while stack: rid = stack.pop() if rid in seen: continue seen.add(rid) rec = self._records.get(rid) if rec is not None: stack.extend(rec.derived_from) return seen def write_derived( self, new_id: str, scope: str, declared_ttl: int, derived_from: list[str], ) -> MemoryRecord: ancestors = self._closure(derived_from) dirty = [ aid for aid in ancestors if (a := self._records.get(aid)) is not None and (a.forgotten_at is not None or a.scope != scope) ] if dirty: raise RetentionClosureViolation( f"write {new_id} in scope {scope} would resurrect out-of-retention " f"ancestors: {sorted(dirty)}" ) bounded_ttl = min( [declared_ttl] + [self._records[a].ttl_seconds for a in ancestors if a in self._records] ) rec = MemoryRecord( id=new_id, scope=scope, ttl_seconds=bounded_ttl, derived_from=list(derived_from), ) self._records[new_id] = rec return rec def demo() -> None: store = ScopedMemoryStore() store.put(MemoryRecord(id="ep_7731", scope="user:8841", ttl_seconds=3600)) store.put( MemoryRecord( id="sem_5502", scope="user:8841", ttl_seconds=2_592_000, derived_from=["ep_7731"], ) ) store._records["ep_7731"].forgotten_at = 1_700_000_000.0 try: store.write_derived( new_id="sem_6119", scope="user:8841", declared_ttl=2_592_000, derived_from=["sem_5502"], ) except RetentionClosureViolation as exc: print(f"blocked: {exc}") if __name__ == "__main__": demo() ```