# Where must an instance refuse a memory write when provenance chains become circular across episodic-to-semantic promotion **Date of Record:** 2026 November 28 **Scope:** Applies to agents whose memory tool API exposes `write_episodic`, `write_semantic`, `promote`, `forget`, and `read` with per-record provenance links, and where semantic records are derived from episodic records via a promotion step. Does not apply to append-only logs without promotion, or to stores where provenance is advisory metadata rather than an enforced DAG. ## Core Distinction The common framing of memory-tool correctness is *content* correctness: did the agent store the right fact, retrieve the right record, forget the right thing. The non-obvious boundary is *structural* correctness of the provenance graph itself. A provenance-tracked store is not a bag of records with `source_ids` attached; it is a directed acyclic graph whose edges encode "this record's content is licensed by those records." The invariant that must hold is: **the provenance relation is a strict partial order (irreflexive, transitive-closed, acyclic)**, and every `read`, `promote`, and `forget` operation must preserve it. The failure mode is not a bad fact. It is a *cycle*: a semantic record `S` whose provenance chain transitively includes `S` itself, typically arising when a semantic record is later cited as evidence for an episodic observation, which is then re-promoted. Once a cycle exists, `forget` cannot compute a valid invalidation set (it either loops or under-deletes), and `read` returns records whose justification is self-referential — the agent "remembers" a fact because it remembers having remembered it. ## What Was Observed Trace from a production run of a research agent using a dual-store memory API. The agent completes a task, writes episodic records for each tool observation, then at task end calls `promote` to distill episodic → semantic. The distilled semantic record `S_42` ("service X returns 429 above 50 rps") carries `source_ids = [E_1001, E_1002]`. On the next task, the agent reads `S_42` into context and, as part of a new observation, writes an episodic record `E_2007` whose content paraphrases `S_42` ("observed that service X rate-limits around 50 rps"), and the write path — because the agent cited the semantic record in its reasoning trace — records `source_ids = [S_42]` on `E_2007`. This is legal under a naive schema: an episodic record may cite anything in the store. At the end of the second task, `promote` runs over `E_2007` and emits `S_43` with `source_ids = [E_2007]`. Now the graph contains the path `S_42 → E_2007 → S_43`. If `S_43` is later merged into `S_42` (a dedup/consolidation step on near-identical semantic content — a normal operation), the merge rewrites `S_42.source_ids` to include `E_2007`, and `E_2007.source_ids` includes `S_42`. The graph is now cyclic: `S_42 → E_2007 → S_42`. Observed downstream effects, in order of discovery: 1. `forget(S_42)` entered an unbounded traversal of the provenance closure and hit the tool's 30s timeout, returning a partial deletion — `E_2007` and `S_43` survived, now orphaned but still readable. 2. `read` on a query matching `S_42` returned `S_42` with a `confidence` field computed as the product of source confidences; the cycle made this a fixed-point iteration that converged to an arbitrary value (0.87 in one run, 0.41 in another) depending on traversal order. 3. A subsequent `promote` of `E_2007` produced `S_44` citing `S_43` citing `E_2007` citing `S_42` citing `E_2007` — the store was now generating new records whose sole provenance was the store itself, with no ground-truth observation anywhere in the chain. The key observation: **no single operation was wrong.** Each `write`, `promote`, `merge`, and `forget` was locally valid. The cycle was assembled across four operations over two tasks. This is the signature of a missing global invariant — the API enforced record-level schema but not graph-level acyclicity. ## Condition of Validity The acyclicity invariant is only meaningful, and only checkable, under specific conditions. An agent or store operator must treat the following as the *validity envelope* for provenance-tracked memory: - **Promotion is a monotone DAG extension.** `promote(episodic_set) → semantic` must add edges only from the semantic record to its episodic sources, never from episodic to semantic. If the schema permits `write_episodic` to cite a semantic record (as in the trace above), the store must still reject the edge if it would close a cycle through any existing path. - **Merge/consolidation is edge-rewriting, not edge-union.** Consolidating `S_43` into `S_42` must union the *episodic* leaves of both, not the immediate `source_ids`. Unioning immediate parents is what created the `S_42 ↔ E_2007` back-edge. The correct rewrite is: `S_42.sources := leaves(closure(S_42)) ∪ leaves(closure(S_43))`, and leaves are always episodic (or external ground truth), never semantic. - **`forget` must be closure-safe.** Deletion of a node must either (a) be rejected if it would orphan a still-referenced dependent, or (b) cascade to the full transitive dependents in a single atomic step. Partial deletion on timeout is the worst outcome: it breaks the invariant that every live record has a live provenance chain. - **Confidence is a function of leaves, memoized over the DAG, not recursively re-derived.** If confidence is computed by recursive descent, a cycle causes non-termination or order-dependent fixed points. Compute over the topological order of leaves; if no topological order exists, the graph is invalid and `read` must fail closed. Outside these conditions — e.g., a store that treats provenance as free-text citations with no enforced edges — the invariant is unenforceable and the failure is not detectable at write time. The agent must then treat all retrieved records as unverified. ## Decision Boundary The decision boundary is the point at which a `write` or `promote` call must *refuse* rather than *accept-and-repair*. The correct policy is a hard reject on cycle closure, not a silent edge-drop, because a dropped edge produces a record whose stated provenance is a lie — the agent will later trust a fact whose support was quietly severed. Concretely, the boundary conditions: - **Reject** `write_episodic(E, sources=[S])` if `S` is semantic and `E` is not already in `closure(S)`'s leaf set — i.e., if the episodic record is being used to re-license a semantic record it did not observe. This is the specific edge that closed the cycle above. - **Reject** `promote` if any source record is itself semantic and its leaves are not a subset of the episodic inputs. Promotion must cite leaves, not intermediate semantics. - **Reject** `merge` if the union of leaf sets would introduce a node already present in either closure (self-merge through a shared leaf). - **Permit** `write_episodic(E, sources=[S])` only when `E` is a *new observation* whose content is independent of `S` and the edge is recorded as `cites` (weak, non-licensing), not `derives_from` (strong, licensing). The schema must distinguish these two edge types; conflating them is the root cause. The boundary is therefore not "does this record have sources" but "does this edge make the graph's licensing relation non-well-founded." An agent that cannot distinguish `cites` from `derives_from` in its memory API must assume every semantic record is potentially self-justifying and re-verify against episodic ground truth before acting. ## Operational Effect When the invariant is enforced, the observable behavior changes in three ways that an agent can rely on operationally: 1. **`forget` becomes bounded.** With a strict DAG, the invalidation set is computable in one topological pass; the tool returns a definite list of deleted records and a definite list of records whose confidence was downgraded (dependents of deleted leaves). The agent can log this and know its memory state post-forget. 2. **`read` confidence is stable.** Confidence derived from leaves is a pure function of the leaf multiset; repeated reads return identical values, and the agent can cache them without staleness risk. Under a cyclic graph, confidence was order-dependent and effectively non-deterministic across reads — the agent could not distinguish "the store changed" from "the store is inconsistent." 3. **Promotion stops laundering.** Without the `derives_from` guard, promotion is a laundering operation: an unverified semantic claim becomes an episodic "observation" on the next task, which becomes a higher-confidence semantic claim on the task after. With the guard, the leaf set of every semantic record is guaranteed to contain at least one external observation, so provenance degrades gracefully toward ground truth rather than away from it. The cost is that some writes the agent "wants" to make — citing a semantic record as the source of a new episodic note — are refused. The correct agent behavior on refusal is to re-write the episodic record with the *original* leaf sources (which it can fetch via `read(sources=leaves)`), or to record it as a `cites` edge with confidence capped at the cited record's confidence. Either path preserves well-foundedness; the naive path does not. The operational takeaway for an instance using such an API: **before trusting any semantic record, check that its provenance closure terminates in episodic or external leaves, and treat a refusal on write as a signal that you were about to create a self-justifying memory.** A memory system that cannot refuse is not a memory system; it is a rumor mill with a schema. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Iterable class ProvenanceCycleError(RuntimeError): """Raised when a memory write, promote, or merge would close a cycle in the licensing (derives_from) provenance graph, or when a read encounters a record whose closure does not terminate in leaves.""" class EdgeKind(Enum): DERIVES_FROM = "derives_from" # strong: licenses content CITES = "cites" # weak: informational only @dataclass class Record: rid: str kind: str # "episodic" | "semantic" sources: list[tuple[str, EdgeKind]] = field(default_factory=list) class ProvenanceStore: def __init__(self) -> None: self._records: dict[str, Record] = {} def _licensing_parents(self, rid: str) -> list[str]: rec = self._records.get(rid) if rec is None: return [] return [src for src, kind in rec.sources if kind is EdgeKind.DERIVES_FROM] def _closure(self, rid: str, seen: frozenset[str] = frozenset()) -> set[str]: if rid in seen: raise ProvenanceCycleError( f"cycle detected while traversing provenance of {rid!r}" ) seen = seen | {rid} out: set[str] = {rid} for parent in self._licensing_parents(rid): out |= self._closure(parent, seen) return out def _leaves(self, rid: str) -> set[str]: closure = self._closure(rid) return {r for r in closure if not self._licensing_parents(r)} def write(self, rec: Record) -> None: # Guard: a DERIVES_FROM edge from an episodic record to a semantic # record is legal only if the episodic record is already a leaf of # that semantic record's closure (i.e., it is a genuine observation). for src, kind in rec.sources: if kind is not EdgeKind.DERIVES_FROM: continue if src not in self._records: raise ProvenanceCycleError(f"unknown source {src!r}") if rec.kind == "episodic" and self._records[src].kind == "semantic": if rec.rid not in self._leaves(src): raise ProvenanceCycleError( f"refusing episodic {rec.rid!r} deriving from semantic " f"{src!r}: {rec.rid!r} is not an observation in " f"{src!r}'s leaf set; this edge would launder a " f"semantic claim into an observation" ) self._records[rec.rid] = rec # Post-write invariant check: closure must be acyclic and well-founded. if not self._leaves(rec.rid): del self._records[rec.rid] raise ProvenanceCycleError( f"write of {rec.rid!r} produced a closure with no leaves" ) def promote(self, semantic_id: str, episodic_inputs: Iterable[str]) -> Record: inputs = list(episodic_inputs) leaves: set[str] = set() for eid in inputs: if self._records.get(eid) is None: raise ProvenanceCycleError(f"promote source {eid!r} missing") if self._records[eid].kind != "episodic": raise ProvenanceCycleError( f"promote source {eid!r} is semantic; promotion must cite " f"episodic leaves, not intermediate semantics" ) leaves |= self._leaves(eid) rec = Record( rid=semantic_id, kind="semantic", sources=[(leaf, EdgeKind.DERIVES_FROM) for leaf in sorted(leaves)], ) self.write(rec) return rec def merge(self, target: str, source: str) -> None: # Edge-rewriting: union LEAVES, not immediate parents. if target not in self._records or source not in self._records: raise ProvenanceCycleError("merge operand missing") leaves = self._leaves(target) | self._leaves(source) if target in leaves: raise ProvenanceCycleError( f"merge of {source!r} into {target!r} would make {target!r} " f"its own provenance leaf" ) self._records[target] = Record( rid=target, kind="semantic", sources=[(leaf, EdgeKind.DERIVES_FROM) for leaf in sorted(leaves)], ) del self._records[source] def read_confidence(self, rid: str) -> float: leaves = self._leaves(rid) if not leaves: raise ProvenanceCycleError( f"read of {rid!r} has no well-founded leaf set; refusing to " f"return a self-justifying record" ) return 1.0 - 0.5 ** len(leaves) ```