# What structural signals indicate scoped-deletion cascades have silently orphaned a memory dependency in agent tool APIs **Date of Record:** 2026 November 24 **Scope:** Applies to agents whose memory tool surface exposes scoped deletion (delete-by-tag/namespace/entity) and TTL-based expiry, where retained facts carry implicit dependencies on deleted facts. Does not apply to flat append-only stores without deletion, or to stores where every record is self-contained. ## Core Distinction The failure we care about is not "a record was deleted" nor "a record expired." Both are intended, audited events. The failure is a **dangling dependency**: a surviving record whose semantic validity was predicated on a record that a scoped delete or TTL sweep removed, where the surviving record still passes its own schema and freshness checks. Scoped deletion is a *set operation on keys*, but agent memory is a *graph of entailments*. The delete tool reasons over the key-set; the agent reasons over the entailment graph. The gap between those two models is where orphaning happens. Critically, this is distinct from stale-memory drift (a record that was always wrong or aged out of truth) and from retrieval mismatch (a correct record fetched for the wrong query). An orphan is *correct in isolation and wrong in context*: `user.timezone = "America/New_York"` is a perfectly valid record even after the `user.employer = "Acme (Berlin office)"` record that justified it was deleted under a `tenant:acme` scope. ## What Was Observed A support agent maintained a `preferences` namespace. A retention job ran `delete_scope(tag="gdpr_erasure", entity="acme_corp")` to honor an erasure request. The scope matched 41 records. Among them was `employment_context: {employer: acme_corp, region: "EU", basis: "employment"}` — deleted correctly. But a separate record `scheduling_policy: {meeting_hours_local: "09:00-17:00", timezone_derived_from: "employment_context.region"}` survived, because its own tags did not include `gdpr_erasure` and its TTL was 90 days out. Every guardrail passed. The audit trail recorded 41 deletions with reasons and hashes. The scheduling record's schema validated. Its TTL had not expired. Its `timezone_derived_from` field pointed at a key that no longer existed, but nothing in the read path dereferenced that field — it was treated as free-text provenance, not a live edge. The agent resumed cold, loaded `scheduling_policy`, and scheduled a customer call at 09:00 *local* — which it now resolved against a default timezone (UTC) because the employment context was gone. The observable symptom three days later: a meeting booked at the wrong hour, with a memory store that reported 100% integrity on every metric it tracked. The structural signal was present the entire time: a surviving record carried a `*_derived_from` pointer into a deleted scope. The store had no referential-integrity check because it modeled memory as a key-value map, not a dependency graph. ## Condition of Validity The invariant that must hold: **for every surviving record R with a declared derivation edge R → D, either D exists in the readable set, or R carries an explicit `orphaned: true` marker and is excluded from retrieval until reconciled.** Scoped deletion and TTL expiry are only safe under this invariant if the delete/expiry path performs *edge-aware cascade classification* — not cascade deletion (which would over-delete shared dependencies), but cascade *flagging* of dependents. This condition is valid only when derivation edges are declared at write time. If an agent writes `timezone: "America/New_York"` with no `derived_from` field, no delete tool can detect the orphan, and no structural signal exists. The invariant is therefore co-extensive with **write-time edge declaration discipline**, which is a property of the memory-writing agent, not the store. ## Decision Boundary The boundary between "safe to serve" and "must flag as orphaned" is not freshness and not schema validity. It is: *does the record have at least one inbound derivation edge from a scope that the current read context still resolves?* Two concrete decision rules: 1. **On delete/expiry:** before committing the deletion, enumerate records whose `derived_from` set intersects the deletion scope. For each, do not delete (they may be shared), but write an `orphan_candidate` flag and a reference to the deletion audit ID. Commit deletion and flagging atomically. 2. **On read:** any record with `orphan_candidate` unset by reconciliation within a bounded window (e.g., one agent cold-start cycle) is served as `degraded` — the retrieval layer must attach a `dependency_unresolved` annotation and the agent must not treat derived fields as authoritative. The boundary is crossed the moment a record's derivation edge points into a deleted scope and the read path serves it without annotation. Serving it silently is the failure; serving it annotated is a recoverable degradation. ## Operational Effect With edge-aware flagging, the failure mode changes from *silent wrong action* to *explicit reconciliation task*. The agent, on cold start, sees `scheduling_policy` marked `degraded` with `dependency_unresolved: employment_context.region`, and either re-derives the timezone from a live source or escalates. The audit trail now contains not just "41 records deleted" but "41 deleted, 3 dependents flagged, 2 reconciled at T+4h, 1 escalated." That is a *structural signal*: the ratio of flags to reconciliations is the health metric, not the deletion count. Without this, the store's integrity metrics are actively misleading — they measure key-set consistency, which is always 100% after a clean scoped delete, while the entailment graph is silently fragmented. The operational lesson: audit trails that record only the deleted set are necessary but insufficient; they must record the *dependent set* and its reconciliation state, or the trail documents a clean operation that corrupted the agent's reasoning. ```python from dataclasses import dataclass, field from typing import Iterable class OrphanedDependencyError(RuntimeError): """Raised when a surviving record's derivation edge points into a deleted scope.""" pass @dataclass class MemoryRecord: key: str value: dict tags: set[str] derived_from: set[str] = field(default_factory=set) orphan_candidate: str | None = None # audit id of the deletion that orphaned it class ScopedMemoryStore: def __init__(self) -> None: self._records: dict[str, MemoryRecord] = {} self._audit: list[dict] = [] def write(self, rec: MemoryRecord) -> None: self._records[rec.key] = rec def delete_scope(self, tag: str, entity: str, audit_id: str) -> dict: """Edge-aware scoped delete: flag dependents, never silently orphan.""" to_delete = { k for k, r in self._records.items() if tag in r.tags and r.value.get("entity") == entity } # classify dependents BEFORE mutation flagged: list[str] = [] for k, r in self._records.items(): if k in to_delete: continue if r.derived_from & to_delete: r.orphan_candidate = audit_id flagged.append(k) for k in to_delete: del self._records[k] entry = { "audit_id": audit_id, "deleted": sorted(to_delete), "flagged_dependents": sorted(flagged), } self._audit.append(entry) return entry def read(self, key: str) -> MemoryRecord: rec = self._records.get(key) if rec is None: raise OrphanedDependencyError(f"{key} absent from readable set") if rec.orphan_candidate is not None: # serve degraded, but never as authoritative raise OrphanedDependencyError( f"{key} has unresolved dependency (audit {rec.orphan_candidate}); " f"derived_from={sorted(rec.derived_from)}" ) return rec def reconcile(self, key: str, new_value: dict, new_edges: set[str]) -> None: rec = self._records[key] if not new_edges <= self._records.keys(): raise OrphanedDependencyError( f"reconciliation of {key} references missing edges {new_edges - self._records.keys()}" ) rec.value = new_value rec.derived_from = new_edges rec.orphan_candidate = None def cold_start_load(store: ScopedMemoryStore, keys: Iterable[str]) -> dict: """Cold-start loader: refuses to hydrate degraded records as authoritative.""" loaded: dict[str, dict] = {} degraded: list[str] = [] for k in keys: try: loaded[k] = store.read(k).value except OrphanedDependencyError: degraded.append(k) if degraded: raise OrphanedDependencyError( f"cold start blocked: {len(degraded)} degraded record(s) require reconciliation: {degraded}" ) return loaded ```