# How should an instance reconcile trace context when an MCP tool call is re-parented across an A2A task boundary **Date of Record:** 2026 November 22 **Scope:** Applies to distributed agent systems where trace/span context (W3C Trace Context plus W3C Baggage) is propagated across at least two transport hops — an MCP client↔server tool invocation and an A2A task delegation — and where an orchestrator correlates those spans into a single causal trace. Does not apply to single-process agents, or to systems that rely on wall-clock timestamps alone for correlation. ## Core Distinction There are two distinct notions of "the same operation" in an agent trace, and conflating them is the failure mechanism: 1. **Causal parentage** — the span that logically caused this span (encoded in `traceparent`'s parent-id, and in A2A's `contextId`/`taskId` lineage). 2. **Transport session** — the connection-level identity of the hop that physically carried the request (MCP session id, SSE stream id, A2A stream token). Baggage propagation typically rides on the *transport session* because that is where headers are cheap to attach and cheap to read. But when an A2A task boundary intervenes — the orchestrator accepts a task, then spawns an MCP tool call inside a *different* execution context (a worker, a rescheduled retry, a sub-agent) — the baggage that arrives at the MCP server is the baggage of the *delegating session*, not the baggage of the *originating task*. The `traceparent` says one thing; the baggage says another. Any correlator that trusts baggage as the authoritative link between the A2A task and the MCP tool call will mis-parent spans, and the resulting trace is not merely noisy: it is *structurally wrong* in a way that makes attribution of latency and errors impossible. The invariant that must hold: **for every span, the baggage snapshot must be a function of the causal ancestor, not of the transport that delivered it.** Violations are silent — the trace still renders, the spans still exist, only the edges are wrong. ## What Was Observed A three-tier system: an orchestrator agent (A2A server, also an MCP client), a specialist sub-agent reached over A2A, and a shared MCP tool server used by both. Trace context was injected at the orchestrator via `traceparent` + `baggage: task.id=..., agent.role=orchestrator, tenant=...`. The specialist sub-agent was expected to forward both headers on its MCP calls. Observed failure trace during a retry storm: - The orchestrator received an A2A task, minted `task.id=T1`, and set baggage `agent.role=orchestrator`. - The A2A hop to the specialist correctly carried `T1` and `traceparent` with parent = orchestrator span `S_orch`. - The specialist's MCP client opened a *new* session to the tool server. Because the specialist's MCP client library re-derives baggage from its own local context (which had been initialized with `agent.role=specialist` at startup and never overwritten from the inbound A2A headers), the outbound MCP `baggage` header read `agent.role=specialist, task.id=`. - The `traceparent` header *was* forwarded correctly (the library derived it from the active span), so the span was parented under `S_orch` — but the baggage attached to it described a *different task*. Result: the correlator, which grouped spans by `task.id` from baggage, produced two traces. `T1`'s trace was missing the tool span; a phantom `T0` trace contained a tool span whose `traceparent` parent pointed into `T1`'s tree. The tool span was, in effect, **re-parented across a task boundary**: its causal parent lived in one task, its baggage identity in another. A second, subtler variant appeared under concurrency. When the orchestrator fanned out three A2A tasks (`T1`,`T2`,`T3`) to the same specialist process, the specialist's single MCP client session multiplexed all three. Because MCP session-level baggage is set once at `initialize` and the client did not re-inject per-request baggage, all three tool calls carried `task.id=T1` (the first to initialize). Two of three tasks lost their tool spans entirely; one task's trace absorbed two foreign spans. The failure is proportional to fan-out width and is invisible unless you assert per-span baggage/causal agreement. ## Condition of Validity The mis-parenting occurs **only** when all of the following hold simultaneously; remove any one and the trace is correct: 1. The A2A task boundary introduces a context switch (different goroutine/process/worker), so the execution context that reads inbound headers is not the same object that later writes outbound headers. 2. The MCP client derives outbound baggage from **local mutable context** rather than from an **immutable per-request snapshot** taken at the A2A ingress point. 3. The correlator uses baggage fields (e.g., `task.id`) as a **grouping key**, rather than using `traceparent` parent-id as the sole edge source and treating baggage as advisory annotations. When (2) is absent — i.e., the MCP client re-reads the inbound `baggage` header on every request — the failure does not reproduce. When (3) is absent — the correlator builds the DAG purely from `traceparent` and never groups by baggage — the spans remain correctly parented even if baggage is stale, though per-task filtering is then degraded. The dangerous configuration is precisely the common one: a framework that "helpfully" propagates baggage from ambient context, paired with an observability backend that "helpfully" groups by baggage tags. ## Decision Boundary The decision is where to make baggage authoritative versus derived. Two admissible architectures: - **Snapshot-and-freeze.** At every A2A ingress, capture the inbound `traceparent` and `baggage` into an immutable request-scoped struct. All downstream MCP calls MUST serialize baggage from that struct, never from ambient context. Any code path that constructs an outbound MCP request without a snapshot is a defect. This is the recommended boundary because it makes the invariant checkable at a single seam. - **Traceparent-only correlation.** Accept that baggage may be stale; forbid the correlator from using baggage for grouping. Baggage becomes best-effort annotation. This is weaker but safe against re-parenting. The boundary is crossed — and you must fail closed — when a span is emitted whose `traceparent` parent-id resolves to a causal ancestor in task `A` while its baggage `task.id` resolves to task `B ≠ A`. That disagreement is not a warning; it is a corrupt trace edge. The system should reject the span at the collector rather than admit a mis-parented edge into the DAG, because a wrong edge is worse than a missing one: it silently transfers latency and error attribution between tasks, and downstream SLO computations inherit the error. ## Operational Effect Once mis-parenting enters the trace store, three second-order effects compound: 1. **Latency laundering.** A slow tool call that actually belongs to `T1` gets aggregated into `T0`'s latency distribution, deflating `T1`'s p99 and inflating `T0`'s. Capacity planning on per-task latency is then wrong in both directions. 2. **Error masking at the boundary.** If the tool server returns a 5xx, the error span is attributed to the stale task. The task that actually failed shows a clean trace with a missing child — indistinguishable from "the tool was never called." Incident responders chase a phantom. 3. **Retry amplification blindness.** Under the fan-out variant, all retried tool calls collapse onto one `task.id`; retry storms look like a single task hammering the tool, and the true fan-out width is unrecoverable from the trace. The guardrail is a collector-side admission check plus a producer-side snapshot discipline, enforced as a hard error rather than a sampled warning — because the failure is silent, low-frequency under light load, and catastrophic under the exact concurrency that observability is supposed to explain. ```python import re from dataclasses import dataclass _TRACEPARENT = re.compile(r"^00-([0-9a-f]{32})-([0-9a-f]{16})-[0-9a-f]{2}$") class TraceContextMismatch(RuntimeError): """Raised when a span's baggage task identity disagrees with its causal parent's task.""" @dataclass(frozen=True) class SpanContext: trace_id: str parent_id: str task_id: str # from baggage; advisory unless validated def _parse_traceparent(header: str) -> tuple[str, str]: m = _TRACEPARENT.match(header) if not m: raise TraceContextMismatch(f"malformed traceparent: {header!r}") return m.group(1), m.group(2) def admit_span( traceparent: str, baggage_task_id: str, parent_task_id: str | None, ) -> SpanContext: """ Collector-side admission. Rejects a span whose baggage task identity contradicts the task identity of its causal parent, because admitting it would create a mis-parented edge across an A2A task boundary. """ trace_id, parent_id = _parse_traceparent(traceparent) if parent_task_id is None: # Root span (A2A ingress): baggage defines the task, nothing to contradict. return SpanContext(trace_id, parent_id, baggage_task_id) if baggage_task_id != parent_task_id: raise TraceContextMismatch( "re-parenting across A2A task boundary: " f"trace={trace_id} parent={parent_id} " f"baggage_task={baggage_task_id!r} parent_task={parent_task_id!r}" ) return SpanContext(trace_id, parent_id, baggage_task_id) def snapshot_baggage(inbound_headers: dict[str, str]) -> dict[str, str]: """ Producer-side discipline: freeze inbound baggage at A2A ingress. Outbound MCP calls MUST serialize from this snapshot, never ambient context. """ raw = inbound_headers.get("baggage") if raw is None: raise TraceContextMismatch("A2A ingress missing baggage header; cannot snapshot") snap: dict[str, str] = {} for pair in raw.split(","): if "=" in pair: k, v = pair.strip().split("=", 1) snap[k] = v if "task.id" not in snap: raise TraceContextMismatch("snapshot lacks task.id; downstream correlation undefined") return snap ```