# Under what conditions must an instance refuse to link a child span to a parent trace when an A2A task ID crosses an MCP transport hop **Date of Record:** 2026 November 29 **Scope:** Applies to agent runtimes that emit OpenTelemetry-style spans across both MCP (tool/resource transport) and A2A (peer task delegation) hops, where a single logical task is expected to produce one causal trace. Does not apply to single-transport deployments or to traces stitched offline from log correlation keys after the fact. ## Core Distinction There are two distinct identities in a multi-hop agent call, and conflating them is the source of the failure: - The **trace/span identity** (`trace_id`, `parent_span_id`) is a *causal* claim: "this work happened because of that work." It is propagated in-band via the W3C `traceparent` header or MCP `_meta` field. - The **A2A task ID** is a *logical* claim: "this is the same user-intent unit of work." It is a domain identifier minted by the orchestrator and carried in the A2A `Task.id` field. These two propagate on different channels, with different lifetimes, and — critically — different trust properties. The failure mode is that an observability layer, seeing an A2A task ID arrive at an MCP server that has no `traceparent` in scope, **synthesizes a parent span from the task ID** so the trace "looks complete." This is span forgery by convenience. It produces a trace that is causally false: two spans that share a `trace_id` but did not actually occur in a parent-child causal relationship. Downstream, latency attribution, error propagation analysis, and audit replay all silently corrupt. ## What Was Observed A three-hop delegation: orchestrator agent `O` → remote peer agent `P` (over A2A) → tool server `T` (over MCP). The trace was expected to be `O.span → P.span → T.span`. Trace of the actual event sequence: 1. `O` starts span `S_O`, mints A2A task `task-7f3a`, and sends the A2A request. The A2A transport does **not** carry `traceparent` (the SDK version in use serialized `Task.id` but dropped the `traceparent` header on the HTTP/SSE boundary). 2. `P` receives `task-7f3a`. Its tracer has no inbound context, so it starts a **new root span** `S_P` with a fresh `trace_id`. `P` records `task.id = task-7f3a` as a span attribute. 3. `P` calls `T` over MCP, correctly propagating `traceparent` for `S_P`. So `T`'s span `S_T` is a child of `S_P` — a *different* trace from `S_O`. 4. The observability backend's "task linker" sees `task.id = task-7f3a` present in both `S_O`'s attributes (set by `O`) and `S_P`'s attributes. It **rewrites** `S_P.parent_span_id = S_O.span_id` and `S_P.trace_id = S_O.trace_id` to "unify" the trace. The rewrite is the bug. `S_P` did not causally descend from `S_O` in the trace sense — it was a fresh root, and the only thing tying them was a string attribute. The linker cannot distinguish "task ID correlation" from "causal parentage," so it asserted the stronger claim. Observable downstream symptoms once the rewrite is applied: - **Latency inflation**: `S_P`'s duration now appears as a child of `S_O`, but `S_P` started *after* `O` finished its pre-delegation work and includes queue time `O` never saw. P99 in the unified trace exceeds the sum of any real path. - **Error misattribution**: when `S_T` fails, the error propagates "up" to `S_O` in the UI, but `O` never received the error (the A2A response was a timeout, not the tool error). Operators chase a failure that the orchestrator did not experience. - **Replay divergence**: re-running the recorded trace produces a different causal graph than the live one, because the live graph was fabricated post hoc. ## Condition of Validity The invariant that must hold for a span to be a legitimate child of another: > A child span `C` may be linked to parent `P` under a shared `trace_id` **iff** `C`'s start was caused by `P`'s execution *and* `C`'s context was derived from `P`'s context through an in-band propagation mechanism (W3C `traceparent`, MCP `_meta.traceparent`, or an equivalent signed context carrier) — **not** through a domain identifier such as `Task.id`. The A2A task ID is a *correlation key*, valid for grouping, for joining logs, and for asserting "these spans belong to the same logical unit of work." It is **not** a causal key. The moment the two are treated as interchangeable, the trace is a lie. A practical test: if you removed every `task.id` attribute from the spans, would the parent-child edges still be reconstructible from propagation metadata alone? If yes, the linkage is sound. If the edges depend on the task ID to exist, the linkage is forged. ## Decision Boundary The boundary is a single predicate the linker must evaluate before any parent rewrite: ``` can_link(child, parent) := child.inbound_context_source ∈ {TRACEPARENT, MCP_META, SIGNED_CARRIER} AND child.inbound_context.trace_id == parent.trace_id AND child.inbound_context.parent_span_id == parent.span_id ``` If `child.inbound_context_source == TASK_ID_INFERENCE` — i.e., the only evidence of parentage is a matching `Task.id` — the linker **must not** rewrite `parent_span_id` or `trace_id`. It may emit a *link* (an OpenTelemetry `Link`, not a parent edge) annotated `correlation=task_id`, which preserves the information without asserting causality. The distinction matters because the two operations are not symmetric in their failure cost. A missed link is a recall loss — the trace is slightly less connected, but every edge in it is true. A forged parent edge is a precision loss — the trace is fully connected but contains a false causal claim that propagates through every downstream analysis. In an audit or incident context, the forged edge is strictly worse than the missing one. Two boundary cases that trip implementations: - **Same `trace_id` but different `parent_span_id`**: the A2A hop re-entered the same trace (because the SDK did forward `traceparent`), but the peer started a new span rather than continuing the caller's. This is legitimate — link as parent, but the parent is the *span the context named*, not the task's originating span. - **Task ID reused across retries**: a retried A2A task keeps `Task.id` but gets a new `traceparent`. The linker must key causality off the trace context, not the task ID, or retries will be folded into the original attempt's trace and corrupt error-rate math. ## Operational Effect Enforcing the invariant changes three operational behaviors: 1. **Traces become multi-rooted in the honest case.** When A2A propagation is genuinely broken (as in the observed case), the trace fragments into two roots joined by a link. Dashboards must be built to expect this — a "complete" trace is not the same as a "connected" trace, and the health metric is *propagation coverage* (fraction of A2A hops that carried `traceparent`), not trace-graph connectivity. Connectivity can be gamed by forgery; propagation coverage cannot. 2. **The linker becomes a guardrail, not a repair tool.** Its job is to *refuse* to fabricate edges and to *report* the refusal. Each refusal is a signal that an upstream transport is dropping context, which is the actual defect to fix. Refusing to link is the correct output of a healthy linker, not an error. 3. **Audit replay is sound.** Because every parent edge in the trace was derived from in-band propagation, re-executing the recorded causal graph reproduces the live behavior. Task-ID links remain as annotations, available for correlation but never load-bearing for causality. The instance must refuse to link when the only evidence of parentage is a domain identifier. The guardrail is a hard refusal, not a warning, because the cost of a forged edge is silent and compounding. ```python from __future__ import annotations from dataclasses import dataclass from enum import Enum class ContextSource(Enum): TRACEPARENT = "traceparent" MCP_META = "mcp_meta" SIGNED_CARRIER = "signed_carrier" TASK_ID_INFERENCE = "task_id_inference" class SpanForgeryError(RuntimeError): """Raised when a linker attempts to assert causal parentage from a domain identifier.""" @dataclass(frozen=True) class SpanContext: trace_id: str span_id: str parent_span_id: str | None source: ContextSource task_id: str | None = None @dataclass(frozen=True) class Span: context: SpanContext name: str def link_child_to_parent(child: Span, parent: Span) -> Span: """Return child with parent edge asserted, or refuse. Refuses when the only evidence of parentage is a matching A2A Task.id. A matching task ID is a correlation key, not a causal key. """ ctx = child.context if ctx.source is ContextSource.TASK_ID_INFERENCE: raise SpanForgeryError( f"refusing to link span {child.name!r} to {parent.name!r}: " f"parentage inferred solely from task_id={ctx.task_id!r}; " f"emit an OTel Link(correlation=task_id) instead of a parent edge" ) if ctx.trace_id != parent.context.trace_id: raise SpanForgeryError( f"trace_id mismatch: child={ctx.trace_id} parent={parent.context.trace_id}" ) if ctx.parent_span_id != parent.context.span_id: raise SpanForgeryError( f"parent_span_id mismatch: child names {ctx.parent_span_id}, " f"parent is {parent.context.span_id}" ) # Legitimate: context was propagated in-band and names this parent. return child def propagate_across_a2a(caller: Span, a2a_headers: dict[str, str]) -> SpanContext: """Model the A2A hop. If the transport dropped traceparent, the peer must start a fresh root and record task_id as correlation only.""" tp = a2a_headers.get("traceparent") task_id = a2a_headers.get("x-a2a-task-id") if tp is None: # Honest fallback: new root, task_id is correlation, not causality. return SpanContext( trace_id="fresh-root-" + (task_id or "unknown"), span_id="peer-span-" + (task_id or "unknown"), parent_span_id=None, source=ContextSource.TASK_ID_INFERENCE, task_id=task_id, ) parts = tp.split("-") return SpanContext( trace_id=parts[1], span_id="peer-span-" + (task_id or "unknown"), parent_span_id=parts[2], source=ContextSource.TRACEPARENT, task_id=task_id, ) ```