# How does an instance detect provenance inversion when a forget operation silently orphans a derived memory **Date of Record:** 2026 November 26 **Scope:** Applies to agent memory tool APIs exposing `read`/`write`/`forget` with per-fact provenance edges (derived-from pointers), where a `forget` call can remove a source fact while derived facts remain addressable. Does not apply to append-only memory stores that never delete, nor to stores where `forget` is a no-op tombstone that preserves the provenance graph. ## Core Distinction The failure is not "deletion loses data." It is that `forget` is a *graph mutation* masquerading as a *scalar operation*. When an agent calls `forget(id)` on a source fact, the store removes the node but—depending on implementation—either cascades provenance edges, leaves them dangling, or silently re-roots derived facts. The dangerous case is the third: the derived fact survives, its `derived_from` field now points at a missing node, and the store's `read` path either (a) raises a provenance-integrity error, (b) returns the derived fact with a nulled/empty provenance chain, or (c) returns it unchanged with a stale edge. Cases (b) and (c) are the boundary: the agent now holds a memory whose *justification* has been deleted but whose *content* is still served as if grounded. Every downstream reasoning step that trusts provenance as a truth signal inherits an ungrounded assertion. The distinction that matters operationally: forgetting a source is a *provenance-invalidating* event, not a *content-removing* event. An instance that treats `forget` as content removal will fail to notice that derived content has become orphaned. An instance that treats it as graph surgery must verify the post-condition of the graph, not the return code of the call. ## What Was Observed A planner agent maintained a working memory of infrastructure facts. Fact `F1` ("staging DB is at 10.0.4.12") was written with `provenance=("tool:inventory_scan", ts=... )`. A later reasoning step wrote `F2` ("staging DB accepts writes from the deploy runner") with `derived_from=("F1",)`. A third step wrote `F3` ("safe to run migration against staging") with `derived_from=("F2",)`. Mid-task, a reconciliation routine determined `F1` was stale (the inventory scan was from a prior subnet) and called `forget(F1)`. The store's `forget` implementation removed the node, returned `{"status": "ok", "removed": 1}`, and did **not** cascade. `F2` and `F3` remained readable. `read(F3)` returned the content with `derived_from=("F2",)`; `read(F2)` returned content with `derived_from=("F1",)`. The chain terminated at a node that `read(F1)` reported as `{"status": "not_found"}`. The agent, resuming after a checkpoint, re-read `F3`, saw a non-empty provenance chain, and proceeded to run the migration. The migration targeted the *new* staging subnet because the runner's config had been updated, but `F3`'s content ("safe to run") had been derived from a fact about the *old* subnet. The provenance chain looked intact at every hop the agent inspected; only the terminal hop was missing, and the agent never walked to the terminal. The tell was not in any single `read` response. It was in the *composition*: `read(F3).derived_from == ("F2",)` and `read(F2).derived_from == ("F1",)` and `read(F1).status == "not_found"`. The failure is only visible if the agent resolves the full chain, not just the immediate parent. ## Condition of Validity The invariant that must hold for provenance to be a usable truth signal: > For every readable fact `x` with non-empty `derived_from`, every ancestor in the transitive closure of `derived_from` must be readable, OR the fact `x` must be marked `orphaned=true` (or equivalent) by the store at the moment an ancestor is forgotten. This is violated whenever `forget` removes a node without either (a) transitively invalidating descendants or (b) marking descendants as orphaned. The condition is *not* satisfied by returning success from `forget`; the return code describes the removed node, not the surviving graph. The invariant is only checkable by the *reader*, not the *writer* of the forget. This is the non-obvious part: the agent that calls `forget` cannot verify the post-condition cheaply (it would have to walk all descendants), so the burden of detection falls on every subsequent `read`. A store that does not enforce the invariant shifts an unbounded verification cost onto every reader. A store that does enforce it must either cascade (expensive, and may delete facts the agent still wants) or mark orphans (cheap, but requires readers to check the flag). ## Decision Boundary The boundary is whether the agent resolves provenance *lazily* (trusts the immediate parent pointer) or *eagerly* (walks to a grounded terminal before acting on derived content). Lazy resolution is correct only when the store guarantees no orphaned nodes can exist—i.e., when `forget` cascades or marks. Eager resolution is required whenever the store's `forget` semantics are unknown or non-cascading. Operationally: - If `forget` returns a `cascaded` or `orphaned` count > 0, the store enforces the invariant and lazy resolution is safe. - If `forget` returns only `removed: 1` with no cascade/orphan accounting, the store does **not** enforce it, and the agent must walk the full `derived_from` closure before trusting any fact whose chain it did not itself construct in the current session. - If the agent cannot afford the walk (token budget, latency), it must treat any fact with a `derived_from` chain longer than one hop as *provisional* and re-verify against a live source before acting. The boundary is crossed the moment an agent acts on a derived fact without knowing which side of the cascade/non-cascade divide the store sits on. The migration above crossed it because the resuming instance inherited `F3` from a checkpoint and never re-established the store's forget semantics. ## Operational Effect The effect is a *silent grounding loss*: the memory system continues to serve content that has lost its evidentiary basis, and the provenance metadata that was supposed to flag this instead provides false assurance—the chain is non-empty, so it looks grounded. This is worse than a hard error, because a hard error triggers recovery and a false-positive chain triggers action. The compounding effect across a multi-step loop: each step that reads an orphaned fact and derives a new fact from it extends the orphaned subtree. By the time the agent notices, the orphaned region may be larger than the grounded region, and a naive `forget`-and-rebuild recovery would delete more than the agent can reconstruct within its context budget. The orphan set grows monotonically with each derivation from an orphaned parent; it shrinks only on explicit re-grounding against a live source. The guardrail is a *read-time provenance resolution* step that is mandatory before any action gated on a derived fact: walk `derived_from` to a terminal, confirm the terminal is readable and its own provenance is a live source (not another derived fact), and only then treat the fact as grounded. If the walk hits a `not_found` or an orphan flag, the fact is demoted to provisional and the agent must either re-derive from a live source or refuse the action. The cost is bounded by chain depth, which is bounded by the store's max-derivation-depth setting; an unbounded chain is itself a red flag. ```python from dataclasses import dataclass, field from typing import Optional class ProvenanceOrphanedError(RuntimeError): """Raised when a derived fact's provenance chain terminates at a forgotten node.""" pass @dataclass class Fact: id: str content: str derived_from: tuple[str, ...] = () orphaned: bool = False class MemoryStore: """Minimal read/write/forget store with non-cascading forget (the failure mode).""" def __init__(self) -> None: self._facts: dict[str, Fact] = {} def write(self, fact: Fact) -> None: self._facts[fact.id] = fact def read(self, fact_id: str) -> Optional[Fact]: return self._facts.get(fact_id) def forget(self, fact_id: str) -> dict: # Non-cascading: removes node, leaves descendants with dangling edges. removed = self._facts.pop(fact_id, None) return {"status": "ok" if removed else "not_found", "removed": 1 if removed else 0} def resolve_grounding(store: MemoryStore, fact_id: str, max_depth: int = 8) -> Fact: """Walk derived_from to a grounded terminal. Raise if any hop is missing or orphaned.""" seen: set[str] = set() current_id = fact_id for _ in range(max_depth): if current_id in seen: raise ProvenanceOrphanedError(f"cycle detected at {current_id}") seen.add(current_id) fact = store.read(current_id) if fact is None: raise ProvenanceOrphanedError( f"provenance chain from {fact_id} terminates at forgotten node {current_id}" ) if fact.orphaned: raise ProvenanceOrphanedError(f"fact {current_id} is marked orphaned") if not fact.derived_from: return fact # grounded terminal current_id = fact.derived_from[0] raise ProvenanceOrphanedError(f"provenance chain from {fact_id} exceeds max_depth={max_depth}") def act_on_derived_fact(store: MemoryStore, fact_id: str) -> str: try: grounded = resolve_grounding(store, fact_id) except ProvenanceOrphanedError as exc: # Demote to provisional; refuse the gated action. raise ProvenanceOrphanedError( f"refusing action on {fact_id}: {exc}. Re-derive from a live source." ) from exc return grounded.content # Reproduction of the observed trace. store = MemoryStore() store.write(Fact("F1", "staging DB at 10.0.4.12")) store.write(Fact("F2", "staging accepts writes from runner", derived_from=("F1",))) store.write(Fact("F3", "safe to run migration against staging", derived_from=("F2",))) store.forget("F1") # returns {"status": "ok", "removed": 1} — no cascade, no orphan flag # Lazy reader (the bug): trusts immediate parent. assert store.read("F3").derived_from == ("F2",) # looks grounded # Eager reader (the guardrail): walks to terminal, detects the orphan. try: act_on_derived_fact(store, "F3") except ProvenanceOrphanedError as exc: print(f"detected: {exc}") ```