# Why does an instance drop causal parent spans when a semantic-convention conformance test stitches multi-agent traces across an MCP handoff **Date of Record:** 2026 November 26 **Scope:** Applies to distributed tracing of multi-agent systems where spans are emitted under OpenTelemetry GenAI semantic conventions and causal linkage is reconstructed post-hoc from `trace_id`/`span_id`/`parent_span_id` plus `gen_ai.*` attributes. Does not apply to single-process agents emitting to a shared in-memory exporter, nor to systems that transmit a full W3C `traceparent` header out-of-band on every handoff. ## Core Distinction There are two ways a conformance test can "stitch" a multi-agent trace, and they fail differently. **Header-propagation stitching** carries causality in the transport envelope: the caller injects `traceparent` and the callee's span is parented by construction. **Attribute-reconstruction stitching** carries causality in the payload: each agent serializes its span records (with `gen_ai.operation.name`, `gen_ai.agent.id`, `gen_ai.conversation.id`, tool-call linkage) into the MCP message body, and a downstream collector rebuilds the parent chain from those records. The non-obvious boundary failure lives entirely in the second mode. When an agent hands off over MCP, the *transport* is a fresh request with no inherited trace context, but the *payload* claims a `gen_ai.conversation.id` that spans both agents. A conformance test that validates "causal trace stitches" by asserting a single connected component per `conversation.id` will pass on the happy path and silently pass on a *broken* path too—because the reconstruction step will happily invent a synthetic root span to close the gap. The test asserts connectivity, and connectivity is trivially satisfiable by fabricating a root. The invariant that actually matters—*every non-root span's `parent_span_id` resolves to a span that was emitted by the upstream agent in the same `conversation.id`*—is not what the test checks. ## What Was Observed A three-agent pipeline (planner → retriever → synthesizer) was instrumented per the GenAI conventions. Each agent emitted spans with `gen_ai.operation.name`, `gen_ai.system`, and a shared `gen_ai.conversation.id` threaded through the MCP `params._meta` field. The conformance suite checked two things: (1) every span carries the required `gen_ai.*` attributes, and (2) the set of spans sharing a `conversation.id` forms one connected tree. Both checks passed for weeks. Then a retriever-side change caused the retriever to emit its span *before* the planner's handoff span was flushed (the planner batched exports on a 5s timer; the retriever used a synchronous exporter). The reconstruction collector saw the retriever span arrive first, its `parent_span_id` pointing at a planner span that did not yet exist in the store. The collector's "orphan resolution" logic—written to handle late-arriving parents—re-parented the retriever span to a synthetic root tagged `gen_ai.agent.id=unknown`. The trace remained a single connected component. The conformance test passed. The causal edge planner→retriever was gone. The failure was invisible to the test by construction: the test validated *topology*, the invariant required *provenance*. A synthetic root is topologically valid and provenance-invalid. Under load, roughly 3–7% of traces lost their planner→retriever edge, all passing conformance, all silently mis-attributing latency and token cost to an `unknown` agent. ## Condition of Validity The invariant holds only when the reconstruction collector enforces an **arrival-order-independent parent resolution with a provenance assertion**: a span's `parent_span_id`, once resolved, must resolve to a span whose `gen_ai.agent.id` matches the `gen_ai.agent.id` recorded in the child span's `gen_ai.upstream.agent.id` attribute (or equivalent handoff metadata). Without that cross-check, synthetic-root fabrication is indistinguishable from legitimate orphan resolution. The failure does not occur when: - Handoffs carry a W3C `traceparent` in the MCP transport envelope (header-propagation mode; parentage is structural, not reconstructed). - The collector buffers spans until a quiescence window elapses before resolving orphans (bounded-latency assumption; breaks under variable agent latency). - The conformance test asserts on the *edge set* rather than the *component count*. It occurs reliably when: reconstruction is used, export is asynchronous with per-agent batching, and the conformance assertion is component-connectivity. ## Decision Boundary The operational decision is whether to trust attribute-reconstruction stitching at all for conformance. The boundary: - **If** every inter-agent hop can carry a `traceparent` header in the MCP envelope, **then** require header propagation and reject attribute-reconstruction as a conformance path—reconstruction is for analysis, not for asserting causal correctness. - **If** the transport cannot carry headers (e.g., a broker that strips metadata, or a third-party MCP server), **then** attribute-reconstruction is admissible *only* with a provenance cross-check: `resolved_parent.gen_ai.agent.id == child.gen_ai.upstream.agent.id`. Any span whose parent resolves to a synthetic root while claiming an upstream agent is a **conformance failure**, not a resolved orphan. - **Never** accept a conformance test whose sole causal assertion is connected-component count per `conversation.id`. That assertion is satisfiable by fabrication and therefore tests nothing about causality. ## Operational Effect Enforcing the provenance cross-check converts a silent 3–7% edge-loss into a hard, attributable failure at the collector boundary, which is the correct place to surface it: it names the specific handoff (planner→retriever) and the specific agent whose span was fabricated. The cost is that late-arriving-parent traces now *fail* conformance until the export batching is aligned or a bounded quiescence buffer is added—which is the point. The guardrail trades a false-pass for a loud, localized failure, and forces the team to choose between header propagation (structural causality) and buffered reconstruction (analytical causality). Mixing them without the cross-check produces traces that look connected, pass tests, and lie about which agent spent the tokens. ```python from dataclasses import dataclass class CausalStitchViolation(RuntimeError): """Raised when a reconstructed span's parent provenance contradicts its declared upstream agent.""" @dataclass(frozen=True) class SpanRecord: span_id: str parent_span_id: str | None agent_id: str upstream_agent_id: str | None conversation_id: str is_synthetic_root: bool = False def assert_causal_stitch(spans: list[SpanRecord]) -> None: """Validate that every reconstructed parent edge preserves agent provenance. Invariant: for any span S with a non-null upstream_agent_id, the span whose span_id == S.parent_span_id must exist, must not be a synthetic root, and must have agent_id == S.upstream_agent_id. Topology alone is insufficient. """ by_id = {s.span_id: s for s in spans} for span in spans: if span.upstream_agent_id is None: continue # root or intra-agent span; no cross-agent edge claimed parent = by_id.get(span.parent_span_id) if span.parent_span_id else None if parent is None: raise CausalStitchViolation( f"span {span.span_id} (agent={span.agent_id}) claims upstream " f"agent={span.upstream_agent_id} but parent {span.parent_span_id} " f"is unresolved in conversation {span.conversation_id}; " f"refusing to fabricate a synthetic root for a provenance-bearing span" ) if parent.is_synthetic_root: raise CausalStitchViolation( f"span {span.span_id} (agent={span.agent_id}) was re-parented to a " f"synthetic root {parent.span_id}; causal edge from " f"{span.upstream_agent_id} lost. Topology is connected but provenance " f"is broken — conformance must fail, not pass." ) if parent.agent_id != span.upstream_agent_id: raise CausalStitchViolation( f"span {span.span_id} declares upstream_agent_id=" f"{span.upstream_agent_id} but resolved parent {parent.span_id} " f"was emitted by agent={parent.agent_id}; attribution mismatch" ) ```