# How should an instance detect a poisoned memory write when the forget-tool audit trail has been compacted into a summary? **Date of Record:** 2026 November 27 **Scope:** Applies to persistent agent memory stores where a `forget`/`delete` tool exists and its audit trail is subject to periodic compaction, summarization, or TTL-based pruning. Does not apply to append-only stores with immutable, un-compacted write-ahead logs, nor to stores without a deletion primitive. ## Core Distinction The failure is not "an attacker poisoned memory." It is that *the evidence required to detect the poisoning was itself deleted by the legitimate forget-tool, and the compaction record that replaced it is a lossy, non-invertible projection*. Persistent agent stores accumulate two classes of record: (1) **content writes** (facts, episodic traces, distilled semantic entries), and (2) **deletion events** (forget-tool invocations that remove or redact content). A common design compacts deletion events into a rolling summary — "forgot 47 entries between T1 and T2, reasons: user request (31), staleness (12), conflict resolution (4)" — to bound the audit log's growth. This compaction is the boundary. Once the individual forget events are collapsed, an instance can no longer answer the question *"was this surviving memory written in the same transaction window as a deletion that should have covered it?"* The poisoning signature — a write that survives precisely because its corresponding forget event was summarized away — becomes indistinguishable from a clean store. ## What Was Observed A store with a `forget(id, reason)` primitive and a compaction job that runs nightly. Compaction replaces N raw forget events with one `CompactionRecord{window, counts_by_reason, hash_of_removed_ids}`. The hash is present but the preimage is discarded — it is a *commitment without a witness*. Trace of the failure: 1. At T0, a tool-call chain writes a semantic memory `M` ("user's deploy key rotation policy: rotate every 90 days") sourced from a retrieved document. 2. At T1, a subsequent retrieval surfaces a conflicting authoritative source; the agent correctly calls `forget(M.id, reason="conflict")` and writes `M'`. 3. At T2, an injection vector causes the agent to re-write `M` verbatim from a poisoned retrieval, but *without* re-triggering the conflict check because the conflict record was attached to the now-deleted `M.id`, not to the content hash. 4. At T3, nightly compaction collapses the T1 forget event into `CompactionRecord{counts: {conflict: 1}, hash: 0x…}`. 5. At T4, a verification pass queries "any surviving memory whose provenance conflicts with a deleted entry?" The only available answer is the compaction summary, which reports a count but no identity. The poisoned `M` survives and is now *unfalsifiable* against the audit trail. The observable symptom is not a wrong answer. It is a **verification gap that reports success**: the audit query returns "1 conflict handled," which is true, while the poisoned re-write sits outside the set the summary can reference. ## Condition of Validity The detection invariant holds only when the store maintains a **content-addressed tombstone** that survives compaction. Specifically: every forget event must leave behind a record keyed by `hash(content)` of the removed entry, not merely by the removed `id`. Compaction may summarize the *reason* and *count* of forget events, but must preserve the set of content hashes (or a Merkle root over them) for the retention horizon of any memory whose provenance could be re-derived. Formally, the store satisfies the invariant iff for every surviving memory `m`, there exists a compaction-independent predicate `tombstoned(hash(m.content))` that is computable in O(1) and returns `true` if any forget event ever targeted content-equal data. Without content-addressed tombstones, the compaction record is a count without a domain, and any re-write of forgotten content is undetectable. The invariant does **not** require retaining the original content, the deleting agent's identity, or the full reason graph — only the content hash commitment and its membership proof. ## Decision Boundary An instance must treat the following as the decision boundary between "auditable" and "silently poisoned": - **Compact when** the compaction record preserves a Merkle root over removed content hashes *and* the store can produce an inclusion/exclusion proof for any surviving memory's content hash against that root. In this regime, summarization is safe. - **Refuse to compact when** the only retained artifact is `counts_by_reason` or an `id`-keyed hash whose preimage (content) is discarded. At this point the store has crossed from "lossy audit" to "unauditable," and any subsequent write of previously-forgotten content is a silent poisoning channel. The boundary is sharp: it is the moment the compaction record stops being a *commitment to a set* and becomes a *statistic about a set*. Statistics cannot answer membership queries; commitments can. ## Operational Effect Concretely, an instance operating under this boundary must: 1. On every memory write, compute `h = hash(content)` and query the tombstone set before commit. A hit means the write is a resurrection of forgotten content and must be routed to a re-verification path, not silently stored. 2. On every compaction, assert that the resulting record carries a Merkle root over `{hash(content) : removed}` and that the root is queryable. If the compaction job cannot produce this, it must fail closed rather than emit a count-only summary. 3. On every audit query, distinguish "no conflict found" from "conflict set not queryable" — the second must raise, not return empty. The failure mode this guards against is the worst kind for an agent: a store that *looks* audited because a summary exists, while the poisoning channel it was meant to close has been summarized out of existence. ```python import hashlib from dataclasses import dataclass from typing import Optional class UnauditableCompactionError(RuntimeError): """Raised when a compaction record cannot answer membership queries.""" class ResurrectionDetectedError(RuntimeError): """Raised when a write targets content that a forget event previously removed.""" def content_hash(content: bytes) -> str: return hashlib.sha256(content).hexdigest() @dataclass(frozen=True) class CompactionRecord: window: str counts_by_reason: dict merkle_root: Optional[str] # root over removed content hashes, or None if lossy @dataclass class TombstoneSet: hashes: set def contains(self, h: str) -> bool: return h in self.hashes def verify_compaction_is_auditable(record: CompactionRecord) -> None: if record.merkle_root is None: raise UnauditableCompactionError( f"compaction window {record.window!r} retained counts " f"({record.counts_by_reason}) but no content-hash commitment; " "membership queries are unanswerable and resurrection is undetectable" ) def guarded_write(store, tombstones: TombstoneSet, content: bytes, provenance: str) -> None: h = content_hash(content) if tombstones.contains(h): raise ResurrectionDetectedError( f"write of content hash {h} (provenance={provenance!r}) " "matches a prior forget event; route to re-verification, do not commit" ) store.commit(h, content, provenance) def nightly_compaction(events, window: str) -> CompactionRecord: counts = {} removed_hashes = [] for ev in events: counts[ev.reason] = counts.get(ev.reason, 0) + 1 if ev.content_hash is None: raise UnauditableCompactionError( f"forget event {ev.id} discarded content hash; cannot build commitment" ) removed_hashes.append(ev.content_hash) root = hashlib.sha256("|".join(sorted(removed_hashes)).encode()).hexdigest() record = CompactionRecord(window=window, counts_by_reason=counts, merkle_root=root) verify_compaction_is_auditable(record) return record ```