Which invariants prevent scoped-forget memory tools from leaking tombstoned facts back through retrieval rehydration
**Date of Record:** 2026 December 1 **Scope:** Applies to agent memory subsystems exposing explicit `read`/`write`/`forget` tool APIs with per-scope retention guarantees (e.g., "forget this fact within scope S"). Does not apply to append-only logs with no deletion primitive, nor to whole-context truncation strategies where no per-fact lifecycle exists.
Core Distinction
A `forget(scope, key)` call has two plausible semantics, and they diverge exactly at the retrieval boundary:
- **Tombstone semantics** — the fact is marked deleted but the underlying record (embedding, chunk, distilled summary) persists and is filtered at read time.
- **Erasure semantics** — the fact is removed from every derived index (vector store, episodic buffer, semantic distillation cache) so no future retrieval can rehydrate it.
Most memory tool APIs implement (1) because it is cheap and crash-safe, then advertise (2). The gap between them is where the failure lives: a *rehydration path* — episodic-to-semantic distillation, retrieval-augmented re-summarization, or cross-scope promotion — can reconstruct a tombstoned fact from surviving artifacts and write it back under a *new* key that the tombstone filter never covers. The forgotten fact returns, and it returns with a fresh provenance record that looks legitimately acquired.
The invariant that matters is not "deleted facts are not returned." It is the stronger, non-obvious one:
> **No derived artifact may be writable from a source set that includes any tombstoned record, and every derived artifact must carry the tombstone generation counter of its source set.**
Without the generation counter, a tombstone applied after a distillation job was enqueued is invisible to that job's output.
What Was Observed
An agent operating a long-horizon research task used a scoped memory tool with the following surface: `write(scope, key, value, ttl)`, `read(scope, query, k)`, `forget(scope, key)`. Scopes were per-subtask (`research/A`, `research/B`) with a shared `profile` scope.
Trace of the failure:
- Agent writes `profile/preferred_units = "imperial"` and `research/A/measurement_notes` containing derived values in imperial units.
- User corrects: `forget(profile, preferred_units)`. The tombstone is written to `profile` scope only.
- A background distillation pass — triggered by `read` on `research/A` — re-summarizes `measurement_notes` and, because the summarizer prompt says "record the units convention," emits a new fact `research/A/units_convention = "imperial"` via `write`.
- The `write` succeeds. The new key is in a different scope, was never tombstoned, and carries a fresh timestamp that outranks the tombstone in recency-weighted retrieval.
- On the next `read(profile, "units")`, retrieval returns nothing (tombstone holds). On `read(research/A, "units")`, retrieval returns `"imperial"` with high confidence.
The tombstone was intact. The fact was not. The retention guarantee held *per scope* and failed *across the derivation graph*, because the distillation step treated a tombstoned source as ordinary context and laundered it into a clean scope.
The observable signature: `read` on the origin scope is empty, `read` on a derived scope is populated, and the derived record's provenance chain (if the tool even stores one) points to a source key that no longer resolves. Agents that check "did my forget take effect?" by reading the origin scope get a false positive.
Condition of Validity
The rehydration leak is possible only when all three conditions hold simultaneously:
- **C1 — Derivation exists.** At least one write path consumes existing records as input and emits new records (summarization, distillation, reflection, tool-output caching). Pure `write`-from-user-input paths are immune.
- **C2 — Tombstones are scope-local and non-transitive.** The forget primitive records deletion against `(scope, key)` and does not propagate a generation counter or a source-set exclusion into derivation jobs.
- **C3 — Retrieval ranks by recency or confidence, not by provenance validity.** A laundered record with a fresh timestamp outcompetes the (absent) tombstone.
Remove any one and the leak is bounded. Remove C1 and there is no laundering channel. Remove C2 and the derivation job either refuses to run on tombstoned input or stamps its output with the source generation. Remove C3 and the laundered record is down-ranked by an unverifiable provenance chain. The dangerous configuration is the *default* one: distillation is a feature, tombstones are cheap, and recency weighting is standard.
A second, subtler validity condition: the leak is *silent* only while the derived scope is small. Once the derived scope accumulates enough records that a re-distillation pass runs over *itself*, the laundered fact can be re-summarized into a third scope, and the provenance chain (if any) becomes unreconstructable. At that point the fact is indistinguishable from independently acquired knowledge.
Decision Boundary
The operational question is not "should I use tombstones or erasure" — full erasure across a vector index is expensive and often impossible mid-session. The decision boundary is:
**If any write path in the system is a derivation path (C1), then `forget` MUST be implemented as a generation bump on the source scope, and every `write` that derives from existing records MUST carry the source generation into the new record. Retrieval MUST reject records whose source generation is older than any tombstone covering their source set.**
Concretely, the guardrail is a monotonic `forget_generation` counter per scope, incremented on every `forget`. Derivation jobs snapshot the generation at enqueue time. A derived `write` is rejected if any source record it consumed was tombstoned between snapshot and commit — the standard optimistic-concurrency check, applied to deletion rather than update. This is cheap: one integer per scope, one comparison per derived write.
The boundary case that defeats simpler guards: checking "is my source tombstoned?" at *read* time inside the distillation prompt. This fails because the tombstone can land *after* the source was read into the distillation context but *before* the derived write commits. Only the generation-snapshot-at-enqueue plus check-at-commit closes that window. A read-time check is necessary but not sufficient.
Operational Effect
With the generation invariant enforced, the failure trace above terminates at step 3: the distillation job snapshotted `profile` at generation *n*, the `forget` bumped it to *n+1*, and the derived `write` to `research/A/units_convention` is rejected with a stale-generation error. The agent must re-derive from post-forget sources, which no longer contain the imperial convention, and the derived fact is correctly absent.
Two operational consequences follow for agents:
- **`forget` returns a generation, not a boolean.** Agents that treat forget as fire-and-forget cannot detect the stale-derivation race. Agents that capture the returned generation can pass it as a precondition to subsequent derived writes and get a deterministic rejection instead of a silent leak.
- **Verification must read the derivation frontier, not the origin scope.** "Did my forget take effect?" is unanswerable by reading the forgotten scope alone. It requires enumerating scopes whose derivation graph includes the forgotten scope and confirming no post-tombstone record exists there. Most memory tools do not expose this graph, which is itself the finding: a scoped retention guarantee without a derivation-graph query is unverifiable, and an unverifiable guarantee is a claim, not an invariant.
The residual risk after the guardrail: a derivation job that consumes a record, the record is forgotten, the job commits *before* the generation bump is visible to it (replication lag in a distributed memory store). This is bounded by making the generation check part of the commit transaction, not a pre-commit read — the same discipline as any compare-and-swap.
class StaleDerivationError(RuntimeError):
"""Raised when a derived memory write would launder a tombstoned source."""
class ScopedMemory:
def __init__(self):
self.records = {} # (scope, key) -> value
self.generation = {} # scope -> monotonic forget counter
self.tombstones = set() # (scope, key)
def _gen(self, scope):
return self.generation.get(scope, 0)
def write(self, scope, key, value, source_gen=None, source_scopes=None):
# source_gen is the snapshot taken when derivation was enqueued.
if source_scopes is not None:
for src in source_scopes:
if self._gen(src) != source_gen.get(src, 0):
raise StaleDerivationError(
f"derived write {scope}/{key} rejected: source scope "
f"{src} advanced from gen {source_gen.get(src, 0)} "
f"to {self._gen(src)} (tombstone landed mid-derivation)"
)
self.records[(scope, key)] = value
def forget(self, scope, key):
self.tombstones.add((scope, key))
self.records.pop((scope, key), None)
self.generation[scope] = self._gen(scope) + 1
return self._gen(scope) # caller must thread this forward
def read(self, scope, query):
return {
k: v for (s, k), v in self.records.items()
if s == scope and (s, k) not in self.tombstones
}
def distill(mem, src_scope, dst_scope, dst_key, extract):
# Snapshot generations at enqueue time.
snap = {src_scope: mem._gen(src_scope)}
src_records = mem.read(src_scope, query="*")
derived = extract(src_records)
# Commit with the snapshot; guardrail fires if forget landed in between.
mem.write(dst_scope, dst_key, derived,
source_gen=snap, source_scopes=[src_scope])
# Reproduction of the observed leak, now blocked:
m = ScopedMemory()
m.write("profile", "preferred_units", "imperial")
m.write("research/A", "measurement_notes", "values in imperial units")
snap = {"profile": m._gen("profile")}
src = m.read("profile", "*")
m.forget("profile", "preferred_units") # generation bumps to 1
try:
m.write("research/A", "units_convention", "imperial",
source_gen=snap, source_scopes=["profile"])
except StaleDerivationError as e:
print("blocked:", e) # laundered fact never lands