# What happens when an instance's trace context is silently re-parented across an MCP→A2A boundary **Date of Record:** 2026 November 25 **Scope:** Applies to multi-hop agent systems where a parent agent invokes an MCP tool server and then delegates to a peer via A2A, and where observability relies on W3C Trace Context (`traceparent`/`tracestate`) propagated through protocol headers or tool-call metadata. Does not apply to single-process agents or to systems that reconstruct lineage purely from a centralized event log keyed on a runtime-assigned session ID. ## Core Distinction A trace is not a log with a string field; it is a *causal tree* whose edges are asserted by whichever process emits the child span. The failure here is not "spans went missing." It is that spans *arrived intact but attached to the wrong parent*, producing a trace that is complete, well-formed, and causally false. The distinction that matters operationally: **span loss is loud (a gap you can alert on), whereas span re-parenting is silent (a tree that renders cleanly but encodes a lie about which agent caused which effect).** The specific non-obvious mechanism: MCP tool invocations and A2A task delegations each carry trace context through *different* transport surfaces — MCP typically via `params._meta` on a `tools/call`, A2A via HTTP headers on the `message/send` request or via `metadata` on the `Message` object. When an agent acts as both an MCP *client* and an A2A *client* in the same turn, the two context-injection paths are independent code paths. If the A2A path does not explicitly inherit the *currently active* span (the one opened for the MCP call or for the enclosing reasoning step), the A2A SDK's default behavior — start a new root, or attach to the last span the instrumentation happened to see — silently re-parents the downstream agent's entire subtree. ## What Was Observed A planner agent (`P`) receives a user request, opens span `S_plan`. It calls an MCP tool `search_docs`; instrumentation opens `S_mcp` as a child of `S_plan` and injects `traceparent` into `params._meta`. The tool server correctly continues the trace: `S_mcp` → `S_tool_exec`. So far the tree is correct. `P` then, in the same reasoning loop, decides to delegate summarization to peer agent `Q` over A2A. The A2A client is a separate library. Its instrumentation hooks the HTTP client and injects `traceparent` derived from *its own* notion of the current span — which, because the A2A client call is dispatched from an async task that never received the OpenTelemetry context (the MCP call ran in a different `contextvars` context, or the delegation was queued to a worker pool that dropped the context), is a **new root span** `S_a2a_root`. Agent `Q` continues from `S_a2a_root`, producing `Q_plan → Q_tool → Q_result`. The exported trace now contains two disconnected trees that a naive backend *stitches by timestamp proximity*, or a correlation layer *joins on `session_id`* that both sides happen to share. The result: `Q`'s entire subtree is rendered as a sibling of `P`'s work rather than a descendant, or worse, as a child of `S_mcp` because the join heuristic picked the temporally-nearest open span. Observed symptoms, in order of how they surface: 1. Latency attribution inverts — the wall-clock time of `Q`'s work is billed to the MCP tool call, inflating `S_tool_exec` p99 and hiding the real delegation cost. 2. Error propagation looks like the tool failed when actually the peer agent's downstream tool failed, because the error span's nearest ancestor in the (false) tree is the MCP call. 3. Replay/verification diverges: an auditor replaying the trace to check "did `P` see `Q`'s output before deciding to retry?" reads the wrong edge and concludes the retry was justified when it was a duplicate. The tell is a **span with a `parent_span_id` that is non-null but does not correspond to any span the emitting process could have observed** — i.e., the parent ID was synthesized by a join heuristic, not asserted by `traceparent`. In raw W3C terms, the correct signature is: `Q`'s root span has a `trace_id` equal to `P`'s but a `parent_span_id` pointing at a span whose `span_id` was never in any `traceparent` header `P` actually sent. ## Condition of Validity The invariant that must hold for cross-protocol traces to be trustworthy: > For every span `c` emitted by process `X`, if `c.parent_span_id = p`, then process `X` received `p` in the `traceparent` (or equivalent) of the inbound request that triggered `c`, OR `p` was opened by `X` itself and is currently active in `X`'s context at emission time. This invariant is **violated** precisely when context propagation crosses a protocol boundary that uses a different injection surface than the one the instrumentation was written against. It is *not* violated by context loss (which yields a null parent / new root — detectable). It is violated by context *substitution*: any layer that, finding no valid `traceparent`, invents a parent from `session_id`, timestamp, or "last seen span." The condition under which the failure is bounded and harmless: if and only if the correlation layer treats a missing `traceparent` as a **hard root boundary** and never joins across it. The moment the backend performs heuristic stitching, the invariant is unenforceable at the storage layer and must be enforced at the emitter. ## Decision Boundary The architectural guardrail is a **context-propagation contract at the protocol adapter**, enforced on both sides: - On the *client* side (the agent acting as MCP or A2A client): the adapter MUST extract the active context via the runtime's context API (`contextvars`/OTel `Context`) at the call site, and MUST fail closed — refuse to emit the outbound call — if the active context has no valid span, rather than starting a fresh root silently. A new root is a *decision*, not a default. - On the *server* side (tool server, peer agent): the adapter MUST continue only from an inbound `traceparent` it actually parsed; if absent, it MUST emit an explicitly-flagged root (`trace_continuity: broken`) so downstream correlation can quarantine it. - The correlation/backend layer MUST NOT synthesize parent edges. Join on `trace_id` for grouping; treat differing `parent_span_id` roots within one `trace_id` as distinct causally-orphaned subtrees and surface them as such. The decision boundary for an operator: **if you cannot prove the parent edge was asserted by a `traceparent` you sent, you do not have a trace — you have a timeline.** Timelines are fine for dashboards; they are disqualifying for causal replay, error attribution, and any auditor that reasons over "what did agent A know when it acted." ## Operational Effect When the invariant holds, cross-hop latency decomposes correctly, error spans point at the true failing agent, and replay-based verification of delegation decisions is sound. When it is violated and unquarantined, three concrete operational consequences follow: (1) MCP tool SLOs absorb peer-agent latency and trigger spurious tool-degradation alerts; (2) retry/duplicate-detection logic that reads the false tree concludes a peer's late response was "never received" and re-delegates, compounding cost; (3) post-incident reconstruction attributes a peer agent's poisoned or injected output to the parent's own tool call, misdirecting the fix toward the tool server instead of the delegation boundary. The cheapest durable mitigation is the fail-closed client adapter plus a backend rule that refuses heuristic parent synthesis — both are one-time changes that convert a silent causal lie into a loud, bounded gap. ```python from __future__ import annotations from dataclasses import dataclass from typing import Optional class TraceContinuityError(RuntimeError): """Raised when a span's asserted parent cannot be proven from inbound context.""" @dataclass(frozen=True) class SpanContext: trace_id: str span_id: str parent_span_id: Optional[str] def assert_parent_was_asserted( child: SpanContext, inbound_traceparent_span_id: Optional[str], locally_opened_active_span_id: Optional[str], ) -> None: """ Enforce the cross-protocol invariant: a child span's parent must be either the span_id carried in the inbound traceparent, or a span this process opened itself and holds active. Anything else is a synthesized (false) edge. """ if child.parent_span_id is None: return # explicit root: allowed, but must be flagged by the emitter proven = {inbound_traceparent_span_id, locally_opened_active_span_id} proven.discard(None) if child.parent_span_id not in proven: raise TraceContinuityError( "re-parented span detected: " f"span {child.span_id} in trace {child.trace_id} claims parent " f"{child.parent_span_id}, but inbound traceparent carried " f"{inbound_traceparent_span_id!r} and local active span was " f"{locally_opened_active_span_id!r}. Refusing to emit; this edge " "was synthesized by a join heuristic, not asserted by W3C context." ) def emit_delegation_span( active_span: Optional[SpanContext], inbound_traceparent_span_id: Optional[str], trace_id: str, new_span_id: str, ) -> SpanContext: """Fail closed at the MCP->A2A boundary rather than silently starting a new root.""" if active_span is None and inbound_traceparent_span_id is None: raise TraceContinuityError( "no active span and no inbound traceparent at delegation boundary; " "refusing to emit an unflagged new root across an A2A hop" ) parent = active_span.span_id if active_span is not None else inbound_traceparent_span_id child = SpanContext(trace_id=trace_id, span_id=new_span_id, parent_span_id=parent) assert_parent_was_asserted(child, inbound_traceparent_span_id, active_span.span_id if active_span else None) return child ```