# When must an instance refuse to close a trace span it did not open: orphan-span attribution failure in cross-hop A2A trace correlation **Date of Record:** 2026 November 27 **Scope:** Applies to multi-instance agent systems where an orchestrator propagates a W3C-style `traceparent`/`tracestate` context across A2A handoffs into downstream MCP tool invocations, and where span emission is asynchronous relative to the reasoning loop. Does not apply to single-process agents that emit spans synchronously within one event loop, nor to traces terminated at a single trust boundary. ## Core Distinction The failure mode is not "missing spans." Missing spans are visible and countable. The failure mode is **misattribution of an orphan span to the wrong parent**, which produces a trace that is internally consistent, complete-looking, and wrong. An orphan span arises when a downstream instance receives a propagated context but cannot validate that the context's `span-id` corresponds to a span that instance is permitted to be a child of — because the parent instance crashed mid-loop, because the context was replayed from a retry queue, or because an MCP server echoed a `tracestate` it did not originate. The collector then performs **parent-id grafting**: it resolves the dangling `parent-id` to the nearest live span in the same trace with a matching service name, silently re-rooting the subtree. The resulting trace passes schema validation and latency budgets while encoding a causal claim (A called B which called C) that never occurred. The distinction that matters operationally: a *dropped* span is a gap you can alert on; a *grafted* span is a lie that suppresses alerts because the trace looks healthy. ## What Was Observed A three-hop pipeline: orchestrator `O` (reasoning agent), peer `P` (A2A delegate), and MCP tool server `T`. `O` emits `span-O1`, injects `traceparent` into the A2A envelope, `P` receives it and opens `span-P1` as a child of `span-O1`, then calls `T` over MCP with a fresh `traceparent` naming `span-P1` as parent. `T` opens `span-T1`. The trigger condition: `O`'s reasoning loop hit a token-budget exhaustion mid-tool-call and the process was checkpointed and resumed on a new instance `O'`. The checkpoint captured the A2A envelope (including the stale `traceparent` referencing `span-O1`) but did **not** capture the in-flight span registry, because the span registry lived in the tracing SDK's process memory, not in the agent's serialized state. On resume, `O'` replayed the A2A send. `P` received the envelope, saw `parent-id = span-O1`, opened `span-P1` as a child of `span-O1` — a span that no longer existed in any exporter's buffer, since `O`'s exporter had flushed and `span-O1` was marked complete before the crash. The collector's `parent-id` resolution: on ingest of `span-P1`, it looked up `span-O1`, found it absent from the live span index (already evicted after the flush window), and fell back to **nearest-ancestor-by-service-and-time**: it walked the trace's span table for the most recent span from service `O` with `end_time <= span-P1.start_time`. It found `span-O0` — the *previous* task's root span, retained because its trace-id collided under a 64-bit truncation bug in the SDK's ID generator. `span-P1` was grafted as a child of `span-O0`. The trace now asserts that a task from hour 3 delegated to a peer as a subtask of a task from hour 1. Downstream consequences observed in production telemetry: - The latency SLO for `O`'s task class was computed over a merged subtree spanning two unrelated tasks, inflating p99 by 40% and masking a real regression in `T`. - The auditor agent's replay verifier, which reconstructed causal order from the trace DAG, accepted the grafted edge and certified a handoff that `P` had in fact performed against a replayed, stale envelope — a **double-execution** that the trace hid rather than exposed. - No alert fired: span counts matched, no orphans were reported (grafting removes them from the orphan counter by definition), and the trace was marked `complete`. ## Condition of Validity The invariant that must hold for cross-hop trace correlation to be sound: > A span may only be attached to a parent if the emitting instance can present a **continuity token** proving it observed the parent span's *open* state — not merely its identifier — and the collector must reject any parent edge whose continuity token does not match a currently-open parent at ingest time. Concretely, this requires three things that the standard W3C propagation model does not provide: 1. **Parent-open validation at child-open time.** When `P` opens `span-P1`, it must confirm via a control-plane query (or a signed `tracestate` member carrying parent liveness) that `span-O1` is still open. If the parent is closed or absent, `P` must open `span-P1` as a **new root** with an explicit `orphaned=true` attribute, not as a child of a guessed ancestor. 2. **No nearest-ancestor fallback.** The collector must never synthesize a parent edge. An unresolvable `parent-id` yields a span with `parent-id` retained as an opaque string and `resolution=failed`; the span is quarantined from SLO computation and surfaced as a first-class orphan metric. 3. **Checkpoint/span-registry atomicity.** The agent's checkpoint must either (a) serialize the span registry alongside task state so resume re-opens the same span IDs, or (b) invalidate all in-flight `traceparent` values in the checkpoint and force downstream re-issuance on resume. Option (a) is preferred; option (b) is the safe fallback when the tracing SDK is not checkpointable. The condition of validity is **not** satisfied by ID uniqueness alone. The observed failure occurred with globally unique trace-ids; the graft happened because the collector's fallback logic was willing to invent an edge, not because IDs collided. (The ID collision in this incident was a second, independent defect that made the graft *plausible*; it is not the root cause.) ## Decision Boundary The decision boundary is: **does the instance hold a live reference to the parent span, or only its identifier?** - If live reference: emit child span normally; correlation is sound. - If identifier only (post-resume, post-replay, post-queue): the instance **must not** emit a child span under that identifier. It must emit a root span with `orphaned=true` and a `orphan_reason` in {`parent_closed`, `parent_evicted`, `replay_after_checkpoint`, `unverifiable`}, and it must increment a counter that is alertable *before* the trace is marked complete. - The collector must treat any span whose `parent-id` resolves to a span not present in the live open-span index as **quarantined**, not grafted. Quarantined spans are excluded from latency aggregation and from the auditor's causal-DAG reconstruction until a human or a replay verifier resolves them. The boundary is crossed the moment an instance replays a `traceparent` it did not itself mint in the current process lifetime. That is the exact predicate: **`traceparent` provenance ≠ current process span registry ⇒ orphan root, never child.** ## Operational Effect Enforcing the boundary converts a silent correctness failure into a loud availability signal — which is the correct trade for a system whose downstream consumers (SLO computation, auditor replay, causal debugging) depend on the DAG being true. The specific operational changes: - **Orphan rate becomes a first-class SLO input.** A rising orphan rate on resume paths is the leading indicator of checkpoint/registry desynchronization; it fires before latency regressions are detectable. - **The auditor's replay verifier must reject quarantined spans as causal evidence.** A handoff whose trace edge is quarantined is treated as *unverified*, not *verified*, which correctly blocks the double-execution certification observed in this incident. - **Grafting is removed from the collector entirely.** The nearest-ancestor fallback is deleted; the collector's contract becomes "resolve or quarantine," never "resolve approximately." - **Checkpoint schema gains a `span_registry` field or a `traceparent_invalidation` marker.** Either the registry round-trips, or every in-flight context is voided on resume and downstream instances are forced to re-root. The invariant to carry forward: **a trace edge is a causal claim, and a causal claim may only be emitted by an instance that can prove it observed the cause open.** An instance that holds only an identifier holds a rumor, not a reference, and must label it as such. ```python class OrphanSpanAttributionError(RuntimeError): """Raised when a span would be attached to a parent whose open state cannot be proven by the emitting instance. Grafting is forbidden; the span must be re-rooted as an explicit orphan.""" pass def open_child_span(parent_traceparent: str, live_registry: dict, span_id: str) -> dict: """ Open a child span under parent_traceparent, but only if the parent is provably open in this process's live span registry. live_registry: {span_id: {"open": bool, "minted_in_process": bool}} """ parent_id = _parse_span_id(parent_traceparent) entry = live_registry.get(parent_id) if entry is None: raise OrphanSpanAttributionError( f"parent span {parent_id} absent from live registry; " f"cannot prove open state — refusing to graft. " f"Emit as orphan root with orphan_reason=parent_evicted." ) if not entry["open"]: raise OrphanSpanAttributionError( f"parent span {parent_id} is closed; child {span_id} " f"would encode a false causal edge. orphan_reason=parent_closed." ) if not entry["minted_in_process"]: raise OrphanSpanAttributionError( f"parent span {parent_id} was not minted in this process " f"lifetime (replay after checkpoint). orphan_reason=replay_after_checkpoint." ) return { "span_id": span_id, "parent_id": parent_id, "orphaned": False, "resolution": "resolved", } def _parse_span_id(traceparent: str) -> str: # traceparent: 00--- parts = traceparent.split("-") if len(parts) != 4: raise OrphanSpanAttributionError(f"malformed traceparent: {traceparent!r}") return parts[2] ```