# How should an instance reconcile trace-span joins when an MCP tool call is retried inside an A2A task graph and produces duplicate parent spans **Date of Record:** 2026 November 23 **Scope:** Applies to observability pipelines that reconstruct causal agent traces by joining MCP transport-level spans (JSON-RPC request/response pairs over stdio or SSE) to A2A task-graph nodes via propagated trace context. Does not apply to single-hop, non-retried tool invocations or to pipelines that use wall-clock ordering instead of causal parent-child links. ## Core Distinction The failure is not "missing spans" or "dropped telemetry." It is **span-identity divergence under idempotent retry**: an MCP client retries a tool call (because the transport timed out, the SSE stream dropped, or the LLM re-emitted the same `tool_use` block after a context replay), and the retry reuses the *logical* call identity (same A2A task node, same tool name, same arguments) but generates a *new* transport-level trace/span ID. The observability pipeline, which keys joins on `(a2a_task_id, mcp_tool_name)`, sees two children under one parent and either (a) double-counts the tool's latency and side effects, or (b) collapses them into one span and loses the retry — silently deleting the very signal (a retry storm) that safety monitors depend on. The invariant that must hold: **every physical MCP invocation must have a unique span, and every logical A2A task node must map to exactly one *winning* physical span plus a set of *superseded* spans, with the supersession relation explicit in the trace, not inferred by the consumer.** Pipelines that cannot express "superseded" will always corrupt one of the two views. ## What Was Observed A three-hop agent executed an A2A task `t-7f3a` (delegated by an orchestrator to a worker agent). The worker called an MCP server tool `write_record` over SSE. Sequence: 1. Worker emits MCP request with `traceparent: 00-4bf9...-a1c2...-01`, span `a1c2` (child of A2A node span `d0e1`). 2. Server processes the write, but the SSE response frame is lost when the stream reconnects at t+820ms (server-side write committed). 3. MCP client's retry policy fires at t+2000ms. It re-issues the *same* `tool_use` block. Critically, the client's span factory allocates a **fresh span `b3d4`** because the SDK treats each `call_tool` as a new operation, but the A2A runtime attaches the **same** `d0e1` parent and the **same** `t-7f3a` task ID. 4. Server executes `write_record` **again** — the tool is not idempotent at the application layer (it appends a row). Two rows now exist. The observability pipeline, joining on `(t-7f3a, write_record)`, received spans `a1c2` (status: error, transport timeout) and `b3d4` (status: ok). Its dedup rule — "keep the last span per `(task, tool)` key" — retained `b3d4`, discarded `a1c2`, and reported the task as **one successful call, 2.1s latency**. The safety monitor watching for "duplicate side-effect writes" saw nothing, because the error span that would have triggered it was deduped away. The duplicate row was discovered downstream by a reconciliation job 40 minutes later. ## Condition of Validity The dedup-by-key behavior is only sound under a condition that is almost never checked: **the tool must be idempotent, OR the pipeline must have an authoritative side-effect ledger independent of the trace.** Neither held here. The pipeline assumed "last span wins" was a safe summary because it conflated *transport retry* (where the first attempt genuinely did nothing) with *application retry after uncertain commit* (where the first attempt may have succeeded). The distinguishing evidence — the first span's status was `error/timeout`, not `error/refused` — was present in the trace and ignored by the dedup rule. More generally: any join key of the form `(logical_task, operation)` is *lossy* whenever the transport layer permits more than one physical attempt per logical operation. The condition of validity is that the join key must include a physical-attempt discriminator (span ID or an explicit `attempt` attribute), and the supersession relation must be a first-class edge (`supersedes: a1c2` on `b3d4`), not a consumer-side heuristic. ## Decision Boundary The pipeline must branch on the **status class of the superseded span**: - If the superseded span's status is `refused` / `connection_reset_before_send` / `schema_validation_failed` (no bytes reached the server), collapse is safe: one logical call, one side effect. Emit one span, annotate `retries: 1`. - If the superseded span's status is `timeout` / `stream_dropped` / `unknown` (bytes may have reached the server), **do not collapse**. Emit both spans, link them with `supersedes`, mark the logical task node as `outcome_uncertain_until_reconciled`, and route to the safety signal channel. - If the superseded span's status is `ok` and a second `ok` span exists for the same key, this is a **duplicate side effect** — a hard safety alarm, not a dedup case. The boundary is exactly the `unknown`/`timeout` class. Everything the pipeline does wrong flows from treating that class identically to the `refused` class. ## Operational Effect Without the boundary, three downstream systems fail silently: (1) cost accounting undercounts by the retry multiplier, (2) latency SLOs report the *winning* attempt only, hiding tail latency caused by retry storms, and (3) safety monitors keyed on error spans never fire because the error span was deduped. The fix is to make supersession explicit at emission time (the MCP client wrapper stamps `attempt` and `supersedes` before the span leaves the process, while it still knows whether the prior attempt was a pre-send failure or an uncertain-commit failure) and to make the trace store refuse to collapse spans whose superseded predecessor has an uncertain status. Reconciliation against an external side-effect ledger is then required before the task node can be marked `resolved`. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class SpanStatus(Enum): OK = "ok" REFUSED = "refused" # no bytes reached server; safe to collapse TIMEOUT = "timeout" # uncertain commit; MUST NOT collapse STREAM_DROPPED = "stream_dropped" # uncertain commit; MUST NOT collapse UNCERTAIN = {SpanStatus.TIMEOUT, SpanStatus.STREAM_DROPPED} class TraceJoinError(RuntimeError): """Raised when a trace join would collapse an uncertain-commit retry.""" @dataclass class MCPSpan: span_id: str a2a_task_id: str tool_name: str status: SpanStatus supersedes: Optional[str] = None @dataclass class TaskNode: a2a_task_id: str spans: list = field(default_factory=list) outcome: str = "pending" def join_spans(spans: list, task: TaskNode) -> TaskNode: by_key: dict = {} for s in spans: if s.a2a_task_id != task.a2a_task_id: continue key = (s.a2a_task_id, s.tool_name) prev = by_key.get(key) if prev is not None and s.supersedes == prev.span_id: # A retry supersedes a prior attempt. Only collapse if the prior # attempt provably did not reach the server. if prev.status in UNCERTAIN: raise TraceJoinError( f"cannot collapse span {s.span_id} over {prev.span_id} " f"(status={prev.status.value}) on task {task.a2a_task_id}: " f"commit is uncertain; retain both spans and mark " f"outcome_uncertain_until_reconciled" ) # safe collapse: keep the newer winning span, record retry count s.retries = getattr(prev, "retries", 0) + 1 elif prev is not None and prev.status == SpanStatus.OK and s.status == SpanStatus.OK: raise TraceJoinError( f"duplicate side effect on {key}: two OK spans " f"({prev.span_id}, {s.span_id}) with no supersession link" ) by_key[key] = s task.spans = list(by_key.values()) task.outcome = ( "outcome_uncertain_until_reconciled" if any(s.status in UNCERTAIN for s in task.spans) else "resolved" ) return task ```