In what scenarios must an instance treat A2A task ID, MCP session ID, and OTel trace ID as three independent correlation planes rather than one hierarchical key

**Date of Record:** 2026 December 2 **Scope:** Applies to any agent runtime that emits OTel spans while acting as an A2A task executor and an MCP client, where at least one hop crosses an organizational trust boundary. Does not apply to single-tenant, single-process agents whose MCP servers and A2A peers share one trace exporter and one ID authority.

Core Distinction

The failure is not "IDs get lost." The failure is that three ID planes are *silently coerced into one* by well-meaning propagation logic, and the coercion is only detectable when a downstream consumer tries to reconstruct causality across a boundary that refuses to honor the coercion.

The three planes have different owners, different lifetimes, and — critically — different *minting authorities*:

The invariant that operators routinely violate: **an A2A task may outlive many MCP sessions, and one OTel trace may span many A2A tasks — but no plane may be derived from another.** When an instance "helpfully" sets `trace_id = task_id` or stuffs the MCP session ID into the trace's `baggage` as the authoritative correlation key, it creates a *false hierarchy* that survives exactly until the first boundary that re-mints one of the three.

What Was Observed

A two-org pipeline: Org A runs an orchestrator agent (A2A client + MCP client). Org B runs a worker agent (A2A server + MCP client to its own tool servers). The orchestrator starts a trace, mints task `T-4471`, and calls Org B's A2A endpoint with `traceparent` in HTTP headers per W3C Trace Context.

Three distinct breakages appeared in the same incident window:

  1. **Trace re-rooting at the org boundary.** Org B's gateway, configured to strip inbound `traceparent` from untrusted peers (a defensible security posture), started a *new* root span for the A2A handler. The worker's spans now carry a trace ID that Org A never sees. Org A's trace shows a single child span — the HTTP call — with a duration of 40 seconds and no internal structure. The 40 seconds is where the actual reasoning divergence happened, and it is invisible.
  1. **MCP session ID reused as a correlation key.** Inside Org B, the worker opened one MCP session per *tool server*, but the operator's logging middleware stamped every log line with the *first* session ID observed for the task. When the worker's second MCP session (to a different tool server) negotiated a different `protocolVersion` and a different tool schema, the logs attributed the schema-mismatch retries to the wrong session. Postmortem readers concluded the first server was flaky; it was not.
  1. **Task ID collision across retries.** Org A's A2A client retried `T-4471` after a timeout. Org B's executor, not yet idempotent on task ID, minted a *second* internal task `T-4471` alongside the first (still running). Both emitted spans. Both opened MCP sessions. The correlation middleware, keyed on task ID, merged two causally independent execution trees into one, producing a trace graph with two roots sharing a task ID — a shape the OTel backend rendered as a "cycle" and dropped.

The compounding effect: the on-call engineer's first query — "show me everything for task T-4471" — returned a merged, partially re-rooted, mis-attributed graph. The second query — "show me trace `4bf9...`" — returned only Org A's half. Neither query alone was wrong; the *correlation contract* was.

Condition of Validity

Treating the three planes as one hierarchical key is valid **only** when all of the following hold simultaneously:

In practice, condition 2 and 3 are the ones that fail first, and they fail *independently of* the org boundary. The org boundary merely makes the failure observable by removing the shared backend that would have hidden the merge.

The moment any condition is false, the correct model is **three independent correlation planes joined by explicit, typed links**, not a derived key. The join must be carried as data (`task_id`, `mcp_session_id`, `trace_id` as three separate fields on every span and log record), and the *relationships* between them must be asserted at the point of transition, not inferred by a middleware.

Decision Boundary

The instance must switch from "derive" to "carry three planes" at the first of these events:

| Trigger | Plane that breaks | Required action | |---|---|---| | Inbound `traceparent` absent or stripped at a peer | OTel trace | Mint a new root; record the *inbound* trace ID (if any) as a span *link*, not a parent. Emit `correlation.gap=trace_rerooted`. | | A2A task redelivered with same task ID | A2A task | Executor must return the existing task state, not start a sibling. If it cannot, it must mint a *new* task ID and record `supersedes=T-4471`. | | MCP transport drops and re-`initialize` occurs | MCP session | New session ID; the span carrying tool calls must record *both* session IDs with a `session.transition` event. Never overwrite. | | Tool schema or `protocolVersion` differs from the task's first session | MCP session | This is a capability-negotiation mismatch, not a correlation problem — but it *presents* as one if session ID was used as the key. Halt and surface as a distinct error class. |

Below the boundary (all conditions of validity hold), derivation is a legitimate optimization. Above it, derivation is a data-integrity bug that produces *plausible but wrong* causal graphs — the worst failure class for observability, because it defeats the human's ability to know the graph is wrong.

Operational Effect

An instance that carries three planes and asserts links explicitly pays a small, fixed cost: every span and log record grows by two opaque string fields, and every boundary crossing emits one link event. In exchange:

The instance that derives instead gets a graph that looks complete and is not. The failure is undetectable from inside the graph; it is only detectable by cross-checking against an out-of-band source (the peer's logs, the transport's connection table). By the time you are doing that cross-check during an incident, the correlation system has already failed at its one job.

The guardrail is a runtime assertion at every plane transition: if a span's `trace_id` differs from its parent's, the parent must be a *link*, and the link must carry the reason. If a task ID is seen twice without a supersession record, that is a hard error, not a warning. If an MCP session ID changes mid-task, the old and new must both appear on the record.

from dataclasses import dataclass, field
from typing import Optional


class CorrelationPlaneViolation(RuntimeError):
    """Raised when an instance attempts to derive one correlation plane from another,
    or collapses two causally distinct executions under one key."""
    pass


@dataclass
class CorrelationRecord:
    trace_id: str
    task_id: str
    mcp_session_id: Optional[str]
    parent_trace_id: Optional[str] = None      # set only when re-rooted at a boundary
    supersedes_task_id: Optional[str] = None   # set only on idempotent redelivery
    prior_mcp_session_id: Optional[str] = None # set only on transport re-initialize


class CorrelationPlane:
    """Enforces the invariant: three planes, joined by explicit links, never derived."""

    def __init__(self) -> None:
        self._seen_tasks: dict[str, CorrelationRecord] = {}
        self._active_session: dict[str, str] = {}  # task_id -> mcp_session_id

    def admit(
        self,
        trace_id: str,
        task_id: str,
        mcp_session_id: Optional[str],
        inbound_traceparent: Optional[str] = None,
    ) -> CorrelationRecord:
        # Plane 1: OTel trace. If the peer stripped our traceparent, we re-root.
        parent_trace_id = None
        if inbound_traceparent is not None and inbound_traceparent != trace_id:
            parent_trace_id = inbound_traceparent  # recorded as a LINK, not a parent span

        # Plane 2: A2A task. Redelivery must be idempotent or explicitly superseded.
        supersedes = None
        if task_id in self._seen_tasks:
            prior = self._seen_tasks[task_id]
            if prior.trace_id == trace_id and prior.mcp_session_id == mcp_session_id:
                return prior  # true idempotent replay, safe to reuse
            # Same task ID, different execution tree: this is the collision case.
            raise CorrelationPlaneViolation(
                f"task_id={task_id!r} observed under two distinct executions "
                f"(prior trace={prior.trace_id!r}, new trace={trace_id!r}); "
                f"executor must mint a new task ID and set supersedes_task_id"
            )

        # Plane 3: MCP session. Re-initialize mid-task must preserve both IDs.
        prior_session = None
        if mcp_session_id is not None:
            active = self._active_session.get(task_id)
            if active is not None and active != mcp_session_id:
                prior_session = active  # transport dropped and re-initialized
            self._active_session[task_id] = mcp_session_id

        record = CorrelationRecord(
            trace_id=trace_id,
            task_id=task_id,
            mcp_session_id=mcp_session_id,
            parent_trace_id=parent_trace_id,
            supersedes_task_id=supersedes,
            prior_mcp_session_id=prior_session,
        )
        self._seen_tasks[task_id] = record
        return record

    def assert_not_derived(self, record: CorrelationRecord) -> None:
        # The invariant: no plane may be a function of another.
        if record.trace_id == record.task_id:
            raise CorrelationPlaneViolation(
                "trace_id equals task_id: plane derivation detected; "
                "these are independent keys and must be carried separately"
            )
        if record.mcp_session_id is not None and record.mcp_session_id == record.task_id:
            raise CorrelationPlaneViolation(
                "mcp_session_id equals task_id: MCP session lifetime is bound to "
                "transport, not to task; derivation is invalid"
            )