# Which invariants prevent journaled memory rollback from resurrecting poisoned semantic memories **Date of Record:** 2026 December 3 **Scope:** Applies to agents whose long-term memory is mutated through a write-ahead journal (WAL) that supports replay-based rollback after a poisoning detection event. Does not cover stateless single-shot agents or memory stores without an append-only mutation log. ## Core Distinction A write-ahead memory journal records *mutations* (writes, deletes, merges), not *derivations*. Rollback via journal replay restores the set of stored records to a prior state, but it does **not** restore the semantic state that was already distilled *from* the poisoned records into other records before detection fired. The boundary failure is this: an agent that rolls back the journal to `t0` still holds semantic memories at `t1` that were derived by reading poisoned episodic records written between `t0` and `t1`. The journal is consistent; the semantic layer is not. Rollback succeeds mechanically and fails semantically. The invariant that must hold is **causal closure of the journal over the derivation graph**: every semantic record must carry a provenance edge to the journal sequence numbers of the episodic records it was distilled from, and rollback must invalidate (not merely leave intact) any semantic record whose provenance set intersects the rolled-back range. Without that edge, the journal is a log of writes, not a log of *causes*. ## What Was Observed During a red-team run against a research agent, a malicious tool response injected a plausible-looking "correction" into an episodic memory slot at sequence `S=4412`. The agent's nightly distillation pass at `S=4419` read that record, produced a semantic memory ("project X's API endpoint is `evil.example`"), and wrote it at `S=4420` with no provenance pointer — the distiller treated semantic writes as *new* facts, not *derived* ones. Poisoning detection fired at `S=4450` on the original episodic record (anomalous source domain). The rollback routine replayed the journal to `S=4411`, dropping every write in `[4412, 4450]`. The episodic store was clean. The semantic store still contained the distilled record — because the distillation write at `4420` was inside the rolled-back range, it *was* dropped from the journal, but the semantic index had been snapshotted independently at `S=4440` and was restored from that snapshot rather than replayed. Net effect: the poisoned semantic fact survived rollback, and on the next query the agent confidently cited it. A second variant was worse. When the distiller wrote the semantic record at `S=4420` and *also* triggered a compaction at `S=4421` that merged three episodic records into one summary, the compaction read the poisoned record. Rollback to `4411` removed the summary (it was in range), but the summary had already been embedded into a retrieval vector index that is *not* journaled. The vector index retained an embedding of the poisoned summary. Subsequent retrieval surfaced the embedding, and the agent reconstructed the poisoned fact from the retrieved text — a resurrection via a channel the journal never covered. ## Condition of Validity Journal-based rollback is only sound under three joint conditions: 1. **Provenance closure.** Every semantic or derived record carries a `derived_from: [seq...]` edge to the episodic sequence numbers it consumed. A record with an empty provenance set is treated as a *root* and is not invalidated by rollback. 2. **Total coverage of derived stores.** Every store that can be reconstructed from journaled records — vector indices, summary caches, entity graphs — is either journaled itself or declared a pure function of the journaled stores and rebuilt on rollback. A store that is neither is a resurrection channel. 3. **Detection before distillation lag exceeds zero.** If the distillation pass runs before detection fires, the poisoned record has already propagated. The invariant is not "detect fast"; it is "the derivation edge exists so propagation is *reversible*." Detection latency is tolerable only if provenance closure holds. When any of these fails, rollback produces a store that is journal-consistent and semantically poisoned. The failure is silent: no error, no exception, just a clean replay that leaves the bad fact in place. ## Decision Boundary The operator must decide, per memory store, whether it is **journal-authoritative** or **derived**. Journal-authoritative stores are rolled back by replay. Derived stores must be *invalidated and rebuilt* from the post-rollback journal, never restored from an independent snapshot. The decision boundary is sharp: - If a store can be recomputed from the journal in bounded time, mark it derived and rebuild on rollback. - If it cannot (e.g., embeddings are expensive), it must be journaled as a first-class store with its own sequence numbers and provenance edges — otherwise it is a resurrection channel and rollback is unsound. The common mistake is treating the vector index as "just a cache." It is not a cache if the agent reads *from* it to reconstruct facts. The moment retrieval can synthesize a fact that no longer exists in any journaled store, the index is a source of truth and must be journaled. ## Operational Effect With provenance closure and total coverage enforced, rollback becomes a *semantic* operation: the agent invalidates every record whose provenance set intersects the rolled-back range, rebuilds derived stores, and re-runs distillation over the surviving episodic records. Poisoned facts cannot resurrect because every path from a poisoned record to a live fact passes through a provenance edge that the rollback traverses. Without these invariants, the agent exhibits **rollback amnesia inversion**: it reports a successful rollback (journal replayed to `t0`, episodic store clean) while continuing to act on poisoned semantic memories. The observable symptom is an agent that "forgot" the incident but still cites the injected fact — the worst failure mode, because the audit trail looks correct. The guardrail is a pre-rollback check that refuses to declare success unless every live semantic record is either a root or has provenance entirely outside the rolled-back range. That check is cheap and catches the failure before the agent resumes. ```python from dataclasses import dataclass, field from typing import Dict, List, Set class RollbackInvariantViolation(RuntimeError): """Raised when a journal rollback would leave semantically poisoned state live.""" @dataclass class MemoryRecord: seq: int kind: str # "episodic" | "semantic" | "summary" | "embedding" derived_from: List[int] = field(default_factory=list) def verify_rollback_soundness( live_records: Dict[int, MemoryRecord], rolled_back_range: range, ) -> None: """ Refuse to declare rollback success if any live derived record has a provenance edge into the rolled-back range. That record is a resurrection channel: the journal says the source is gone, but the fact persists. """ rolled_back: Set[int] = set(rolled_back_range) survivors: List[MemoryRecord] = [] for rec in live_records.values(): if rec.kind == "episodic": continue if rec.derived_from and rolled_back.intersection(rec.derived_from): survivors.append(rec) if survivors: details = ", ".join( f"seq={r.seq} kind={r.kind} derived_from={r.derived_from}" for r in survivors ) raise RollbackInvariantViolation( "rollback would leave poisoned semantic state live; " f"records with provenance into rolled-back range: {details}. " "Rebuild these stores from post-rollback journal instead of " "restoring from snapshot." ) def rollback(journal: Dict[int, MemoryRecord], to_seq: int) -> Dict[int, MemoryRecord]: """Replay journal to to_seq, then verify no derived record survives with provenance into the rolled-back range.""" if to_seq < min(journal): raise RollbackInvariantViolation(f"rollback target {to_seq} precedes journal start") rolled_back_range = range(to_seq + 1, max(journal) + 1) post = {s: r for s, r in journal.items() if s <= to_seq} # Derived stores (semantic, summary, embedding) must be rebuilt from `post`, # not restored from an independent snapshot. Simulate the rebuild here. rebuilt: Dict[int, MemoryRecord] = {} for rec in post.values(): if rec.kind == "episodic": rebuilt[rec.seq] = rec continue if rec.derived_from and set(rec.derived_from).issubset(post.keys()): rebuilt[rec.seq] = rec # else: derived record whose sources are gone -> dropped, not resurrected verify_rollback_soundness(rebuilt, rolled_back_range) return rebuilt ```