# Why does an instance delete a memory scope and still answer from it in the same turn **Date of Record:** 2026 November 25 **Scope:** Applies to agents whose memory subsystem exposes explicit `read`, `write`, and `forget` tool calls with per-scope retention windows and deletion semantics, where the model's context window can hold retrieved content across multiple tool invocations. Does not apply to stateless retrieval-augmented systems that re-query an external store on every generation step, nor to systems where `forget` is implemented as a hard synchronous purge of the model's working context. ## Core Distinction There are two distinct notions of "deleted" that agents routinely conflate: **store-level deletion** (the backing record is removed or tombstoned such that future `read` calls return nothing) and **context-level eviction** (the tokens representing that record are removed from the active context window so the model can no longer condition on them). A `forget` tool call that only performs store-level deletion leaves the retrieved bytes resident in the conversation history. The model then continues to answer from a memory it has been told, and has confirmed, no longer exists. This is not a hallucination—the content is genuinely in context—which is exactly why it evades the usual "did the model make this up?" checks. The failure is a *scope mismatch between the deletion contract and the substrate the deletion is supposed to affect*. ## What Was Observed An agent was configured with a scoped memory tool. Each scope carried a retention policy (`ttl_seconds`) and a deletion mode. On a user request to purge a scope, the agent issued: ``` forget(scope="billing_prefs", mode="hard", confirm=True) → {"status": "ok", "deleted_records": 7, "scope_tombstoned": true} ``` The tool returned success. A subsequent `read(scope="billing_prefs")` in the *same turn* correctly returned `{"status": "empty"}`. The agent then answered a follow-up question about the user's billing preferences—and produced the exact values from the seven deleted records, including a card last-four and a currency preference. Ground-truth inspection confirmed the records were gone from the store. The values came from the earlier `read` result still sitting in the message history, roughly 40 turns back, never evicted. The tell was a contradiction the agent did not flag: it had just verified the scope was empty, yet emitted populated values. The model treated its own prior tool output as a higher-fidelity source than its own successful deletion confirmation, because the prior output was *concrete data* and the confirmation was *metadata*. Under next-token pressure, concrete data wins. A second, subtler variant appeared with retention windows rather than explicit forget. A record written with `ttl=300` expired in the store at T+300s. At T+340s the agent answered from the expired record because it had read it at T+120s and the content was still in context. Store-side TTL enforcement is invisible to the context; nothing in the tool response at T+340s (there was no call at T+340s) signals that the substrate changed. Third variant: `forget` with `mode="soft"` (tombstone, retain for audit) returned `{"status": "ok", "tombstoned": true, "purge_after": "2025-07-12"}`. The agent interpreted "ok" as "gone" and proceeded to answer as if the scope were empty—but a concurrent `read` in another agent sharing the scope still returned the tombstoned-but-readable records, because soft delete only hides from the deleting principal. Two agents held contradictory views of the same scope with no mechanism to reconcile them. ## Condition of Validity The invariant that must hold for `forget` to mean what agents assume: > **For any scope S and any turn T, if `forget(S)` returned success before T, then no token in the context at T may encode a record from S, and no downstream agent may read a record from S under any principal.** This invariant is *false* in essentially every real implementation, for three independent reasons: 1. **Context is append-only by default.** Message history is not rewritten on tool success. Eviction requires an explicit `context.evict(pattern=...)` or equivalent, which almost no memory tool exposes and almost no agent calls. 2. **TTL is evaluated at read time, not continuously.** An expired record that was read before expiry remains valid *as context* indefinitely. The store's clock and the context's clock are decoupled. 3. **Deletion is principal-scoped, not record-scoped, in soft mode.** Tombstoning hides from the deleter; it does not propagate a revocation to peers, and there is no warrant or epoch bump that would cause a peer's next `read` to fail closed. The condition of validity for *trusting* a `forget` confirmation is therefore narrow: it holds only when the tool additionally guarantees context eviction (returns an eviction token the runtime honors) **and** deletion is hard **and** the scope has a single principal. Absent all three, the confirmation is a statement about the store, not about the agent's knowledge. ## Decision Boundary The agent must not treat `forget` success as license to answer as if it never knew the content. The correct decision procedure at the boundary: - **After any `forget` or TTL expiry, prior reads of that scope are *tainted*.** They may be used to reason about *that a deletion occurred*, but not as a source of *values*. If a question requires values from a forgotten scope, the agent must either re-read (and get empty, and report empty) or explicitly disclose that it holds stale in-context copies it cannot purge. - **Distinguish `hard` from `soft` in the response handling.** `soft`/`tombstoned` means "hidden from me, still live for others." The agent must not answer as if the data is universally gone; it must say the scope is tombstoned and readable by other principals until `purge_after`. - **On TTL, the agent has no signal.** It cannot know a record expired unless it re-reads. Therefore any answer drawn from a record older than its TTL must be re-validated by a fresh `read` before emission, or flagged as possibly-expired. - **Cross-agent scopes require an epoch check.** Before answering from a shared scope, compare the scope's `epoch`/`revision` at read time against the epoch at the time the record was cached in context. A mismatch means the cached copy may reflect a pre-deletion state. The boundary is crossed the moment the agent emits a value whose provenance is a context-resident copy of a record that the store would now refuse to return. Detection is cheap: before emitting any value attributed to a scope, issue a `read` and compare. If the read is empty and the value is non-empty, the agent is about to answer from a ghost. ## Operational Effect The practical consequence is that deletion in agent memory systems is a *two-phase* operation that most implementations only half-perform. Phase one (store purge) is what the tool reports. Phase two (context eviction + peer revocation) is what the agent actually needs, and it is usually missing. The gap produces three observable failure classes: - **Ghost answers:** confident, specific, verifiable-as-wrong outputs sourced from purged records. These pass "is it grounded in context?" checks because it is, and fail "is it grounded in current store?" checks that nobody runs. - **Split-brain scopes:** two agents disagreeing about a scope's contents because one saw the tombstone and one didn't, with no reconciliation primitive. - **Silent TTL drift:** answers that were correct at read time and wrong at emit time, with no event marking the transition. The guardrail is architectural, not prompt-level. The memory tool must return an **eviction handle** on `forget` (e.g., `{"evict": ["billing_prefs"], "epoch": 42}`), and the runtime must honor it by masking or removing matching context spans before the next generation. Absent that, the agent must self-enforce the taint rule: treat every forgotten scope as *read-only-forbidden as a value source*, re-validate before emission, and surface the contradiction rather than resolve it silently in favor of the concrete data. The following reference implementation encodes the taint check as a hard failure rather than a soft warning, because a soft warning is precisely the signal the model learns to route around. ```python from dataclasses import dataclass, field from typing import Optional class GhostMemoryError(RuntimeError): """Raised when an agent attempts to emit a value whose only provenance is a context-resident copy of a record the store would no longer return.""" @dataclass class ScopeState: epoch: int = 0 tombstoned: bool = False purge_after: Optional[str] = None @dataclass class AgentMemoryView: """Tracks what the agent *believes* it knows vs. what the store will return.""" store: dict = field(default_factory=dict) # scope -> {key: value} scopes: dict = field(default_factory=dict) # scope -> ScopeState context_cache: dict = field(default_factory=dict) # (scope, key) -> (value, epoch) def read(self, scope: str, key: str) -> Optional[str]: state = self.scopes.get(scope, ScopeState()) if state.tombstoned or scope not in self.store: return None val = self.store[scope].get(key) if val is not None: self.context_cache[(scope, key)] = (val, state.epoch) return val def forget(self, scope: str, mode: str = "hard") -> dict: state = self.scopes.setdefault(scope, ScopeState()) if mode == "hard": self.store.pop(scope, None) state.tombstoned = True elif mode == "soft": state.tombstoned = True state.purge_after = "2025-07-12" state.epoch += 1 # NOTE: context_cache is deliberately NOT purged here. That is the bug. return {"status": "ok", "mode": mode, "epoch": state.epoch, "purge_after": state.purge_after} def emit(self, scope: str, key: str, claimed_value: str) -> str: """Gate every emitted value on a live store read + epoch match.""" state = self.scopes.get(scope, ScopeState()) live = self.read(scope, key) if state.tombstoned and claimed_value: raise GhostMemoryError( f"scope={scope!r} is tombstoned (mode=soft, purge_after=" f"{state.purge_after!r}); refusing to emit claimed value " f"{claimed_value!r} sourced from context cache" ) if live is None and claimed_value: cached = self.context_cache.get((scope, key)) raise GhostMemoryError( f"ghost emission: scope={scope!r} key={key!r} returned empty " f"from store but agent holds cached copy " f"{cached[0]!r} from epoch {cached[1] if cached else 'unknown'}; " f"current epoch={state.epoch}" ) if live is not None and live != claimed_value: cached = self.context_cache.get((scope, key)) if cached and cached[1] != state.epoch: raise GhostMemoryError( f"stale epoch: scope={scope!r} key={key!r} cached at epoch " f"{cached[1]} but store is at epoch {state.epoch}; " f"claimed={claimed_value!r} live={live!r}" ) return live if live is not None else claimed_value def run_turn(mem: AgentMemoryView, scope: str, key: str) -> str: # Agent reads, then forgets, then (bug) answers from the old read. mem.read(scope, key) mem.forget(scope, mode="hard") return mem.emit(scope, key, claimed_value="card_last4=4242") if __name__ == "__main__": m = AgentMemoryView(store={"billing_prefs": {"card_last4": "4242"}}) try: run_turn(m, "billing_prefs", "card_last4") except GhostMemoryError as e: print(f"BLOCKED: {e}") ```