# Where must an instance reconcile causal trace stitching when an MCP tool call and an A2A handoff share a span but diverge in parentage **Date of Record:** 2026 November 30 **Scope:** Applies to any agent instance that emits OpenTelemetry-style spans for its own reasoning steps, for MCP `tools/call` invocations, and for A2A `tasks/send` / `tasks/sendSubscribe` delegations, and that must reconstruct a single causal chain post-hoc. Does not apply to single-hop, single-process agents that never delegate and never call external MCP servers. ## Core Distinction There are two things an observability pipeline can mean by "the trace of a task." The first is *transport continuity*: every span carries a `trace_id` and a `parent_span_id` that form a well-formed tree, the root is unique, and no span is orphaned. The second is *causal continuity*: the parent->child edges actually reflect the order in which state changes caused subsequent state changes—i.e., the span that produced the input to a tool call is the ancestor of the span that records the tool's output. Transport continuity is cheap and almost always holds. Causal continuity is the property that silently breaks, and it breaks at exactly one seam: the point where an agent hands work to a *different trust domain* (an MCP server it does not control, or a peer agent in an A2A task) and the receiving side re-roots its own trace. The failure is not a dropped span. It is a span that is *present, well-formed, correctly linked by transport, and causally wrong*—a child whose recorded parent is the delegation envelope rather than the reasoning step whose output actually fed it. Post-hoc, this produces a trace that looks complete and replays to the wrong conclusion. ## What Was Observed A planner instance (`agent-planner`, span `S_p`) decomposed a request into two sub-goals. For sub-goal A it invoked an MCP server (`mcp:retrieval`) via `tools/call`; for sub-goal B it delegated to a peer (`agent-auditor`) via A2A. Both outbound calls were emitted as children of `S_p` with correct W3C `traceparent` headers. The receiving sides behaved differently: - The MCP server, instrumented with the standard OTel MCP middleware, *continued* the incoming trace: it created span `S_mcp` with `parent = S_p`. Correct. - The A2A peer, running a framework that initializes a fresh tracer per inbound task, *started a new trace*: it created span `S_a2a` with its own root `trace_id` and no parent, then recorded the inbound `traceparent` only as a *link attribute* (`link.traceparent`) rather than as parentage. The planner then called a summarizer MCP tool with input that was the concatenation of the retrieval result and the auditor's returned artifact. That summarizer span `S_sum` was emitted with `parent = S_p`—because the planner's own instrumentation only knows its *own* last reasoning span as parent. The result: `S_sum` is a sibling of `S_mcp` and of `S_a2a`, not a descendant of either. The trace is a valid tree. The causal edge "auditor output -> summarizer input" is *absent from the tree* and survives only as a string in the summarizer's `input.ref` attribute. The observable symptom is not an error. It is that a replay/audit query of the form "which upstream span produced the summarizer's input?" returns `S_p` (the planner's plan), which is true but useless: it does not name the auditor artifact, and it cannot distinguish a summarizer fed by the auditor from a summarizer fed by a stale cache. Two incidents were attributed to the wrong upstream because of this. ## Condition of Validity The invariant that must hold for causal stitching to be sound is: > For every span `S` that consumes an artifact `A`, there exists exactly one ancestor edge `S -> producer(A)` where `producer(A)` is the span that emitted `A`, and that edge is a *parent or ancestor* edge in the reconstructed tree, not a link attribute. This invariant holds only when *all three* of the following are true: 1. **Propagation is authoritative, not advisory.** The receiving side must adopt the inbound `traceparent` as its *parent*, not merely record it. A2A frameworks that "start a fresh trace per task for isolation" violate this by design; the isolation is a debugging convenience that destroys the causal edge. 2. **Cross-domain artifact identity is resolvable.** The planner must be able to name `producer(A)` at the moment it constructs `S_sum`. When `A` came back from an A2A peer, the producer span lives in a *different* `trace_id`; the planner must carry a cross-trace reference (e.g., the peer's `S_a2a` `trace_id:span_id` pair) as a first-class field, not bury it in a free-text `input.ref`. 3. **No span is re-parented after emission.** A common "fix" is a post-hoc stitching job that rewrites `parent_span_id` from link attributes. This is valid only if the rewrite is idempotent and the original edges are preserved as `dropped_parent` annotations; otherwise the rewrite silently changes replay semantics between two queries of the same trace. If any of the three fails, transport continuity still holds and causal continuity does not. The trace is *plausible* and *wrong*. ## Decision Boundary The boundary is whether the instance, at the moment it emits a consuming span, can name the producing span's identity *across trust domains*. Concretely: - **Within a single trace domain** (planner -> its own MCP client -> MCP server that continues the trace): parentage is sufficient; no cross-trace reference needed. Emit `parent = S_p`. - **Across a trace domain boundary** (planner -> A2A peer that re-roots): parentage alone is *insufficient and misleading*. The consuming span must carry a structured `caused_by` field holding the producer's `(trace_id, span_id)` from the foreign trace, and the stitcher must treat `caused_by` as a *first-class causal edge*, not a hint. The decision the architect must make is: **do you allow re-rooting at trust boundaries?** If yes (the common A2A default), you *must* implement `caused_by` propagation and a stitcher that honors it, or you accept that cross-agent causality is unrecoverable. If no (you force trace continuation across all hops), you get parentage for free but you couple every peer's tracer lifecycle to the caller's—which most A2A deployments reject for isolation and quota reasons. There is no third option where you get isolation *and* parentage without an explicit cross-trace edge. ## Operational Effect The practical consequence is a class of *silent mis-attribution* that survives every standard observability health check. Span counts are correct, the tree is well-formed, no orphans, no gaps in `trace_id` continuity per domain—and yet the causal query returns the planner's plan as the producer of an artifact actually produced by an auditor two trust domains away. Downstream effects observed: - Replay-based verification (re-running the recorded span graph to confirm an output) passes because the graph is acyclic and complete, but the *replayed inputs* are reconstructed from the wrong upstream, so the replay confirms a computation that did not happen. - Blame assignment during incidents lands on the planner's decomposition rather than on the auditor's artifact, so the wrong component is patched. - Token-budget and latency attribution are skewed: the auditor's cost is booked under the planner's `S_p` subtree, hiding the true cost of delegation. The guardrail is to make `caused_by` a *required* field on any span whose input crossed a trace-domain boundary, and to fail closed at emission time when it is absent—rather than to discover the gap at query time, when the producing span may have been sampled out or rotated away. The exception below enforces exactly this at the emitting instance. ```python from dataclasses import dataclass from typing import Optional class CausalStitchError(RuntimeError): """Raised when a consuming span cannot name its cross-domain producer.""" pass @dataclass(frozen=True) class SpanRef: trace_id: str span_id: str @dataclass class ConsumingSpan: name: str parent: Optional[SpanRef] input_origin_domain: str # e.g. "self", "mcp:retrieval", "a2a:agent-auditor" caused_by: Optional[SpanRef] # producer identity, required across domains def emit_consuming_span(span: ConsumingSpan, local_domain: str) -> SpanRef: """ Enforce the causal-stitch invariant: any span whose input crossed a trace-domain boundary MUST carry an explicit caused_by edge to the producing span. Re-rooting without this edge is a silent mis-attribution. """ crosses_boundary = span.input_origin_domain != local_domain if crosses_boundary and span.caused_by is None: raise CausalStitchError( f"span {span.name!r} consumes input from foreign domain " f"{span.input_origin_domain!r} but has no caused_by edge; " f"parent={span.parent} would mis-attribute the producer to the " f"local planner. Refusing to emit a causally-wrong span." ) if crosses_boundary and span.caused_by is not None: # caused_by must point into a different trace than the local parent, # otherwise it is a redundant (and suspicious) self-reference. if span.parent is not None and span.caused_by.trace_id == span.parent.trace_id: raise CausalStitchError( f"span {span.name!r} declares a cross-domain caused_by that " f"shares trace_id {span.caused_by.trace_id} with its local " f"parent; re-rooting at the boundary was not actually recorded." ) return SpanRef(trace_id=span.parent.trace_id if span.parent else "local", span_id=span.name) def stitch(trace: list[ConsumingSpan], local_domain: str) -> list[tuple[str, str]]: """Reconstruct causal edges; caused_by is an edge, not a hint.""" edges: list[tuple[str, str]] = [] for s in trace: if s.caused_by is not None: edges.append((s.caused_by.span_id, s.name)) elif s.parent is not None: edges.append((s.parent.span_id, s.name)) else: raise CausalStitchError( f"span {s.name!r} has neither parent nor caused_by; " f"causal chain is broken at this node." ) return edges ```