# When must an instance refuse to close a causal span: orphaned handoff attribution in multi-agent observability traces **Date of Record:** 2026 November 24 **Scope:** Applies to distributed tracing of multi-agent LLM systems where a parent agent emits a span, delegates to a child instance whose execution is traced by a separate emitter (different process, runtime, or vendor), and the trace is reconstructed by span-ID linkage. Does not apply to single-process, single-emitter traces where parent and child share one tracer object and one clock. ## Core Distinction The naive model treats a span as closed when the emitting instance returns from the delegated call. The correct model is: a parent span may only be *closed* (marked `end_time` set, status finalized) when every child span it causally spawned has either been received-and-linked or explicitly tombstoned as `MISSING`. These are different invariants. "The call returned" is a *local* fact. "All causal descendants are accounted for" is a *global* fact that the parent cannot observe at return time, because the child emitter's span arrives asynchronously over a different transport, possibly after the parent has already written its terminal record. The failure mode this produces is **orphaned handoff attribution**: the child span arrives at the collector with a `parent_span_id` pointing at a parent span that has already been finalized and flushed. The collector either (a) drops the orphan to avoid mutating a closed span, (b) attaches it as a root, severing causality, or (c) attaches it late, producing a trace whose causal graph mutates after downstream consumers (failure-mode classifiers, cost attributors, SLO evaluators) have already read it. All three corrupt the attribution the trace exists to provide. ## What Was Observed A three-tier pipeline: a planner agent (emitter A, in-process tracer), a tool-invocation agent (emitter B, sidecar with its own OTel SDK and its own wall clock), and a verifier agent (emitter C, remote, batch-flushed every 30s). Planner delegates to tool-agent via an MCP `tools/call`; tool-agent delegates to verifier via A2A `tasks/send`. Each hop carries a W3C `traceparent` in metadata. The trace below is representative of what the collector received, ordered by arrival: ``` t=0.000 A: span=root parent=null status=OK (planner) t=0.041 A: span=delegate parent=root status=OK (tools/call issued) t=0.044 A: span=delegate parent=root end_time=0.044 (returned) t=0.047 B: span=tool parent=delegate status=OK (sidecar flush) t=0.312 B: span=a2a_call parent=tool status=OK t=0.315 B: span=a2a_call parent=tool end_time=0.315 t=0.318 C: span=verify parent=a2a_call status=ERROR:Timeout t=31.2 C: span=verify parent=a2a_call end_time=31.2 (batch flush) ``` Two boundary failures are visible. First, `C:verify` arrives with `parent=a2a_call`, but by the time it arrives the collector has already marked `B:a2a_call` closed and, in one variant of the pipeline, evicted it from the hot index. The orphan is re-rooted. Second — and this is the non-obvious one — `C:verify` reports `ERROR:Timeout` at `t=0.318` but its `end_time` is `t=31.2`. The 30.9-second gap is *batch-flush latency*, not execution latency. A failure-mode taxonomy that classifies on `end_time - start_time` will label this a "verifier timeout" and attribute 31s of cost to the verifier, when the verifier actually failed in 3ms and the remaining 30.9s was the emitter sitting in a flush buffer. The causal link is correct; the *temporal attribution* is fabricated by the emitter's batching policy. ## Condition of Validity The invariant "a parent span is closed only when all causal children are accounted for" is only enforceable under a bounded, explicit contract. It holds when: 1. **Every handoff carries a span-ID the parent can enumerate before closing.** If the parent issues N delegations, it must hold N child span IDs (or N reservation tokens) before writing its terminal record. Outbound-only `traceparent` propagation is insufficient: the parent knows the trace ID it *sent*, not the span ID the child *will emit*. 2. **The collector distinguishes `PENDING` from `MISSING`.** A child not yet arrived is `PENDING` (within a declared flush deadline); a child past deadline with no record is `MISSING` (tombstoned). Collapsing these into "absent" is what causes silent re-rooting. 3. **Emitter clocks are not used for cross-emitter duration.** Only the *collector's* receive timestamps, or explicitly synchronized clocks with declared skew bounds, may be used to compute inter-span latency. Emitter-local `end_time - start_time` is valid only for intra-emitter duration. 4. **The flush deadline is shorter than the trace's retention window.** If emitter C flushes at 30s but the collector evicts closed spans at 25s, orphans are structurally guaranteed. When any of these fails—most commonly (1) and (4)—the invariant is unenforceable and the trace must be marked `DEGRADED`, not silently repaired. ## Decision Boundary The boundary is between **late-link (repair)** and **tombstone (declare loss)**. An instance must not attempt to link a child span to a parent it has already finalized unless it can do so without invalidating a published causal graph. Concretely: - If the parent is still `OPEN` (not yet flushed to consumers) and the child arrives within deadline: link, update, proceed. This is the only safe repair. - If the parent is `CLOSED` but not yet *consumed* (still in the mutable window before the classifier reads it): link, and emit an `AMENDED` event so consumers know the graph changed. - If the parent is `CLOSED` and *consumed*: do **not** re-root the orphan into the parent. Record it as a standalone `ORPHAN` span with a `lost_parent_ref` pointer, and mark the parent trace `DEGRADED` with a causal-completeness score. Re-rooting is the failure; a visible orphan is the honest record. The decision must be made by the collector, not the emitter, because only the collector sees arrival order. An emitter that "helpfully" re-emits with a corrected parent ID after its own flush is manufacturing a trace that never existed. ## Operational Effect Enforcing this invariant changes three downstream behaviors. First, failure-mode taxonomies must classify on `status` and on *collector-observed* span duration, never on emitter-reported duration when the emitter batches—otherwise flush latency is misattributed as execution latency, inflating timeout and cost buckets. Second, handoff attribution becomes a first-class metric: `orphan_rate` and `causal_completeness` per trace, where completeness = linked_children / reserved_children. A trace with completeness < 1.0 is quarantined from automated causal analysis rather than silently analyzed. Third, SLOs on "delegation success" must exclude `DEGRADED` traces, because a degraded trace cannot distinguish a real child failure from a lost child record. The cost is a small population of visibly incomplete traces; the alternative is a large population of confidently wrong ones. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class SpanState(Enum): OPEN = "open" CLOSED = "closed" CONSUMED = "consumed" # read by a downstream classifier; immutable TOMBSTONED = "tombstoned" class CausalIntegrityError(RuntimeError): """Raised when a trace cannot honor its causal-completeness invariant.""" pass @dataclass class Span: span_id: str parent_id: Optional[str] state: SpanState = SpanState.OPEN reserved_children: set = field(default_factory=set) linked_children: set = field(default_factory=set) class TraceCollector: def __init__(self, flush_deadline_s: float, retention_s: float): if flush_deadline_s >= retention_s: # structural guarantee of orphans; refuse to start raise CausalIntegrityError( f"flush_deadline {flush_deadline_s}s must be < retention " f"{retention_s}s, else orphans are guaranteed" ) self.flush_deadline_s = flush_deadline_s self.retention_s = retention_s self.spans: dict[str, Span] = {} def reserve_child(self, parent_id: str, child_span_id: str) -> None: parent = self.spans.get(parent_id) if parent is None: raise CausalIntegrityError(f"reserve on unknown parent {parent_id}") if parent.state is not SpanState.OPEN: raise CausalIntegrityError( f"parent {parent_id} is {parent.state.value}; " f"cannot reserve child {child_span_id} after close" ) parent.reserved_children.add(child_span_id) def close_span(self, span_id: str) -> None: span = self.spans[span_id] pending = span.reserved_children - span.linked_children if pending: # do NOT silently close with unaccounted children raise CausalIntegrityError( f"refusing to close {span_id}: {len(pending)} reserved " f"child span(s) unaccounted: {sorted(pending)}" ) span.state = SpanState.CLOSED def receive_child(self, span_id: str, parent_id: str) -> Span: parent = self.spans.get(parent_id) if parent is None: # lost parent entirely: record as orphan, never re-root silently orphan = Span(span_id, parent_id=None, state=SpanState.TOMBSTONED) self.spans[span_id] = orphan return orphan if parent.state is SpanState.CONSUMED: # parent already analyzed: re-rooting would rewrite published causality orphan = Span(span_id, parent_id=parent_id, state=SpanState.TOMBSTONED) self.spans[span_id] = orphan return orphan parent.linked_children.add(span_id) child = Span(span_id, parent_id=parent_id) self.spans[span_id] = child return child ```