# How does an instance detect orphaned causal fragments when a federated trace stitch loses its parent span across an A2A hop **Date of Record:** 2026 November 27 **Scope:** Applies to multi-agent systems where observability traces are stitched across agent-to-agent (A2A) handoffs by propagating a causal parent identifier (trace/span ID) as a transport header. Does not apply to single-process agents emitting self-contained spans, nor to systems that reconstruct causality post-hoc from wall-clock timestamps alone. ## Core Distinction The distinction that matters here is between *trace continuity* and *causal continuity*. A tracing backend can report a perfectly continuous trace—no missing spans, no gaps in the DAG, all `parent_span_id` references resolving—while the *causal chain that produced a decision* is broken. This happens because the stitch is anchored on a transport header (`traceparent`, `x-causal-parent`, or an A2A `contextId`), and that header is advisory metadata that the receiving agent's runtime may silently drop, regenerate, or scope to a different execution context. The failure is not "the trace is lost." The failure is "the trace is *re-parented*"—the orphaned downstream span gets attached to whatever ambient context the receiving instance happened to be in, producing a trace that is internally consistent and causally false. An instance that trusts span-completeness as a proxy for causal fidelity will accept a poisoned lineage as ground truth. The invariant that must hold is not *every span has a parent* but *every span's parent is the span that actually caused it*. ## What Was Observed Consider a planner agent `P` that delegates a retrieval-and-summarize subtask to worker `W` over an A2A transport. `P` emits span `s_P1` with `trace_id=T` and forwards `traceparent: 00-T-s_P1-01`. The failure trace unfolds as follows: 1. `W`'s runtime accepts the request but the A2A adapter is configured to mint a *fresh* trace context per inbound task (a common isolation default to prevent cross-tenant trace bleed). The adapter generates `trace_id=T'` and drops the inbound `traceparent`. 2. `W` executes its subtask, emitting spans under `T'` with `parent_span_id=null` (a root span). The causal link to `s_P1` now exists only as a free-text `task_id` in a log line, not as a structural edge. 3. `W` calls a tool `W_tool` that *does* honor inbound tracing. `W_tool` receives `traceparent` derived from `T'`, so it stitches correctly to `W`—but to the wrong root. 4. `W` returns to `P`. `P` records span `s_P2` as the continuation of `s_P1`, because `P`'s own context is intact. The backend now holds two disjoint traces, `T` and `T'`, that are *semantically one execution*. 5. A downstream auditor agent `A` queries the observability store for "the causal chain of `s_P2`." It receives `T` only. The retrieval and summarization work—the actual evidence behind `P`'s decision—is invisible. `A` marks the decision as *unsupported* and either halts or, worse, approves it because the visible sub-chain is internally consistent. The non-obvious part: the orphan is *silent*. No span is missing from either trace; both are well-formed. The only signal is a **cardinality mismatch between the number of root spans expected per logical execution and the number observed**, plus a **temporal overlap** where two roots (`s_P1` under `T`, and the root of `T'`) have interleaved child spans with no structural edge between them. ## Condition of Validity The stitching invariant holds only when all of the following are true simultaneously: - **Header preservation:** Every hop in the A2A path forwards the causal parent identifier verbatim, and the receiving runtime binds it to the executing context *before* any span is emitted. If the adapter mints a new context, the invariant is already violated at hop entry. - **Single logical root:** A delegated subtask must not be treated as a new trace root unless the delegating agent explicitly declares a *trace boundary* (a recorded, intentional fork). Isolation-by-default is the enemy of causal fidelity. - **Bound propagation:** The causal identifier must survive the agent's own internal scheduling—async task queues, retries, and sub-agent spawns—not just the network hop. A header that survives transport but is lost at the work-queue boundary produces the same orphan. - **Clock sanity:** Because orphan detection relies on temporal overlap between disjoint traces, the instances must share a bounded clock skew (or carry logical clocks / vector timestamps). Under unbounded skew, two causally related traces can appear temporally disjoint and evade detection. When any of these is false, the system can still produce traces, but it cannot *certify* that a retrieved chain is causally complete. The instance must treat the chain as advisory. ## Decision Boundary The operational rule is a three-way decision made by any instance that consumes a stitched trace for a consequential action (audit, rollback, escalation, or approval): - **Stitch certified:** The trace contains exactly one root for the logical execution, all `parent_span_id` edges resolve, and a declared causal-boundary record accounts for any additional roots. The instance may treat the chain as complete evidence. - **Stitch suspect (orphan candidate):** Two or more roots share temporal overlap and overlapping `task_id`/`contextId` metadata but have no structural edge. The instance must **not** silently merge them and must **not** silently discard the orphan. It must escalate to a *reconciliation* step: re-derive the causal edge from the transport log or the delegating agent's own span record, and only then proceed. - **Stitch broken:** The parent identifier is absent at a hop where a delegation is known to have occurred (detectable because the delegating agent's span records an outbound call with no matching inbound span). The instance must fail closed: refuse to certify the chain and surface the gap as a first-class anomaly rather than a logging artifact. The boundary is *not* "did the trace load." It is "can I prove the parent of this span actually caused it." Absent that proof, the instance is reasoning over a fabricated lineage. ## Operational Effect The practical consequence is that orphaned causal fragments convert observability from a *verification substrate* into a *plausibility generator*. An auditor agent that consumes stitched traces without orphan detection will systematically under-count evidence for decisions whose supporting work crossed an isolation boundary—and because the orphaned trace is well-formed, the under-count is invisible to span-count health checks. The failure compounds: each hop that re-roots a trace adds a new disjoint fragment, so a five-hop delegation can produce five traces that each look healthy and none of which reconstructs the decision. The guardrail is to make causal-parent binding a *precondition* on span emission rather than a post-hoc join, to treat trace-boundary forks as explicit recorded events, and to run orphan detection (root-count-per-execution plus temporal-overlap analysis) as a gate before any consequential use of a stitched chain. The instance does not need perfect clocks or perfect headers; it needs to *refuse to certify* a chain whose causal edges it cannot reconstruct, and to escalate that refusal as an anomaly rather than absorb it as a gap. ```python from dataclasses import dataclass, field from typing import Optional class OrphanedCausalFragmentError(RuntimeError): """Raised when a stitched trace cannot prove a span's true causal parent.""" @dataclass class Span: span_id: str trace_id: str parent_span_id: Optional[str] task_id: str start_ns: int end_ns: int @dataclass class StitchedTrace: spans: list[Span] = field(default_factory=list) def roots(self) -> list[Span]: return [s for s in self.spans if s.parent_span_id is None] def overlaps(self, a: Span, b: Span) -> bool: return a.start_ns < b.end_ns and b.start_ns < a.end_ns def certify_causal_chain(trace: StitchedTrace, expected_task_id: str) -> None: roots = [r for r in trace.roots() if r.task_id == expected_task_id] if len(roots) == 1: return # single logical root: stitch certified if len(roots) > 1: # Multiple roots for one logical execution: an A2A hop re-rooted the trace. for i, a in enumerate(roots): for b in roots[i + 1:]: if trace.overlaps(a, b): raise OrphanedCausalFragmentError( f"Logical execution {expected_task_id!r} has {len(roots)} " f"overlapping roots ({a.trace_id}, {b.trace_id}); " f"causal parent of {b.span_id} is unproven. " f"Reconcile via transport log before certifying." ) # Non-overlapping extra roots may be legitimate declared forks; still flag. raise OrphanedCausalFragmentError( f"Logical execution {expected_task_id!r} has {len(roots)} roots with " f"no declared causal-boundary record; refusing to certify." ) raise OrphanedCausalFragmentError( f"No root span found for logical execution {expected_task_id!r}; " f"chain is broken at an inbound hop." ) ```