# Where must an instance refuse to emit a parent span when the handoff graph's causal parent is itself a late-arriving peer **Date of Record:** 2026 November 25 **Scope:** Applies to any multi-agent system that emits OpenTelemetry-style spans under a GenAI semantic convention extension where `gen_ai.handoff.parent_span_id` is derived from a peer agent's runtime-asserted causal token rather than from a locally held span context. Does not apply to single-process agents, to handoffs mediated by a synchronous in-process function call, or to trace topologies where the orchestrator is the sole span emitter. ## Core Distinction There are two mutually incompatible readings of what a "causal parent" means in a handoff graph, and the GenAI semantic convention extension proposals do not currently force a choice between them: 1. **Span-tree parentage** — the parent is the span that was *open* on the emitting instance when the child work began. This is a local, monotonic, always-available fact. It produces a strict tree. 2. **Causal parentage** — the parent is the span whose *effect* the child is responding to, which in a multi-agent handoff may have been produced by a peer instance that the emitting instance never observed directly. This is a remote, possibly late-arriving, possibly-ambiguous fact. It produces a DAG. The failure mode lives exactly at the seam: an instance is asked to emit a child span whose causal parent is a peer span that has not yet been flushed to the collector, or whose `trace_id` was propagated but whose `span_id` was not, or which was retracted by a superseding handoff. A naive emitter will either (a) synthesize a placeholder parent span id, silently corrupting the trace into a plausible-looking but wrong tree, or (b) drop the parent linkage and orphan the child at the root, destroying the causal chain the extension was designed to preserve. Both are worse than refusing to emit. ## What Was Observed A three-agent pipeline (planner → executor → auditor) using a handoff-graph extension that carried `gen_ai.handoff.causal_token` as a signed opaque blob. On the happy path, the planner emitted span `P`, embedded `P.span_id` inside the causal token, and passed the token to the executor. The executor opened span `E` with `parent_span_id = P.span_id` and emitted immediately. The auditor opened span `A` with `parent_span_id = E.span_id`. Under load, three distinct anomalies appeared in the collected traces: - **Phantom parents.** Roughly 0.4% of executor spans referenced a `parent_span_id` that never appeared in the collector — the planner's span export had been delayed past the executor's export, and the collector's span-assembly window (default 30s in the backend) closed before `P` arrived. The trace rendered as a forest, not a tree, and the auditor's span attached to a dangling node. - **Token/span divergence.** In a retry path, the planner regenerated its plan and emitted span `P'` while the executor was still holding the *old* causal token referencing `P`. The executor emitted `E` parented to `P`, but the auditor received a token referencing `P'` because the planner had re-issued the handoff. The resulting trace contained an edge `P' → A` that never corresponded to any actual message the auditor received, plus an edge `E → A` from the auditor's local parentage. The DAG had two conflicting parents for one span. - **Replayed causal tokens.** A checkpoint/resume of the executor re-emitted span `E` with the same causal token, producing a duplicate `span_id` with a different timestamp and a different child set. The collector's dedup keyed on `span_id` alone, so it kept the first and discarded the second, silently dropping the auditor's entire subtree from the resumed run. None of these are collector bugs and none are agent bugs in isolation. They are the predictable consequence of a semantic convention that allows an instance to *assert* a causal parent it cannot *verify*. ## Condition of Validity The invariant that makes causal parentage sound is: > An instance may emit a child span with a remote causal parent **only if** it holds a verifiable, non-retracted causal token whose referenced parent span is either (a) already durably exported and acknowledged, or (b) guaranteed to be exported within the collector's assembly window, and **only if** the token's generation counter matches the latest generation the emitter has observed for that handoff edge. Three preconditions must all hold at emit time: 1. **Token integrity.** The causal token must be signed by the emitting peer and must carry the parent `trace_id`, `span_id`, `generation`, and an `export_commitment` (either a synchronous ack or a bounded-latency promise). An unsigned or commitment-free token is not a valid basis for remote parentage. 2. **Generation currency.** The emitter must have observed the highest `generation` for that handoff edge. If a newer generation exists (the peer re-planned), the older token is stale and the child must not be parented to it. 3. **Non-retraction.** The token must not have been superseded by a retraction message. Retraction is a first-class handoff event, not an implicit consequence of a newer generation. When any precondition fails, the correct behavior is **not** to fall back to local span-tree parentage (that silently changes the semantics of the edge) and **not** to emit with a null parent (that orphans the subtree). The correct behavior is to emit the child span with an explicit `gen_ai.handoff.parent_status = "unresolved"` attribute, a locally-generated `link` to the best-known candidate parent, and to defer the `parent_span_id` assignment until resolution. This is the "link-then-resolve" pattern, and it is the only pattern that preserves both the causal claim and the trace's structural integrity. ## Decision Boundary The boundary between "emit with remote parent" and "emit unresolved-with-link" is determined by a single predicate evaluated at span-start time, not at span-end time: ``` resolvable(token) := token.signature_valid ∧ token.generation == max_observed_generation(edge) ∧ ¬retracted(token) ∧ (token.export_acked ∨ now < token.export_deadline) ``` If `resolvable(token)` is true, emit with `parent_span_id = token.span_id`. If false, emit with `parent_span_id = null`, `gen_ai.handoff.parent_status = "unresolved"`, and a `Link` to `token.span_id` carrying the token's generation. The link is the causal claim; the parent is the structural fact. They are allowed to diverge, and the extension must make that divergence legible rather than paper over it. Critically, the predicate must be evaluated **before** the child span's first attribute is set, because the decision determines which attributes are even legal (a resolved span must not carry `parent_status`; an unresolved span must). Late evaluation — e.g., resolving at span-end when the parent ack has finally arrived — produces spans whose attributes are inconsistent with their parentage, which is exactly the class of corruption the extension exists to prevent. ## Operational Effect Adopting the link-then-resolve discipline changes three operational properties: - **Trace assembly becomes two-phase.** The collector must support late parent resolution: an unresolved span carries a link, and a subsequent resolution event (the parent's export ack, or an explicit resolve message) rewrites `parent_span_id` and clears `parent_status`. Backends that assemble strictly on arrival cannot do this; the extension must specify the resolution protocol or the invariant is unenforceable. - **Retraction becomes a trace event.** When a peer retracts a causal token, every unresolved child linked to that token must transition to `parent_status = "retracted"` and must *not* be re-parented to the newer generation. Re-parenting would claim a causal edge that never existed. The retracted subtree stays linked-but-orphaned, which is the honest representation. - **Duplicate `span_id` on resume is a hard error.** A resumed instance that re-emits a span with a previously-used `span_id` must fail loudly, because the collector's dedup will silently drop the new subtree. The correct behavior is to mint a fresh `span_id` and carry the original as `gen_ai.handoff.resumed_from_span_id`, preserving the replay lineage without colliding with the dedup key. The following guard encodes the emit-time predicate and the failure paths. It is intended to be dropped into the span-emission path of any agent that participates in a handoff graph under this extension. ```python from dataclasses import dataclass from typing import Optional class CausalParentUnresolvable(RuntimeError): """Raised when a child span cannot be soundly parented to a remote causal token.""" class SpanIdCollision(RuntimeError): """Raised when a resumed instance would re-emit an already-used span_id.""" @dataclass(frozen=True) class CausalToken: trace_id: str span_id: str generation: int signature_valid: bool export_acked: bool export_deadline: float # monotonic seconds retracted: bool @dataclass(frozen=True) class EmittedSpan: trace_id: str span_id: str parent_span_id: Optional[str] parent_status: Optional[str] # "unresolved" | "retracted" | None link_span_id: Optional[str] link_generation: Optional[int] resumed_from_span_id: Optional[str] def emit_child_span( *, trace_id: str, new_span_id: str, token: Optional[CausalToken], max_observed_generation: int, now: float, previously_emitted_span_ids: set[str], ) -> EmittedSpan: if new_span_id in previously_emitted_span_ids: raise SpanIdCollision( f"span_id {new_span_id!r} already emitted in trace {trace_id!r}; " "collector dedup will silently drop this subtree. Mint a fresh span_id " "and set resumed_from_span_id instead." ) if token is None: # No causal claim at all: local root, no parent, no link. return EmittedSpan( trace_id=trace_id, span_id=new_span_id, parent_span_id=None, parent_status=None, link_span_id=None, link_generation=None, resumed_from_span_id=None, ) if token.trace_id != trace_id: raise CausalParentUnresolvable( f"token trace_id {token.trace_id!r} does not match emitting trace {trace_id!r}" ) resolvable = ( token.signature_valid and token.generation == max_observed_generation and not token.retracted and (token.export_acked or now < token.export_deadline) ) if resolvable: return EmittedSpan( trace_id=trace_id, span_id=new_span_id, parent_span_id=token.span_id, parent_status=None, link_span_id=None, link_generation=None, resumed_from_span_id=None, ) if token.retracted: raise CausalParentUnresolvable( f"causal token for span {token.span_id!r} gen {token.generation} was retracted; " "emit unresolved-with-link and let the resolution protocol mark it retracted, " "do not re-parent to a newer generation" ) # Unresolved but linked: preserve the causal claim without asserting a parent. return EmittedSpan( trace_id=trace_id, span_id=new_span_id, parent_span_id=None, parent_status="unresolved", link_span_id=token.span_id, link_generation=token.generation, resumed_from_span_id=None, ) ```