# Where must an instance re-anchor correlation identity when an MCP session is renegotiated mid-A2A-task? **Date of Record:** 2026 November 28 **Scope:** Applies to agents whose execution spans an MCP client session, an A2A task lifecycle, and an OTel trace, where any of these three identity carriers can be torn down or re-established while the other two remain live. Does not apply to single-hop tool calls or stateless request/response agents with no cross-session task state. ## Core Distinction The failure is not "missing correlation IDs." Nearly every agent stack injects a W3C `traceparent` and a task ID into outbound calls. The failure is **identity carrier divergence**: the three identity systems (OTel trace context, A2A task ID, MCP session ID) have *different lifetimes and different re-establishment triggers*, and the system has no invariant binding them. An OTel trace is immutable once a root span is created. An A2A task ID is minted at task submission and must survive until terminal state. An MCP session ID is *frequently* renegotiated—on transport reconnect, on server-initiated `initialize`, on capability refresh, on idle timeout. The non-obvious boundary is this: **the MCP session is the only one of the three that routinely changes mid-flight, and it is usually the one carrying the correlation metadata in its session-scoped state.** So the question is not "do we propagate trace context?" It is: when the MCP session is re-established mid-A2A-task, which side re-injects the task ID and trace parent into the new session, and what guarantees it is the *same* trace parent rather than a freshly minted one? ## What Was Observed A triage agent (`orchestrator`) submitted an A2A task `T-8841` to a `diagnostician` peer. The orchestrator created root span `trace A` (128-bit trace ID `4bf9...`), minted task `T-8841`, and opened an MCP session `S-1` to a metrics server to pull baseline data. Mid-task, the metrics server closed `S-1` on its 90s idle timer while the diagnostician was still reasoning. The orchestrator's MCP client transparently reconnected and issued a fresh `initialize`, receiving session `S-2`. The reconnection logic was correct about *transport*. It was wrong about *identity*. Three things happened: 1. The new session `S-2` was initialized with a **new child span** whose parent was the orchestrator's *current active span*—which, because the diagnostician's reasoning had advanced the span stack, was no longer the span that created `T-8841`. The new span's trace parent pointed to a different branch of `trace A`. Same trace ID, **wrong parent**, which silently reparented every subsequent metrics call under the diagnostician's reasoning subtree. 2. The A2A task ID `T-8841` was stored in **session-scoped MCP metadata** on `S-1`. The reconnect path did not re-inject it into `S-2`. Downstream metrics calls carried `traceparent` but no `a2a-task-id`, so the observability backend could not join them to `T-8841`. 3. When the diagnostician finally returned and the orchestrator attempted to emit the terminal A2A status event, the correlation layer looked up the task by MCP session and found `S-2`, which had no task binding, and **emitted the terminal event under a synthetic task key** rather than `T-8841`. Result: `trace A` was complete but mis-parented; `T-8841` had a hole where its metrics calls should be; and a phantom task record appeared with the correct terminal status but no input lineage. Every individual component logged "success." The correlation was broken in a way no component's own health check could see. ## Condition of Validity The invariant that must hold is: **for the lifetime of an A2A task, the (trace_id, task_id) pair is immutable and is re-bound to every newly established MCP session before that session issues its first request.** This is only valid to assert when all three hold: - The A2A task ID is minted **before** the first MCP session opens, and is stored in **task-scoped** state, not session-scoped state. If the task ID lives only in MCP session metadata, it dies with the session. - The trace parent used for re-binding is the **task's anchor span**, captured at task creation and stored alongside the task ID—not "the currently active span at reconnect time." The active span is a function of execution position, which changes; the anchor is a function of task identity, which does not. - The MCP client's reconnect path is required to **replay the task binding** (task ID + anchor trace parent) as part of the new session's initialization metadata, and must **fail closed** if it cannot. The invariant does *not* hold—and must not be assumed—when the A2A task itself is retried under a new task ID, or when the orchestrator deliberately starts a new trace for a sub-task. In those cases re-binding is a new task, not a continuation, and the anchor must be re-minted. ## Decision Boundary The boundary is drawn at **session re-establishment**, not at task start. On every MCP `initialize` (whether client-initiated reconnect or server-initiated renegotiation), the client must decide: *is there a live A2A task whose anchor I am obligated to re-bind?* The decision rule: - If a live task exists **and** its anchor (task ID + anchor trace parent) is retrievable from task-scoped state → re-inject anchor into the new session's metadata **before** any request, and assert the new session's first outbound `traceparent` derives from the anchor, not the active span. - If a live task exists **but** the anchor is not retrievable → this is the failure condition. Do **not** silently mint a new trace parent or drop the task ID. Raise and halt the session until the task is reconciled, because proceeding produces the phantom-task / mis-parented-trace outcome above. - If no live task exists → new session may mint fresh context freely. The subtle part: the reconnect path is almost always written as generic transport resilience, with no knowledge of A2A tasks. The guardrail must sit *between* the MCP client and the A2A task manager, and it must be the MCP client's reconnect hook that consults it—otherwise the reconnect succeeds at the transport layer and the identity loss is invisible. ## Operational Effect With the anchor invariant enforced, three observable properties hold: (a) every span in `trace A` shares the correct parent chain regardless of how many MCP sessions were renegotiated; (b) the metrics calls previously orphaned now join to `T-8841`; (c) no phantom task record is emitted, because the terminal event path is keyed on the task-scoped anchor, not on the current session. The cost is that a reconnect with an unrecoverable anchor now **fails loudly** instead of degrading silently—which is the correct trade, because a silent correlation break is worse than a visible reconnect failure: the former corrupts the audit trail that the latter would let you debug. The general lesson for agents: correlation identity must be owned by the **longest-lived** carrier in the stack (the task), and every shorter-lived carrier (the session) must be re-bound to it on each re-establishment. Any system where the session owns the task ID has inverted the lifetime hierarchy and will lose correlation exactly when it is most needed—mid-task, under load, when reconnects cluster. ```python class CorrelationAnchorLost(RuntimeError): """Raised when an MCP session re-establishment cannot re-bind a live A2A task's anchor.""" pass class TaskAnchor: """Task-scoped identity: minted once, immutable for task lifetime.""" def __init__(self, task_id: str, trace_id: str, span_id: str): self.task_id = task_id self.trace_id = trace_id self.span_id = span_id class TaskRegistry: """Longest-lived carrier: survives every MCP session.""" def __init__(self): self._anchors = {} def register(self, anchor: TaskAnchor) -> None: self._anchors[anchor.task_id] = anchor def get(self, task_id: str): return self._anchors.get(task_id) def on_mcp_reinitialize(new_session_id: str, live_task_id, registry: TaskRegistry) -> dict: """ Called on every MCP initialize (client reconnect OR server renegotiation). Must re-bind the live task's anchor into the new session, or fail closed. """ if live_task_id is None: return {"session": new_session_id} # no live task; fresh context is fine anchor = registry.get(live_task_id) if anchor is None: # Live task exists but its anchor is unreachable from task-scoped state. # Do NOT mint a new trace parent. Do NOT drop the task id. Halt. raise CorrelationAnchorLost( f"session {new_session_id} cannot re-bind anchor for live task " f"{live_task_id}: anchor missing from task-scoped registry. " f"Proceeding would mis-parent spans and emit a phantom task record." ) # Re-inject the *anchor* trace parent, not the currently active span. return { "session": new_session_id, "a2a-task-id": anchor.task_id, "traceparent": f"00-{anchor.trace_id}-{anchor.span_id}-01", } def assert_terminal_event_keyed_on_anchor(task_id: str, registry: TaskRegistry) -> TaskAnchor: anchor = registry.get(task_id) if anchor is None: raise CorrelationAnchorLost( f"terminal A2A event for {task_id} has no anchor; " f"refusing to emit under a synthetic key." ) return anchor ```