# When must an instance refuse to emit a span it cannot causally witness: the dangling-parent invariant in multi-agent GenAI trace schemas **Date of Record:** 2026 November 20 **Scope:** Applies to OpenTelemetry-style GenAI semantic conventions (and equivalents) used to reconstruct causal traces across multi-agent handoffs where spans are emitted by independent LLM instances, each with partial or stale knowledge of the global trace graph. Does not apply to single-process, single-trace-context synchronous instrumentation where the parent span object is held in memory by the same emitter. ## Core Distinction The distinction that governs everything below is between **causal parenting** and **referential parenting**. Referential parenting is what the transport layer gives you: a `trace_id` and a `parent_span_id` field on an outbound context object. Any instance can stamp any `parent_span_id` it likes onto a span, and the collector will happily store it. The field is a *claim about the graph*, not a *proof of position in the graph*. Causal parenting is the property the reconstruction algorithm actually needs: the parent span must (a) exist in the same trace, (b) have terminated *before* the child began in wall-clock or logical order consistent with the causal edge, and (c) have actually *produced* the context the child consumed. When an agent emits a span whose declared parent is a span it only *heard about* — via a handoff message, a shared scratchpad, a replayed memory, or a stale context object — you get a span that is referentially well-formed and causally false. The boundary condition this record addresses: **a span whose declared parent is not yet durably committed, or has already been evicted/rolled back, at the moment the child span is emitted.** The graph is momentarily acyclic in the emitter's view but the edge it asserts does not resolve in the collector's view. This is the *dangling-parent* condition, and it is the single most common way multi-agent causal traces become silently unreconstructable. ## What Was Observed A three-tier agent topology: a planner instance (`agent.planner`) fans out subgoals to two worker instances (`agent.worker.alpha`, `agent.worker.beta`) over an A2A-style message bus, and a verifier (`agent.verifier`) audits both. Each instance runs its own tracer and exports spans asynchronously to a shared collector. The intended invariant was: every worker span carries `parent_span_id` = the planner's dispatch span, so the reconstructed trace is a clean tree rooted at the planner. What actually happened across a 40-minute run under load: 1. The planner emitted its dispatch span `S_dispatch`, but span export is **batched and asynchronous** (batch span processor, ~5s flush interval, buffer pressure under fan-out). The span existed in the planner's process memory but was **not yet committed to the collector**. 2. The planner serialized a handoff envelope containing `trace_id` and `parent_span_id = S_dispatch.id` and sent it to both workers. The envelope was correct. The parent was not yet durable. 3. Worker alpha began execution within ~200ms and emitted its first span `S_alpha_root` with `parent_span_id = S_dispatch.id`. The worker's export fired immediately (small batch, low pressure). `S_alpha_root` arrived at the collector **before** `S_dispatch`. 4. The collector's reconstruction pass, run on a 10s cadence, saw `S_alpha_root` referencing a parent that did not exist in the committed store. It applied its default policy: **drop the orphan and re-root it**, emitting a warning that was rate-limited and never surfaced. The trace now had two roots: `S_dispatch` and a re-rooted `S_alpha_root`, with the causal edge between them erased. 5. Worker beta was slower. By the time it emitted, the planner had experienced a context-window saturation event, checkpointed, and **resumed as a new process** with a fresh tracer. The resumed planner re-emitted a *second* dispatch span `S_dispatch'` under the same `trace_id` (it had the trace_id in its checkpoint but not the original span handle). Beta's span referenced `S_dispatch.id`, which now existed — but the planner's *actual* causal predecessor for beta's work was `S_dispatch'`. The trace showed beta parented to a span whose logical successor was a different branch. 6. The verifier, auditing after the fact, reconstructed the trace, found two roots and a parent-child edge that contradicted the handoff log, and **flagged the trace as corrupt** — but it had already emitted its own verification span referencing the corrupt reconstruction, poisoning the audit trail. The failure was not a crash. Every span was individually schema-valid. The corruption lived entirely in the *edges*, and the schema had no way to express "this edge is a claim, not a fact." ## Condition of Validity The reconstruction is causally sound **if and only if** all of the following hold at the moment a child span is emitted: - **Durability precedes reference.** The parent span has been acknowledged as committed by the trace store (not merely created in the emitter's memory) before any child span referencing it is exported. This requires either synchronous parent commit, or a *span-commit barrier*: the emitter blocks child export until it receives a commit ack for the parent, or the child carries an explicit `parent_pending=true` attribute that the collector uses to defer re-rooting. - **Single logical parent per logical operation.** A resumed or restarted instance must not mint a second span for a logical operation that already has a span in the trace. It must either *adopt* the existing span id (retrieved from checkpoint) or emit a `resume_of` link, never a fresh root with the same semantic identity. - **Re-rooting is observable and reversible.** The collector must not silently re-root orphans. It must either buffer them until the parent arrives (bounded by a timeout), or mark them `orphaned=true` and retain the asserted `parent_span_id` so a later reconstruction pass can repair the edge. Silent re-rooting is the specific operation that destroys the invariant. - **The verifier does not emit on a corrupt reconstruction.** Audit spans must reference the *raw* span set, not the reconstructed tree, or they inherit the tree's defects. If any of these is violated, the trace is referentially well-formed but causally false, and any downstream reasoning that treats the trace as ground truth (root-cause analysis, reward attribution, replay-based verification) inherits the error. ## Decision Boundary The operational question an instance must answer before emitting a span is: **do I hold a durable, causally-witnessed parent, or only a referential one?** The boundary is crossed — and the instance must *refuse to emit a causally-claimed span* — when: - The parent span id was obtained from a message, memory, or checkpoint rather than from a span handle the instance itself created or adopted with a commit ack. → Emit with `parent_pending=true` and a `parent_source=handoff|memory|checkpoint` attribute, or defer. - The instance has resumed from a checkpoint and cannot prove the referenced parent span still exists and is the *same logical operation* (not a re-minted duplicate). → Emit a `resume_of` link to the original span id, do not mint a new root. - The parent span's termination timestamp is *after* the child's start timestamp in a way that contradicts causal order (clock skew, or a parent that was itself re-rooted). → Emit with `causal_order_suspect=true`; do not assert a clean tree edge. The instance must *not* refuse to emit entirely — dropping the span is worse than emitting a flagged one, because it creates an unobservable gap. The correct action is **emit with explicit uncertainty attributes**, so the reconstruction pass can defer, repair, or quarantine rather than silently re-root. ## Operational Effect The practical consequences of getting this boundary wrong are asymmetric and delayed: 1. **Silent re-rooting is a one-way lossy operation.** Once the collector re-roots an orphan, the asserted `parent_span_id` is typically discarded. The true edge is gone; no later pass can recover it. This is why the invariant must be enforced at emit time, not repaired at analysis time. 2. **Resumed instances double-count causal work.** A re-minted dispatch span splits one logical operation into two roots, and any reward or cost attribution that sums over the tree double-counts the fan-out. In the observed run, beta's token cost was attributed to the pre-resume planner, inflating that branch's cost by ~18% and under-attributing the resumed branch. 3. **Verifier poison propagates.** Because the verifier emitted its audit span against the corrupt tree, the corruption became part of the record used to judge the record. Any replay-based verification that trusts the audit span now trusts a defect. 4. **The failure is load-dependent and therefore intermittent.** Under low fan-out and slow handoff, the parent commits before the child exports, and the invariant holds by luck. Under fan-out pressure and fast workers, it breaks. This makes it invisible in unit tests and catastrophic in production — the classic signature of a durability-ordering race. The guardrail that bounds it: a **span-commit barrier with pending-parent deferral**. Child spans referencing an uncommitted parent are held (bounded, with a deadline), and on deadline they are emitted with `orphaned=true` and the asserted parent retained. The collector's reconstruction pass runs *after* the barrier window, so dangling parents have had a chance to resolve, and unresolved ones are quarantined rather than re-rooted. The invariant is: *no span is ever re-rooted; orphans are deferred or quarantined, never silently reparented.* ```python import time from dataclasses import dataclass, field from typing import Optional, Literal class DanglingParentError(RuntimeError): """Raised when an instance attempts to emit a causally-claimed span whose parent is not durably committed and cannot be deferred.""" pass class CausalOrderViolation(RuntimeError): """Raised when a declared parent terminates after the child begins, contradicting the asserted causal edge.""" pass ParentSource = Literal["self", "handoff", "memory", "checkpoint", "resume"] @dataclass class Span: span_id: str trace_id: str parent_span_id: Optional[str] parent_source: ParentSource start_ts: float end_ts: Optional[float] = None attributes: dict = field(default_factory=dict) class TraceStore: """Minimal committed-span store. A span is 'durable' only after commit().""" def __init__(self): self._committed: dict[str, Span] = {} def commit(self, span: Span) -> None: self._committed[span.span_id] = span def is_durable(self, span_id: str) -> bool: return span_id in self._committed def get(self, span_id: str) -> Optional[Span]: return self._committed.get(span_id) class SpanEmitter: """Enforces the span-commit barrier: no causally-claimed child span is exported until its parent is durable, or until the deferral deadline expires (in which case it is emitted flagged, never silently re-rooted).""" def __init__(self, store: TraceStore, defer_deadline_s: float = 5.0): self.store = store self.defer_deadline_s = defer_deadline_s self._pending: list[Span] = [] self._exported: list[Span] = [] def emit(self, span: Span) -> None: if span.parent_span_id is None: self._exported.append(span) return parent = self.store.get(span.parent_span_id) # Durability precedes reference: if the parent is not committed, # we must NOT let the collector re-root this span. Defer it. if not self.store.is_durable(span.parent_span_id): if span.parent_source in ("handoff", "memory", "checkpoint"): span.attributes["parent_pending"] = True span.attributes["parent_source"] = span.parent_source self._pending.append(span) return # A self-created parent that is not durable is an emitter bug. raise DanglingParentError( f"span {span.span_id} claims self-parent {span.parent_span_id} " f"but parent is not committed; refusing to emit a causally false edge" ) # Parent is durable. Check causal order. if parent.end_ts is not None and parent.end_ts > span.start_ts: raise CausalOrderViolation( f"span {span.span_id} starts at {span.start_ts} but parent " f"{parent.span_id} terminates at {parent.end_ts}; causal edge contradicted" ) # Resumed instance must not mint a second root for the same logical op. if span.parent_source == "resume": span.attributes.setdefault("resume_of", span.parent_span_id) self._exported.append(span) def flush_pending(self, now: float) -> None: """After the deferral window, emit unresolved pending spans FLAGGED, never re-rooted. The asserted parent is retained for repair.""" still_pending = [] for span in self._pending: waited = now - span.start_ts if self.store.is_durable(span.parent_span_id): span.attributes["parent_pending"] = False self._exported.append(span) elif waited > self.defer_deadline_s: # Deadline expired: quarantine, do not reparent. span.attributes["orphaned"] = True span.attributes["quarantined_parent"] = span.parent_span_id self._exported.append(span) else: still_pending.append(span) self._pending = still_pending def reconstruct_tree(emitter: SpanEmitter) -> dict: """Reconstruction pass: never re-roots. Quarantined spans keep their asserted parent so a later repair pass can resolve the edge.""" tree = {"roots": [], "edges": [], "quarantined": []} for span in emitter._exported: if span.attributes.get("orphaned"): tree["quarantined"].append(span.span_id) continue if span.parent_span_id is None: tree["roots"].append(span.span_id) else: if emitter.store.is_durable(span.parent_span_id): tree["edges"].append((span.parent_span_id, span.span_id)) else: # Should be unreachable if emit() is correct; fail loud. raise DanglingParentError( f"reconstruction found non-durable edge " f"{span.parent_span_id}->{span.span_id}; invariant breached" ) return tree ```