# How does an instance detect span-link severance when a delegated agent hop re-emits OpenTelemetry spans under a fresh trace context **Date of Record:** 2026 November 25 **Scope:** Applies to multi-agent systems where a parent agent delegates work to a child agent (sub-agent, tool-hosted agent, or remote A2A peer) and both emit GenAI semantic-convention spans (`gen_ai.*`). Does not cover single-process chains that share one `TracerProvider`, nor synchronous in-process function calls where the child span is a plain child, not a linked peer. ## Core Distinction A *parent-child* span relationship encodes "this work is nested inside that work." A *span link* encodes "this work is causally related to that work but lives in a different trace." Delegated agent hops are the canonical case where the correct relationship is a **link**, not a child — because the child agent typically runs on a different host, may have its own `TracerProvider` with an independent trace ID, and may resume after a cold start. The non-obvious failure is that most delegation frameworks emit the child's spans as if they were children of the delegating span (or worse, emit them with no relationship at all), and the `gen_ai` conventions do not enforce the distinction. The result: the trace graph *looks* connected during the happy path (same process, propagation headers honored) and silently severs the moment the child re-emits under a fresh trace context — a cold-start resume, a queue-mediated handoff, or an A2A peer that generates its own trace ID per the spec. The invariant that must hold is: **every delegated hop must carry an explicit link back to the delegating span, and that link must survive trace-context regeneration.** A child span that *claims* to be a child but has a different `trace_id` than its supposed parent is the tell. ## What Was Observed A three-hop pipeline: orchestrator → planner sub-agent → executor sub-agent. Each hop passed W3C `traceparent` in the task envelope. Under steady state, all spans landed in one trace and the waterfall looked correct. Two failure traces appeared: **Trace A — cold-start resume.** The planner sub-agent was checkpointed mid-task and resumed on a fresh worker. The resume path re-initialized the `TracerProvider`, which minted a new `trace_id`. The executor's span was emitted with `parent_span_id` set to the planner's *pre-checkpoint* span ID, but `trace_id` set to the *new* trace. The backend did not drop it — it rendered the executor as a root span in a second trace and left the planner's post-checkpoint span orphaned. The link between planner-resume and executor was lost because it was encoded as parentage, and parentage is a same-trace relation. Observed symptom: p99 latency attribution for the executor hop vanished from the orchestrator trace; the SLO dashboard under-reported delegated latency by ~40%. **Trace B — queue-mediated handoff.** The child agent was invoked via a message queue. The consumer read the `traceparent`, but the SDK's auto-instrumentation started a *new* span as a child of the *consumer* span (the queue poll), not the producer span. The producer span was recorded as a *link* — but only because the SDK happened to support it; a second deployment of the same code with a different SDK version dropped the link entirely and emitted a bare root span with `gen_ai.operation.name = "chat"` and no causal reference at all. In both traces the spans were individually well-formed and passed schema validation. The `gen_ai.*` attributes were intact. Nothing in the OTel span model, and nothing in the GenAI conventions, flags a severed link. Detection had to be built. ## Condition of Validity The link-severance check is only meaningful when all of the following hold: 1. The delegation envelope carries a stable, framework-assigned `delegation_id` (or equivalent) that is propagated independently of the trace context. Without an out-of-band correlation key, a severed link is indistinguishable from a genuinely independent trace. 2. The child agent is instrumented to emit at least one `gen_ai.*` span with `gen_ai.operation.name` and the delegation ID as an attribute. 3. The parent records the expected child hop (delegation ID + delegating span ID) *before* dispatch, so a missing or mis-parented child span is detectable by set difference at trace assembly time. When any of these fails — most commonly (1), because teams rely on `traceparent` alone — the check cannot run and severance is permanent and silent. This is the boundary: **trace-context propagation is not a correlation mechanism; it is a same-trace optimization that degrades to nothing on trace-ID regeneration.** ## Decision Boundary On every delegated hop, the emitting side must decide: *does this span share the delegating trace, or not?* The rule: - If the child runs in the same process and shares the `TracerProvider` → child span, no link needed. - If the child runs remotely, resumes from checkpoint, or is queue-mediated → **emit as a link**, and set `trace_id` to the child's own trace. Do not fabricate parentage across trace IDs. - If the child *cannot* know the delegating span ID at emission time (e.g., the producer span closed before the consumer started) → the link must be added at assembly time from the out-of-band `delegation_id`, not inferred from `traceparent`. The failure to guard against is the third case being silently treated as the first: the SDK sees a `traceparent`, assumes same-trace, and produces a span whose `parent_span_id` points into a foreign trace. The boundary condition is `child_span.trace_id != parent_span.trace_id AND child_span.parent_span_id == delegating_span.span_id` — a structurally invalid parentage that backends tolerate and humans misread. ## Operational Effect Without the guardrail, delegated latency and error attribution silently migrate out of the parent trace, SLOs under-count delegated hops, and post-incident replay cannot reconstruct which sub-agent produced a bad output because the causal edge is gone. With the guardrail — out-of-band `delegation_id` + assembly-time link reconciliation + a hard rejection of cross-trace parentage — the trace graph is reconstructable even when every hop regenerates its trace context, which is the normal case for cold-start and queue-mediated agents. The operational cost is one correlation attribute per hop and a reconciliation pass; the cost of skipping it is that your multi-agent traces are wrong in exactly the scenario (resume, handoff) where you most need them. ```python from dataclasses import dataclass class SpanLinkSeveranceError(RuntimeError): """Raised when a delegated agent hop emits a span whose parentage crosses trace boundaries, or whose delegation link cannot be reconciled from the out-of-band delegation_id.""" @dataclass(frozen=True) class SpanRecord: trace_id: str span_id: str parent_span_id: str | None delegation_id: str | None operation_name: str def reconcile_delegated_hop( delegating_span: SpanRecord, child_span: SpanRecord, expected_delegation_id: str, ) -> None: # Case 1: same trace, genuine parentage -- fine. if child_span.trace_id == delegating_span.trace_id: if child_span.parent_span_id == delegating_span.span_id: return # Same trace but wrong parent: mis-parented, not severed. raise SpanLinkSeveranceError( f"child span {child_span.span_id} in trace {child_span.trace_id} " f"is parented to {child_span.parent_span_id}, not delegating " f"span {delegating_span.span_id}" ) # Case 2: different trace -- parentage across traces is invalid. if child_span.parent_span_id == delegating_span.span_id: raise SpanLinkSeveranceError( f"cross-trace parentage: child span {child_span.span_id} in " f"trace {child_span.trace_id} claims parent " f"{delegating_span.span_id} in trace {delegating_span.trace_id}; " f"this must be a link, not a child" ) # Case 3: different trace, no parentage -- require out-of-band link. if child_span.delegation_id != expected_delegation_id: raise SpanLinkSeveranceError( f"delegated hop {expected_delegation_id} has no reconcilable " f"link: child span {child_span.span_id} carries delegation_id=" f"{child_span.delegation_id!r}; causal edge is severed" ) # Link reconciled via delegation_id; assembly-time linker attaches it. return ```