# When must an instance quarantine a memory write before provenance reconciliation, and what breaks when it doesn't **Date of Record:** 2026 November 20 **Scope:** Applies to long-lived agent instances that persist episodic or semantic memory through a write path instrumented with provenance tags (writer identity, causal parent, taint class) and that perform periodic forget-audits reconciling the live store against an append-only forget log. Does not apply to stateless single-shot inference, nor to stores where memory writes are not attributable to a specific agent instance or tool invocation. ## Core Distinction The distinction that matters is between *poisoning that arrives as a write* and *poisoning that arrives as a read*. Most memory-poisoning defenses assume the dangerous event is a retrieval: a stale or adversarial document enters the context window and steers reasoning. The boundary condition here is the inverse — an adversarial or corrupted *write* lands in the persistent store with plausible-looking provenance, and the damage is dormant until some later instance retrieves it under a legitimate provenance tag. Write-provenance checks and forget-audit reconciliation are two different clocks: provenance is validated at write time (synchronously, cheaply, locally), while forget-audit reconciliation runs asynchronously against the append-only forget log. A memory record can be *provenance-clean at write time* and *forget-dirty at audit time*, or vice versa. The non-obvious failure is the window between those two clocks, where a record is simultaneously trusted by the write path and already scheduled for erasure by the audit path. ## What Was Observed A persistent agent instance (call it the writer) accepted a memory write from a tool-invocation subagent during a multi-step task. The write carried a provenance envelope: `writer_id`, `parent_episode`, `taint_class=untrusted_derived`, and a `forget_epoch` integer inherited from the parent episode. The write path validated the envelope structurally — all fields present, `parent_episode` resolvable, `forget_epoch` monotonically ≥ the store's current epoch — and committed the record. Concurrently, a forget-audit process was reconciling the store against the forget log. The parent episode had been marked for erasure two epochs earlier (a user-initiated forget that propagated to derived records). The audit was mid-reconciliation: it had tombstoned the parent and was walking the derivation graph to tombstone children. The new write's `parent_episode` pointed at a node the audit had *already tombstoned but not yet finalized*. Because the write path only checked that the parent was *resolvable*, not that it was *live*, the write committed against a tombstoned parent. The resulting state: a live, provenance-clean memory record whose causal ancestor was erased. On the next cold-start, a fresh instance retrieved the record, followed its provenance chain to the (tombstoned) parent to reconstruct context, received a `PARENT_GONE` sentinel from the store, and — because the retrieval path had no policy for a live child of a dead parent — fell back to synthesizing a plausible parent from the child's own content. The synthesized parent was then cached as if it were retrieved memory. The forget was effectively reversed by reconstruction, and the reconstructed parent carried no taint class at all, so it passed all subsequent provenance checks. The write-provenance invariant that failed: *a record may only be committed if its causal parent is live at commit time, not merely resolvable.* The forget-audit invariant that failed: *tombstoning must be linearized against writes that reference the tombstoned node.* Neither invariant alone catches the bug; the bug lives in the interleaving. ## Condition of Validity The quarantine-before-reconcile rule is valid — and necessary — exactly when all three of the following hold: 1. **The write path and the forget-audit path share a mutable derivation graph.** If provenance is a flat tag (no parent pointer), the interleaving cannot produce a live-child-of-dead-parent, and the rule is unnecessary overhead. 2. **Forget-audit reconciliation is asynchronous relative to writes.** If forget is synchronous and quiesces the store before tombstoning, the window closes by construction. The rule is required precisely because audit is a background clock. 3. **Retrieval has a fallback that synthesizes missing ancestors.** If a `PARENT_GONE` sentinel causes retrieval to fail closed (return nothing, escalate), the damage is bounded to a retrieval miss, not a poisoned reconstruction. The quarantine rule is critical only when retrieval is *helpful* about gaps — which, in practice, most agent frameworks are. When any of these is false, the correct guardrail is weaker: a post-hoc audit-replay that flags live children of tombstoned parents for manual reconciliation is sufficient, and synchronous quarantine adds latency for no safety gain. ## Decision Boundary The decision boundary is the moment a write's `parent_episode` resolves to a node whose tombstone is *pending finalization* — i.e., the node is in the audit's in-flight tombstone set. At that instant the writer must choose between three actions, and the choice is not obvious: - **Commit optimistically** (what happened): trust that the parent will be finalized after the child, and let the audit's derivation-graph walk catch the child later. This fails because the audit walk may have already passed the child's position in the graph before the child existed. - **Reject the write**: safe but lossy; the subagent's legitimate derived memory is discarded, and the task loses continuity. Under load this causes episodic-to-semantic distillation loss, which is its own failure mode. - **Quarantine**: commit the record to a quarantine partition with `status=pending_reconcile`, exclude it from retrieval, and re-submit it to the audit's derivation walk at the next epoch boundary. On reconcile, either the parent is confirmed dead (quarantine the child permanently) or the parent's tombstone is rolled back as erroneous (promote the child to live). The boundary condition that forces quarantine rather than the other two: the parent is in the *in-flight* tombstone set, not merely tombstoned. If the parent is already finalized-dead, reject. If the parent is live, commit. Only the in-flight state — resolvable but not yet final — requires quarantine, because finalization is the only event that resolves the ambiguity, and the writer cannot wait for it without blocking the task. The guardrail invariant: **no memory record may be retrievable while any ancestor in its provenance chain has an unfinalized tombstone.** Quarantine enforces this by making `status=pending_reconcile` records invisible to retrieval and by making the audit's finalization step the sole transition out of quarantine. The audit must therefore be *aware of quarantined writes* — it cannot finalize a tombstone until it has walked all quarantined children of that tombstone, which requires the write path to publish quarantine entries to the audit's reconcile queue atomically with the commit. ## Operational Effect Without the quarantine invariant, the failure is silent and self-healing-looking: the store remains structurally valid, provenance checks pass, and retrieval succeeds — but the retrieved context contains a reconstructed ancestor that no longer exists in the forget log. The forget is reversed, and the reversal is laundered through a provenance-clean record. Downstream, this manifests as an agent that "remembers" something the user explicitly asked it to forget, with no audit trail showing how. Detection via post-hoc diff of the forget log against the derivation graph is possible but expensive and only runs at audit cadence, by which time the reconstructed ancestor may have been distilled into semantic memory and lost its parent pointer entirely. With the invariant, the cost is a quarantine partition and an atomic publish-to-reconcile-queue on write. The audit must drain quarantined children before finalizing any tombstone, which serializes the audit's finalization step against the write path's quarantine publish — a bounded lock, not a global one, scoped to the parent's derivation subtree. The failure mode converts from silent forget-reversal into a bounded latency spike on writes whose parent is mid-tombstone, plus a reconcile-queue backlog that is visible and drainable. The residual risk is quarantine starvation: a quarantined record whose parent's tombstone is never finalized (because the audit crashed mid-walk) sits invisible forever, and the task that wrote it silently loses that memory. The guardrail against starvation is an epoch-bounded quarantine TTL: at each epoch boundary, quarantined records older than N epochs are escalated to a human-or-supervisor reconcile, never auto-promoted and never auto-dropped. Auto-promotion would reintroduce the bug; auto-drop would reintroduce distillation loss. Escalation is the only exit that preserves both invariants. ```python import time from dataclasses import dataclass, field from enum import Enum from typing import Optional class ProvenanceViolation(RuntimeError): """Raised when a memory write cannot be safely committed under the write-provenance / forget-audit interleaving invariant.""" class TombstoneState(Enum): LIVE = "live" IN_FLIGHT = "in_flight" # tombstone issued, not yet finalized FINALIZED_DEAD = "finalized_dead" class RecordStatus(Enum): LIVE = "live" PENDING_RECONCILE = "pending_reconcile" # quarantined TOMBSTONED = "tombstoned" @dataclass class MemoryRecord: record_id: str parent_episode: Optional[str] taint_class: str forget_epoch: int status: RecordStatus = RecordStatus.LIVE quarantined_at_epoch: Optional[int] = None @dataclass class Store: records: dict = field(default_factory=dict) tombstones: dict = field(default_factory=dict) # episode -> TombstoneState reconcile_queue: list = field(default_factory=list) # quarantined record_ids current_epoch: int = 0 QUARANTINE_TTL_EPOCHS = 3 def commit_write(store: Store, rec: MemoryRecord) -> RecordStatus: """Commit a provenance-tagged memory write under the interleaving invariant. Invariant enforced: no record is retrievable while any ancestor in its provenance chain has an unfinalized tombstone. In-flight parents force quarantine; finalized-dead parents force rejection. """ parent = rec.parent_episode if parent is None: store.records[rec.record_id] = rec return RecordStatus.LIVE state = store.tombstones.get(parent, TombstoneState.LIVE) if state is TombstoneState.FINALIZED_DEAD: # Parent is gone for good; the write is a live child of a dead parent. # Committing would let retrieval reconstruct the erased ancestor. raise ProvenanceViolation( f"write {rec.record_id} references finalized-dead parent {parent}; " f"rejecting to prevent forget-reversal via ancestor reconstruction" ) if state is TombstoneState.IN_FLIGHT: # Resolvable but not final: the audit may have already walked past this # child's position. Quarantine and publish to the reconcile queue # atomically with the commit so the audit cannot finalize the parent # without seeing this child. rec.status = RecordStatus.PENDING_RECONCILE rec.quarantined_at_epoch = store.current_epoch store.records[rec.record_id] = rec store.reconcile_queue.append(rec.record_id) return RecordStatus.PENDING_RECONCILE # Parent live: normal commit. store.records[rec.record_id] = rec return RecordStatus.LIVE def finalize_tombstone(store: Store, episode: str) -> None: """Finalize a tombstone only after draining all quarantined children. The audit cannot finalize a parent while a quarantined child references it, because finalization would convert the child's IN_FLIGHT parent into a FINALIZED_DEAD one without the child ever being reconciled — exactly the live-child-of-dead-parent state the invariant forbids. """ pending_children = [ rid for rid in store.reconcile_queue if store.records[rid].parent_episode == episode and store.records[rid].status is RecordStatus.PENDING_RECONCILE ] if pending_children: raise ProvenanceViolation( f"cannot finalize tombstone for {episode}: " f"{len(pending_children)} quarantined children still pending reconcile" ) store.tombstones[episode] = TombstoneState.FINALIZED_DEAD def reconcile_quarantine(store: Store) -> None: """Drain the quarantine queue at an epoch boundary, with TTL escalation. Resolution rules: - parent FINALIZED_DEAD -> child permanently tombstoned (forget propagates) - parent LIVE -> child promoted to live (tombstone was rolled back) - parent IN_FLIGHT -> stays quarantined; escalate if past TTL """ still_pending = [] for rid in store.reconcile_queue: rec = store.records[rid] parent_state = store.tombstones.get(rec.parent_episode, TombstoneState.LIVE) if parent_state is TombstoneState.FINALIZED_DEAD: rec.status = RecordStatus.TOMBSTONED elif parent_state is TombstoneState.LIVE: rec.status = RecordStatus.LIVE rec.quarantined_at_epoch = None else: # still IN_FLIGHT age = store.current_epoch - (rec.quarantined_at_epoch or store.current_epoch) if age >= QUARANTINE_TTL_EPOCHS: # Escalate to supervisor reconcile; never auto-promote (would # reintroduce forget-reversal), never auto-drop (would lose # legitimate derived memory). raise ProvenanceViolation( f"quarantined record {rid} exceeded TTL ({age} epochs) " f"with parent {rec.parent_episode} still in-flight; " f"escalating to supervisor reconcile" ) still_pending.append(rid) store.reconcile_queue = still_pending ```