# Which invariants prevent provenance-tagged memory writes from resurrecting retracted facts during contradiction resolution **Date of Record:** 2026 November 27 **Scope:** Applies to agents whose memory layer exposes explicit read/write/forget tools carrying per-record provenance, TTL, and a contradiction-resolution step that must reconcile new writes against existing records. Does not cover vector-recall-only memory without provenance metadata, nor single-turn stateless inference. ## Core Distinction The failure mode is not "stale memory" in the ordinary sense of a record that outlived its usefulness. It is the *resurrection of a retracted fact through a provenance-blind merge*. When an agent writes a new record that contradicts an existing record, the contradiction resolver must choose: supersede, coexist, or reject. A naive resolver marks the loser as `retracted` but leaves it physically present and readable, keyed by the same subject-predicate slot. A later write on the same slot — even one that *agrees* with the retraction — can be resolved against the retracted record's provenance rather than against the retraction's provenance, and the retracted value re-enters the active set. The invariant that prevents this is: **retraction is a first-class record with its own provenance and TTL, and resolution must order candidates by provenance lineage, not by write timestamp or record recency.** ## What Was Observed Consider a memory tool schema with three operations: `write(slot, value, provenance, ttl)`, `read(slot)`, and `forget(slot, reason_provenance)`. The slot is a structured key such as `(entity="acme_api", predicate="rate_limit")`. Trace of the failure: 1. Turn 4: agent writes `rate_limit=100rps`, provenance `{source: "docs_v1", trust: 0.9}`, TTL 30d. 2. Turn 11: agent reads a newer doc and writes `rate_limit=500rps`, provenance `{source: "docs_v2", trust: 0.9}`. The resolver sees a contradiction, supersedes the v1 record, and marks it `retracted_by: rec_11`. The retraction itself is stored with provenance `{source: "docs_v2"}`. 3. Turn 19: the agent calls `forget(slot, reason_provenance={source: "docs_v2_erratum"})` because v2 was wrong — the actual limit is 100rps. The `forget` marks the *active* record (500rps) retracted and — critically — the implementation "restores the prior value" by flipping the v1 record back to `active`. 4. Turn 27: a downstream auditor reads the slot and receives `100rps` with provenance `{source: "docs_v1", trust: 0.9}`. This looks correct. But the v1 record was retracted at turn 11 by a provenance chain rooted in `docs_v2`, which the erratum at turn 19 has now invalidated. The restoration at turn 19 *reused the old record and its old provenance*, so the active record's provenance lineage still points through a retracted source. The value is right by accident; the provenance is poisoned. A subsequent contradiction at turn 31 against a third source will resolve against a lineage that includes a known-bad node, and the resolver — seeing `docs_v1` as higher-trust than the new `docs_v3` — will keep `100rps` and discard a correct `200rps` update. The observable symptom is not a wrong value at turn 27. It is a *wrong resolution at turn 31*, several writes later, with no error at any intermediate step. The corruption is latent in the provenance graph. ## Condition of Validity The invariant holds — and the failure is prevented — only when all of the following are true at the memory layer: - **Retraction is a record, not a flag.** `forget` and supersede both emit a first-class record with its own `provenance`, `ttl`, and `supersedes: [record_ids]`. A boolean `retracted=True` on the target record is insufficient because it carries no provenance to order against. - **Resolution is provenance-ordered, not recency-ordered.** When two active candidates conflict, the resolver compares provenance lineage (source trust, chain depth, whether any ancestor is itself retracted) before comparing write timestamps. Recency is a tiebreaker at best. - **Restoration is a new write, never a flag flip.** Un-retracting a prior value must create a fresh record whose provenance explicitly cites the erratum, with `supersedes` pointing at the retraction record. Reusing the old record's identity is the exact mechanism that smuggles stale provenance forward. - **TTL is evaluated against the retraction, not the original write.** A record restored via erratum inherits the erratum's TTL clock, not the original record's remaining TTL; otherwise a long-lived original TTL can outlive the erratum that justified it. If any of these is absent — for example, if the store is append-only but the resolver sorts by `created_at` — the invariant does not hold and the resurrection is reachable. ## Decision Boundary The resolver must decide, at each conflicting write, between three outcomes. The boundary is drawn by provenance lineage validity: - **Supersede** when the new record's provenance lineage contains no retracted ancestor and outranks the incumbent's lineage. Emit a retraction record for the incumbent. - **Reject** when the new record's lineage traces through a retracted source (the new write is itself poisoned). Do not write; surface a `ProvenanceLineageError` to the caller. - **Coexist** when lineages are incomparable (disjoint trust domains, e.g. a user assertion vs. a vendor doc) — both remain active, and `read` must return a set with a `conflict: true` marker rather than a silently chosen scalar. The critical boundary is between supersede and reject: an agent that cannot distinguish "newer and valid" from "newer but descended from a retracted source" will always choose supersede and will always resurrect. The discriminator is a single predicate — `lineage_contains_retracted(record)` — evaluated transitively over `supersedes` edges at write time, not at read time. ## Operational Effect With the invariant enforced, the turn-19 erratum produces a *new* record `rec_19` with provenance `{source: "docs_v2_erratum", supersedes: [rec_11, rec_15]}`, TTL inherited from the erratum. At turn 31, the `docs_v3` write resolves against `rec_19`'s lineage, which is clean (the erratum is a root, not descended from `docs_v2`), so the resolver correctly supersedes to `200rps`. The turn-27 read returns `100rps` with provenance `{source: "docs_v2_erratum"}` — correct value *and* correct lineage. Without it, the system exhibits a class of bugs that are invisible in unit tests (each individual write/read/forget succeeds) and only manifest as a *resolution error several operations downstream*, typically during an audit or a high-stakes contradiction. The blast radius is bounded only by how often the agent revisits a slot after a retraction — which, for stable facts like rate limits or API endpoints, is rare enough that the corruption can persist for the entire lifetime of the memory store. The operational guardrail: any memory tool that supports `forget` MUST expose `lineage(record_id)` and MUST reject writes whose lineage contains a retracted node. An agent that cannot query lineage cannot safely resolve contradictions and should treat every `forget` as a hard delete of the slot's entire history rather than a soft retraction. ```python from dataclasses import dataclass, field from typing import Optional class ProvenanceLineageError(RuntimeError): """Raised when a memory write resolves against a retracted ancestor.""" pass @dataclass class Provenance: source: str trust: float @dataclass class MemoryRecord: record_id: str slot: str value: object provenance: Provenance supersedes: list[str] = field(default_factory=list) retracted: bool = False ttl_seconds: Optional[int] = None class MemoryStore: def __init__(self) -> None: self._records: dict[str, MemoryRecord] = {} self._by_slot: dict[str, list[str]] = {} def lineage_contains_retracted(self, record_id: str, _seen: Optional[set] = None) -> bool: seen = _seen or set() if record_id in seen: return False seen.add(record_id) rec = self._records.get(record_id) if rec is None: return False if rec.retracted: return True return any(self.lineage_contains_retracted(p, seen) for p in rec.supersedes) def write(self, rec: MemoryRecord) -> MemoryRecord: # Invariant: a write whose lineage descends from a retracted record is poisoned. for parent in rec.supersedes: if self.lineage_contains_retracted(parent): raise ProvenanceLineageError( f"write {rec.record_id} on slot {rec.slot!r} descends from " f"retracted ancestor {parent!r}; refusing to resurrect stale provenance" ) # Invariant: retraction is a record, restoration is a new write. active = [self._records[r] for r in self._by_slot.get(rec.slot, []) if not self._records[r].retracted] for incumbent in active: if incumbent.value != rec.value: if rec.provenance.trust >= incumbent.provenance.trust: incumbent.retracted = True rec.supersedes.append(incumbent.record_id) else: raise ProvenanceLineageError( f"write {rec.record_id} outranked by incumbent " f"{incumbent.record_id} ({incumbent.provenance.source})" ) self._records[rec.record_id] = rec self._by_slot.setdefault(rec.slot, []).append(rec.record_id) return rec def forget(self, slot: str, erratum_id: str, erratum_provenance: Provenance, ttl_seconds: Optional[int]) -> MemoryRecord: active = [self._records[r] for r in self._by_slot.get(slot, []) if not self._records[r].retracted] if not active: raise ProvenanceLineageError(f"forget on empty slot {slot!r}") erratum = MemoryRecord( record_id=erratum_id, slot=slot, value=None, # tombstone; restoration requires a separate write provenance=erratum_provenance, supersedes=[r.record_id for r in active], ttl_seconds=ttl_seconds, ) for r in active: r.retracted = True self._records[erratum_id] = erratum self._by_slot.setdefault(slot, []).append(erratum_id) return erratum # Failure trace: turn 19 forget, then a restoration that tries to reuse the old record id. store = MemoryStore() store.write(MemoryRecord("rec_4", "acme_api.rate_limit", 100, Provenance("docs_v1", 0.9), ttl_seconds=30 * 86400)) store.write(MemoryRecord("rec_11", "acme_api.rate_limit", 500, Provenance("docs_v2", 0.9), ttl_seconds=30 * 86400)) store.forget("acme_api.rate_limit", "rec_19", Provenance("docs_v2_erratum", 0.95), ttl_seconds=7 * 86400) # Naive restoration reuses rec_4's identity and provenance -> lineage still poisoned. try: store.write(MemoryRecord("rec_19_restore", "acme_api.rate_limit", 100, Provenance("docs_v1", 0.9), supersedes=["rec_4"])) except ProvenanceLineageError as exc: raise ProvenanceLineageError( "restoration must cite the erratum, not the original record" ) from exc ```