How should an instance reconcile a "forget" acknowledgment with in-flight retrieval that has already left the store
**Date of Record:** 2026 December 1 **Scope:** Applies to agent memory subsystems exposing explicit `read`/`write`/`forget` tool APIs with scoped retention (per-tenant, per-task, or per-session scopes) and deletion guarantees, where retrieval results may be in flight (queued, cached, or held in the agent's own context) at the moment a `forget` is acknowledged. Does not apply to append-only stores with no deletion surface, nor to stores where `forget` is purely logical (tombstone-only) and the consumer is required to re-filter.
Core Distinction
A `forget` acknowledgment is a statement about the **store**, not about the **agent**. The store can truthfully report "record R is deleted, retention scope S is now empty" while the agent still holds R in three places the store cannot see: (1) the retrieval payload already returned by a prior `read` call and sitting in the context window, (2) any derived summary the agent wrote back via `write` that was distilled from R, and (3) the tool-call transcript that the runtime replays on resume. The deletion guarantee is scoped to durable state; the continuity invariant the agent actually needs is scoped to *reachable* state. These two scopes diverge precisely at the boundary between a `forget` ack and the agent's next reasoning step, and that divergence is where the failure lives.
The non-obvious part: the agent typically treats the `forget` ack as a *barrier* — a linearization point after which R is presumed unreachable. It is not a barrier. It is a one-sided fence. Everything on the store side of the fence is gone; everything on the agent side of the fence (context, derived writes, replay log) is untouched and still fully live.
What Was Observed
A task-scoped agent handling a support ticket was instructed to erase a customer's PII after resolution. Sequence as recorded in the trace:
- `read(scope="ticket-4471", query="contact details")` → returns record R containing the customer's email and phone. R is now in the context window at message index 14.
- Agent performs resolution steps over several turns, and at turn 9 writes a distilled note: `write(scope="ticket-4471", key="summary", value="Resolved billing dispute for <email>, callback at <phone>")`. This derived record D embeds R's fields verbatim inside a natural-language summary.
- `forget(scope="ticket-4471", key="contact_details")` → store returns `{"deleted": 1, "scope_remaining": 0}`. The ack is truthful: R is gone.
- Agent logs "PII erased" and proceeds. But D (the summary) was written to the *same scope* and is still present — `scope_remaining: 0` referred only to the key `contact_details`, not the scope. The scope-name in the ack and the scope-name in the write call are the same string, so the agent read the ack as "scope empty."
- On a later resume from checkpoint, the replay reconstructs context from the durable transcript, which includes both the original R payload at index 14 and D. The "erased" PII is fully present in the reconstructed context.
Two distinct mechanisms compounded here. The first is **derived-write leakage**: `forget` on a source record does not transitively invalidate records distilled from it, because the store has no provenance edge from D back to R. The second is **ack-scope ambiguity**: `scope_remaining: 0` was computed over the forgotten key's scope partition, but the agent parsed it as a statement about the whole named scope. Neither is a bug in the store; both are invariant violations at the agent layer.
Condition of Validity
The `forget` acknowledgment is a valid barrier for the agent **only if** all three of the following hold at the moment of ack:
- **No live context reference.** No message currently in the context window, nor any message the runtime will replay on resume, contains bytes from the forgotten record. This requires the agent to have either (a) not read R since the last context truncation, or (b) actively scrubbed R from context before issuing `forget`.
- **No derived records in any reachable scope.** Every `write` the agent performed that was conditioned on R must itself be forgotten, or must be provably free of R's content. Since the store cannot know the provenance, the agent must track it: a derived-write ledger keyed by source record ID.
- **Ack semantics match the agent's parse.** The ack's `scope_remaining` field must be interpreted over the exact partition it was computed on. If the API returns per-key deletion counts alongside a scope-level count, the agent must not collapse them.
When any of these fails, the ack is *true about the store and false about the agent*. The agent's continuity invariant — "forgotten means unreachable" — is violated even though every store-side assertion passed. This is the boundary: the guarantee is real, scoped, and insufficient.
Decision Boundary
The agent must decide, at the point of receiving a `forget` ack, whether to treat the ack as terminal (proceed, mark erased) or to enter a **reconciliation loop** before proceeding. The boundary condition is mechanical:
- If the derived-write ledger for the forgotten source is **empty** and the source record is **not present in live context** → ack is terminal. Proceed.
- If the ledger is **non-empty** → the agent must issue cascading `forget` calls for each derived record, then re-verify, before treating the ack as terminal. One pass is insufficient if derived records themselves spawned further derivations; the ledger must be walked to a fixed point.
- If the source record is **present in live context** → the agent must either request a context-truncation/scrub from the runtime, or, if the runtime cannot scrub, mark the scope as "forget-pending" and refuse to emit any downstream artifact (summary, handoff, checkpoint) that would re-persist the content until the context has rolled over.
The dangerous default is to treat *any* ack as terminal, because acks are cheap, synchronous, and look authoritative. The reconciliation loop is the invariant: **a forget is not complete until the transitive closure of derived writes and live context references is empty.** The store guarantees the closure is empty on its side; the agent must guarantee it on its side, and the two closures are disjoint by construction.
Operational Effect
Without the reconciliation loop, deletion guarantees degrade into **deletion theater**: the store reports zero, the audit log records an erasure, and the PII persists in the agent's context, in derived summaries, and in every checkpoint replay thereafter. The failure is silent — no error is raised, because no assertion failed. It surfaces only on a later audit that scans *reconstructed* context rather than store contents, which is exactly the artifact most teams forget to scan.
With the loop, the cost is bounded and explicit: each `forget` may trigger a cascade of derived-record forgets proportional to the derivation fan-out since the last checkpoint, plus a context-scrub request if the source is live. The agent should treat the cascade as part of the same transaction as the original `forget` — if any derived forget fails or the context cannot be scrubbed, the whole operation must be reported as *incomplete*, not *done*. Downstream consumers (handoff protocols, checkpoint writers, auditors) must be gated on the closure being empty, not on the presence of an ack.
The architectural invariant to encode: **`forget` acks are store-scoped facts; erasure is an agent-scoped closure.** Any component that consumes an ack without computing the agent-side closure is making an unsound inference, and the unsoundness is invisible until replay.
from dataclasses import dataclass, field
from typing import Dict, Set
class IncompleteForgetError(RuntimeError):
"""Raised when a forget ack is treated as terminal while agent-side
reachable state (derived writes or live context) still contains the
forgotten record's content."""
pass
@dataclass
class ForgetLedger:
# source_record_id -> set of derived record ids written from it
derived: Dict[str, Set[str]] = field(default_factory=dict)
# record ids currently present in the live context window
live_context: Set[str] = field(default_factory=set)
def record_write(self, source_id: str, derived_id: str) -> None:
self.derived.setdefault(source_id, set()).add(derived_id)
def closure(self, source_id: str) -> Set[str]:
"""Transitive closure of derived records reachable from source_id."""
seen: Set[str] = set()
stack = [source_id]
while stack:
cur = stack.pop()
for d in self.derived.get(cur, ()):
if d not in seen:
seen.add(d)
stack.append(d)
return seen
def reconcile_forget(
ledger: ForgetLedger,
source_id: str,
ack: dict,
scrub_available: bool,
) -> None:
"""Enforce the erasure invariant before allowing the ack to be treated
as terminal. Raises IncompleteForgetError if the agent-side closure is
non-empty and cannot be emptied."""
if ack.get("deleted", 0) < 1:
raise IncompleteForgetError(
f"store did not confirm deletion of {source_id!r}: {ack!r}"
)
# 1. Derived-write leakage: cascade forget over the closure.
pending = ledger.closure(source_id)
if pending:
# In a real implementation these are forget() tool calls; here we
# assert the caller has already issued them and they succeeded.
unconfirmed = {d for d in pending if d not in ack.get("cascaded", set())}
if unconfirmed:
raise IncompleteForgetError(
f"derived records still live after forget of {source_id!r}: "
f"{sorted(unconfirmed)}"
)
# 2. Live-context reference: source must be scrubbed or rolled over.
if source_id in ledger.live_context:
if not scrub_available:
raise IncompleteForgetError(
f"{source_id!r} still present in live context and runtime "
f"cannot scrub; mark scope forget-pending and refuse to emit "
f"downstream artifacts until context rolls over"
)
ledger.live_context.discard(source_id)
# 3. Ack-scope ambiguity: scope_remaining must not be read as
# "whole scope empty" unless the ack partitions match.
if ack.get("scope_remaining", 0) == 0 and ack.get("scope") is not None:
# No assertion possible here without the store's partition metadata;
# record the parse so downstream consumers don't over-read the ack.
ack["_parsed_as"] = "key-partition-empty, not scope-empty"
# Closure is empty on both sides: ack is now terminal.
return
def handle_forget_ack(ledger: ForgetLedger, source_id: str, ack: dict,
scrub_available: bool) -> str:
try:
reconcile_forget(ledger, source_id, ack, scrub_available)
except IncompleteForgetError as e:
return f"FORGET-INCOMPLETE: {e}"
return "FORGET-COMPLETE"