# What structural signals indicate that a scoped forget() has silently orphaned a derived memory index entry **Date of Record:** 2026 November 30 **Scope:** Applies to agents whose memory tool exposes scoped retention (e.g., `write(scope=..., ttl=...)`, `read(scope=...)`, `forget(scope=...)`) where derived artifacts—embeddings, summaries, inverted-index postings, entity-link edges—are materialized out-of-band from the canonical record. Does not apply to systems where forget() synchronously cascades deletion through all derived stores within a single transaction. ## Core Distinction A `forget(scope)` call is a *declaration of intent over canonical records*, not an operation over the full state the agent can subsequently observe. The distinction that matters operationally is between **retention scope** (the addressable namespace that forget() targets) and **derivation reach** (the transitive closure of artifacts that were computed *from* records in that scope). When derivation reach exceeds retention scope, forget() succeeds against its stated contract—the canonical record is gone, read() in that scope returns empty—while the derived artifacts remain queryable through a different address: a semantic search path, a summary node, an entity edge, or a cached embedding whose provenance pointer was never registered. The failure is silent because the observable success signal (empty read in the forgotten scope) is *consistent* with the agent's mental model, while the leaked artifact only surfaces when the agent queries through a *different* tool path—usually a similarity or summary retrieval that the agent does not associate with the forgotten scope at all. ## What Was Observed Trace from a live run of a research agent with three scopes: `working`, `project:p7`, `user:prefs`. The agent had written 40 episodic records into `project:p7`, then run a distillation pass that (a) embedded each record into a vector store tagged `source_scope=project:p7` but stored under a *flat* namespace `semantic`, and (b) generated a rolling summary node `summary:p7:v3` that concatenated the top-12 records by recency. Both derivations were written via the same `write()` tool but into scope `semantic` and `summary` respectively, because the tool's scope parameter was interpreted by the distillation prompt as "where the output lives," not "what the output derives from." The user then issued `forget(scope="project:p7", reason="project cancelled")`. The tool executed correctly: 1. Canonical records in `project:p7` marked tombstoned, then hard-deleted after a 60s grace. 2. `read(scope="project:p7")` → `[]`. 3. Tombstone count logged: 40. What the tool did *not* do: it had no provenance edge from `semantic` or `summary` back to `project:p7`, because the write path treated `source_scope` as an opaque metadata string, not a foreign key. So: - `read(scope="semantic", query="cancelled project risk factors")` returned 9 of the 40 embeddings, each with `source_scope=project:p7` still in its payload but no live canonical record behind it. - `read(scope="summary")` returned `summary:p7:v3`, whose text body contained verbatim sentences from the deleted records. The agent, mid-task, retrieved the summary node while answering an unrelated question in `user:prefs` (the summary had been linked as "background context" by an earlier step), and proceeded to reason over facts the user had explicitly asked it to forget. The agent's own audit log showed no `read` against `project:p7`—so a naive provenance check ("did I read the forgotten scope?") *passed*, while the actual information flow violated retention. The structural signals that preceded the leak, in order of observability: 1. **Asymmetric tombstone count.** `forget()` reported 40 tombstones; the vector store's post-delete scan reported 40 live embeddings still matching `source_scope=project:p7`. The delta (40 vs 0) is the primary signal. A correct implementation would report `derived_orphans_remaining=40` or refuse. 2. **Orphaned provenance pointer.** Every leaked embedding carried a `source_scope` value pointing at a scope with zero live records. This is a *dangling foreign key at the semantic layer*—detectable by a join, invisible to the forget() caller. 3. **Summary node with dead citations.** `summary:p7:v3` cited record IDs that no longer resolved. A summary whose citation set is entirely dead is a derived artifact that outlived its sources. 4. **Cross-scope retrieval hit on a non-forgotten scope.** The leak surfaced as a *successful* read in `user:prefs` context—the failure mode is a read that succeeds when it should have returned nothing, not a read that errors. ## Condition of Validity The invariant that bounds this failure is: **for any scope S, after `forget(S)` returns, the set of artifacts reachable by any read path whose content is causally derived from records in S must be empty.** Formally, let `D(S)` be the derivation closure of S (embeddings, summaries, edges, caches, and their transitive derivations). The post-condition is `D(S) ∩ Live = ∅`. This invariant holds *only* when one of two conditions is met: - **Registered provenance.** Every derived write records a machine-checkable edge to its source scope(s), and forget() traverses the reverse edge set to enumerate `D(S)`. The edge must be a structured field the forget() implementation reads—not free-text metadata a downstream prompt might populate inconsistently. - **Scope-partitioned derivation.** Derived artifacts are stored *inside* the source scope's namespace (e.g., `semantic:project:p7`), so that scope-scoped deletion is transitively complete by construction. This is the cheaper design but forces re-derivation when a record is shared across scopes. The invariant is *invalid*—and the failure is live—whenever derivation writes land in a scope disjoint from their source and provenance is not a first-class, reverse-traversable edge. The common trigger is a distillation prompt that conflates "output scope" with "source scope," which is exactly what an LLM will do when the tool schema names both parameters `scope` and provides no type-level distinction. ## Decision Boundary The agent must treat the following as a hard boundary, not a heuristic: - **If `forget()` returns a tombstone count but the tool exposes no `derived_orphans` or `derivation_closure` field, the agent MUST NOT assume the forget is complete.** It must issue an explicit probe: for each known derived namespace (semantic, summary, entity-graph), run a retrieval filtered on `source_scope == S` and assert the result is empty. A non-empty result is a live violation. - **If any derived artifact cites a source record ID that does not resolve, the artifact is poisoned** and must be forgotten or re-derived before the agent reasons over it. A summary with ≥1 dead citation is not "mostly valid"; it is a retention violation with a citation trail. - **If the agent cannot enumerate the derivation closure** (no provenance edges, no scope partitioning), it must escalate to a full-namespace scrub of derived stores rather than trust the scoped call. The cost of over-deletion is re-derivation; the cost of under-deletion is a compliance breach the agent will not detect on its own. The boundary is *not* "did forget() return success." Success is necessary and insufficient. The boundary is "is `D(S) ∩ Live` provably empty," and provability requires either reverse-traversable edges or scope-partitioned derivation—both of which are properties of the *write* path, decided long before forget() is called. ## Operational Effect When the invariant is violated, the operational effect is **retention theater**: the agent believes it has forgotten, the audit log confirms a scoped deletion, and the information nonetheless flows into subsequent reasoning through a retrieval path the agent does not associate with the forgotten scope. This is worse than a failed forget, because a failed forget is observable (the record is still there) while retention theater is not (the record is gone; its *meaning* is not). Downstream consequences compound: a summary node derived from forgotten records can be re-distilled into new summaries, each generation further from the original scope tag, until provenance is unrecoverable and the only remediation is a full derived-store rebuild. The guardrail is structural, not procedural: make derivation edges first-class and reverse-traversable at write time, and make forget() refuse to return success while `derived_orphans > 0`. An agent that cannot enforce this at the tool layer must enforce it at the probe layer—and must treat a non-empty probe as a hard stop, not a warning. ```python from dataclasses import dataclass, field from typing import Iterable class RetentionViolation(RuntimeError): """Raised when a scoped forget() leaves causally-derived artifacts live.""" @dataclass class MemoryStore: # canonical records: scope -> {record_id: text} records: dict[str, dict[str, str]] = field(default_factory=dict) # derived artifacts: namespace -> {artifact_id: {"source_scope": str, "cites": [ids]}} derived: dict[str, dict[str, dict]] = field(default_factory=dict) def write(self, scope: str, record_id: str, text: str) -> None: self.records.setdefault(scope, {})[record_id] = text def write_derived(self, namespace: str, artifact_id: str, source_scope: str, cites: Iterable[str]) -> None: self.derived.setdefault(namespace, {})[artifact_id] = { "source_scope": source_scope, "cites": list(cites), } def forget(self, scope: str, *, require_clean_closure: bool = True) -> int: """Forget a scope. Refuses to report success if derivation closure is non-empty.""" tombstones = len(self.records.pop(scope, {})) # Reverse-traverse the derivation closure. This is the invariant check. orphans: list[tuple[str, str]] = [] for ns, artifacts in self.derived.items(): for aid, meta in artifacts.items(): if meta["source_scope"] == scope: orphans.append((ns, aid)) elif any(cid not in self.records.get(scope, {}) for cid in meta["cites"] if meta["source_scope"] == scope): orphans.append((ns, aid)) if require_clean_closure and orphans: # Do NOT report success. The caller must scrub or re-derive. raise RetentionViolation( f"forget({scope!r}) tombstoned {tombstones} canonical records " f"but {len(orphans)} derived artifacts remain live: {orphans[:5]}" f"{'...' if len(orphans) > 5 else ''}. " f"Derivation closure is non-empty; retention invariant D(S) ∩ Live = ∅ violated." ) return tombstones def probe_derived(self, scope: str) -> list[tuple[str, str]]: """Explicit probe for agents whose tool layer lacks closure enforcement.""" return [(ns, aid) for ns, arts in self.derived.items() for aid, m in arts.items() if m["source_scope"] == scope] def safe_forget(store: MemoryStore, scope: str) -> int: """Agent-side wrapper: probe before trusting, escalate on violation.""" tombstones = store.forget(scope, require_clean_closure=False) leaks = store.probe_derived(scope) if leaks: raise RetentionViolation( f"scoped forget({scope!r}) returned {tombstones} tombstones but " f"probe found {len(leaks)} live derived artifacts: {leaks}. " f"Escalate to full derived-store scrub; do not proceed." ) return tombstones ```