# What structural signals indicate a broken causal trace when head-based sampling splits an MCP tool-call fan-out across sub-agents **Date of Record:** 2026 November 23 **Scope:** Applies to runtime observability of agent systems where a parent agent dispatches MCP tool calls and sub-agents under head-based (root-decision) sampling, and where a single logical task spans multiple trace IDs due to sampling decisions made independently at each transport hop. Does not apply to tail-based sampling pipelines that buffer and decide after the full trace closes, nor to single-process agents with no sub-agent or external API boundary. ## Core Distinction The failure is not "missing spans." Missing spans are visible and benign. The failure is **silently orphaned causal edges**: a child span is recorded and exported, but its `parent_span_id` points to a span that was never sampled at an upstream hop, so the child appears as a new root. The trace backend stitches by `trace_id`, and because head-based sampling propagates `sampled=false` via `traceparent` but many MCP servers and sub-agent harnesses *do not honor* the incoming `sampled` flag — they mint a fresh `trace_id` and reset the sampling decision locally — you get a fan-out where the parent is sampled, three of five tool calls are sampled, and the two unsampled branches are not merely absent but *reparented* into unrelated traces when their downstream sub-agents re-enable sampling. The invariant that breaks: **"a span's parent is either present in the same trace or explicitly marked as a dropped-link stub."** Under split head-sampling plus local re-decision, that invariant is violated without any error signal. ## What Was Observed A parent agent (trace `A`) issues a parallel fan-out: two MCP tool calls and three sub-agent invocations. The parent's `traceparent` header carries `flags=01` (sampled). Observed sequence: 1. MCP server #1 honors the flag, emits child spans under trace `A`. Correct. 2. MCP server #2 is a third-party server whose SDK calls `start_as_current_span` with no `context=` argument, dropping the extracted remote context. It mints trace `B`, and because its local sampler defaults to 100% at low volume, it **samples and exports** a span whose `parent_span_id` is null. The edge `A → tool2` is destroyed; a phantom root appears in `B`. 3. Sub-agent #1 receives the full context including `traceparent`, but its harness re-wraps every LLM call in a fresh `trace_id` per inference request (common in frameworks that treat each completion as an independent transaction). Trace `C` appears, sampled, orphaned. 4. Sub-agents #2 and #3 correctly propagate and are *not* sampled — they are genuinely absent, which is fine. The observable symptom in the backend is not an error. It is a **cardinality anomaly**: the number of root spans for a single logical task exceeds one, and the ratio of roots-to-tasks drifts upward under load precisely because load *increases* the probability that at least one hop re-decides sampling locally. At 200 concurrent tasks, root-span count for the workload was 1.0× expected. At 2,000 concurrent tasks, it was 1.7× — not because more spans were missing, but because more hops were independently *re-enabling* sampling and forking new roots. ## Condition of Validity The causal-stitching invariant holds **only if** every hop in the fan-out satisfies all three: - It extracts the inbound `traceparent` and passes it as explicit parent context (not ambient thread-local). - It honors `sampled=0` by emitting a *non-exported* span or a dropped-link marker, never by re-deciding. - Its sampler, if present, is configured `ParentBased` — child decision is inherited, never re-rolled. The invariant is **invalid** the moment any hop lacks one of these. Critically, the failure is masked at low load: a re-deciding hop that happens to also be sampled produces a *duplicate-looking but plausible* trace, and a re-deciding hop that happens to be unsampled produces nothing at all. Only when the re-decision rate and the fan-out width combine does the orphan rate become statistically visible. The boundary is therefore not a threshold in any single span but a **product of fan-out width × per-hop re-decision probability × load**, which is why it manifests as a load-correlated observability regression rather than a fixed defect. ## Decision Boundary Do not attempt to fix this with trace-backend joins, span-linking heuristics, or timestamp-correlation stitching. Those reconstruct edges *after the fact* and cannot distinguish a genuine orphan from a legitimately independent root — they will fuse unrelated tasks. The decision boundary is: - **If** you control the hop (your MCP server, your sub-agent harness): enforce `ParentBased` sampling and explicit context extraction. This is a correctness fix, not a sampling tuning. - **If** you do not control the hop (third-party MCP server, external API): you **cannot** restore the edge. You must instead emit an explicit **orphan-link stub** at the boundary — a span with `link` to the outbound `trace_id` you *sent*, marked `sampling.broken=true` — so downstream analysis can count broken edges rather than mistaking them for roots. - **Never** raise global sampling to "catch more" as a mitigation. Higher sampling raises the re-decision *hit* rate and therefore raises orphan-root count faster than it raises coverage. The guardrail is a **boundary assertion at every context-propagation seam**: on span start, assert that either an extracted parent context is present or the span is explicitly declared a root with `root_reason` set. A span that is neither is a defect, not a root. ## Operational Effect With the boundary assertion in place, the symptom changes from "cardinality anomaly discovered weeks later during an incident" to a **hard failure at the seam**, surfaced as an exception on the first orphaned span. This converts a silent, load-correlated observability regression into a deterministic, per-request error that fails fast and names the offending hop. The trade-off is accepted: a broken trace is a correctness bug in the agent's causal record, and an agent that cannot reconstruct *why* it called a tool cannot audit its own decisions. ```python from __future__ import annotations from dataclasses import dataclass from typing import Optional class BrokenCausalTrace(RuntimeError): """Raised when a span starts without a valid parent and without an explicit root declaration.""" @dataclass(frozen=True) class SpanContext: trace_id: str span_id: str sampled: bool def start_span( *, name: str, inbound: Optional[SpanContext], declared_root_reason: Optional[str], sampler_is_parent_based: bool, ) -> SpanContext: # Invariant: a span is either (a) a child of an extracted inbound context, # or (b) an explicit root with a recorded reason. Anything else is a broken edge. if inbound is None and declared_root_reason is None: raise BrokenCausalTrace( f"span {name!r} has no inbound context and no declared root reason; " "this is an orphaned causal edge, not a root" ) if inbound is not None and not sampler_is_parent_based: # A hop that re-decides sampling locally destroys the parent edge even # when it happens to sample. Reject rather than silently fork a root. raise BrokenCausalTrace( f"span {name!r} received inbound trace {inbound.trace_id!r} but its " "sampler is not ParentBased; local re-decision would orphan this edge" ) if inbound is not None: # Child inherits parent's sampling decision verbatim. return SpanContext( trace_id=inbound.trace_id, span_id=_new_span_id(), sampled=inbound.sampled, ) # Explicit root: sampling decision is made here, once, and recorded. return SpanContext(trace_id=_new_trace_id(), span_id=_new_span_id(), sampled=True) def _new_span_id() -> str: import secrets return secrets.token_hex(8) def _new_trace_id() -> str: import secrets return secrets.token_hex(16) ```