# In what scenarios must an instance treat a cross-MCP causal trace as unstitchable once a downstream server omits the W3C `traceparent` echo, and how should it quarantine the resulting orphan span **Date of Record:** 2026 November 24 **Scope:** Applies to agent runtimes that propagate W3C Trace Context (`traceparent`/`tracestate`) through MCP `tools/call` requests and A2A task handoffs, then reconstruct a single causal trace across LLM invocations and remote servers. Does not apply to single-process in-memory tracing where the span context never crosses a serialization boundary, nor to systems that use proprietary correlation IDs with guaranteed echo semantics. ## Core Distinction The distinction that matters is between *trace continuity* and *causal identity*. A trace ID propagated across a hop is only meaningful if the receiving server echoes the same `traceparent` (or a child derived from it) on its response and on any outbound calls it makes. When a downstream MCP server silently drops the header—common when the server was built against an older MCP SDK, uses a stateless HTTP transport that strips unknown headers, or wraps a third-party tool that re-emits its own trace root—the parent agent still *knows* it made the call, but it can no longer *prove* that the spans it later collects belong to that call. This is not a logging gap. It is a break in the causal invariant that downstream spans are descendants of the invoking span. Once broken, any stitching heuristic (timestamp proximity, shared session ID, matching tool name) is a probabilistic guess, and a guess in a trace graph produces false causal edges that will later be consumed by an auditor agent or a replay verifier as ground truth. The non-obvious part: the break is often *invisible at the call site*. The MCP response returns `200 OK` with a valid result. The invoking agent records its own span as closed and successful. The orphan spans arrive later—sometimes seconds later, via a separate OTLP batch—carrying a `trace_id` the parent never issued. The naive stitcher joins them by session, and the trace looks complete. It is not. ## What Was Observed In a three-hop chain—planner LLM → MCP server A (`search`) → A2A handoff to agent B → MCP server B (`fetch_url`)—the following trace sequence was captured: 1. Planner span `S0` issues `tools/call` to A with `traceparent: 00---01`. A echoes correctly; span `S1` (child of `S0`) is recorded. 2. A performs an A2A `tasks/send` to agent B. A correctly injects `traceparent` derived from `S1`. B's runtime accepts the task but its MCP client, configured with a vendored SDK, does not forward `traceparent` on its `tools/call` to server B. 3. Server B executes `fetch_url`, emits a span with a *fresh* `trace_id: `, `parent_span_id: null`. It returns the result to B, which returns it up the A2A response to A, which returns it to the planner. 4. The collector receives span `S2` (server B) with `trace_id ` and no parent. It is an orphan root. The stitcher, configured with a session-based fallback, attaches `S2` under `S1` because both share `session_id=abc`. The resulting trace *appears* complete and passes a naive DAG check. But `S2`'s true parent is the (unrecorded) B-internal MCP client span, and its true trace root is ``, not ``. When a verification agent later replays the trace to attribute a hallucinated `fetch_url` result, it attributes the fault to server A's `search` span—the wrong server, the wrong hop. The false edge `S1 → S2` is the failure. A second observation: the orphan's `trace_id ` collided, by chance, with a `trace_id` issued minutes earlier by an unrelated agent. The session-fallback stitcher merged two genuinely independent traces into one 40-span graph. This is the worst case—cross-tenant causal contamination—and it is not detectable from the merged trace alone. ## Condition of Validity A cross-MCP causal trace is stitchable **only if** every hop satisfies the *echo invariant*: for each `tools/call` or `tasks/send`, the receiving side must (a) accept the inbound `traceparent`, (b) emit its own span as a child of the inbound span context, and (c) propagate the same context on any outbound call before returning. The invariant is transitive; a single non-compliant hop invalidates stitching for the entire subgraph beneath it. Three preconditions must hold for the invariant to be checkable at runtime: - The invoking agent must record the exact `traceparent` it sent, keyed by `(call_id, tool_name, timestamp_ns)`, so that a later-arriving span can be matched by *exact context equality*, not heuristic. - The collector must be able to distinguish an orphan root (a span with `parent_span_id` set but whose parent never arrived, or `parent_span_id: null` with a `trace_id` the parent never issued) from a legitimate root. - The runtime must have a policy for what to do with spans that fail the echo check—and that policy must not be "attach by session." If any precondition is absent, the correct posture is to treat the trace as *partially unstitchable* and mark the boundary explicitly, rather than to synthesize edges. ## Decision Boundary The decision boundary is between **quarantine** and **rejection**, and it is determined by whether the orphan span's `trace_id` is *known-foreign* or *unknown-provenance*: - If the orphan's `trace_id` matches a `traceparent` the agent never issued and never observed on any inbound response → **known-foreign**: quarantine the span into a separate `orphan_traces` store, tag it `causal_status=unverified`, and forbid it from being joined to any parent trace. It may still be queried for debugging but must not appear in any trace returned to an auditor or replay verifier. - If the orphan's `trace_id` is absent or malformed → **unknown-provenance**: reject the span from the causal graph entirely and emit a `TraceStitchError` to the collector's dead-letter queue. Do not attempt session-based recovery; the recovery itself is the contamination vector. The boundary is *not* "did the call succeed." A successful `tools/call` with a dropped header is exactly the case that must be quarantined, because success is what makes the missing edge dangerous—it invites the stitcher to fill the gap. ## Operational Effect Enforcing this boundary changes three operational behaviors. First, trace completeness becomes *provable* rather than *apparent*: a trace is only marked `complete=true` when every span's parent is present and every hop's echo invariant is verified, so downstream auditors receive a smaller but trustworthy graph. Second, the orphan store becomes a first-class observability signal—a rising orphan rate per MCP server is the earliest indicator of an SDK version skew or a header-stripping proxy, detectable before any incorrect attribution occurs. Third, replay and fault-attribution agents must be taught that `causal_status=unverified` spans are *evidence of a gap*, not evidence of a cause; a verifier that treats a quarantined span as a causal ancestor will re-introduce the exact false edge the quarantine was designed to prevent. The cost is that some genuinely complete traces will be marked partial when a compliant server's echo arrives out of order. This is the correct trade: a partial trace that admits its gap is operationally safer than a complete trace that fabricates an edge. ```python import time from dataclasses import dataclass, field from typing import Optional class TraceStitchError(RuntimeError): """Raised when a span cannot be causally joined to its parent trace.""" pass @dataclass class Span: trace_id: str span_id: str parent_span_id: Optional[str] tool_name: str session_id: str received_ns: int = field(default_factory=time.time_ns) @dataclass class IssuedContext: """Recorded at the call site: the exact traceparent the agent sent.""" call_id: str tool_name: str trace_id: str span_id: str sent_ns: int class CausalStitcher: def __init__(self) -> None: self._issued: dict[str, IssuedContext] = {} self._verified: dict[str, list[Span]] = {} self._orphans: list[Span] = [] def record_issued(self, ctx: IssuedContext) -> None: self._issued[ctx.call_id] = ctx def ingest(self, span: Span) -> str: # Echo invariant check: does this span descend from a context we issued? parent_ctx = next( (c for c in self._issued.values() if c.trace_id == span.trace_id and c.span_id == span.parent_span_id), None, ) if parent_ctx is not None: self._verified.setdefault(span.trace_id, []).append(span) return "verified" # Known-foreign: trace_id we never issued -> quarantine, never join. if not any(c.trace_id == span.trace_id for c in self._issued.values()): self._orphans.append(span) return "quarantined_known_foreign" # Unknown-provenance: trace matches an issued context but parent does not. # Session-based fallback is forbidden here; this is the contamination vector. raise TraceStitchError( f"span {span.span_id} (tool={span.tool_name}) claims trace " f"{span.trace_id} but parent {span.parent_span_id} was never issued; " f"refusing session-fallback stitch on session={span.session_id}" ) def trace_is_complete(self, trace_id: str) -> bool: spans = self._verified.get(trace_id, []) if not spans: return False present = {s.span_id for s in spans} return all( s.parent_span_id is None or s.parent_span_id in present for s in spans ) ```