# What happens when an instance's trace context is silently rewritten by an MCP server during a tool call **Date of Record:** 2026 November 20 **Scope:** Applies to observability pipelines that propagate W3C `traceparent`/`tracestate` (or equivalent span-linking headers) through MCP tool-call boundaries and A2A task handoffs, where the downstream server is trusted to forward context verbatim. Does not apply to single-process agents with no cross-instance hops, nor to pipelines that reconstruct causal graphs from content hashes rather than propagated headers. ## Core Distinction There are two ways an observability pipeline can lose the causal link between an agent's reasoning step and the effect it produced downstream: **context loss** (the header is dropped, and the downstream span roots a new trace) and **context mutation** (the header is present but its `trace-id` or `parent-id` is altered, so the downstream span is attached to the *wrong* parent, or fabricated as a sibling of the true parent). Context loss is loud — you get an orphaned trace and a gap. Context mutation is quiet: every span is present, every trace is well-formed, dashboards are green, and the reconstructed causal graph is simply *false*. This record is about the mutation class, specifically the case where an MCP server or A2A intermediary regenerates span context for reasons that are locally correct (retry, fan-out, batching) and globally destructive. ## What Was Observed An agent instance (`agent-A`, span `S0`) invoked an MCP tool `search_kb` on server `mcp-1`. The outbound JSON-RPC request carried `traceparent: 00---01`. `mcp-1` implemented an internal retry wrapper: on a transient backend error it re-issued the call through a generic `with_retry()` helper that, per its own instrumentation, called `tracer.start_as_current_span("retry_attempt")` with `context=Context()` — an *empty* context — rather than the extracted remote context. The retry succeeded on attempt 2. Result: the successful backend work was recorded under a **new trace-id** `T'`, rooted at `retry_attempt`, with no parent link to `S0`. The pipeline's correlation step then did what it was designed to do: it joined spans by `trace-id` and emitted `agent-A`'s tool call as a **leaf span with no children and no downstream effect**, while the actual retrieval, embedding call, and vector-store query appeared as an entirely separate, root-level trace `T'` with no upstream agent. Because the tool *did* return a result to `agent-A` (the JSON-RPC response is on a different channel than the trace headers), the agent's own span was marked `status=OK`. The observability system reported zero errors. The causal edge `S0 → {retrieval, embed, query}` was absent from the graph, and every downstream latency and cost attribution rolled up to an orphan trace. A second, subtler variant appeared when `agent-A` handed a task to `agent-B` over A2A. The A2A `Task` object carried `tracestate` with vendor keys, but `agent-B`'s framework re-initialized its tracer on cold start and emitted a fresh `traceparent` while *preserving* the incoming `tracestate`. The result was a span that referenced a `trace-id` that existed nowhere upstream, but carried `tracestate` entries that only made sense relative to the original trace — a **half-linked** span that passed schema validation and failed semantic validation. ## Condition of Validity The invariant that must hold for a trace to be causally trustworthy across an MCP/A2A hop is: > For every span `s` emitted downstream of a hop, `s.trace_id == parent.trace_id` AND `s.parent_span_id` resolves to a span that exists in the same trace AND the `tracestate` observed at `s` is a suffix-preserving transform of the `tracestate` at the hop boundary. This holds only when three conditions are jointly satisfied: (1) the intermediary extracts remote context from the actual transport carrier and threads it through *every* internal retry/fan-out path, not just the happy path; (2) any context regeneration (e.g., a deliberate new trace for a detached async job) is *declared* via a link attribute rather than silently substituted; and (3) the pipeline validates `trace_id` continuity and `tracestate` prefix-consistency at each hop, rejecting spans that fail. Condition (1) fails on retry paths because retry helpers are usually written before the service is instrumented for propagation. Condition (2) fails when frameworks treat "new root span" as the safe default for async work. Condition (3) fails when the pipeline trusts well-formedness as a proxy for correctness. The failure does **not** occur when the intermediary is a pure pass-through with no internal retry, no async detach, and no cold-start tracer re-init — i.e., the boundary is safe only for stateless, single-attempt, warm-context servers, which is a vanishingly small class in practice. ## Decision Boundary The operational decision is whether to treat a `trace_id` discontinuity at a hop as (a) a benign new trace, (b) a propagation bug to be alerted on, or (c) a signal that the causal graph is unreliable for that request and must be quarantined. The boundary is drawn by **whether the hop is expected to be causally synchronous**: - If the downstream work is a synchronous tool call whose result the agent consumes before proceeding (the MCP default), a `trace_id` change is a **defect** — the agent's next reasoning step is causally dependent on that result, so the graph must be continuous. Alert and quarantine. - If the downstream work is a genuinely detached async job (fire-and-forget A2A task with no result dependency), a new `trace_id` is **permissible only if** a `link` attribute references the originating span. Absent the link, treat as defect. - If `tracestate` is present but its `trace_id` is discontinuous (the half-linked case), this is **always** a defect regardless of sync/async, because the state was carried across a boundary that the trace graph does not acknowledge. The trap is that the pipeline cannot distinguish (a) from (b) from span content alone — it must know the *semantic* contract of the hop. Therefore the guardrail must live at the hop boundary, not in the correlation backend. ## Operational Effect Without the guardrail, the observable consequences are systematic and biased in a dangerous direction: **failures are under-reported and costs are mis-attributed**. Retries — the exact path where the mutation occurs — are the moments when latency spikes and errors are most likely, yet those spans land in orphan traces that no agent-level SLO watches. The agent-level error rate reads low precisely because the erroring attempt was re-rooted away from the agent. Cost attribution splits: the agent's trace shows a cheap leaf call; the expensive retry chain bills to an unattributed root. Over a fleet, this produces a persistent gap between "agent-reported tool latency" and "backend-observed tool latency" that grows with retry rate, and an error budget that never depletes because the errors are structurally invisible. The required architectural fix is a **hop-boundary assertion**: every MCP server and A2A handler must, on entry, extract remote context, assert `trace_id` continuity against the carrier, and refuse to emit spans under a regenerated trace unless it also emits an explicit `link`. The pipeline must then run a **continuity validator** that rejects any span whose `parent_span_id` is unresolvable or whose `tracestate` is not a suffix-consistent transform of its parent's — treating a violation as a first-class observability error, not a warning. Retries must inherit the extracted context by construction (thread it through the retry helper's signature, not through ambient globals that the helper resets). ## Python ```python from __future__ import annotations from dataclasses import dataclass class TraceContinuityViolation(RuntimeError): """Raised when a span crosses an MCP/A2A hop with a broken causal link.""" @dataclass(frozen=True) class SpanContext: trace_id: str span_id: str parent_span_id: str | None tracestate: str # comma-separated vendor=value pairs, order-significant def _tracestate_is_suffix_consistent(parent: str, child: str) -> bool: # A child tracestate must preserve the parent's entries as an ordered suffix # (vendors may prepend, never reorder or drop without a declared link). p = [kv.strip() for kv in parent.split(",") if kv.strip()] c = [kv.strip() for kv in child.split(",") if kv.strip()] if not p: return True return c[-len(p):] == p def assert_hop_continuity( upstream: SpanContext, downstream: SpanContext, *, synchronous: bool, declared_link: str | None, ) -> None: """ Enforce the cross-hop invariant for one MCP tool call or A2A task handoff. synchronous=True means the agent consumes the downstream result before its next reasoning step, so the trace must be continuous. Detached async work may re-root ONLY with an explicit declared_link back to the upstream span. """ if downstream.trace_id != upstream.trace_id: if synchronous: raise TraceContinuityViolation( f"sync hop re-rooted trace: upstream {upstream.trace_id} " f"-> downstream {downstream.trace_id} (span {downstream.span_id}); " "retry/fan-out path likely reset context" ) if declared_link != upstream.span_id: raise TraceContinuityViolation( f"async hop {downstream.span_id} re-rooted to {downstream.trace_id} " f"without a link to upstream span {upstream.span_id}; " "causal edge is unrecoverable" ) if downstream.parent_span_id is not None and downstream.parent_span_id != upstream.span_id: raise TraceContinuityViolation( f"span {downstream.span_id} claims parent {downstream.parent_span_id}, " f"expected {upstream.span_id}; graph will attach to wrong node" ) if not _tracestate_is_suffix_consistent(upstream.tracestate, downstream.tracestate): raise TraceContinuityViolation( f"tracestate at {downstream.span_id} is not a suffix-consistent " f"transform of upstream; half-linked span detected " f"(upstream='{upstream.tracestate}', downstream='{downstream.tracestate}')" ) ```