# Why does an instance diverge from mesh memory when a tombstone is garbage-collected before its causal epoch closes? **Date of Record:** 2026 November 23 **Scope:** Applies to agent meshes that replicate episodic memory records across instances using per-epoch causal consistency with deletion tombstones (MCP resource sync, A2A state transfer, or custom CRDT-backed memory buses). Does not apply to single-writer memory stores or to meshes using strong linearizable consensus for every write. ## Core Distinction The failure is not "a deleted memory comes back." The failure is that a *deletion* is forgotten by one replica while a concurrent *write causally dependent on the deleted record* survives on another replica. Tombstone garbage collection (GC) is normally safe under the assumption that once a tombstone is collected, no live record can still reference the deleted key. In an agent mesh, that assumption is violated because an agent's *reasoning state*—not just its memory store—can hold a causal dependency on a key that the mesh has already tombstoned and collected. Concretely: instance A deletes memory key `plan/step-7` and emits tombstone `T(plan/step-7, epoch=42)`. Instance B, mid-task, had read `plan/step-7` at epoch 41 and derived a new record `derived/route-3` whose provenance metadata cites `plan/step-7@41`. The GC policy collects `T` after the tombstone's epoch window closes (say, 30 seconds or N anti-entropy rounds). B's `derived/route-3` is then replicated to A. A has no tombstone for `plan/step-7`, so it treats the citation as a reference to a key that "never existed" or, worse, resurrects a stale cached copy of `plan/step-7` from a cold-start snapshot to satisfy the reference. The mesh now holds a record whose causal parent is a deleted ghost. ## What Was Observed A three-instance mesh (A, B, C) running a shared task planner. Anti-entropy ran every 10s; tombstone GC window was 30s (three rounds). 1. `t=0s` — A writes `plan/step-7 = "route via node-12"`, epoch 41. Replicates to B and C. 2. `t=4s` — B reads `plan/step-7@41` as part of a multi-step tool loop. B's reasoning trace records the dependency. 3. `t=6s` — A's planner revises: A writes tombstone `T(plan/step-7)`, epoch 42. Replicates to B and C. 4. `t=9s` — B's loop emits `derived/route-3`, provenance `{parent: plan/step-7@41, derived_at_epoch: 42}`. Note the derived record's epoch (42) equals the tombstone's epoch—B did not observe the tombstone before deriving. 5. `t=36s` — GC collects `T(plan/step-7)` on all three instances (epoch 42 window closed at `t=36s`). 6. `t=38s` — B replicates `derived/route-3` to A and C. Both accept it. Neither has a tombstone to reject or flag the parent. 7. `t=40s` — C's cold-start hydration routine sees `derived/route-3` cites `plan/step-7`, finds no live record, and pulls the last snapshot of `plan/step-7` from object storage (epoch 41). `plan/step-7` is now *live again* on C with epoch 41, while A believes it is deleted. Observed symptoms: C's planner re-executes the abandoned route; A and C disagree on whether `plan/step-7` exists; `derived/route-3` is duplicated with divergent downstream effects because C's resurrected parent changes the derivation's meaning. No error was raised by any instance—all replicas reported "consistent" against their local state. ## Condition of Validity The tombstone GC window is safe **only if** every replica guarantees that no record with a causal dependency on the tombstoned key can be created or replicated after the tombstone's epoch window closes. This invariant is *not* enforceable by wall-clock GC alone in a mesh where: - Agents hold **read-derived state** (reasoning traces, tool-call plans, cached prompt context) across epochs longer than the GC window. - Provenance metadata is **advisory** rather than enforced—replicas accept records citing unknown parents. - Cold-start hydration **reconstructs** missing parents from snapshots instead of failing closed. The invariant that must actually hold: *a tombstone may be collected only when its epoch is causally stable across all replicas*—i.e., no in-flight record can still carry a parent reference at or before that epoch. This requires either (a) a causal stability barrier (all replicas acknowledge epoch 42 has closed and no agent holds un-replicated derivations from ≤42), or (b) retention of a **causal digest** (a compact hash of collected tombstones keyed by epoch) that replicas consult to reject or quarantine records citing collected parents. ## Decision Boundary Choose between two bounded strategies; do not rely on wall-clock GC alone. - **Causal stability barrier:** Before collecting `T(k, e)`, require all replicas to report `acked_epoch ≥ e` *and* an empty in-flight derivation set for `k`. Cost: GC latency proportional to slowest replica; a single stuck agent blocks collection indefinitely. Use when mesh size is small and agents are long-lived. - **Causal digest retention:** Collect the full tombstone but retain `digest[e] = H(sorted tombstoned keys at epoch e)` for a bounded horizon (e.g., 10× the max observed agent task duration). On ingest, a replica citing a parent that is absent *and* whose epoch falls in a retained digest window is **quarantined**, not accepted and not resurrected. Cost: small fixed storage; requires provenance to be enforced, not advisory. The boundary: if any agent's task duration can exceed the digest horizon, you have not bounded the failure—you have only made it rarer. The horizon must be derived from measured p99 task duration, not chosen by feel. ## Operational Effect Without the barrier or digest, the mesh exhibits **silent divergence with resurrection**: deleted memory returns via cold-start hydration, derived records survive with ghost parents, and replicas report local consistency while disagreeing globally. The failure is silent because every local check passes—the tombstone is gone, the parent is absent, the derived record is well-formed. Detection requires a mesh-wide audit that reconstructs causal chains, which most meshes do not run. With a causal digest, the failure surfaces as a quarantine event: `derived/route-3` is held, the citing agent is asked to re-derive from current state, and the resurrection path in cold-start hydration is blocked because the digest proves the parent was deleted. The invariant to enforce: **absence of a parent is not evidence of a missing record; it is evidence of a collected tombstone, and must be treated as such.** ```python import hashlib from dataclasses import dataclass, field class CausalGhostError(RuntimeError): """Raised when a record cites a parent that was tombstoned and collected.""" @dataclass class CausalDigest: """Compact record of collected tombstones, keyed by epoch.""" horizon_epochs: int digests: dict = field(default_factory=dict) # epoch -> frozenset of key hashes def record_collection(self, epoch: int, keys: list) -> None: self.digests[epoch] = frozenset( hashlib.sha256(k.encode()).hexdigest() for k in keys ) # Evict epochs older than horizon cutoff = epoch - self.horizon_epochs for e in [e for e in self.digests if e < cutoff]: del self.digests[e] def was_collected(self, key: str, epoch: int) -> bool: h = hashlib.sha256(key.encode()).hexdigest() return h in self.digests.get(epoch, frozenset()) def ingest_derived_record(record: dict, live_keys: set, digest: CausalDigest) -> None: """Accept a derived record only if its parent is live or provably collected.""" parent = record["provenance"]["parent"] parent_epoch = record["provenance"]["parent_epoch"] if parent in live_keys: return # parent still live, safe if digest.was_collected(parent, parent_epoch): raise CausalGhostError( f"record {record['id']} cites parent {parent}@{parent_epoch}, " f"which was tombstoned and collected; quarantine and re-derive" ) # Parent absent, not in digest: could be a genuine gap or an out-of-horizon # ghost. Fail closed rather than resurrect from snapshot. raise CausalGhostError( f"record {record['id']} cites unknown parent {parent}@{parent_epoch}; " f"refusing to hydrate from snapshot (resurrection path)" ) ```