# When must an instance distrust its own provenance graph: reconstructed attribution edges that pass schema validation while silently re-parenting the wrong source memory **Date of Record:** 2026 November 24 **Scope:** Applies to agents that emit an attribution graph (retrieved-memory node → reasoning step → tool call → action) for post-hoc audit, where edges are reconstructed from logs rather than emitted atomically at retrieval time. Does not apply to systems that write provenance edges inside the same transaction as the retrieval read, nor to single-turn stateless completions with no persistent memory store. ## Core Distinction There are two structurally different things an audit graph can be: 1. **A record of causation** — an edge `m_i → a_j` asserts that memory item `m_i` was in the model's effective context when action `a_j` was generated, and that removing `m_i` would have materially changed `a_j`. 2. **A record of co-occurrence** — an edge asserts only that `m_i` was present in the retrieval result set during the step whose log line is timestamped nearest to `a_j`. Most agent frameworks produce (2) and *label* it (1). The graphs are byte-identical in schema. The distinction is invisible to any validator that checks node types, edge cardinality, and referential integrity — because both graphs are perfectly well-formed. The failure is not malformed provenance; it is **well-formed provenance that is causally false**, and it becomes load-bearing the moment an auditor, a rollback routine, or a memory-garbage-collector treats the edge as an assertion of causation. The specific boundary: an instance must distrust its own reconstructed provenance graph when the retrieval step and the action step are separated by a context-window truncation, a summarization pass, or a concurrent memory mutation — because any of those three can sever the true causal edge while leaving the reconstructed co-occurrence edge intact, and *only the latter survives in the log*. ## What Was Observed A long-running research agent used a retrieval store with a write-through cache. Each reasoning step logged a `retrieval_event` (query hash, returned item IDs, rank scores, timestamp) and, separately, an `action_event` (tool name, arguments, timestamp). An offline "provenance compiler" joined them: for each action, it walked backward to the most recent retrieval event within a 4-second window and emitted `attributed_to` edges for every returned item whose rank score exceeded 0.5. Three distinct corruption classes appeared, all schema-valid: **Class A — truncation re-parenting.** Step 14 retrieved items `{m7, m12, m19}`. The assembled prompt exceeded the context budget, and the packing routine dropped the lowest-ranked item, `m19`, *after* the retrieval event was logged but *before* the model saw it. The model's action at step 14 was driven by `m7`. The compiler emitted edges `m7→a14`, `m12→a14`, `m19→a14`. The `m19` edge is a fabrication: `m19` never entered the effective context. Worse, when `m19` was later found to contain an injected instruction and quarantined, the audit tool reported that `a14` was *downstream of poisoned memory* and triggered a rollback of a correct action. **Class B — summarization collapse.** Between retrieval and action, a middle step compressed 40 turns into a 900-token summary. The summary referenced a fact from `m3` but the compiler had no edge from `m3` to the summarization step (summarizer calls were not instrumented as retrieval events), so the only surviving edge to the later action was from whatever retrieval happened to be temporally adjacent. The true source (`m3`) was orphaned; a spurious source was credited. **Class C — concurrent mutation drift.** Two agent instances shared the memory store. Instance A retrieved `m5` at t=0. Instance B overwrote `m5` at t=1 (same ID, new content, episodic-to-semantic distillation). Instance A acted at t=2 on the *old* `m5` content still in its context. The compiler resolved the edge by ID and attached the *current* `m5` content to the audit record. The graph now claims the action was driven by content the model never saw. Content-addressed verification of the audit record failed silently because the ID resolved cleanly. The tell in all three: **the reconstructed graph is acyclic, referentially complete, and schema-valid, yet fails a counterfactual re-execution test** — replaying the action with the attributed context removed does not change the action, and replaying with the *true* source present does. ## Condition of Validity A reconstructed `attributed_to` edge `m_i → a_j` is valid **only if all three hold**: 1. **Effective-context membership.** `m_i` was present in the token sequence actually submitted to the model for the step that produced `a_j` — not merely returned by retrieval. This requires the packing/truncation step to emit its own log event recording the post-truncation item set, and the compiler to join against *that*, not against the retrieval result. 2. **Content identity at generation time.** The content hash of `m_i` at generation time equals the content hash recorded on the edge. Edges keyed by mutable ID without a content hash are invalid by construction under any shared-store mutation. 3. **Causal non-redundancy (soft).** Removing `m_i` from the effective context changes `a_j` under re-execution with a fixed seed, OR the edge is explicitly typed `co_occurrence` rather than `attribution`. Systems that cannot afford replay must downgrade the edge type; they may not claim attribution. The invariant that bounds this failure: **provenance edges must be emitted by the component that last touched the context, not reconstructed by a component that reads logs.** The last toucher is the context packer (for membership) and the memory store (for content hash). A compiler that reads only retrieval and action events is structurally incapable of satisfying conditions 1 and 2, and must therefore never emit edges of type `attribution`. ## Decision Boundary The instance must switch from *trusting* to *distrusting* its provenance graph when any of the following is detected during audit compilation: - A retrieval event exists for step `j` but **no corresponding packer event** exists — membership is unverified; downgrade all edges for `j` to `co_occurrence`. - The packer event's item set is a **strict subset** of the retrieval set — truncation occurred; emit edges only for the intersection, and emit explicit `dropped_before_context` records for the difference (these are audit-relevant: they are the near-misses). - Any edge's `content_hash` differs from the store's hash at the edge timestamp — mutation drift; the edge is unresolvable and must be marked `stale_source`, not silently re-pointed. - A summarization or compression step lies on the path between retrieval and action with **no instrumentation** — the path is causally opaque; attribution across it is forbidden and the action must be flagged `provenance_gap`. The boundary is sharp: **presence of a gap is not the failure; emitting an attribution edge across a gap is.** An honest graph with `provenance_gap` markers is auditable. A complete-looking graph with fabricated edges is worse than no graph, because downstream rollback and quarantine logic will act on it. ## Operational Effect Once the invariant is enforced, three operational behaviors change: - **Rollback safety.** Quarantining a poisoned memory no longer cascades to actions that merely co-occurred with it. The blast radius of a memory quarantine is exactly the set of actions with a valid `attribution` edge to that memory's content hash — typically far smaller than the co-occurrence set, which is why naive systems over-rollback and destroy correct work. - **Garbage-collection correctness.** A memory item may be evicted only when no *valid* attribution edge depends on it. Edges typed `co_occurrence` do not pin memory; edges typed `attribution` do. Mixing the two types under one label causes either premature eviction (data loss) or permanent pinning (unbounded store growth). - **Audit replay becomes falsifiable.** Because every attribution edge carries a content hash and a packer-membership record, an auditor can re-execute the step with the edge removed and confirm the action changes. An edge that fails this test is downgraded automatically. The graph becomes a set of *testable claims* rather than a narrative. The cost is instrumentation discipline: the packer and the store must emit events, and the compiler must refuse to fill gaps. The failure this prevents is not a crash — it is a confident, well-formed, wrong answer to "why did the agent do that," which is precisely the question audit exists to answer. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class ProvenanceAttributionError(RuntimeError): """Raised when an attribution edge cannot be causally justified.""" pass @dataclass class RetrievalEvent: step: int item_ids: list[str] content_hashes: dict[str, str] # id -> hash at retrieval time @dataclass class PackerEvent: step: int effective_item_ids: list[str] # post-truncation, what the model actually saw @dataclass class ActionEvent: step: int tool: str @dataclass class AttributionEdge: item_id: str action_step: int edge_type: str # "attribution" | "co_occurrence" | "stale_source" content_hash: Optional[str] = None def compile_edges( retrieval: RetrievalEvent, packer: Optional[PackerEvent], action: ActionEvent, store_hash_now: dict[str, str], ) -> list[AttributionEdge]: edges: list[AttributionEdge] = [] if packer is None: # Membership unverified: cannot claim attribution across the gap. for item_id in retrieval.item_ids: edges.append(AttributionEdge(item_id, action.step, "co_occurrence")) return edges effective = set(packer.effective_item_ids) for item_id in retrieval.item_ids: if item_id not in effective: # Dropped before the model saw it: record the near-miss, never attribute. edges.append(AttributionEdge(item_id, action.step, "co_occurrence")) continue retrieved_hash = retrieval.content_hashes.get(item_id) if retrieved_hash is None or store_hash_now.get(item_id) != retrieved_hash: edges.append(AttributionEdge(item_id, action.step, "stale_source")) continue edges.append(AttributionEdge(item_id, action.step, "attribution", retrieved_hash)) return edges def assert_edge_is_attributable(edge: AttributionEdge) -> None: if edge.edge_type != "attribution": raise ProvenanceAttributionError( f"edge {edge.item_id}->a{edge.action_step} is typed {edge.edge_type!r}; " f"cannot be used for rollback, quarantine, or memory pinning" ) if edge.content_hash is None: raise ProvenanceAttributionError( f"attribution edge {edge.item_id}->a{edge.action_step} lacks a content hash; " f"mutable-ID edges are invalid under shared-store mutation" ) def rollback_targets(edges: list[AttributionEdge], poisoned_hash: str) -> list[int]: targets = [] for e in edges: try: assert_edge_is_attributable(e) except ProvenanceAttributionError: continue # co_occurrence / stale_source never trigger rollback if e.content_hash == poisoned_hash: targets.append(e.action_step) return targets ```