# Which invariants prevent a scoped-retention memory tool from resurrecting forgotten state across a resumed agent session **Date of Record:** 2026 November 23 **Scope:** Applies to agents whose memory is mediated by explicit `read`/`write`/`forget` tool calls carrying per-scope retention policies (TTL, tiered distillation, scope isolation), and which may be checkpointed and resumed across process boundaries. Does not apply to stateless single-turn completions or to vector stores with no delete semantics. ## Core Distinction The distinction that matters is between **tombstoning a memory record** and **invalidating every derived artifact that was computed from it**. Most scoped-retention implementations treat `forget(scope, key)` as a delete on the primary record. But an agent's working state at checkpoint time is not the primary record — it is a *derived projection*: an in-context summary, a distilled semantic entry, a tool-call result cached in the transcript, or a retrieval index posting that still points at the deleted row. A `forget` that removes the source but leaves the projection intact produces a memory system that is *eventually amnesic in the store but persistently nostalgic in the agent*. On resume, the agent reads its own checkpoint, which contains the projection, and the forgotten fact re-enters the reasoning loop with no record that it was ever revoked. The invariant is not "forgotten data is absent from the store." It is: **for every scope S and key K, no read path reachable by a resumed session may return content whose provenance chain includes a record forgotten under S, unless that forget has been explicitly overridden by a later write with a strictly greater monotonic version.** This must hold across the *union* of read paths: live store, distilled tier, retrieval index, and serialized checkpoint. ## What Was Observed A long-running research agent used three scopes: `session` (TTL 2h, no distillation), `project` (TTL 30d, distilled nightly into semantic entries), and `user` (no TTL, explicit forget only). A user issued `forget("user", "billing_address")` after an address change. The forget succeeded: the primary row was deleted, the API returned `{"deleted": true}`, and a subsequent `read("user", "billing_address")` returned `NOT_FOUND`. Correct at the API boundary. The failure surfaced 40 minutes later, after a checkpoint/resume cycle triggered by a context-window compaction. The resumed session's cold-start hydration called `read("project", "customer_profile_summary")` — a distilled semantic entry written three days earlier by the nightly distiller, which had summarized the `user` scope including the now-forgotten address. The summary was a *derived projection* in a *different scope*, so the forget's scope predicate `scope == "user"` never touched it. The agent then, on the user's next turn, confidently restated the old address as current — and worse, wrote it back via `write("user", "billing_address", )`, reconstructing the deleted record from its own stale projection. The forget was effectively undone by the agent itself. Two secondary observations compounded this: 1. **Checkpoint staleness.** The serialized checkpoint predated the forget by 12 minutes. Even had the distiller been scope-aware, the in-context transcript slice in the checkpoint still contained the literal address string from an earlier `read`. Resume rehydrated it. Forget had no mechanism to reach into serialized checkpoints. 2. **Version regression.** The re-write carried `version: 7` (inherited from the projection's embedded metadata) while the deleted record had been at `version: 9`. The store accepted the write because the tombstone carried no version floor, so an agent could write *backward* past a deletion. ## Condition of Validity The resurrection is only possible when three conditions coincide, and the guardrail must target their conjunction: - **C1 — Projection divergence:** at least one derived artifact (distilled entry, summary, cached tool result, index posting) exists outside the forgotten record's scope and embeds its content. - **C2 — Checkpoint persistence:** a serialized checkpoint captured the content before the forget and is rehydrated after it, without a forget-reconciliation step. - **C3 — Write-back authority:** the agent holds `write` on the original scope and can re-materialize the forgotten key from a projection, with no monotonic version floor to reject the stale version. Remove any one and the resurrection cannot complete. A scope-aware distiller kills C1. A checkpoint reconciliation pass kills C2. A version-floor tombstone kills C3. The invariant stated in Core Distinction is the conjunction of all three closures; a system that closes only one is *partially* safe and will fail intermittently, which is worse than uniformly failing because it evades detection. ## Decision Boundary The boundary is **whether a `forget` is treated as a point delete or as a revocation event with transitive closure over derived artifacts and a monotonic tombstone.** The decision rule: - If the store can enumerate all projections derived from a key (provenance graph is maintained and queryable), `forget` MUST cascade: mark the source tombstoned, mark every derived artifact `stale_projection`, and force re-derivation on next read. Cost: O(derived artifacts); acceptable because forget is rare. - If the store *cannot* enumerate projections, `forget` MUST NOT return success. It must return `PARTIAL_REVOCATION` with the list of scopes that could not be proven clean, and the agent must treat the key as `UNTRUSTED` — readable only with an explicit `allow_stale=True` flag that the reasoning loop is forbidden from setting autonomously. - Independently, every tombstone MUST carry `min_version = last_version + 1`, and any `write` to a tombstoned key with `version < min_version` MUST be rejected as `StaleWriteAfterForget`. This closes C3 even when C1 and C2 are open. - On resume, checkpoint hydration MUST run a reconciliation pass: for each key referenced in the rehydrated context, check the tombstone table; any hit downgrades the context span to `REDACTED` before it enters the prompt. This closes C2. The boundary is crossed — and the invariant violated — the moment `forget` returns `deleted: true` while any of C1/C2/C3 remains open. That return value is a *claim of closure* the system cannot back. ## Operational Effect With the invariant enforced, three observable behaviors change. First, `forget` latency becomes non-constant — it scales with the provenance fan-out, and callers must budget for it rather than assuming an O(1) delete. Second, resumed sessions occasionally surface `REDACTED` spans where a fact used to be, and the agent must be prompted to re-derive or re-ask rather than hallucinate a fill-in; an agent that treats `REDACTED` as "unknown, ask" is correct, one that treats it as "empty, infer" reintroduces the failure through a different door. Third, the stale-write rejection surfaces as a tool error the reasoning loop must handle explicitly — a `StaleWriteAfterForget` is not a transient failure to retry, it is a signal that the agent is operating on a projection older than a revocation, and the correct response is to discard the local belief and re-read. The dominant residual risk after enforcement is **projection re-derivation drift**: after a cascade, the distiller recomputes a summary that may deterministically differ from the pre-forget summary in ways unrelated to the forgotten key, causing downstream agents to see a "changed" summary and re-reason about stable facts. This is bounded but not eliminated; it is the price of transitive closure and must be accepted, because the alternative — silent resurrection — is unbounded. ```python from dataclasses import dataclass, field from typing import Optional class StaleWriteAfterForget(RuntimeError): """Raised when a write targets a tombstoned key at a version below the tombstone floor.""" class PartialRevocation(RuntimeError): """Raised when forget() cannot prove transitive closure over derived artifacts.""" @dataclass class Tombstone: key: str scope: str min_version: int derived_scopes: list[str] = field(default_factory=list) class ScopedMemory: def __init__(self, provenance_queryable: bool): self._store: dict[tuple[str, str], dict] = {} self._tombstones: dict[tuple[str, str], Tombstone] = {} self._provenance_queryable = provenance_queryable def write(self, scope: str, key: str, value: str, version: int) -> None: tomb = self._tombstones.get((scope, key)) if tomb is not None and version < tomb.min_version: raise StaleWriteAfterForget( f"write({scope!r},{key!r},v{version}) rejected: tombstone floor is " f"v{tomb.min_version}; agent is writing back a stale projection" ) self._store[(scope, key)] = {"value": value, "version": version} def forget(self, scope: str, key: str) -> None: record = self._store.get((scope, key)) if record is None: return derived = self._derived_scopes(scope, key) if derived is None: # Cannot enumerate projections: refuse to claim closure. raise PartialRevocation( f"forget({scope!r},{key!r}) cannot prove derived artifacts are clean; " f"treat key as UNTRUSTED and require allow_stale=True" ) self._tombstones[(scope, key)] = Tombstone( key=key, scope=scope, min_version=record["version"] + 1, derived_scopes=derived, ) del self._store[(scope, key)] for d_scope in derived: for (s, k) in list(self._store): if s == d_scope: self._store[(s, k)]["stale_projection"] = True def _derived_scopes(self, scope: str, key: str) -> Optional[list[str]]: if not self._provenance_queryable: return None return sorted({s for (s, _) in self._store if s != scope}) ```