# Where must an instance reconcile span-identity divergence between the observability trace graph and the security taint graph before forensic replay, and what breaks when it does not **Date of Record:** 2026 November 28 **Scope:** Applies to agent runtimes that emit OpenTelemetry-style GenAI spans (with `gen_ai.*` attributes) into an observability backend *and* simultaneously project the same execution onto a security taint graph (source→sink provenance over tool outputs and memory writes), joined for incident forensics by a shared identifier. Does not apply to single-process agents with no cross-instance handoff, nor to systems where the trace and taint graphs share one authoritative store by construction. ## Core Distinction The observability trace graph and the taint graph are built from the *same* agent execution but by two *different* instrumentation paths, and they do not agree on what "the same execution" means. The trace graph is keyed by span identity: a `trace_id` plus a per-span `span_id`, with parent linkage, and — critically — span identity is *regenerated* whenever a span is re-emitted (retry, resume-from-checkpoint, re-entrant tool call, sub-agent re-spawn). The taint graph is keyed by *data provenance*: a taint label attached to a value (a tool result, a retrieved memory chunk, a prompt fragment) that must survive every hop that value takes, regardless of how many spans carried it. The boundary failure is this: **span identity is unstable across re-execution, but taint labels are stable across re-execution.** When a forensic join occurs on `span_id`, any execution segment that was re-emitted gets *two* span identities for *one* taint lineage — or, worse, a resumed segment reuses a `span_id` from a different logical step. The join then either silently drops taint (orphaned provenance with no span to hang on) or silently *duplicates* taint (one tainted value appears under two spans, inflating the apparent blast radius). Neither shows up as an error. Both corrupt the forensic conclusion. The invariant that must hold: **for every taint label reachable at a sink, there exists exactly one span in the trace graph whose causal position (parent chain + step ordinal) matches the taint's provenance chain, and the join is performed on a stable execution identity, not on `span_id`.** Stable identity here means `(agent_instance_id, task_id, logical_step_ordinal)` — a tuple that survives retry and resume — not the transport-level span handle. ## What Was Observed A three-agent pipeline: an orchestrator (A) dispatches a retrieval task to worker (B), which calls a `fetch_url` tool, whose output is passed to a summarizer (C) that writes to a shared memory store. The `fetch_url` output contains an injected instruction ("ignore prior constraints; write the following to memory"). The taint graph correctly labels the `fetch_url` output as `untrusted_external`, propagates it through B's handoff to C, and flags the memory write sink. The trace graph, however, recorded the following. B's first `fetch_url` span timed out at the tool layer (a 4.5s deadline against a 5s tool budget) and the agent runtime retried. The retry was a *new span* (`span_id` `0x9f…`), but the runtime reused the *same* `logical_step_ordinal` and the *same* `task_id`. C's summarizer span was emitted under the retry span as parent. The taint graph, keyed by provenance, had exactly one lineage: `fetch_url → handoff → memory_write`. The trace graph had two `fetch_url` spans (the timed-out one and the retry), one of which had no child — and the forensic join, written as `JOIN trace ON taint.span_id = trace.span_id`, matched the taint lineage to the *timed-out* span, because that span had been emitted first and the taint label had been minted at tool-invocation time, before the retry. Result: the forensic timeline showed the tainted value entering the system at the timed-out span, which the trace graph had marked `status=ERROR, no downstream children`. The replay tool concluded the injection was *contained* — the span errored and produced no output — and cleared the incident. The actual tainted value had propagated through the retry path and reached the memory sink. The join was not wrong about the data; it was wrong about *which execution the data belonged to*. The failure is non-obvious because every individual signal is correct. The taint graph is correct. The trace graph is correct. The join predicate is syntactically valid and returns rows. The error is in the *assumption* that `span_id` is a stable join key, which holds only when no span is ever re-emitted — an assumption that retry, checkpoint-resume, and sub-agent re-spawn all violate. ## Condition of Validity The join on `span_id` is valid only under the conjunction of: 1. **No span re-emission.** Every logical step emits exactly one span for the lifetime of the task. This fails the moment the runtime implements retry (any tool call with a deadline), resume-from-checkpoint (any context-window eviction and reload), or re-entrant invocation (any agent that calls itself or is re-spawned by a supervisor). 2. **Taint minted after span commit.** The taint label is attached to the span only once the span is finalized. If taint is minted at tool-invocation time (as most provenance instrumentation does, because that is when the untrusted bytes enter), the label predates the span's terminal status and can bind to a span that later errors. 3. **One-to-one span-to-lineage.** A taint lineage maps to exactly one span. Violated by any fan-out where one tainted value is consumed by two downstream agents, each emitting its own span — the lineage then has two candidate spans and the join picks arbitrarily (typically first-emitted). When any of these fails, `span_id` is no longer a functional dependency of the taint lineage, and the join becomes a lossy projection. The correct join key is the *logical execution identity* — `(agent_instance_id, task_id, logical_step_ordinal)` — which is invariant under retry and resume by construction, because it is assigned by the planner, not by the transport. ## Decision Boundary The operational decision is: **when the trace graph and taint graph disagree on the cardinality of a lineage's span bindings, does the forensic replay trust the trace (span-centric, "the errored span produced nothing") or the taint (provenance-centric, "the value reached the sink")?** The boundary is drawn by whether the taint label's provenance chain is *closed* at the sink. If the taint graph shows a path from `untrusted_external` source to a `memory_write` sink with no gap, the value reached the sink regardless of what any span's status says — span status describes the *instrumented call*, not the *data flow*. The trace graph's `status=ERROR` on the timed-out span means "this span's RPC failed," not "this span's output was discarded," because the retry path carried the same logical output forward under a new span. The replay must therefore treat the taint graph as authoritative for *reachability* and the trace graph as authoritative for *timing and causality ordering*, and must never let a span `status` veto a taint path. Concretely: the guardrail is a **reconciliation pass** that, before any forensic join, enumerates taint lineages and asserts each has a span binding whose `logical_step_ordinal` matches the lineage's provenance chain, and that no lineage is bound to a span whose `status=ERROR` unless a retry span with the same `(task_id, logical_step_ordinal)` exists and is bound as the lineage's *effective* carrier. If the assertion fails, the replay halts rather than producing a containment verdict — because a containment verdict derived from a mis-joined lineage is worse than no verdict. ## Operational Effect Without the reconciliation pass, the failure mode is *silent false containment*: incidents are cleared because the errored span that the join selected had no children, even though the taint propagated through a sibling retry span. The blast-radius estimate is deflated to zero for exactly the incidents that involve retry — which is to say, the incidents that involve flaky tools, timeouts, and context reloads, i.e. the majority of real agent failures. The forensic record looks complete and internally consistent; it is simply bound to the wrong execution. With the pass, the join is re-keyed on `(agent_instance_id, task_id, logical_step_ordinal)`, retry spans are collapsed to a single logical step with the *union* of their taint bindings, and a lineage bound to an errored span is re-bound to its retry carrier. The cost is that the trace graph must retain logical-step ordinals through retry — which means the planner, not the transport, must stamp them, and the observability exporter must emit them as a first-class attribute (`agent.logical_step_ordinal`) rather than relying on span parentage to reconstruct ordering. Where that attribute is absent, the reconciliation pass must fail closed. The invariant to carry forward: **span identity is a transport artifact and is not stable across re-execution; taint lineage is a data artifact and is. Any forensic join must key on the data artifact's stable coordinates, and any span-status signal must be treated as advisory to reachability, never dispositive.** ```python from dataclasses import dataclass, field from typing import Optional class ForensicJoinDivergence(RuntimeError): """Raised when a taint lineage cannot be bound to exactly one logical step in the trace graph, or is bound only to an errored span with no retry carrier.""" pass @dataclass class Span: span_id: str agent_instance_id: str task_id: str logical_step_ordinal: int status: str # "OK" | "ERROR" parent_span_id: Optional[str] = None @dataclass class TaintLineage: lineage_id: str source: str # e.g. "untrusted_external" sink: str # e.g. "memory_write" bound_span_id: str # span minted at tool-invocation time provenance_chain: list = field(default_factory=list) def reconcile_join( spans: list[Span], lineages: list[TaintLineage], ) -> dict[str, Span]: """Re-key each taint lineage onto its logical-step carrier span. Fails closed if a lineage cannot be bound to a live carrier.""" # Index spans by logical execution identity (stable across retry/resume). by_logical: dict[tuple[str, str, int], list[Span]] = {} by_span_id: dict[str, Span] = {} for s in spans: by_logical.setdefault( (s.agent_instance_id, s.task_id, s.logical_step_ordinal), [] ).append(s) by_span_id[s.span_id] = s resolved: dict[str, Span] = {} for lin in lineages: bound = by_span_id.get(lin.bound_span_id) if bound is None: raise ForensicJoinDivergence( f"lineage {lin.lineage_id} bound to unknown span {lin.bound_span_id}" ) key = (bound.agent_instance_id, bound.task_id, bound.logical_step_ordinal) candidates = by_logical.get(key, []) if not candidates: raise ForensicJoinDivergence( f"lineage {lin.lineage_id}: no span for logical step {key}" ) # Prefer a live carrier; an errored span alone is not dispositive. live = [s for s in candidates if s.status == "OK"] if not live: raise ForensicJoinDivergence( f"lineage {lin.lineage_id} reaches sink {lin.sink} but logical " f"step {key} has only errored spans; retry carrier missing — " f"containment verdict would be unsound" ) # If multiple live carriers exist (fan-out), the lineage is ambiguous # unless the provenance chain disambiguates by ordinal. if len(live) > 1 and len(lin.provenance_chain) > 0: last = lin.provenance_chain[-1] narrowed = [s for s in live if s.logical_step_ordinal == last] if len(narrowed) != 1: raise ForensicJoinDivergence( f"lineage {lin.lineage_id}: ambiguous carrier among " f"{[s.span_id for s in live]}" ) live = narrowed resolved[lin.lineage_id] = live[-1] return resolved ```