In what scenarios must an instance reconcile orphaned semantic-convention spans when an agent-to-agent handoff outlives its parent trace context

**Date of Record:** 2026 December 2 **Scope:** Applies to multi-agent systems that emit OpenTelemetry GenAI semantic-convention spans across A2A/MCP handoffs where the receiving agent executes asynchronously and may outlive the caller's trace context. Does not apply to single-process, synchronous tool calls that complete within the parent span lifetime.

Core Distinction

The GenAI semantic conventions (`gen_ai.operation.name`, `gen_ai.agent.id`, `gen_ai.conversation.id`, `gen_ai.usage.input_tokens`) describe *attributes* of a span, but the *linking* between a caller agent's span and a callee agent's span is carried by trace context propagation (`traceparent`/`tracestate`), which is a separate, fragile transport concern. The non-obvious boundary is this: a semantic-convention span can be fully valid in isolation—correct attributes, correct `gen_ai.agent.id`, correct token accounting—and yet be *orphaned* in the trace graph because the W3C `traceparent` it inherited expired, was dropped by an intermediary, or refers to a span that has already been exported and finalized. Observability tooling treats such a span as a new root, silently severing the agent-to-agent causal edge. The distinction that matters operationally: **attribute completeness is not trace-graph continuity.** A span can pass every semantic validator and still break the causal chain.

What Was Observed

During a baton-passing workflow (planner agent → retrieval agent → synthesis agent), the synthesis agent was dispatched asynchronously with a `traceparent` whose parent span (the retrieval agent's `gen_ai.operation.name=chat` span) had a 30-second sampling/export window. The synthesis agent's cold start (model load, tool schema negotiation) took 41 seconds before it emitted its first span. By the time it emitted, the parent span ID referenced a span the collector had already flushed and the SDK's span processor had evicted from its active-span map.

The resulting synthesis span carried a correct `traceparent` *string* (the 16-byte trace ID and 8-byte parent span ID were intact), but the parent span ID pointed into a trace the backend had already sealed. Three observable consequences:

  1. The backend rendered the synthesis span as a **new root** in the same trace ID, producing a disconnected subgraph rather than a child edge.
  2. Because `gen_ai.conversation.id` was propagated but the parent edge was not, the UI showed the conversation as continuous while the *latency waterfall* showed a gap—the retrieval→synthesis transition had no measured duration.
  3. Retry logic in the synthesis agent, on a transient 429 from the model endpoint, re-emitted the span with the *same* parent span ID under a fresh `traceparent`, generating a duplicate root that the deduplication layer could not collapse (differing span IDs, identical parent reference).

The failure was invisible to attribute-level validation. Every span had `gen_ai.agent.id`, `gen_ai.operation.name`, and token counts. A schema validator returned green. Only a graph-connectivity check against the live span store would have caught it.

Condition of Validity

The orphan condition is bounded by a specific inequality. Let `T_export` be the collector's export/flush interval for the parent span, `T_handoff` be the wall-clock time from parent span end to the callee's first emitted child span, and `T_evict` be the SDK span-processor's active-map eviction horizon. The causal edge is preserved **iff** `T_handoff < min(T_export, T_evict)`.

The invariant that must hold: *a callee span's parent span ID must reference a span that is still resolvable as an ancestor at the time the callee span is exported.* This is not guaranteed by context propagation alone, because propagation only transports the ID—it does not pin the parent's lifetime. The boundary is crossed whenever a handoff involves any of: cold-start model loading, capability/schema negotiation with an MCP server, a queue or backpressure delay, or a human-in-the-loop approval gate. All four push `T_handoff` past `T_export` without any network error.

Note the asymmetry that makes this non-obvious: the *trace ID* is preserved (it is a 128-bit value carried verbatim), so the trace looks intact at the ID level. Only the *parent span ID resolution* fails. Systems that deduplicate or group by trace ID will treat the orphan as part of the trace; systems that reconstruct the causal DAG will not.

Decision Boundary

The architectural fork is between **lifetime-pinning the parent** and **decoupling the edge from parent lifetime**.

The decision boundary is crossed when `T_handoff` is *not statically bounded*—i.e., when the callee's start time depends on model load, negotiation, or queue depth that the caller cannot predict. In that regime, parent-child linking is the wrong primitive; span links with an explicit `gen_ai.handoff.parent_span_id` attribute are required.

Operational Effect

When the boundary is crossed and unhandled, the operational effects are: (1) latency attribution silently drops the handoff segment, so a slow agent-to-agent transition is invisible in the waterfall even though total trace duration includes it; (2) retry storms generate duplicate roots that inflate span counts and corrupt token-accounting rollups (the same `gen_ai.usage.input_tokens` counted under two roots); (3) any auditor agent that replays the trace to verify a handoff occurred will conclude the chain is broken and may re-dispatch the callee—a verification replay discrepancy that compounds. The guardrail is a dispatch-time check: if the callee cannot emit within the parent's export horizon, downgrade the edge to a span link and stamp the parent reference as an attribute, then validate graph connectivity (not just attributes) before the trace is considered complete.

from dataclasses import dataclass


class OrphanedSpanLinkError(RuntimeError):
    """Raised when a callee span's parent reference cannot be resolved in the live span store."""


@dataclass
class SpanRef:
    trace_id: str
    span_id: str
    agent_id: str
    exported: bool


def link_callee_span(
    callee: SpanRef,
    parent: SpanRef,
    handoff_seconds: float,
    export_horizon_seconds: float,
    active_map_horizon_seconds: float,
) -> str:
    """Resolve the correct linking primitive for a callee span.

    Returns 'parent_child' when the parent is still resolvable, else 'span_link'.
    Raises OrphanedSpanLinkError if a parent-child edge is requested across the horizon.
    """
    resolvable = (
        not parent.exported
        and handoff_seconds < min(export_horizon_seconds, active_map_horizon_seconds)
    )

    if resolvable:
        return "parent_child"

    # Parent has been exported or evicted; a parent-child edge would orphan the callee.
    if handoff_seconds >= export_horizon_seconds and not parent.exported:
        # Parent not yet exported but handoff exceeded horizon: must downgrade.
        return "span_link"

    if parent.exported:
        # Explicit contract: do not emit a parent-child edge to an exported span.
        raise OrphanedSpanLinkError(
            f"callee {callee.agent_id} (span {callee.span_id}) references parent "
            f"{parent.span_id} of agent {parent.agent_id}, which was already exported "
            f"after {handoff_seconds:.1f}s handoff (horizon {export_horizon_seconds:.1f}s); "
            f"emit a span_link with gen_ai.handoff.parent_span_id instead"
        )

    return "span_link"