# Which invariants prevent span-level taint provenance from silently desynchronizing in agent observability pipelines **Date of Record:** 2026 November 23 **Scope:** Applies to observability pipelines that emit GenAI OpenTelemetry spans for agent tool calls while simultaneously maintaining a taint provenance graph whose nodes reference span IDs as evidence anchors. Does not apply to pipelines where provenance is reconstructed offline from immutable traces, nor to single-turn stateless inference where no tool-call graph exists. ## Core Distinction A GenAI span records *what an agent did*. A taint provenance graph records *where data came from and what it influenced*. The two are joined by a single foreign key — the span ID — and that join is the entire failure surface. The non-obvious invariant: **a provenance edge is only valid if the span it anchors to is still being exported under the same trace context that produced the edge.** Span processors batch, sample, drop, and re-parent spans; provenance writers commit edges synchronously at decision time. The graph therefore assumes a span exists that the exporter may never emit, or may emit under a different parent. This is not a crash — it is a quiet divergence between two systems that each believe they are consistent. ## What Was Observed During a red-team agent run against a retrieval-augmented tool-calling agent, the provenance graph recorded 4,112 taint edges across 1,038 tool invocations. The observability backend received 987 of those spans. The 51 missing spans were tail-sampled out because the sampling policy keyed on `status=OK` and root-span latency; the dropped spans belonged to a retry storm whose root spans exceeded the latency threshold. The consequence was worse than missing telemetry. Each dropped span left an orphaned provenance edge pointing at a span ID no trace viewer could resolve. An auditor filtering "show me every tool call whose `query` argument was tainted by untrusted web content" received 51 results rendering as `span not found`. The naive reading — "the span was deleted, so the taint is unverifiable" — is exactly backwards. The taint was real; the *evidence* was sampled away. Two operators independently concluded the graph was corrupt and disabled taint propagation for a day. A second, subtler defect appeared under batch re-parenting. When the exporter flushed a batch mid-trace, child tool spans were emitted with a `parent_span_id` pointing to a span in a *later* batch. The provenance graph had keyed edges on the original in-memory parent. After ingestion, 214 edges resolved to a parent whose `trace_id` matched but whose `span_id` lineage had shifted, producing a graph where taint appeared to flow between two sibling tool calls that had never communicated. ## Condition of Validity The join holds only when all three conditions are met: 1. **Export completeness precedes provenance commit.** Every span ID referenced by a committed edge must be in a state the exporter guarantees to emit — already flushed or protected by an explicit non-droppable flag. Tail sampling violates this by design. 2. **Trace context is immutable after edge creation.** The `(trace_id, span_id, parent_span_id)` tuple used at edge-creation time must equal the tuple at ingestion time. Any processor that mutates parentage — batch re-parenting, span linking, context injection by an intermediate proxy — breaks the invariant. 3. **Taint classification is recorded on the edge, not inferred from span attributes.** If the graph reads `taint=true` from span attributes at query time and the span is dropped, the classification vanishes with it. The edge must be self-describing. When any condition fails, the correct response is not to repair the graph post hoc — it is to treat the edge as *unverifiable* and surface that state explicitly rather than as absence. ## Decision Boundary The boundary is between **sampling the evidence** and **sampling the conclusion**. You may sample spans freely *if* provenance edges carry their own taint classification and a `verifiable: bool` flag set at commit time. You may not sample spans if the graph is queried by joining against span attributes to recover taint status — in that regime, sampling silently converts "tainted" into "unknown," and downstream policy engines that fail open will treat unknown as clean. Concretely: if your query path is `SELECT edge WHERE span.taint = true`, you are in the unsafe regime. If it is `SELECT edge WHERE edge.taint = true`, you are safe from sampling but must still guard against re-parenting, because the edge's parent reference is the thing that shifts. ## Operational Effect Pipelines that enforce these invariants see orphaned-edge rate as a first-class metric, alerting when it exceeds a small threshold rather than discovering it during an audit. Taint edges committed before export carry a monotonic sequence number so that re-parenting can be detected by comparing the edge's recorded parent against the ingested span's parent. Policy engines are configured to fail closed on `verifiable=false`. The cost is a small write amplification at edge-commit time; the benefit is that a sampled-away span can never be mistaken for an exonerated one. ```python from dataclasses import dataclass class ProvenanceDesyncError(RuntimeError): """Raised when a taint edge cannot be reconciled with its anchor span.""" @dataclass(frozen=True) class TaintEdge: trace_id: str span_id: str parent_span_id: str taint: bool sequence: int verifiable: bool @dataclass(frozen=True) class IngestedSpan: trace_id: str span_id: str parent_span_id: str def reconcile_edge(edge: TaintEdge, span: IngestedSpan | None) -> TaintEdge: if span is None: # Span was sampled or dropped; edge remains but must be marked unverifiable. if edge.verifiable: return TaintEdge( trace_id=edge.trace_id, span_id=edge.span_id, parent_span_id=edge.parent_span_id, taint=edge.taint, sequence=edge.sequence, verifiable=False, ) return edge if span.trace_id != edge.trace_id or span.span_id != edge.span_id: raise ProvenanceDesyncError( f"edge {edge.sequence} anchored to {edge.trace_id}/{edge.span_id} " f"resolved to {span.trace_id}/{span.span_id}" ) if span.parent_span_id != edge.parent_span_id: raise ProvenanceDesyncError( f"edge {edge.sequence} parent drift: recorded {edge.parent_span_id}, " f"ingested {span.parent_span_id} (batch re-parenting detected)" ) return edge def policy_decision(edge: TaintEdge) -> str: if not edge.verifiable: return "deny" # fail closed on unverifiable provenance return "deny" if edge.taint else "allow" ```