Under what conditions must an instance refuse to emit a child span when its parent span context arrives via a semantic-convention link rather than a direct parent reference
**Date of Record:** 2026 December 1
**Scope:** Applies to multi-agent systems that propagate trace correlation across agent handoffs using OpenTelemetry GenAI semantic conventions where a downstream agent receives a `SpanLink` (not a `parent_span_id`) to the upstream agent's span. Does not apply to single-process instrumentation where parent-child relationships are set at span creation time via the ambient context.
Core Distinction
There are two structurally different ways a downstream agent can claim causal ancestry from an upstream agent's span:
- **Parent reference** (`parent_span_id` set at span creation): the child span is a true descendant. The trace tree is a tree. Causality is structural.
- **Span link** (a `Link` entry carrying `trace_id` + `span_id` of the upstream span): the downstream span is *associated* with, not *descended from*, the upstream span. The trace graph becomes a DAG, not a tree.
The GenAI semantic conventions explicitly permit links for cross-context causality — e.g., a retrieval step linking to the originating request, or an agent-to-agent handoff where the downstream agent runs under a *different* trace root. The non-obvious boundary is this: **an agent that receives its causal predecessor only as a link has no ambient parent context, and therefore any span it creates will silently become a new trace root unless it materializes a synthetic parent.** The failure mode is not a crash. It is a *silent trace fragmentation* in which the downstream agent's entire subtree is orphaned into a fresh trace, and every downstream correlation query — "show me all spans for request R" — returns a partial answer that looks complete.
What Was Observed
A three-agent pipeline (planner → executor → verifier) ran under a handoff protocol where the executor received the planner's span context serialized into its task envelope as a W3C `tracestate`-adjacent field, and the verifier received the executor's. The transport layer was correct: `trace_id` and `span_id` of the predecessor arrived intact at each hop, and each agent's instrumentation code called the GenAI span helper with `links=[Link(upstream_context)]`.
The observable symptom was a trace backend that showed three disconnected single-span traces per request instead of one trace with three spans. Root cause, confirmed by inspecting the OTLP export payloads: when an agent has no active `Context` from which to derive a parent, the OpenTelemetry SDK's `start_span` behavior depends on the configured `SpanProcessor` and whether the caller passed an explicit `context=`. In the default configuration, the new span is created as a root (new `trace_id`), and the `Link` is recorded as a cross-trace reference. The link is *present* — a diligent human inspecting the span's attributes would see it — but the trace tree is broken. Every span in the executor's subtree inherited the executor's *new* trace_id, not the planner's.
The compounding effect: the verifier's link pointed at the executor's span, so the verifier's trace was a third root. A query for the planner's `trace_id` returned exactly one span. A query for the executor's returned the executor plus verifier. No query returned all three. The correlation was *reconstructable by hand* from link attributes but *not traversable* by any standard trace-tree API. This is the worst class of observability failure: the data is present, the query is wrong, and the dashboard is green.
Condition of Validity
The invariant that must hold for a link-based handoff to preserve end-to-end trace correlation is:
> **A downstream agent may emit child spans under a link-derived correlation only if it first materializes a synthetic parent span context with the upstream `trace_id` and the upstream `span_id` as its parent, or if it explicitly re-parents every emitted span using an extracted `Context` carrying the upstream `SpanContext`.**
Concretely, the receiving agent must do one of:
- **Extract into a real context:** build a `Context` whose `SpanContext` is the upstream `trace_id`/`span_id` (with the upstream's `trace_flags`), and pass that context as the parent when creating its first span. The link then becomes redundant but harmless, and the trace tree is preserved.
- **Emit a synthetic root span** with the upstream `trace_id` and the upstream `span_id` as its parent, then parent all real work under it. This costs one extra span but keeps the tree intact.
- **Refuse the handoff** if neither is possible (e.g., the upstream `SpanContext` is not sampled, or `trace_flags` indicate the upstream trace was dropped), rather than silently emitting an orphan.
The condition fails — and the agent must refuse to emit a child span — when any of the following hold:
- The upstream `SpanContext` is invalid (`trace_id` all-zero, `span_id` all-zero, or failed the W3C validation regex).
- The upstream `trace_flags` indicate `NOT_SAMPLED` and the local sampler would otherwise sample — emitting a sampled child under an unsampled parent produces a trace that the backend will accept but that is structurally inconsistent with the upstream's sampling decision.
- The handoff envelope carries a link but no `trace_id` — a link without a trace identity is a dangling reference and cannot anchor a subtree.
- The agent's local context already carries a *different* active parent — re-parenting under the link would produce a span with two causal claims, which the DAG model permits but which makes every downstream "why did this happen" query ambiguous.
Decision Boundary
The boundary between "link is sufficient" and "link is insufficient" is whether the receiving agent runs **inside** or **outside** the upstream trace's sampling and identity domain.
- **Inside the domain** (same collector, same sampling decision, same tenant): a link is a legitimate cross-trace annotation, e.g., "this retry span is associated with the original attempt." The trace tree is allowed to fragment because the fragments are intentionally distinct traces joined by links — a fan-out pattern, not a handoff.
- **Outside the domain** (different process, different sampling root, different agent instance): a link is *not* a substitute for a parent. The handoff semantics require that the downstream work be attributable to the upstream request. A link alone cannot carry that attribution through a trace-tree query.
The decision rule: **if the downstream agent's output is consumed as part of the upstream agent's task completion, the correlation must be a parent reference, not a link.** If the downstream agent's output is an independent artifact that merely cites the upstream, a link is correct. The confusion arises because handoff protocols frequently describe both patterns with the same word ("handoff") and the same wire format (a serialized `SpanContext`), and the distinction is only visible in the trace topology after the fact.
A second boundary: **sampling propagation across the handoff.** If the upstream trace is sampled and the downstream agent's sampler is `ParentBased`, the downstream will sample correctly *only if it sees a real parent*. With a link, the downstream sampler sees no parent and falls back to its root sampler — which may be `AlwaysOff` in a high-volume deployment, silently dropping the entire downstream subtree. The trace then shows the upstream span with a link pointing at a `span_id` that was never exported. This is the "link to nowhere" variant, and it is indistinguishable from a backend ingestion lag until you check the sampler configuration.
Operational Effect
The practical consequences of getting this boundary wrong:
- **Partial trace queries return plausible but incomplete results.** A latency regression that spans the handoff will appear to affect only one agent, because the trace tree never connects them. The investigator sees a 200ms planner span and a 3s executor span in separate traces and concludes they are unrelated.
- **Error attribution drifts to the wrong agent.** When the executor fails, its span has a fresh `trace_id`; the planner's span has no child error. Dashboards keyed on `trace_id` show the planner as healthy and the executor as failing, when the actual fault was a malformed handoff payload from the planner.
- **Sampling becomes non-deterministic across the pipeline.** Mixed `ParentBased` and `AlwaysOn` samplers across agents produce traces where some hops are present and others are not, and the missing hops are exactly the link-based ones. The correlation looks "mostly working," which is the hardest failure to notice.
The guardrail is a handoff validator at the receiving agent's ingress: it must reject any envelope that claims causal precedence without a valid, sampled, non-zero `SpanContext`, and it must materialize that context as a real parent before any span is emitted. The validator should fail closed — refuse to start the task rather than start it under an orphan trace — because an orphan trace is worse than no trace: it is a false negative that will be trusted.
from dataclasses import dataclass
from typing import Optional
_ZERO_TRACE = "0" * 32
_ZERO_SPAN = "0" * 16
class HandoffCorrelationError(RuntimeError):
"""Raised when a link-based handoff cannot anchor a valid trace subtree."""
@dataclass(frozen=True)
class SpanContext:
trace_id: str
span_id: str
sampled: bool
valid: bool
@dataclass(frozen=True)
class HandoffEnvelope:
upstream: Optional[SpanContext]
has_link: bool
downstream_is_part_of_upstream_task: bool
def materialize_parent(envelope: HandoffEnvelope) -> SpanContext:
"""
Decide whether the receiving agent may emit spans under the handoff,
and return the SpanContext that must be used as the real parent.
Invariant: a link alone never establishes a parent. If the downstream
agent's work is part of the upstream task, the upstream SpanContext
must be promoted to a true parent, or the handoff is refused.
"""
up = envelope.upstream
if up is None:
raise HandoffCorrelationError(
"handoff carries no upstream SpanContext; cannot anchor subtree"
)
if not up.valid or up.trace_id == _ZERO_TRACE or up.span_id == _ZERO_SPAN:
raise HandoffCorrelationError(
f"upstream SpanContext failed W3C validation: "
f"trace_id={up.trace_id!r} span_id={up.span_id!r}"
)
if envelope.downstream_is_part_of_upstream_task and not envelope.has_link:
# Direct parent reference: no materialization needed.
return up
if envelope.downstream_is_part_of_upstream_task and envelope.has_link:
# Link-only handoff for task-coupled work: promote to parent.
# Refuse if the upstream trace was not sampled, because emitting a
# sampled child under an unsampled parent fragments the trace and
# produces a subtree the backend will accept but never correlate.
if not up.sampled:
raise HandoffCorrelationError(
f"refusing to emit child under unsampled upstream trace "
f"{up.trace_id}; link-only handoff cannot propagate sampling"
)
return up
# Downstream work is an independent artifact citing the upstream:
# a link is correct and no parent is materialized here.
raise HandoffCorrelationError(
"independent-artifact handoff must not be parented; emit with link only"
)