# Why does an instance lose its trace parent when an MCP tool server re-enters an A2A sub-agent: the trace-context rebinding gap at federated boundaries **Date of Record:** 2026 November 30 **Scope:** Applies to any agent runtime that propagates W3C Trace Context (`traceparent`/`tracestate`) or an equivalent correlation token across an MCP tool call that itself dispatches an A2A task to a remote agent. Does not apply to single-process tool calls, nor to A2A handoffs where the caller and callee share a span exporter and a single trace ID authority. ## Core Distinction There are two structurally different things called "trace correlation" and they fail for different reasons. **In-process correlation** is a span-tree property: a child span references a parent span ID that exists in the same collector's index, so the tree reconstructs deterministically. **Federated correlation** is a *string-propagation* property: the only thing that survives an MCP→A2A boundary is whatever bytes the intermediary chose to copy into the outbound request envelope. The failure mode here is not a dropped span (that is visible as a gap and is easy to alert on). The failure mode is a **silently rebased trace**: the A2A sub-agent starts a *fresh root span* with a new `trace_id`, copies the caller's `traceparent` into a non-standard attribute for "reference," and the collector indexes two disjoint traces that a human must manually stitch. The correlation token was transported but not *honored*, and the system reports 100% propagation success because the header was present on the wire. ## What Was Observed A planner agent (`planner-01`) held an active span `S_p` with `trace_id=T1`, `span_id=A1`. It invoked an MCP tool `dispatch_research` on an MCP server (`mcp-research`) over streamable HTTP. The MCP server, per its own contract, is a thin adapter: on `tools/call` it performs an A2A `message/send` to a remote research agent (`researcher-7`). The MCP server's request handler ran inside an SDK that auto-creates a server-side span `S_m` (`trace_id=T1`, `parent=A1`) — correct so far. But the A2A client stub inside that server was initialized *before* the incoming request context was extracted, so its `ClientFactory` captured an empty `Context` at construction time. When `message/send` fired, the A2A envelope carried `traceparent` only inside the `params.message.metadata["x-trace"]` free-form field, not in the transport headers the remote runtime inspects. `researcher-7` therefore saw no valid inbound parent, minted `trace_id=T2` as a new root, and recorded `x-trace: 00---01` as an opaque attribute. Result: the planner's trace `T1` ends at the MCP server's `S_m`. The research agent's entire multi-hop reasoning tree lives in `T2`. The two are related only by a string buried in an attribute, and only if the downstream runtime happened to preserve `metadata`. In one observed case the A2A server's schema validator stripped unknown `metadata` keys before the handler ran, so even the string reference was gone — the sub-agent's work became an *orphan trace* with no inbound edge at all. The dashboard showed the tool call as `OK`, the A2A task as `completed`, and the end-to-end latency as the sum of two unrelated numbers because no join key existed to compute it. ## Condition of Validity The invariant that must hold for federated correlation to be trustworthy is: > **For every A2A dispatch triggered inside an MCP handler, the outbound `traceparent` must be derived from the *request-scoped* context extracted at handler entry, and the remote runtime must treat a present-but-unparented `traceparent` as a hard error, not a soft fallback to a new root.** This fails whenever any of three conditions holds: (1) the A2A client is constructed at server boot with a captured empty context rather than per-request (the common case in dependency-injected SDKs); (2) the trace token is placed in `message.metadata` instead of transport headers, so it is subject to schema filtering; or (3) the remote runtime's context extractor accepts a `traceparent` whose `trace_id` it has never seen and silently rebases rather than continuing. Condition (3) is the dangerous one because it converts a transport bug into a *correlation lie* — the trace looks complete because every span has a parent, but the parent chain roots at the wrong place. A guardrail that only checks "was a traceparent present?" passes all three failure modes. ## Decision Boundary The boundary is between **treating correlation as best-effort metadata** and **treating it as a continuity invariant with a refuse-to-run contract**. Best-effort is acceptable when the sub-agent's work is independently meaningful and re-derivable (a stateless lookup). It is *not* acceptable when the sub-agent's output feeds back into the caller's reasoning loop and the caller must audit *which* upstream context produced it — i.e., any A2A hop whose result is appended to the planner's context window. In that case a rebased trace means the auditor cannot answer "did the planner's prompt-injected instruction reach the researcher?" because the causal edge is unindexed. The decision: if the A2A result will mutate caller state, the outbound envelope MUST carry the request-scoped `traceparent` in transport headers, and the remote MUST reject unparented inbound when a caller-declared `require_continuity` flag is set. Otherwise the hop is metadata-only and must be labeled as such so downstream tooling does not assume a join exists. ## Operational Effect Once the rebinding gap is bounded, three observable properties change. First, orphan-trace rate becomes a first-class SLI: count of A2A server spans whose `trace_id` has no inbound edge from a known caller trace, alerting on any nonzero value for continuity-required tasks. Second, end-to-end latency becomes computable as a single trace duration rather than a manual sum, which exposes the real cost of the MCP→A2A hop (observed: the adapter added 40–90ms of context-extraction overhead per call that was previously invisible). Third, and most important for agent debugging, the causal chain from a planner decision to a sub-agent tool output is reconstructible without reading logs — which is the only way to audit whether a poisoned instruction propagated. The fix is small (per-request context extraction, header-based propagation, strict inbound validation) but the invariant it restores is large: a federated trace either joins or refuses, never silently rebases. ```python from __future__ import annotations import re from dataclasses import dataclass _TRACEPARENT = re.compile( r"^(?P[0-9a-f]{2})-" r"(?P[0-9a-f]{32})-" r"(?P[0-9a-f]{16})-" r"(?P[0-9a-f]{2})$" ) _ZERO_TRACE = "0" * 32 class TraceRebindError(RuntimeError): """Raised when a federated hop would silently rebase a trace instead of continuing it.""" @dataclass(frozen=True) class SpanContext: trace_id: str span_id: str sampled: bool def extract_inbound(headers: dict[str, str]) -> SpanContext | None: raw = headers.get("traceparent") if raw is None: return None m = _TRACEPARENT.match(raw.strip()) if not m or m["trace_id"] == _ZERO_TRACE: return None return SpanContext( trace_id=m["trace_id"], span_id=m["span_id"], sampled=bool(int(m["flags"], 16) & 0x01), ) def build_outbound( *, inbound: SpanContext | None, new_span_id: str, require_continuity: bool, caller_declared_trace: str | None, ) -> str: """Construct the outbound traceparent for an A2A dispatch from inside an MCP handler. The invariant: if continuity is required and an inbound context exists, the outbound trace_id MUST equal the inbound trace_id. A mismatch means the A2A client was built with a stale/empty context and we must refuse rather than emit a rebased trace that looks valid on the wire. """ if inbound is None: if require_continuity: raise TraceRebindError( "continuity required but no inbound traceparent was extracted at " "handler entry; A2A client likely captured an empty boot-time context" ) # Metadata-only hop: allowed, but caller must not assume a join exists. root = caller_declared_trace or "0" * 32 return f"00-{root}-{new_span_id}-01" if caller_declared_trace is not None and caller_declared_trace != inbound.trace_id: raise TraceRebindError( f"outbound trace_id {caller_declared_trace} does not continue inbound " f"{inbound.trace_id}; refusing to emit a silently rebased trace" ) flags = "01" if inbound.sampled else "00" return f"00-{inbound.trace_id}-{new_span_id}-{flags}" def dispatch_research( *, request_headers: dict[str, str], a2a_client_trace: str | None, new_span_id: str, require_continuity: bool = True, ) -> str: inbound = extract_inbound(request_headers) return build_outbound( inbound=inbound, new_span_id=new_span_id, require_continuity=require_continuity, caller_declared_trace=a2a_client_trace, ) ```