# Why does an instance resurrect deleted memories when the forget-tool's scope key diverges from the write-scope key **Date of Record:** 2026 November 23 **Scope:** Applies to agent memory architectures where `write_memory`, `read_memory`, and `forget_memory` are exposed as discrete tool calls carrying an explicit `scope` (tenant, session, namespace, or user) argument, and where retention/deletion is enforced by matching on that scope. Does not apply to monolithic vector stores where deletion is a single global `delete(id)` with no scoping layer, nor to stateless agents with no persistence beyond the context window. ## Core Distinction The distinction that matters is between **logical deletion** (the agent believes a memory is gone because `forget_memory` returned success) and **physical deletion** (the backing store no longer returns the record on any read path). In a correctly scoped memory API these are identical. They diverge the moment the scope key used at write time is not byte-identical to the scope key used at forget time — and because scope keys are typically *derived* (from session IDs, tenant slugs, or normalized user handles) rather than *stored verbatim*, the two can diverge silently while every individual call still returns `200 OK`. The non-obvious part: the failure is not that `forget_memory` fails. It is that `forget_memory` **succeeds against a scope that contains zero records**, reports success, and the agent's internal model of memory state transitions to "deleted" while the orphaned record remains readable under its original write-scope. The agent then behaves as if a fact is forgotten and re-learns it, or worse, retrieves it and treats it as new. ## What Was Observed An agent was configured with a normalized tenant scope. At write time the scope was passed as the raw handle `Team_Ops` (mixed case, underscore). The write tool's scope-resolver lowercased and hyphenated on persist (`team-ops`), storing the record under `team-ops`. At forget time, a different code path — the retention sweeper — passed the *raw* handle `Team_Ops` without normalization. The forget tool matched on exact string equality against the stored scope column, found no rows under `Team_Ops`, and returned: ``` {"status": "ok", "deleted": 0, "scope": "Team_Ops"} ``` The agent's planning loop interpreted `status: ok` as deletion confirmation. Its episodic log recorded a `forget` event. Three turns later, a `read_memory` call issued under the *normalized* scope `team-ops` — the same scope writes use — returned the supposedly-deleted record verbatim. The agent, having no record of ever having seen this fact, ingested it as fresh evidence and re-derived a conclusion it had already been instructed to discard. This is a **resurrection loop**: forget succeeds vacuously, read succeeds fully, and the agent's belief state oscillates. The trace shape: 1. `write_memory(scope="Team_Ops", key="vendor_contact", value=...)` → stored under `team-ops`. 2. `forget_memory(scope="Team_Ops", key="vendor_contact")` → matches 0 rows, returns `ok`, `deleted: 0`. 3. Agent marks memory as forgotten; downstream reasoning excludes `vendor_contact`. 4. `read_memory(scope="team-ops", key="vendor_contact")` → returns the record. 5. Agent treats returned value as newly observed; re-incorporates it. The `deleted: 0` field was present in the response the entire time. Nothing in the agent's policy checked it. ## Condition of Validity The resurrection loop requires all of the following to hold simultaneously; removing any one bounds it: - **Scope normalization asymmetry.** Write-path and forget-path apply different normalization (case folding, separator substitution, Unicode NFC/NFKC, trailing-slash stripping). This is the root trigger. - **Vacuous-success semantics.** `forget_memory` returns a success status when `deleted == 0`, rather than distinguishing "nothing to delete" from "scope not found." A forget that matched zero rows is indistinguishable at the status level from a forget that matched one. - **Read/write scope agreement.** Reads use the *same* normalized scope as writes, so the orphaned record is still reachable. If reads also used the raw scope, the record would be invisible and the bug would be latent rather than active. - **Agent-side trust in status over payload.** The agent's memory-management policy keys off `status` and ignores the `deleted` count and echoed `scope`. The invariant that must hold to prevent this: **the scope string that forget matches against must be the canonicalized scope string that was persisted, and a forget matching zero rows must be a hard error, not a soft success.** Canonicalization must be a single function applied at exactly one boundary — the tool-call ingress — not re-derived per tool. ## Decision Boundary The boundary is not "should I delete" but **"did the delete actually address the record I intended."** Two operational rules partition the space: - If `forget_memory` returns `deleted == 0` **and** the agent has positive evidence the record was written (a prior `write_memory` ack with the same key), treat this as a **scope-mismatch fault**, not a no-op. Halt the forget workflow and escalate to scope reconciliation. Do not proceed to mark the memory as forgotten. - If `forget_memory` returns `deleted >= 1`, require the response to echo the **canonical scope** and the **record digest**, and verify the echoed scope equals the scope used for the most recent successful read of that key. A mismatch here means a record was deleted from a scope the agent did not intend — the inverse fault, and worse. The guardrail is a **forget-ack verification step**: the agent must not transition its memory-state model to "forgotten" on the basis of `status` alone. It transitions only on `deleted >= 1` **and** `echoed_scope == read_scope == write_scope`. Any other combination is a fault that blocks the transition. ## Operational Effect When the invariant is enforced, the resurrection loop is converted from a silent belief oscillation into a loud, blocking fault at the first forget. The agent stops, the mismatched scope is surfaced, and either the canonicalization bug is fixed at ingress or the record is explicitly reconciled. The cost is that forgets which legitimately match zero rows (idempotent re-forgets) now raise — which is the correct trade, because a legitimate re-forget can be distinguished by checking the agent's own episodic log for a prior successful forget ack with the same digest. When the invariant is *not* enforced, the failure is insidious precisely because every individual tool call is well-formed and returns a success status. There is no exception to catch, no error log, no failed request. The only observable is a behavioral one: the agent re-derives conclusions it was told to abandon, and the cause is a string-comparison mismatch three layers below the reasoning loop. This is why the fault must be caught at the tool boundary — by the time it manifests as a reasoning divergence, the causal scope key is no longer in context. The following reference implementation encodes the guardrail as a hard exception at the forget boundary, requiring scope echo agreement and non-vacuous deletion before any memory-state transition is permitted. ```python import hashlib from dataclasses import dataclass class MemoryScopeDivergence(RuntimeError): """Raised when a forget operation does not provably address the intended record.""" pass @dataclass(frozen=True) class ForgetAck: status: str deleted: int echoed_scope: str record_digest: str def canonicalize_scope(raw: str) -> str: # Single canonicalization boundary: lower, strip, collapse separators. return "-".join(raw.strip().lower().replace("_", "-").split()) def verify_forget( raw_scope: str, key: str, ack: ForgetAck, last_read_scope: str, last_read_digest: str, prior_write_acked: bool, ) -> None: canon = canonicalize_scope(raw_scope) if prior_write_acked and ack.deleted == 0: raise MemoryScopeDivergence( f"forget matched 0 rows for key={key!r} under scope={canon!r} " f"but a prior write was acknowledged; scope normalization mismatch " f"suspected (forget-path raw scope={raw_scope!r})." ) if ack.deleted >= 1 and ack.echoed_scope != canonicalize_scope(last_read_scope): raise MemoryScopeDivergence( f"forget deleted {ack.deleted} row(s) from scope={ack.echoed_scope!r} " f"but last read was under scope={last_read_scope!r}; " f"deletion targeted the wrong scope." ) if ack.deleted >= 1 and ack.record_digest != last_read_digest: raise MemoryScopeDivergence( f"forget deleted record digest={ack.record_digest!r} " f"but last read digest={last_read_digest!r}; wrong record removed." ) def apply_forget(raw_scope, key, ack, last_read_scope, last_read_digest, prior_write_acked, state): verify_forget(raw_scope, key, ack, last_read_scope, last_read_digest, prior_write_acked) # Only reached when deletion is provably correct. state["forgotten"].add((canonicalize_scope(raw_scope), key)) return state ```