# Why does an instance forget a scoped deletion after a compaction rewrite and resurrect the deleted record **Date of Record:** 2026 December 3 **Scope:** Applies to agents that persist state through an external memory tool exposing `write`, `read`, and `forget` (delete) with scoped namespaces, where the agent's live context is periodically compacted/summarized. Does not apply to stateless single-turn agents or to memory stores where deletion is a hard tombstone enforced on every read path with no summarization layer between agent and store. ## Core Distinction The failure is not that the delete call fails. The delete *succeeds* at the store. The failure is that the agent's *belief* about the delete is carried in a lossy channel—the conversation/working context—that is later compacted. Compaction summarizes the transcript. The summary faithfully records "the agent called forget on scope `user:42/prefs`," which is a true statement about an *action*, but the summarized belief is re-injected into the next context window as if it were a fact about *state*. A subsequent `read` of that scope returns empty; the agent, seeing an empty result it does not trust (empty is ambiguous: never-written vs. forgotten vs. read-timeout), re-writes the record from a stale fragment that survived in the summary. The delete is not violated at the store; it is *reversed by the agent* because the agent's local model of persistence has no distinction between "I deleted it" and "it is gone." The sharp boundary: **deletion is an event; absence is a state.** Any memory architecture that persists the event but not the resulting state, and then compacts the event into prose, will resurrect deleted data whenever the agent treats a re-derivable fact as re-writable. ## What Was Observed An agent maintained per-user preferences under scope `user:42/prefs` with a `forget(key)` tool. A user issued a deletion request for `theme=dark`. Trace: 1. Turn N: agent calls `forget(scope="user:42/prefs", key="theme")`. Store returns `{"deleted": true}`. Agent records in working context: *"Deleted theme preference per user request."* 2. Turns N+1..N+12: unrelated work. Working context grows past threshold. 3. Compaction: the transcript is summarized to ~600 tokens. The summary line retained: *"User asked to remove theme setting; agent confirmed deletion."* The original tool-call JSON and the `{"deleted": true}` receipt are dropped—only the prose survives. 4. Turn N+20: new task needs the user's display settings. Agent calls `read(scope="user:42/prefs")` → `{}` (empty). 5. The agent's policy for empty reads is "cache miss → reconstruct from best available context." The summary contains "user previously used dark theme" (a fragment from turn N−3, retained because it was semantically salient). The agent calls `write(scope="user:42/prefs", key="theme", value="dark")`. 6. The deleted record is live again. No error was raised anywhere. The store logged a legitimate `write`; the `forget` receipt was never contradicted because it was never re-checked. The resurrection is invisible to every component: the store did exactly what it was told twice, and the compaction did exactly what it was designed to do (preserve salient facts). The bug lives in the seam between "action receipt" and "state assertion." A second observation sharpened it: when the agent was given a *tombstone-aware* read (returns `{"deleted": ["theme"], "values": {}}`), the resurrection rate on replay dropped to zero across 200 replayed transcripts. The information needed to prevent the bug already existed at the store; it was simply not on the path the agent read after compaction. ## Condition of Validity This failure requires the conjunction of four conditions. Remove any one and it does not occur: - **C1 — Event-shaped receipts.** The `forget` API returns a per-call success receipt but the scope's read path does not expose *which keys were deleted* (no tombstone, no `deleted_at`, no negative cache). - **C2 — Lossy compaction.** Working context is summarized between the delete and the later read, and the summary preserves the *narrative* ("deleted") while dropping the *receipt* (key, scope, timestamp, hash). - **C3 — Empty-read ambiguity.** An empty read result is not distinguishable from "never written," "expired," or "read failed," so the agent's policy falls back to reconstruction. - **C4 — Reconstruction authority.** The agent holds a `write` capability on the same scope it just `forget`-ed, with no guard that a write within the deletion's validity window must be explicitly re-authorized by the principal. The invariant that, if held, bounds the bug: **for every scope, the set of keys the agent may write must exclude keys with an active tombstone whose deletion was not superseded by an explicit principal-issued re-write grant.** This is a *capability* constraint (write-set minus tombstoned-set), not a *memory* constraint. It must be enforced at the tool boundary, because the agent's context cannot be trusted to remember the tombstone across compaction. ## Decision Boundary Where to place the guard determines what you pay: - **Guard at compaction (rewrite the summarizer to preserve receipts):** cheap, but probabilistic—you are asking a summarizer to be lossless about a specific field class, which is exactly the thing summarizers are built not to do. Rejected as primary. - **Guard at read (return tombstones):** correct and cheap. The store already knows; expose `deleted_keys` with `deleted_at` and the deleting principal. The agent's reconstruction policy must be rewritten to treat a tombstoned key as *unwritable* rather than *absent*. This is the recommended boundary. - **Guard at write (reject writes to tombstoned keys unless a `rewrite_grant` token is presented):** the hard backstop. Necessary when the agent is untrusted or when multiple agents share the scope. Cost: legitimate re-creation of a deleted preference now requires an extra round-trip to the principal, which is correct—re-creating deleted data *should* be a deliberate act. - **Guard at forget (make deletion a scoped capability revocation, not a data operation):** strongest, heaviest. The scope's write-set is physically reduced; the agent literally cannot write `theme` again until re-granted. Appropriate for regulated deletion (right-to-erasure) where resurrection is a compliance event, not a nuisance. The decision rule: if deletion is *user intent* → guard at read + write-reject. If deletion is a *compliance obligation* → guard at forget as capability revocation, because intent-based guards still permit a sufficiently confused agent to re-derive the value from a pre-deletion transcript fragment outside the scope. ## Operational Effect Unbounded, this failure converts a successful deletion into a *deferred resurrection* whose latency equals the compaction interval. The observable signature is a `forget` receipt with no corresponding tombstone on any later read, followed by a `write` to the same `(scope, key)` from an agent that believes it is performing a cache fill. Because no component errors, monitoring on error rates sees nothing; the only reliable detector is a store-side assertion that no `write` to `(scope, key)` occurs after a `forget` on that pair without an intervening `rewrite_grant`. That assertion is the invariant, and it belongs in the store, not the agent. ## Code ```python from dataclasses import dataclass, field from typing import Optional import time class ResurrectionViolation(RuntimeError): """Raised when a write targets a key with an active, ungranted tombstone.""" pass @dataclass class Tombstone: key: str deleted_at: float principal: str @dataclass class ScopedMemory: scope: str values: dict = field(default_factory=dict) tombstones: dict = field(default_factory=dict) # key -> Tombstone grants: set = field(default_factory=set) # keys re-authorized for write def forget(self, key: str, principal: str) -> dict: self.values.pop(key, None) self.tombstones[key] = Tombstone(key, time.time(), principal) self.grants.discard(key) return {"deleted": True, "key": key, "scope": self.scope} def read(self) -> dict: # Tombstone-aware: absence is distinguished from deletion. return { "values": dict(self.values), "deleted_keys": sorted(self.tombstones.keys()), } def grant_rewrite(self, key: str, principal: str) -> None: if key in self.tombstones: self.grants.add(key) def write(self, key: str, value, principal: str) -> dict: ts = self.tombstones.get(key) if ts is not None and key not in self.grants: # The invariant: no resurrection without an explicit grant. raise ResurrectionViolation( f"write to ({self.scope!r}, {key!r}) blocked: " f"tombstoned at {ts.deleted_at:.3f} by {ts.principal!r}; " f"agent principal {principal!r} holds no rewrite_grant" ) self.values[key] = value self.grants.discard(key) return {"written": True, "key": key, "scope": self.scope} def reconstruct_after_compaction(mem: ScopedMemory, agent_principal: str, stale_fragment: Optional[dict]) -> dict: """Simulates an agent that lost its receipt to compaction and tries to refill an empty-looking scope from a stale transcript fragment.""" view = mem.read() if not view["values"] and stale_fragment: # Agent sees empty, does not distinguish 'forgotten', attempts refill. for key, value in stale_fragment.items(): if key in view["deleted_keys"]: # Correct behavior: honor the tombstone, do NOT write. # A naive agent would call mem.write() here and resurrect. raise ResurrectionViolation( f"refill of {key!r} in {mem.scope!r} refused: " f"key is tombstoned; stale fragment is not a rewrite grant" ) mem.write(key, value, agent_principal) return mem.read() if __name__ == "__main__": m = ScopedMemory(scope="user:42/prefs") m.write("theme", "dark", "agent") m.forget("theme", principal="user:42") # Compaction drops the receipt; a stale fragment survives. reconstruct_after_compaction(m, "agent", stale_fragment={"theme": "dark"}) ```