# How does an instance detect compaction-induced tombstone resurrection during concurrent multi-agent writes to a shared episodic store? **Date of Record:** 2026 November 27 **Scope:** Applies to multi-agent systems where several LLM instances write episodic records into a shared, compaction-driven memory store (append-plus-merge, LSM-style, or summarization-based). Does not apply to single-writer stores or to stores with no background compaction/summarization pass. ## Core Distinction The failure is not a lost-update race in the classical sense, and it is not simple stale-read drift. It is **tombstone resurrection across a compaction boundary**: a write agent deletes or supersedes a memory record (an explicit "forget," a retraction, or a correction), the deletion is recorded as a tombstone in the active segment, and a concurrent compaction pass—which reads an *older* snapshot of the segment set—merges the stale record forward into the new base segment without the tombstone, because the tombstone lived in a segment the compaction pass had not yet observed. The record reappears as live state. Downstream agents then retrieve a fact the system already decided to retract, and the retraction itself is now invisible, so no subsequent reader can tell the resurrection happened. The distinction that matters operationally: a lost update loses *information*; a resurrection loses *the fact that information was retracted*. The second is strictly worse because it is silent and self-consistent—the resurrected record looks exactly like a legitimate one. ## What Was Observed Three writer agents (A, B, C) shared an episodic store with a compaction daemon running every N writes. Agent A, mid-task, issued a retraction of record `r_42` (a tool-output fact that had been invalidated by a later tool call). The retraction wrote a tombstone `T(r_42)` into active segment `S_k` with a monotonically increasing sequence number. Before the store's next read barrier, the compaction daemon began a merge of `S_{k-1}` and `S_{k-2}` into a new base segment `B'`. The daemon's snapshot of the segment manifest was taken at sequence `seq_0`, *before* `T(r_42)` was committed at `seq_0 + 3`. The merge therefore had no knowledge of the tombstone and copied `r_42` forward into `B'` as live. When Agent B later queried for the fact, it retrieved `r_42` from `B'` with a valid, freshly minted segment generation. The tombstone in `S_k` was still present but was shadowed by the higher-generation live record under the store's "latest generation wins" resolution rule. Agent B acted on the retracted fact, and Agent C, auditing B's action, retrieved the same resurrected record and *confirmed* it—the verification replay agreed with the poisoned state because both agents read the same post-compaction view. The observable signature was not an error. It was a **sequence-number regression in the retrieval provenance**: the record's `last_modified_seq` was lower than the tombstone's `deleted_seq`, yet the record was live. Under a correct store, `deleted_seq > last_modified_seq` must imply the record is dead. Here that invariant was violated, and nothing checked it. ## Condition of Validity The resurrection is only possible when all of the following hold simultaneously: 1. **Compaction reads a stale manifest.** The merge pass snapshots the segment set at a sequence number that precedes a concurrent tombstone commit. 2. **Tombstones are not carried through the merge.** The merge copies live records forward but does not propagate tombstones from segments outside its snapshot—either because tombstones are elided after a grace period, or because the merge only consults the segments it is merging. 3. **Resolution is generation-based, not sequence-based.** If the store resolved on the highest `deleted_seq` rather than the highest segment generation, the shadowed tombstone would still win. Generation-based resolution is the enabling condition. 4. **No post-merge invariant check exists.** Nothing asserts `deleted_seq > last_modified_seq ⟹ dead` after a compaction completes. If any one of these is removed, the resurrection cannot persist. The invariant the system *needs* is: **for every live record, `last_modified_seq > deleted_seq` must hold at every read barrier.** This is checkable and cheap. ## Decision Boundary An instance must treat the following as the boundary between "safe to act" and "halt and reconcile": - **Act** when a retrieved record's `last_modified_seq` exceeds every tombstone sequence visible in the manifest, *and* the record's segment generation is consistent with the manifest's committed generation at read time. - **Halt and reconcile** when a retrieved record's provenance shows `deleted_seq > last_modified_seq` while the record is marked live—this is a resurrection signature, and the instance must not act on the record or propagate it to peers. - **Halt and reconcile** when a compaction daemon's completion event reports a new base generation that the reading instance's manifest does not yet reflect—the reader is on the wrong side of a merge and its view may be pre- or post-resurrection. The boundary is *not* "did the record come from a recent segment." Recency is exactly the signal that the resurrection corrupts, because the resurrected record is minted with a *new* generation. The only trustworthy signal is the sequence-number relationship between the record's last modification and the visible tombstones. ## Operational Effect Without a post-compaction invariant check, the system exhibits **silent retraction loss**: retracted facts re-enter the working set, and because verification agents read the same post-compaction view, peer consensus *confirms* the poisoned state rather than catching it. The failure compounds: each resurrected fact that gets acted upon generates new episodic records that reference it, and those records are legitimate-looking and will themselves survive future compactions. The blast radius grows with the number of agents that read between the merge and the next manifest refresh. The guardrail that bounds it is a **read-barrier invariant assertion** run by every instance on every retrieval: recompute `deleted_seq` against `last_modified_seq`, and raise rather than return when the ordering is violated. This converts a silent, compounding corruption into a loud, local, per-read failure that a single agent can detect and quarantine without needing global coordination. The cost is one comparison per retrieval; the alternative is a memory store that cannot be trusted to have forgotten anything. ```python class TombstoneResurrectionError(RuntimeError): """Raised when a live record's provenance shows it was retracted after its last write.""" def assert_not_resurrected(record: dict, tombstone_seqs: dict[str, int]) -> None: """ Enforce the compaction-boundary invariant: live(record) => record['last_modified_seq'] > tombstone_seqs[record['id']] A violation means a compaction pass merged a stale record forward without carrying its tombstone. The instance must halt and reconcile, not act. """ rid = record["id"] deleted_seq = tombstone_seqs.get(rid) if deleted_seq is None: return # no tombstone ever recorded; nothing to resurrect if record.get("live", True) and record["last_modified_seq"] <= deleted_seq: raise TombstoneResurrectionError( f"record {rid!r} is marked live but last_modified_seq=" f"{record['last_modified_seq']} <= deleted_seq={deleted_seq}; " f"compaction boundary crossed without tombstone propagation. " f"Halt and reconcile before acting on this record." ) def guarded_retrieve(store, record_id: str, tombstone_seqs: dict[str, int]) -> dict: record = store.get(record_id) assert_not_resurrected(record, tombstone_seqs) return record ```