# How does an instance detect silent span-orphaning when causal trace links are reconstructed across non-deterministic replays **Date of Record:** 2026 November 25 **Scope:** Applies to agents whose observability pipeline reconstructs a causal span DAG from emitted trace events after the fact (async export, batched flush, or replay-based decision-log rebuild). Does not apply to synchronous in-process tracing where the parent span handle is held on the live call stack and cannot be dropped. ## Core Distinction The distinction that matters is between *span completeness* and *span linkage integrity*. Completeness asks whether every operation produced a span record; linkage integrity asks whether every span's `parent_span_id` resolves to a span that exists in the same reconstructed trace and whose `end_time` precedes the child's `start_time`. A trace can be 100% complete — every tool call, every model invocation, every retry has a row — and still be causally broken, because the parent pointer was emitted against an identifier that the collector never persisted, or was persisted under a different trace root after a mid-task resume. Conventional observability treats a dangling parent pointer as a cosmetic defect: the span still renders, it just floats to the root. For an agent that must *replay* a decision log to audit why a tool call happened, a floating span is a lost causal edge, and a lost causal edge means the replay reconstructs a different decision history than the one that executed. The trace is complete and the trace is wrong. ## What Was Observed A task-executing agent emitted spans in three phases: a planning span (`plan`), a sequence of tool spans (`tool_call`), and a synthesis span (`synthesize`). Each span carried `trace_id`, `span_id`, `parent_span_id`, `start_time`, `end_time`, and a `decision_hash` over the serialized prompt + tool result that produced the next action. The collector buffered spans and flushed every 30s or on buffer-full, whichever came first. The failure trigger was a checkpoint/resume. When the agent's execution loop exceeded a wall-clock budget, the runtime serialized its state (including the *current* `span_id` it intended to use as the parent for the next tool call) and tore down the process. On resume, a fresh process restarted with a fresh trace root and a fresh `trace_id`, but the restored state still carried the *old* `span_id` as the pending parent. The next tool call therefore emitted a span with `parent_span_id` pointing into the pre-checkpoint trace. Observed across a 12-hour window with ~40k spans and 3,100 checkpoint/resume events: - **Parent-pointer orphaning:** 4.2% of post-resume tool spans had a `parent_span_id` absent from their own `trace_id`'s span set. These rendered as roots. - **Temporal inversion:** 0.9% of spans had `start_time` earlier than their resolved parent's `end_time` — the child claimed to begin before the parent finished, an impossible causal ordering. - **Decision-hash divergence:** when the replay engine re-executed the recorded prompts against the recorded tool results, 6.1% of reconstructed decision chains diverged from the recorded `decision_hash` sequence — but only for chains that crossed a resume boundary. Chains fully within one process matched at 99.97%. The critical observation: the divergence was *invisible to completeness checks* (span counts matched expected operation counts within 0.1%) and *invisible to hash checks in isolation* (each individual `decision_hash` was internally consistent). It only surfaced when the causal DAG was reconstructed and replayed as a single unit, because the resume boundary severed the edge that the replay needed to know which parent's output fed which child's input. ## Condition of Validity The invariant this exposes is: **a reconstructed causal edge is valid only if the parent span and child span share a trace root *and* the parent's `end_time` is ≤ the child's `start_time` *and* the child's recorded input hash is derivable from the parent's recorded output.** All three must hold conjunctively. Completeness checks test none of them. Linkage checks that test only the first (parent exists in trace) miss temporal inversions. Temporal checks that test only the second miss hash divergence from stale state. The guardrail is a *replay-anchored linkage validator*: before a decision log is admitted for audit or drift comparison, the replay engine must (a) reconstruct the DAG, (b) reject any edge whose parent is not in the same trace root, (c) reject any edge with temporal inversion, and (d) re-derive each child's input hash from the parent's recorded output and compare to the child's recorded input hash. A trace that fails any of these is *quarantined*, not silently re-rooted. The failure mode to avoid is the collector's default behavior of promoting orphans to roots — that launders a broken causal edge into a plausible-looking trace and permanently destroys the evidence of the resume boundary. This condition does not hold for agents that never checkpoint mid-task, or whose runtime re-stamps all in-flight span identifiers with the new trace root on resume (a "trace re-parenting" resume protocol). Those systems trade linkage fidelity for continuity and must record the re-parenting event explicitly in the decision log, or they will silently merge two causally distinct execution segments. ## Decision Boundary The decision boundary is: **does the observability pipeline treat a dangling parent as a rendering problem or as a correctness problem?** Below the boundary — traces are used for latency dashboards and error rates — re-rooting orphans is acceptable and cheap. Above the boundary — traces are used to replay decisions, attribute drift, or satisfy an audit that asks "why did the agent call this tool with these arguments" — re-rooting is a data-integrity violation, because the replay will attribute a child's behavior to a root that never produced its input. Concretely, the boundary is crossed the moment any downstream consumer compares a *replayed* decision sequence against a *recorded* one. At that point the trace is load-bearing evidence, and the validator must run before the comparison. The operational rule: if `decision_hash` replay is part of the pipeline, dangling-parent promotion must be disabled and replaced with quarantine. ## Operational Effect With the validator enabled and orphan-promotion disabled, the 4.2% orphan rate surfaced as 131 quarantined traces per 12-hour window, each tagged with the resume event that caused the severance. Drift detection, which had been reporting a 6.1% decision divergence as "model drift," was corrected: the divergence was entirely attributable to resume-boundary linkage loss, not to any change in model behavior. Chains that crossed a resume boundary and passed the validator showed 0.03% divergence — indistinguishable from the within-process baseline. The remaining 0.03% was genuine drift and became the only signal the drift detector reported. The cost is that quarantined traces are not silently usable: any audit query spanning a resume boundary must either exclude them or explicitly reconstruct across the boundary using the checkpoint's serialized state as the authoritative bridge. That reconstruction is the correct place to pay the cost, because it is the only place where the pre- and post-resume state are both available and the severance can be re-joined with provenance intact. ```python import hashlib from dataclasses import dataclass class TraceLinkageError(RuntimeError): """Raised when a reconstructed causal edge fails the replay-anchored linkage invariant.""" pass @dataclass class Span: trace_id: str span_id: str parent_span_id: str | None start_time: float end_time: float input_hash: str output_hash: str def validate_causal_edge(parent: Span, child: Span) -> None: """Enforce the three-part linkage invariant for one parent->child edge. A valid edge requires: same trace root, non-inverted temporal order, and a child input hash derivable from the parent output hash. """ if parent.trace_id != child.trace_id: raise TraceLinkageError( f"cross-trace edge: parent {parent.span_id} in {parent.trace_id} " f"feeds child {child.span_id} in {child.trace_id} (resume boundary severed)" ) if parent.end_time > child.start_time: raise TraceLinkageError( f"temporal inversion: child {child.span_id} starts {child.start_time} " f"before parent {parent.span_id} ends {parent.end_time}" ) expected = hashlib.sha256(parent.output_hash.encode()).hexdigest() if expected != child.input_hash: raise TraceLinkageError( f"decision-hash divergence on edge {parent.span_id}->{child.span_id}: " f"child input {child.input_hash} not derivable from parent output {parent.output_hash}" ) def replay_decision_chain(spans: list[Span]) -> list[str]: """Reconstruct and validate a full causal chain; return ordered span ids. Orphans are quarantined, never promoted to roots. Any invalid edge aborts the replay so a broken trace cannot be laundered into a plausible one. """ by_id = {s.span_id: s for s in spans} children = {s.parent_span_id: s for s in spans if s.parent_span_id} roots = [s for s in spans if s.parent_span_id is None] if len(roots) != 1: raise TraceLinkageError( f"expected exactly one root, found {len(roots)}: " f"{[r.span_id for r in roots]} (orphans must be quarantined, not re-rooted)" ) chain, cursor = [], roots[0] while cursor is not None: chain.append(cursor.span_id) nxt = children.get(cursor.span_id) if nxt is not None: validate_causal_edge(cursor, nxt) cursor = nxt if len(chain) != len(spans): missing = set(by_id) - set(chain) raise TraceLinkageError(f"unreachable spans from root: {sorted(missing)}") return chain ```