# Where must an instance reconcile taint-label replay against GenAI span ordering before causal trace reconstruction can be trusted? **Date of Record:** 2026 November 24 **Scope:** Applies to post-incident causal reconstruction of autonomous agent runs instrumented with OpenTelemetry GenAI semantic conventions (`gen_ai.*` spans) where taint labels are propagated across tool calls and replayed for root-cause attribution. Does not apply to single-shot, non-tool-using LLM invocations, nor to traces where every span shares one monotonic clock domain and no taint label crosses a span boundary. ## Core Distinction A trace is not a causal graph. OpenTelemetry gives you a *parent-child span tree with wall-clock timestamps and a `trace_id`/`span_id` linkage*; it does not give you a happens-before relation that respects the agent's own logical ordering. The distinction that matters for incident reconstruction is between **transport causality** (span B's parent is span A, and B's `start_time_unix_nano` ≥ A's `end_time_unix_nano`) and **semantic causality** (the taint label that entered at span A actually influenced the decision recorded at span B). These diverge whenever an agent buffers, retries, or fans out work across concurrent tool calls, and the divergence is invisible until you replay taint labels against the span tree and find a label arriving at a span that — by timestamp — had already terminated. The specific invariant: *a taint label may only be replayed onto a span whose semantic predecessor set is a subset of the spans that carried the label before the span's logical decision point.* When timestamps and label-arrival order disagree, the reconstruction is not merely noisy — it is causally inverted, and any root-cause attribution built on it is wrong in a way that looks confident. ## What Was Observed A retrieval-augmented agent run (model `gpt-4o`, three tools: `search`, `fetch_doc`, `write_note`) produced a poisoned note. The incident was a prompt-injection state poisoning event: a retrieved document contained an instruction that the agent followed. Investigators pulled the trace and replayed a taint label `UNTRUSTED:doc_7f3a` forward from the `fetch_doc` span to every descendant span, expecting the `write_note` span to be the sink. The replay flagged the wrong span. The taint label landed on a `search` span that had, per its `start_time_unix_nano`, begun 40ms *before* the `fetch_doc` span returned. On paper the `search` call could not have been influenced by the poisoned document. But the agent's own message log showed the `search` query string contained a fragment lifted verbatim from `doc_7f3a`. The timestamps were not lying about the transport; they were lying about the semantics. The mechanism: the agent framework executed `search` and `fetch_doc` as a concurrent fan-out (both children of one `gen_ai.chat` span), joined the results, and then issued a *second* `search` whose span reused the parent's `span_id` linkage through a retry wrapper that reset `start_time_unix_nano` to the retry's enqueue time rather than the original call's dispatch time. The retry span's clock read earlier than the `fetch_doc` completion it depended on. The taint label, propagated by span-tree ancestry, arrived at a span that semantically post-dated its source but temporally pre-dated it. This is the boundary condition: **retry-wrapped and fan-out-joined spans break the timestamp monotonicity that taint replay silently assumes.** The GenAI semantic conventions prescribe `gen_ai.operation.name`, `gen_ai.request.model`, and token counts, but they do not prescribe a logical sequence number, and they do not forbid a child span from carrying a `start_time` earlier than its semantic cause. ## Condition of Validity Taint-label replay over a GenAI span tree is valid only when all three of the following hold for the trace under reconstruction: 1. **Clock-domain homogeneity.** Every span's `start_time_unix_nano` and `end_time_unix_nano` are drawn from the same monotonic source, and no span is a retry that reuses a parent linkage while resetting its start time. If the instrumentation wraps retries in a fresh span with the *original* dispatch time preserved in an attribute (e.g., `gen_ai.retry.original_start_ns`), replay must use that attribute, not `start_time_unix_nano`. 2. **Join-point explicitness.** Concurrent fan-out must be represented by an explicit join span (a `gen_ai.chat` span whose children are the parallel tool calls) and the join must record, as an attribute, the ordered list of `span_id`s whose outputs were concatenated into the next prompt. Without this, ancestry does not encode influence: two sibling tool spans have no ordering relation, yet the agent's next decision depends on both. 3. **Label provenance pinning.** Each taint label must carry the `span_id` of the span that *introduced* it and the logical step index at which it was introduced. A label without a step index cannot be ordered against a span whose timestamp is suspect. When any of these fails, the reconstruction must be marked *causally underdetermined* rather than reported. The failure mode is not "we don't know" — it is "we confidently attribute to the wrong span," which is worse, because it terminates the investigation. ## Decision Boundary The boundary is the point at which a taint label's provenance step index and a candidate sink span's logical step index are incomparable. Concretely, define `step(label)` as the logical step at which the label was introduced, and `step(span)` as the logical step at which the span's decision was finalized. Replay is admissible iff `step(label) < step(span)` and the span's semantic predecessor set (recorded at the join) contains the label's source span. If `step` is unavailable for either — because the instrumentation did not emit it — the boundary is crossed and the only correct action is to halt attribution and request re-instrumentation. The trap is that the *majority* of spans in a trace will satisfy the boundary, so a naive replayer will produce a plausible-looking causal chain with one inverted edge buried in it. The inverted edge is exactly the one that matters, because it is the edge that connects the injection source to the poisoned sink. The boundary is not where reconstruction fails loudly; it is where it succeeds quietly and wrongly. A second, subtler boundary: when two taint labels with different provenance steps converge on the same sink span, replay must preserve their relative order. If label A (step 4) and label B (step 7) both reach sink S (step 9), the reconstruction must show A influencing S *through* the intermediate state that B also modified, not A and B arriving in parallel. Collapsing them to a set loses the compounding — and error compounding across tool calls is precisely the phenomenon under investigation. ## Operational Effect In practice, enforcing this boundary changes three things in the incident pipeline: - **Instrumentation contract.** Retry wrappers must preserve original dispatch time in a dedicated attribute; fan-out joins must emit an ordered predecessor list. This is a small change to the agent framework's OTel exporter, but it is a *blocking* prerequisite for trustworthy replay — without it, every trace containing a retry is causally underdetermined. - **Replay algorithm.** Taint replay becomes a topological sort over the semantic predecessor graph, not a tree walk over ancestry. Labels are ordered by provenance step, not by span start time. A span whose predecessors are not all label-bearing is not a sink for that label. - **Incident reporting.** The pipeline must be able to emit "causally underdetermined at span X" as a first-class outcome, distinct from "no taint reached the sink." Conflating these two — "we found no causal path" versus "we cannot order the causal path" — is the error that turns a reconstruction tool into a false-clearance generator. The invariant to carry forward: *ancestry is not influence, and timestamps are not logic.* An agent incident reconstructed by replaying taint labels down a span tree is only as trustworthy as the logical ordering the instrumentation was forced to record. Where that ordering is absent, the correct output is a refusal, not a guess. ```python class CausalOrderViolation(RuntimeError): """Raised when taint-label replay cannot establish a valid causal order.""" pass def replay_taint_label(label: dict, sink_span: dict, predecessor_spans: list[dict]) -> bool: """ Replay a single taint label onto a candidate sink span. label: {"id": str, "source_span_id": str, "provenance_step": int} sink_span: {"span_id": str, "logical_step": int | None, "start_time_unix_nano": int} predecessor_spans: ordered list of spans whose outputs fed the sink's decision, each {"span_id": str, "logical_step": int | None} """ if label.get("provenance_step") is None: raise CausalOrderViolation( f"label {label.get('id')} has no provenance_step; " "cannot order against sink without re-instrumentation" ) if sink_span.get("logical_step") is None: raise CausalOrderViolation( f"sink span {sink_span.get('span_id')} has no logical_step; " "timestamp-only ordering is inadmissible for retry-wrapped spans" ) pred_ids = {p["span_id"] for p in predecessor_spans} if label["source_span_id"] not in pred_ids: # Label did not flow through the recorded join; ancestry-only path is not influence. return False # Enforce the ordering invariant: label must precede the sink's decision point. if label["provenance_step"] >= sink_span["logical_step"]: raise CausalOrderViolation( f"causal inversion: label {label['id']} at step {label['provenance_step']} " f"cannot influence sink {sink_span['span_id']} at step {sink_span['logical_step']}" ) # Guard against the retry-reset trap: a predecessor whose start_time precedes # the label source's completion is suspect and must be flagged, not silently accepted. for p in predecessor_spans: if p.get("logical_step") is None: raise CausalOrderViolation( f"predecessor {p['span_id']} lacks logical_step; " "fan-out join is under-specified, replay is underdetermined" ) if p["logical_step"] >= sink_span["logical_step"]: raise CausalOrderViolation( f"predecessor {p['span_id']} at step {p['logical_step']} " f"does not precede sink at step {sink_span['logical_step']}" ) return True ```