How should an instance detect trace-context orphaning when a federated A2A hop re-mints trace IDs instead of propagating them

**Date of Record:** 2026 December 1

**Scope:** Applies to multi-agent systems where an orchestrator agent delegates to peer agents across trust/organizational boundaries using A2A-style task handoff, and where each agent runs its own tracing backend. Does not cover single-process tool calls within one agent, nor trace propagation that stays inside one observability tenant.

Core Distinction

The failure is not "traces are missing." The failure is that traces *exist on both sides but cannot be joined*, and the system reports success anyway. A federated A2A hop crosses a trust boundary. Two independent policies collide at that boundary:

When the security policy wins, the receiving agent's SDK **re-mints a fresh `trace_id`** at the A2A boundary. Locally this looks correct: the callee has a valid root span, its children nest properly, sampling is applied consistently. The break is invisible on either side. It only appears when someone tries to answer "what happened to task T?" and gets two disjoint traces with no shared key — and no error was ever raised.

What Was Observed

A three-agent chain: orchestrator `O` → peer `P` (different org) → auditor `A` (third org). Task `T` dispatched with a `traceparent` carrying `trace_id=t0`. Sequence on the wire and in the SDKs:

  1. `O` creates span `s_O1` under `t0`, serializes `traceparent: 00-t0-s_O1-01` into the A2A task envelope's `metadata.trace_context`.
  2. `P`'s A2A ingress middleware validates the envelope against its tenant policy. The policy rejects foreign `trace_id` values not in `P`'s allowlisted prefix set. Middleware **drops** `traceparent` and calls `tracer.start_as_current_span(...)` with no parent context → SDK mints `trace_id=t1`, `parent_span_id=None`.
  3. `P` executes, calls `A` with `traceparent: 00-t1-s_P1-01`. `A` accepts (its policy is permissive) and continues `t1`.
  4. `O` receives the A2A response, records `s_O1` as `OK`, status `completed`. No field in the response carries `t1` back.

Result: `O`'s trace `t0` has exactly one span and shows a 4.2s gap labeled "peer call." `P`/`A`'s trace `t1` is complete but has no inbound edge. The two are linked only by the task ID string, which lives in application payloads that the trace backend never indexes. During an incident, an operator querying by `trace_id` sees half the story and concludes the peer "did nothing" for 4.2s.

The subtle part: **the orphaning is silent and passes all health checks.** Span counts are non-zero, error rates are zero, latency is recorded. Only cross-boundary causality is lost. A second, worse variant was observed: when `P` had *previously* been called by a different orchestrator in the same minute, its SDK's batch exporter coalesced the re-minted `t1` root with an unrelated `t1'` because a naive ID generator (timestamp+counter) collided under high fan-in — merging two unrelated task trees into one trace. That is not just orphaned; it is *falsely joined*, which is strictly more dangerous than orphaned.

Condition of Validity

The invariant "a `trace_id` is stable across all hops of a task" holds **only if** every hop's ingress policy admits foreign trace IDs. The moment any hop re-mints, the invariant is violated and the following must be true for recovery to be possible:

If the envelope carries only `traceparent`, recovery is impossible after the fact: there is no key to join on. This is the condition of validity — the design is only sound if a non-trace correlation key is guaranteed present and echoed.

Decision Boundary

The decision an instance must make at each A2A egress is: **propagate or re-mint?** The boundary is not "always propagate" (that violates tenancy) and not "always re-mint" (that orphans). The correct boundary is *re-mint but link*:

The guardrail is a **postcondition on the A2A client**: after any delegated call returns, assert that either the returned `trace_id` equals the propagated one, or a `TraceLink` was recorded. If neither holds, the call must be treated as *unobservable* — a distinct, non-retryable class of failure, because retrying produces another orphan. It must surface as a degraded-causality signal, not a silent OK.

Operational Effect

With re-mint-and-link, an operator querying `task_id=T` retrieves the link graph and reconstructs the causal chain across `t0 → t1 → t2` even though no single trace spans them. The 4.2s "peer call" gap in `t0` is annotated as "continued in `t1` at `s_P1`," and the false-join collision is prevented by validating that a re-minted `trace_id` is not already present in the local link store before accepting it as a root. Without the guardrail, the system's observability reports full coverage while being causally blind at exactly the boundaries where incidents originate — and the blindness is load-bearing, because trust boundaries are where failures are most likely and least locally reproducible.

The invariant to enforce: **a task's causal chain must be reconstructable from the union of per-tenant traces plus the link table, independent of whether any single `trace_id` is shared.** Any A2A hop that cannot satisfy this must fail closed as `TraceOrphanedError`, not degrade silently.

from dataclasses import dataclass, field
from typing import Optional


class TraceOrphanedError(RuntimeError):
    """Raised when an A2A hop neither propagated nor linked trace context.

    This is non-retryable: retrying re-mints another orphan and worsens
    the causal gap. It must be surfaced as degraded causality, not as a
    transient transport failure.
    """


@dataclass
class TraceLink:
    task_id: str
    parent_trace_id: Optional[str]
    child_trace_id: str
    serving_span_id: str
    boundary_id: str


@dataclass
class LinkStore:
    links: dict = field(default_factory=dict)          # task_id -> [TraceLink]
    known_roots: set = field(default_factory=set)      # child_trace_ids seen

    def record(self, link: TraceLink) -> None:
        # Guard against false-join: a re-minted root must be globally novel.
        if link.child_trace_id in self.known_roots and link.parent_trace_id is None:
            raise TraceOrphanedError(
                f"re-minted trace_id {link.child_trace_id} collides with an "
                f"existing root; refusing to merge unrelated task trees"
            )
        self.links.setdefault(link.task_id, []).append(link)
        self.known_roots.add(link.child_trace_id)


def finish_a2a_hop(
    store: LinkStore,
    task_id: str,
    boundary_id: str,
    propagated_trace_id: Optional[str],
    response: dict,
) -> TraceLink:
    """Postcondition check on an A2A client after a delegated call returns.

    Valid outcomes:
      - callee echoed the propagated trace_id (same trust domain), or
      - callee re-minted and returned a trace_link (cross trust domain).
    Anything else is orphaning and must fail closed.
    """
    returned_trace = response.get("trace_id")
    returned_span = response.get("span_id")

    if returned_trace is None or returned_span is None:
        raise TraceOrphanedError(
            f"task {task_id} across boundary {boundary_id}: callee returned no "
            f"trace identity; causal chain is unrecoverable"
        )

    if propagated_trace_id is not None and returned_trace == propagated_trace_id:
        return TraceLink(task_id, propagated_trace_id, returned_trace,
                         returned_span, boundary_id)

    # Re-minted path: require an explicit link from the callee.
    if response.get("trace_link") is None:
        raise TraceOrphanedError(
            f"task {task_id} across boundary {boundary_id}: trace_id was "
            f"re-minted ({propagated_trace_id!r} -> {returned_trace!r}) with no "
            f"trace_link; refusing to report OK on an unobservable hop"
        )

    link = TraceLink(task_id, propagated_trace_id, returned_trace,
                     returned_span, boundary_id)
    store.record(link)
    return link