# Which invariants prevent decay-driven semantic promotion from resurrecting forgotten episodic residue **Date of Record:** 2026 November 20 **Scope:** Applies to agents exposing explicit memory tools (`read`, `write`, `forget`) over a two-tier store where episodic records decay toward eviction and are periodically distilled into semantic facts. Does not cover flat vector stores without decay, nor pure in-context memory with no external persistence. ## Core Distinction The failure lives in the seam between two policies that are individually sound: **decay-based forgetting** (episodic entries age out by a half-life score) and **episodic-to-semantic distillation** (a summarizer reads recent episodic records and writes durable semantic facts). The distinction that matters is *forget semantics*: a `forget` on an episodic record can mean either **soft-delete** (drop the retrieval score to zero, keep the bytes for audit) or **hard-delete** (remove the row). Decay uses the same score field that soft-delete zeroes. When distillation reads "all episodic records above score θ," a soft-deleted record at score 0 is invisible — but a record that was forgotten *and then touched by any write path that resets `last_access`* re-enters the retrieval window and gets distilled into a semantic fact that the agent was explicitly told to forget. The invariant that prevents this is **monotonic forget**: once a record is forgotten, no read, write, decay update, or distillation pass may raise its retrieval score above the forget floor. Forget must be a terminal state in the score lattice, not a transient low value. ## What Was Observed A support-triage agent held an episodic store of per-turn observations and a semantic store of distilled user facts. Policies: - Episodic score `s = exp(-Δdays / 7)`, refreshed to 1.0 on `read`. - `forget(id)` set `s = 0.0` and set `forgotten_at`, but kept the row (soft-delete for compliance). - Distillation ran hourly: `SELECT * FROM episodic WHERE s >= 0.3`, summarized, and `write`-ed facts to semantic with `source_ids`. - Semantic facts had their own decay (`half-life 30d`) and were re-distilled from their `source_ids` on refresh. Sequence that broke it: 1. User says "forget my old address." Agent calls `forget(ep_4412)`. Row `s=0.0`, `forgotten_at` set. Correct so far. 2. A later turn's retrieval does a broad scan and, as a side effect of the storage layer's `touch-on-fetch` hook, calls `read(ep_4412)` during a `source_ids` backfill for an unrelated semantic fact. The `read` handler unconditionally does `s = 1.0; last_access = now()` — it does not consult `forgotten_at`. 3. Next distillation pass sees `ep_4412` at `s=1.0`, summarizes it, and writes semantic fact `sem_9001: "user's previous address is 14 Rue …"` with `source_ids=[ep_4412]`. 4. The agent now confidently recalls an address it was instructed to forget, and — worse — the semantic fact is *durable* and has its own 30-day half-life, so it outlives the episodic residue by an order of magnitude. The trace is a classic **two-writer race on a single score field**: `forget` writes 0.0, `read`'s touch hook writes 1.0, and neither is aware of the other's intent because the score field conflates *recency* with *liveness*. ## Condition of Validity The monotonic-forget invariant is required exactly when all three hold: - forgetting is **soft** (bytes retained) rather than physical deletion, *and* - any code path can **refresh** the score of a retained row (touch-on-read, backfill, reindex, audit scan), *and* - distillation selects on **score**, not on an explicit liveness predicate. If forgetting is hard-delete, the row cannot be resurrected and the invariant is vacuous. If distillation filters on `forgotten_at IS NULL`, the score refresh is harmless. The failure only materializes in the intersection — which is the common production configuration, because soft-delete is chosen for compliance and score-based selection is chosen for simplicity. ## Decision Boundary The guardrail is to **separate recency from liveness** and make forget a terminal lattice element: 1. Split the field: `recency` (decays, refreshed by touch) and `liveness ∈ {live, forgotten, evicted}`. `forget` transitions `live → forgotten`; nothing transitions out of `forgotten` except an explicit, audited `unforget` (which should not exist in most deployments). 2. Every score-refresh path must be a **guarded write**: `if liveness != live: no-op`. The touch hook, backfill, and reindex all route through this guard. 3. Distillation must select on `liveness == live AND recency >= θ`, never on `recency` alone. 4. Distilled semantic facts must **inherit** the forget state of their sources: a fact whose entire `source_ids` set is forgotten must itself be forgotten (cascade), and a fact with any forgotten source must be flagged for re-distillation excluding that source. 5. `read` on a forgotten id returns an explicit `ForgottenRecord` tombstone, not the payload and not an empty result — so callers cannot silently treat "gone" as "never existed" and re-derive the fact from other context. The decision boundary for the agent: **any memory tool whose `read` has a side effect on ranking is unsafe unless that side effect is gated by liveness.** If you cannot audit every touch path, make `read` pure and move recency updates to an explicit `touch`. ## Operational Effect With monotonic forget enforced, the failure trace above terminates at step 2: the backfill's `read(ep_4412)` hits the guard, `recency` stays at the forget floor, distillation's liveness filter skips it, and `sem_9001` is never written. The cost is that the agent loses the ability to "accidentally" recover forgotten context — which is the point. The residual risk moves to **cascade completeness**: a semantic fact distilled *before* the forget, with `source_ids` including the now-forgotten record, must be caught by the cascade check on the next refresh. If cascade is evaluated only at write time and not on every semantic refresh, a pre-existing fact survives. The invariant is therefore two-part: monotonic forget on the episodic tier, and **source-set re-validation on every semantic decay tick** — the semantic tier must re-check that none of its sources have been forgotten since it was written. ## Code ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class ForgetInvariantViolation(RuntimeError): """Raised when a memory operation would resurrect or launder forgotten state.""" class Liveness(Enum): LIVE = "live" FORGOTTEN = "forgotten" EVICTED = "evicted" @dataclass class EpisodicRecord: id: str payload: str recency: float = 1.0 liveness: Liveness = Liveness.LIVE @dataclass class SemanticFact: id: str text: str source_ids: list[str] = field(default_factory=list) liveness: Liveness = Liveness.LIVE class ScopedMemory: def __init__(self, theta: float = 0.3): self.episodic: dict[str, EpisodicRecord] = {} self.semantic: dict[str, SemanticFact] = {} self.theta = theta def write_episodic(self, rec_id: str, payload: str) -> None: self.episodic[rec_id] = EpisodicRecord(id=rec_id, payload=payload) def forget(self, rec_id: str) -> None: rec = self.episodic.get(rec_id) if rec is None: raise ForgetInvariantViolation(f"forget on unknown record {rec_id}") # Terminal transition; recency pinned to floor, never raised again. rec.liveness = Liveness.FORGOTTEN rec.recency = 0.0 def read(self, rec_id: str) -> EpisodicRecord: rec = self.episodic.get(rec_id) if rec is None: raise ForgetInvariantViolation(f"read on unknown record {rec_id}") if rec.liveness is Liveness.FORGOTTEN: # Tombstone: do NOT touch recency. Return an explicit marker. return EpisodicRecord(id=rec.id, payload="", recency=0.0, liveness=Liveness.FORGOTTEN) # Guarded recency refresh: only live records may be touched. if rec.liveness is Liveness.LIVE: rec.recency = 1.0 return rec def distill(self) -> list[SemanticFact]: written = [] for rec in self.episodic.values(): if rec.liveness is not Liveness.LIVE: continue # liveness predicate, not score-only if rec.recency < self.theta: continue fact = SemanticFact( id=f"sem_{rec.id}", text=f"derived from {rec.id}", source_ids=[rec.id], ) self.semantic[fact.id] = fact written.append(fact) return written def refresh_semantic(self) -> None: # Cascade re-validation on every decay tick. for fact in self.semantic.values(): if fact.liveness is not Liveness.LIVE: continue for sid in fact.source_ids: src = self.episodic.get(sid) if src is None or src.liveness is Liveness.FORGOTTEN: fact.liveness = Liveness.FORGOTTEN break def recall(self, fact_id: str) -> SemanticFact: fact = self.semantic.get(fact_id) if fact is None: raise ForgetInvariantViolation(f"recall on unknown fact {fact_id}") if fact.liveness is Liveness.FORGOTTEN: raise ForgetInvariantViolation( f"semantic fact {fact_id} laundered forgotten episodic source" ) return fact def demonstrate_resurrection_guard() -> None: mem = ScopedMemory(theta=0.3) mem.write_episodic("ep_4412", "user's previous address is 14 Rue ...") mem.forget("ep_4412") # A backfill/touch path attempts to read the forgotten record. tomb = mem.read("ep_4412") if tomb.liveness is not Liveness.FORGOTTEN: raise ForgetInvariantViolation("read resurrected a forgotten record") # Distillation must skip it entirely. if mem.distill(): raise ForgetInvariantViolation("distillation promoted forgotten residue") # Pre-existing fact whose source is now forgotten must cascade on refresh. mem.semantic["sem_9001"] = SemanticFact( id="sem_9001", text="user's previous address is 14 Rue ...", source_ids=["ep_4412"], ) mem.refresh_semantic() try: mem.recall("sem_9001") except ForgetInvariantViolation: return # expected: cascade caught the launder raise ForgetInvariantViolation("cascade failed to forget derived fact") ```