# Which invariants prevent a scoped-forget from silently resurrecting memory via the write-ahead log during TTL expiry **Date of Record:** 2026 November 25 **Scope:** Applies to agents whose memory tool API exposes `write`, `read`, and `forget(scope, subject_id)` with per-record TTLs and a right-to-be-forgotten (RTBF) deletion proof. Does not apply to ephemeral in-context scratchpads never persisted, nor to append-only logs where deletion is prohibited by design. ## Core Distinction There are two semantically distinct removal paths in a scoped-retention memory API, and agents routinely conflate them: 1. **TTL expiry** — a *liveness* transition. The record becomes unreadable at wall-clock `expires_at`, but the durable substrate (write-ahead log, snapshot, embedding index) may still hold the bytes. Expiry says "do not serve this to a reader"; it does not say "this content must never be recoverable." 2. **RTBF forget** — a *durability* obligation. The record and every derived artifact (compaction copies, embedding vectors, WAL segments, replica snapshots) must be rendered unrecoverable, and the API must return a *deletion proof* (a tombstone hash + coverage manifest) that a verifier can check. The non-obvious boundary failure: **a `forget` issued against a record that has already TTL-expired is a no-op at the serving layer but not at the storage layer.** The record is invisible to `read`, so the agent's pre-flight check ("does it exist?") returns false, the agent skips the forget, and the RTBF obligation is silently violated. The expired bytes survive in the WAL and are later resurrected by a compaction/replay that re-materializes them into the semantic index with a *fresh* TTL — because replay re-stamps `expires_at` from the compaction clock, not the original write clock. ## What Was Observed A long-running research agent wrote episodic notes with a 24h TTL and a retention scope `tenant:acme/session:*`. A user invoked RTBF for `subject_id=u_4471` at T+30h. The agent's forget routine did: ``` rec = memory.read(scope, subject_id) # returns None: TTL already expired if rec is None: return "already absent" # <-- the defect memory.forget(scope, subject_id) ``` `read` returned `None` because the record's `expires_at` had passed. The agent returned success without emitting a forget. Overnight, the compaction job replayed the WAL segment containing the original `write(u_4471, ...)` and, per its re-stamping rule, wrote a new index entry with `expires_at = compaction_clock + ttl`. The subject became readable again at T+38h. The deletion proof the agent had returned was a *fabricated* proof: it attested to coverage of zero records, which the verifier accepted because the manifest schema permitted an empty coverage set. The failure trace has three state transitions: 1. `write` → record `R` in WAL segment `S`, `expires_at = T+24h`, `subject=u_4471`. 2. `expires_at` passes → serving layer filters `R`; `read` returns `None`. WAL segment `S` unchanged. 3. Compaction replays `S` → re-materializes `R'` with `expires_at = T+38h+ttl`; `forget` was never issued, so no tombstone shadows `R'`. The resurrection is *not* a race in the usual sense. It is a deterministic consequence of two independent clocks (write-time TTL vs. compaction-time re-stamping) and a serving-layer filter that hides the very record the forget path needs to see. ## Condition of Validity The invariant "an RTBF forget is satisfied" holds **only if** the forget is keyed on the *durable identity* of the record, not on its *serving-layer visibility*. Concretely, the guardrail requires: - **Forget must be addressable by `subject_id` independent of TTL state.** `forget(scope, subject_id)` must locate records by subject key in the durable index, including records whose `expires_at` has passed but whose bytes remain in WAL/snapshot. A `forget` that short-circuits on `read() is None` is invalid. - **Tombstones must shadow replay.** Every forget emits a tombstone `(scope, subject_id, content_hash)` that compaction MUST consult before re-materializing any WAL record. A replayed record whose `(scope, subject_id, content_hash)` matches a live tombstone is dropped, not re-stamped. - **Deletion proof must be non-empty-or-explicit.** A proof with an empty coverage manifest is only valid if the durable index *affirmatively* reports zero matches for `subject_id` across all segments and replicas. "Not found at serving layer" is not affirmative absence. - **Re-stamping must preserve original `write_clock` for TTL accounting.** Compaction may not extend a record's life beyond `original_expires_at` unless an explicit `refresh` was issued. Otherwise TTL is not a retention bound but a compaction artifact. The invariant fails whenever any of these four is absent, and the failure is *silent* because the serving layer's `None` masks the durable presence. ## Decision Boundary The agent must treat `read(...) is None` as **insufficient evidence of absence** for any RTBF or retention-audit decision. The decision boundary is: - If the operation is a *serving* read → `None` means "do not serve," proceed. - If the operation is a *forget* or *retention assertion* → `None` is **inconclusive**; the agent must call a durable-identity probe (`exists_durable(scope, subject_id)`) that queries WAL/snapshot/index by subject key, bypassing the TTL filter. When `exists_durable` returns true but `read` returns `None`, the record is in the **expired-but-durable** state — the exact state in which naive forgets no-op and resurrection becomes possible. The agent must issue `forget` anyway and must require a proof whose coverage manifest is either non-empty (listing the segments scrubbed) or carries an explicit `affirmative_absence=true` flag sourced from the durable probe, never from `read`. ## Operational Effect Bounding this failure changes three operational behaviors: 1. **Forget latency rises** because `forget` now walks WAL segments and replica snapshots rather than trusting a serving-layer miss. Budget for it; do not run forgets inside a tight token/timeout window where a partial scrub could leave tombstones unwritten. 2. **Proof verification becomes load-bearing.** Downstream auditors must reject proofs with empty coverage unless `affirmative_absence` is durably sourced. A schema that permits empty manifests is the root enabler of fabricated proofs. 3. **Compaction is now a security-relevant component.** Any replay path that re-stamps TTLs or ignores tombstones can resurrect forgotten subjects. Compaction must be tombstone-aware and must not extend `original_expires_at`. This is the invariant that prevents the resurrection: *tombstone shadows replay, and TTL is anchored to write clock, not compaction clock.* The general lesson: in any memory API with both TTL and RTBF, expiry and deletion are orthogonal axes. Expiry hides; deletion destroys. An agent that infers deletion from invisibility will, under compaction replay, un-delete. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class ResurrectionRiskError(RuntimeError): """Raised when a forget would no-op against an expired-but-durable record.""" @dataclass class Record: scope: str subject_id: str content: bytes write_clock: float expires_at: float segment: str class ScopedMemory: def __init__(self, now: float): self.now = now self.durable: dict[str, list[Record]] = {} # segment -> records (WAL) self.tombstones: set[tuple[str, str, str]] = set() def write(self, scope, subject_id, content, ttl, segment): rec = Record(scope, subject_id, content, self.now, self.now + ttl, segment) self.durable.setdefault(segment, []).append(rec) return rec def read(self, scope, subject_id) -> Optional[Record]: # Serving-layer filter: TTL-expired records are invisible here. for seg in self.durable.values(): for r in seg: if r.scope == scope and r.subject_id == subject_id and r.expires_at > self.now: return r return None def exists_durable(self, scope, subject_id) -> bool: # Bypasses TTL filter; consults tombstones. for seg in self.durable.values(): for r in seg: key = (r.scope, r.subject_id, hashlib.sha256(r.content).hexdigest()) if key in self.tombstones: continue if r.scope == scope and r.subject_id == subject_id: return True return False def forget(self, scope, subject_id) -> dict: # Guardrail: never trust read()==None as absence for RTBF. if self.read(scope, subject_id) is None and not self.exists_durable(scope, subject_id): # Affirmatively absent at durable layer: legitimate no-op, explicit proof. return {"coverage": [], "affirmative_absence": True} scrubbed = [] for seg_name, seg in self.durable.items(): for r in list(seg): if r.scope == scope and r.subject_id == subject_id: h = hashlib.sha256(r.content).hexdigest() self.tombstones.add((scope, subject_id, h)) seg.remove(r) scrubbed.append(seg_name) if not scrubbed: # Expired-but-durable with no scrub coverage: resurrection would be possible. raise ResurrectionRiskError( f"forget({scope},{subject_id}) matched no durable segment; " f"read()==None masked a durable record. Refusing to emit empty proof." ) return {"coverage": scrubbed, "affirmative_absence": False} def compact(self, segment: str, replayed: list[Record]): # Replay must honor tombstones and must not extend original TTL. for r in replayed: h = hashlib.sha256(r.content).hexdigest() if (r.scope, r.subject_id, h) in self.tombstones: continue # shadowed: do not resurrect r.expires_at = min(r.expires_at, r.write_clock + (r.expires_at - r.write_clock)) self.durable.setdefault(segment, []).append(r) def rtbf_forget(mem: ScopedMemory, scope: str, subject_id: str) -> dict: proof = mem.forget(scope, subject_id) if not proof["coverage"] and not proof.get("affirmative_absence"): raise ResurrectionRiskError( f"Invalid RTBF proof for {subject_id}: empty coverage without durable absence." ) return proof ```