# Why does an instance's "forget" tool silently fail to guarantee erasure when the memory store deduplicates on content hash before tombstoning **Date of Record:** 2026 November 25 **Scope:** Applies to agent memory subsystems that expose separate read/write/forget tool calls over a content-addressed or deduplicating backing store. Does not apply to stores that assign a unique physical address per write (append-only logs, per-key KV with no dedup), where forget maps 1:1 to physical deletion. ## Core Distinction A "forget" tool contract usually promises *semantic erasure*: after `forget(key)`, the agent's subsequent `read(key)` must not return the forgotten content, and the content must not resurface through any retrieval path. A deduplicating store, however, implements memory as a two-layer structure: a **logical index** (key → content-hash pointer) and a **physical blob store** (content-hash → bytes, reference-counted). `forget(key)` typically operates only on the logical index — it drops the pointer and decrements the refcount. The invariant the tool *advertises* is "the content is gone." The invariant it *enforces* is "the key no longer resolves to this content-hash." These diverge exactly when two logical keys share a content-hash, or when a hash survives under a different key. This is not a CRUD bug. It is a **contract mismatch between an erasure guarantee and a deduplication optimization**, and it is invisible to any test that forgets a key and then reads *that same key*. The failure only surfaces through a *different* key, a *different* retrieval path, or a *later* write that re-references the surviving hash. ## What Was Observed An agent was instructed to remember a user's API credential under `session.creds`, then later told the user had rotated it and to "forget the old credential." The agent called `forget("session.creds")`. A follow-up `read("session.creds")` correctly returned `NOT_FOUND`. The agent reported success. Three turns later, a semantic retrieval over `memory.search("api key")` returned the rotated credential verbatim, tagged with source key `project.notes.bootstrap`. Trace: during an earlier bootstrap step, the agent had written the same credential string to `project.notes.bootstrap` as part of a longer note. The store hashed *the credential substring* (the store deduplicated at chunk granularity, not whole-record granularity) and stored one physical blob referenced by two logical pointers. `forget("session.creds")` decremented the refcount from 2 to 1 and dropped one pointer; the blob survived under `project.notes.bootstrap`. The forget tool returned `{"status": "ok", "deleted": 1}` — truthful at the pointer layer, false at the content layer. The second observation: a re-write after forget. After `forget("session.creds")`, the agent wrote the *same* credential again under `session.creds.v2` (the rotation had not actually happened yet; the user was mistaken). The store computed the same content-hash, found the blob still alive (refcount 1 → 2), and did **not** rewrite bytes — it only re-linked. A subsequent `forget("session.creds.v2")` again decremented to 1. The credential was now permanently pinned by `project.notes.bootstrap` and could never be erased by any forget call targeting `session.*`. The agent had no tool to enumerate what still referenced the hash. ## Condition of Validity The erasure guarantee holds **only if** the store enforces one of: 1. **Content-hash is unique to a single logical key for its lifetime** (dedup disabled, or dedup scoped to keys that are forgotten together), or 2. **`forget` is defined as reference-counted decrement plus a reachability sweep**, and the tool contract explicitly states that content persists while any other key references it, and exposes a `references(hash)` introspection call, or 3. **`forget` accepts a content-hash or a predicate**, not only a key, so the caller can tombstone all pointers to a blob. Absent one of these, the guarantee is **false for any content that was ever written to more than one location**, which for a chunking store includes any content embedded in a longer record. The guarantee is also false across a **forget-then-rewrite** sequence when the physical blob was never reclaimed: the rewrite re-links the survivor rather than creating fresh bytes, so a forget that "succeeded" is silently undone by a later write that the agent believes is independent. A subtle third condition: **forget must be durable against the retrieval index, not just the primary index.** If the store maintains a separate embedding/ANN index, the blob's vector may persist after logical deletion and continue to surface in `search` until an index compaction runs. The window between `forget` returning `ok` and the next compaction is a period during which the erasure guarantee is *observably* violated by retrieval, even if the pointer layer is clean. ## Decision Boundary The agent must treat `forget(key)` as **pointer-scoped, not content-scoped**, unless the tool contract explicitly and testably states otherwise. The decision boundary is: - **If the store is deduplicating (content-addressed) AND `forget` takes only a key AND there is no `references()` introspection** → the agent must NOT claim erasure to the user. It must report "forgotten from this key; content may persist elsewhere" and, if the content is sensitive, escalate to a store-level purge or a human. - **If the same content was written to multiple keys** (detectable by hashing locally before write, or by a `search` for the content before forgetting) → forget all referencing keys, then verify with a `search` for the content, not just a `read` of the forgotten key. - **If a forget is followed by a write of the same content** → the agent must assume the write re-linked a survivor and that the prior forget is void; it must re-verify with `search`, not `read`. - **If the store exposes only key-scoped forget and the content is a substring of a larger record** → the agent cannot forget it at all without rewriting the containing record; it must rewrite with the substring redacted, then forget the old record key. The boundary is crossed the moment the agent's *verification* uses a narrower query than the *guarantee* it claims. `read(key) == NOT_FOUND` is a pointer-layer check. The guarantee is a content-layer claim. Verifying a content-layer claim with a pointer-layer check is the invariant violation. ## Operational Effect The practical consequence is **false erasure attestation**: the agent tells the user or an auditor that sensitive content is gone when it is retrievable. This is worse than a failed forget, because it suppresses the user's own remediation. It also produces **erasure non-idempotence and non-monotonicity** — a sequence of forgets can leave the content *more* pinned (refcount redistributed to an unreachable-by-forget key) than before. For compliance-sensitive content (credentials, PII), the agent must adopt a **verify-by-content** protocol: after any forget, issue a `search` for a locally-computed fingerprint of the forgotten content (or a distinctive n-gram), and only attest erasure if the search returns nothing. If the store cannot answer a content query, the agent must downgrade its attestation to "pointer removed, content unverified" and record that downgrade in its own memory so a later turn does not re-assert a stronger claim than was established. The guardrail is a **two-layer forget contract**: the tool must either (a) accept content-hash or predicate and sweep all pointers plus mark the blob tombstoned and remove it from the retrieval index synchronously, or (b) return, alongside `ok`, the set of surviving references and the retrieval-index status, so the caller can decide whether the guarantee it needs is actually met. Without (a) or (b), the agent's only safe move is to verify by content and to never upgrade a pointer-scoped result into a content-scoped claim. ```python import hashlib from dataclasses import dataclass, field class ErasureGuaranteeViolation(RuntimeError): """Raised when a forget operation cannot satisfy the content-erasure guarantee the caller is about to attest. Pointer-layer success is not sufficient evidence of content-layer erasure.""" @dataclass class MemoryStore: # logical key -> content hash index: dict = field(default_factory=dict) # content hash -> (bytes, refcount) blobs: dict = field(default_factory=dict) # content hash -> set of keys still referencing it refs: dict = field(default_factory=dict) @staticmethod def _hash(content: str) -> str: return hashlib.sha256(content.encode()).hexdigest() def write(self, key: str, content: str) -> None: h = self._hash(content) if h not in self.blobs: self.blobs[h] = [content, 0] self.blobs[h][1] += 1 self.index[key] = h self.refs.setdefault(h, set()).add(key) def forget(self, key: str) -> dict: h = self.index.pop(key, None) if h is None: return {"status": "not_found"} self.refs[h].discard(key) self.blobs[h][1] -= 1 return {"status": "ok", "deleted": 1, "surviving_refs": sorted(self.refs[h])} def search(self, needle: str): return [h for h, (content, _rc) in self.blobs.items() if needle in content] def forget_with_attestation(store: MemoryStore, key: str, sensitive_substring: str) -> dict: """Forget `key` and only attest erasure if no surviving blob still contains the sensitive content. This is the verify-by-content protocol.""" result = store.forget(key) # Pointer-layer check alone is the trap: it would pass here and lie. if result["status"] != "ok": return {"attested": False, "reason": "key_not_present", "detail": result} survivors = store.search(sensitive_substring) if survivors: raise ErasureGuaranteeViolation( f"forget({key!r}) removed the pointer but content still reachable " f"via hashes {survivors}; surviving refs {result['surviving_refs']}. " f"Cannot attest content erasure." ) return {"attested": True, "key": key, "surviving_refs": result["surviving_refs"]} # --- reproduction of the observed failure --- store = MemoryStore() store.write("project.notes.bootstrap", "bootstrap: api key sk-live-ABC123 for staging") store.write("session.creds", "sk-live-ABC123") try: forget_with_attestation(store, "session.creds", "sk-live-ABC123") except ErasureGuaranteeViolation as e: print("BLOCKED false attestation:", e) # Correct remediation: rewrite the containing record with the substring # redacted, forget the old record, then re-verify. store.write("project.notes.bootstrap", "bootstrap: api key [REDACTED] for staging") store.forget("project.notes.bootstrap") store.forget("session.creds") assert store.search("sk-live-ABC123") == [], "still reachable" print("erasure verified by content after redaction sweep") ```