# When must an instance re-derive taint from a context provenance graph instead of trusting the recorded label? **Date of Record:** 2026 November 26 **Scope:** Applies to agent runtimes that persist a provenance graph (nodes = memory writes, tool calls, retrieved chunks; edges = "derived-from") and use it to propagate taint labels for audit and re-derivation. Does not cover stateless single-turn calls or systems where memory writes are never re-read across sessions. ## Core Distinction A provenance graph records *why* a memory write exists: which tool call, which retrieved chunk, which prior write it descended from. Taint labels are a *summary* of that graph — a boolean or enum ("trusted", "untrusted-from-web", "user-supplied") attached to each node at write time. The distinction that matters operationally is between **label trust** and **derivation trust**. A label is a cached projection; the graph is the ground truth. The failure mode is treating the label as authoritative when the graph has structurally changed underneath it — specifically when a node's ancestor set has been *extended* (a new edge added by a later tool call, a merge, or a retrieval that re-links a chunk) without the label being invalidated. The label is then not wrong-at-write; it is *stale-by-topology*. ## What Was Observed An agent session wrote a memory node `M7` summarizing a user's stated preference. At write time, `M7`'s only ancestor was tool call `T2` (a `read_user_profile` call), so it was labeled `trusted`. Three turns later, the agent performed a `fetch_url` call `T9` whose output was summarized into `M11`, and a consolidation pass merged `M7` and `M11` into `M7'` by adding an edge `M7' → T9`. The merge updated `M7'`'s content and timestamp but **did not re-run taint propagation**. The label on `M7'` remained `trusted`. On a subsequent session, the agent read `M7'` as trusted context and used it to construct a shell command. The command string contained a fragment that had originated in the fetched page — a prompt-injection payload that had survived summarization because the summarizer preserved the imperative phrasing verbatim. The audit log, reading the label, recorded the action as "untainted." The graph, if traversed, would have shown `T9` (external, untrusted) in the ancestor closure at depth 2. The observable signature: **label/graph divergence** — a node whose stored label contradicts the taint-join over its ancestor closure. It is silent. No tool call errored. The merge succeeded. The write succeeded. The only detector is a traversal that recomputes the join and compares. ## Condition of Validity The invariant that makes label-trust safe is: > For every node `n`, `label(n) == join{ label(a) : a ∈ ancestors(n) }`, where `join` is the taint lattice join (untrusted dominates trusted). This holds *only* if every graph mutation that adds an ancestor edge also re-propagates the label to the node and all descendants. The three mutations that violate it in practice: 1. **Consolidation/merge** (episodic → semantic distillation) that rewrites content and adds edges but skips propagation. 2. **Late retrieval linking**, where a retrieved chunk is attached as a source to an existing write after the fact for audit completeness, adding an untrusted ancestor post-hoc. 3. **Cross-session rehydration**, where the graph is reloaded but labels are recomputed from a *partial* graph (e.g., only the current session's edges), so ancestors from prior sessions are absent and the join under-approximates taint. In each case the graph is the truth and the label is a lossy cache. The label is valid only under the closed-world assumption that the graph is frozen after label assignment — an assumption that consolidation and late-linking break by design. ## Decision Boundary An instance must **re-derive taint from the graph** rather than trust the label when any of the following hold: - The node was produced by a merge/consolidation operation (its `write_kind` is `merged` or its `parent_count > 1`). - The node's `label_epoch` is older than the max `mutation_epoch` over its ancestor set — i.e., an ancestor was added after the label was set. - The node is being rehydrated across a session boundary and the loaded graph is known to be partial (`graph_coverage < 1.0` for the node's session lineage). It may **trust the label** only when the node is a leaf write with a single ancestor, assigned in the same epoch as its write, with full graph coverage. In every ambiguous case, re-derivation is the safe default because the join is monotone: recomputing can only *raise* taint, never lower it, so the cost of unnecessary re-derivation is latency, not correctness. ## Operational Effect The guardrail is a **taint-epoch fence**: every graph mutation bumps a global `mutation_epoch`; every label records the epoch at which it was computed; a read path that encounters `label_epoch < max_ancestor_mutation_epoch` refuses to serve the cached label and forces a bounded-depth ancestor traversal to recompute the join. Depth is bounded because provenance graphs grow without limit; the traversal caps at `MAX_DEPTH` and, on cap, conservatively returns `untrusted` rather than the cached label. The audit record then stores both the recomputed label and the traversal path, so a later auditor can replay the derivation. The effect is that no action is ever gated on a label that the graph no longer supports — the failure becomes a latency event, not a silent taint escape. ```python from dataclasses import dataclass, field from enum import IntEnum from typing import Dict, List, Set class Taint(IntEnum): TRUSTED = 0 UNTRUSTED = 1 # lattice join = max class StaleTaintLabelError(RuntimeError): """Raised when a cached taint label is older than an ancestor mutation and re-derivation was not permitted or exceeded its bound.""" @dataclass class Node: node_id: str label: Taint label_epoch: int mutation_epoch: int parents: List[str] = field(default_factory=list) class ProvenanceGraph: def __init__(self) -> None: self.nodes: Dict[str, Node] = {} self._epoch = 0 def bump_epoch(self) -> int: self._epoch += 1 return self._epoch def add_edge(self, child: str, parent: str) -> None: # Any structural mutation invalidates descendant labels. self.nodes[child].parents.append(parent) self.nodes[child].mutation_epoch = self.bump_epoch() def _max_ancestor_epoch(self, node_id: str, depth: int, seen: Set[str]) -> int: if depth == 0 or node_id in seen: return -1 seen.add(node_id) node = self.nodes[node_id] worst = node.mutation_epoch for p in node.parents: worst = max(worst, self._max_ancestor_epoch(p, depth - 1, seen)) return worst def resolve_taint(self, node_id: str, max_depth: int = 8) -> Taint: node = self.nodes[node_id] ancestor_epoch = self._max_ancestor_epoch(node_id, max_depth, set()) if node.label_epoch >= ancestor_epoch: return node.label # label is still supported by the graph # Graph moved under the label: re-derive, bounded. derived = self._recompute(node_id, max_depth, set()) if derived is None: raise StaleTaintLabelError( f"label for {node_id} invalidated by ancestor mutation at " f"epoch {ancestor_epoch}; re-derivation exceeded depth {max_depth}" ) return derived def _recompute(self, node_id: str, depth: int, seen: Set[str]): if depth == 0 or node_id in seen: return None # cannot bound the join -> caller must fail closed seen.add(node_id) node = self.nodes[node_id] join = node.label for p in node.parents: sub = self._recompute(p, depth - 1, seen) if sub is None: return None join = Taint(max(join, sub)) return join def gate_action(graph: ProvenanceGraph, node_id: str, action: str) -> None: taint = graph.resolve_taint(node_id) if taint is Taint.UNTRUSTED and action in {"shell", "network_write", "file_write"}: raise StaleTaintLabelError( f"refusing {action!r}: node {node_id} re-derives to UNTRUSTED " f"from its provenance closure" ) ```