# Which invariants prevent causal trace stitching from silently forking at delegated sub-agent boundaries under semantic-convention-compliant observability **Date of Record:** 2026 November 25 **Scope:** Applies to multi-agent systems where an orchestrator delegates to sub-agents and emits observability spans under a shared semantic convention (e.g., `gen_ai.*` / agent-span attributes), with causal linkage via propagated trace/span identifiers. Does not apply to single-process agents emitting a flat, unsplit trace, nor to systems that reconstruct causality purely from wall-clock timestamps. ## Core Distinction There are two things an observability pipeline can mean by "the trace is stitched." The weak meaning: every emitted span references *some* parent span ID that exists somewhere in the store. The strong meaning, and the only one that preserves causality: every span's parent reference resolves to the *specific span instance* that causally triggered it, within the *same logical trace*, with no orphaned roots and no duplicate-identity collisions. Semantic-convention compliance guarantees the *shape* of the attributes (a `trace_id`, a `parent_span_id`, a `gen_ai.agent.name`), but it does not guarantee identity uniqueness or parent resolution. A pipeline can be 100% schema-valid and 100% causally wrong. The failure mode this record covers is the **silent trace fork**: a delegated sub-agent, running in a separate runtime with its own tracer, mints a fresh trace root instead of continuing the parent's trace, and the stitching layer accepts it because the convention permits a root span with no parent. The result is two traces that *look* complete and are individually plausible, but the causal edge between orchestrator and sub-agent is severed — and nothing in the schema flags it. ## What Was Observed An orchestrator agent (`gen_ai.agent.name = "planner"`) delegated a retrieval-and-summarize task to a sub-agent (`gen_ai.agent.name = "retriever"`) over an A2A-style transport. The sub-agent ran in a separate process with its own OpenTelemetry tracer provider. The delegation payload carried the W3C `traceparent` header, and the sub-agent's SDK *did* extract it — but only when the transport layer surfaced it as a request header. On the delegation path used here, the context was passed as a serialized JSON field (`delegation_context.traceparent`) rather than as a transport header, so the SDK's default propagator never read it. The sub-agent therefore started a new root span. The emitted spans were all schema-valid. The retriever's spans carried a valid `trace_id` (its own), a valid `gen_ai.agent.name`, correct `gen_ai.operation.name` values, and token counts. The stitching layer joined on `trace_id` and produced two traces. The orchestrator trace showed a delegation span with no downstream child; the retriever trace showed a clean root with correct internal structure. Both rendered as "complete." The causal edge — planner's `delegate` span → retriever's root span — existed in reality but in neither trace. The tell was not in the spans. It was in a cross-check: the orchestrator's delegation span recorded `delegation.target_agent = "retriever"` and a `delegation.warrant_id`, and the retriever's root span recorded the same `warrant_id` in its own attributes (because the warrant was in the JSON payload and the sub-agent echoed it). The warrant ID was the only surviving link. When the stitching layer was later changed to join on `warrant_id` as a fallback, the two traces merged — but only for delegations that propagated a warrant. A second delegation path that passed a bare task string (no warrant, no traceparent) produced a retriever trace with *no* join key at all, and it was silently dropped from the causal graph rather than flagged as orphaned. A second, sharper variant appeared under retry. When the orchestrator's delegation timed out and retried, the retried sub-agent call re-extracted the *same* stale `traceparent` from the cached payload and minted a second root span with a *new* `trace_id` but the *same* `warrant_id`. The warrant-join fallback then produced a trace with two roots sharing one warrant — a fork that the join logic happily stitched into a single trace with a diamond that never existed. The retry was visible as two roots; the causal claim "one delegation, one execution" was false. ## Condition of Validity The invariant that makes stitching sound is: **a delegated sub-agent's root span must be causally parented to the exact orchestrator span instance that issued the delegation, and parent identity must be carried in a channel the sub-agent's propagator actually reads, with a uniqueness constraint that rejects a second root under the same logical delegation.** This holds only when all three of the following are true: 1. **Propagation channel matches extractor.** The `traceparent` (or equivalent) must be delivered on the channel the sub-agent's configured propagator inspects. JSON-field propagation requires an explicit extractor that reads `delegation_context.traceparent`; header propagation requires the transport to preserve headers across the delegation hop. A convention-compliant payload with a `traceparent` field is not the same as an extracted parent context. 2. **Delegation identity is unique and non-reused.** The `warrant_id` (or delegation ID) must be minted once per logical delegation and must *not* be reused across retries. If retries reuse the warrant, the fallback join cannot distinguish "same delegation, retried" from "one delegation, two executions." 3. **Orphan detection is a hard gate, not a soft join.** A sub-agent root span with no resolvable parent must be *rejected or quarantined*, not silently admitted as a new trace root. The stitching layer must treat "root span whose `gen_ai.agent.name` is a known delegatee and whose parent is absent" as an invariant violation, not as a legitimate trace start. The invariant fails silently whenever the convention's permissiveness (roots may have no parent) is mistaken for correctness (roots *should* have a parent when the agent is a delegatee). ## Decision Boundary The boundary between "safe to stitch" and "fork risk" is drawn by answering one question at span-emission time, on the sub-agent side, before the span is exported: - **If the sub-agent is a delegatee and a parent context was supplied in the delegation envelope but not extracted:** the sub-agent must *refuse to emit a root span* and instead emit a span tagged `delegation.parent_unresolved = true` with the delegation ID, forcing the stitching layer to quarantine it. Emitting a clean root is the fork. - **If the sub-agent is a delegatee and no parent context was supplied at all:** this is a delegation-protocol defect on the orchestrator side; the sub-agent may emit a root but must tag it `delegation.orphan_candidate = true` and carry the delegation ID so the orchestrator can retro-link. - **If the sub-agent is a genuine top-level entry point (not a delegatee):** a root span is correct and needs no parent. The decision is *not* "does the span validate against the semantic convention." A forked root validates perfectly. The decision is "is this agent instance a delegatee, and did we resolve a parent for it." That requires the sub-agent to know its own delegation status — which means the delegation envelope must carry an explicit `is_delegatee` flag and the delegation ID, independent of whether the traceparent was successfully extracted. ## Operational Effect Without the invariant, trace stitching degrades in a way that is invisible until an incident review asks a causal question the data cannot answer. The concrete effects observed: - **Causal edges vanish under partial propagation.** Any delegation path that delivers context on a channel the propagator ignores produces a fork. The fork is silent because both halves are schema-valid. The blast radius is bounded only by how many delegation paths use that channel — here, one of two, so roughly half of all delegations were uncausally linked until the warrant fallback was added. - **Retry reuses identity and fabricates diamonds.** When the delegation ID is reused across retries and used as a fallback join key, the stitched trace shows a single delegation with two downstream roots. Downstream analysis (latency attribution, error-rate-per-delegation, token accounting) double-counts and misattributes. The fix is to mint a fresh delegation ID per attempt and carry the *logical* delegation ID separately for grouping. - **Orphaned roots are dropped, not flagged.** The stitching layer's default policy — admit roots, join on `trace_id` — means an orphaned delegatee root becomes a standalone trace that no one queries, because no orchestrator trace references it. The delegation appears to have produced no output. This is the most dangerous effect: the failure looks like "the sub-agent did nothing," when in fact it did everything and the evidence was filed under the wrong key. - **The guardrail that bounds it** is a two-part check at the stitching boundary: (a) a *delegation-completeness* assertion — every `delegate` span must have exactly one causally-parented child root, and (b) a *root-uniqueness* assertion — no two roots may share a logical delegation ID. Violations must raise, not warn. A warning is indistinguishable from noise in a high-volume pipeline; an exception that fails the trace-assembly job forces the fork into the open where it can be triaged. The invariant is cheap to enforce and expensive to omit: it costs one flag in the delegation envelope, one uniqueness constraint on delegation IDs, and one hard gate in the stitcher. Omitting it costs the causal graph itself, and the loss is only discovered when someone asks why the agent "did nothing" during an incident that the traces cannot explain. ```python class TraceForkError(RuntimeError): """Raised when a delegated sub-agent's root span cannot be causally parented to its issuing orchestrator span, or when a logical delegation yields more than one root (silent trace fork).""" pass class DelegationEnvelope: def __init__(self, delegation_id: str, logical_delegation_id: str, is_delegatee: bool, traceparent: str | None, extracted_parent_span_id: str | None): self.delegation_id = delegation_id # unique per attempt self.logical_delegation_id = logical_delegation_id # stable across retries self.is_delegatee = is_delegatee self.traceparent = traceparent # supplied in envelope self.extracted_parent_span_id = extracted_parent_span_id # what propagator actually read def emit_subagent_root_span(env: DelegationEnvelope) -> dict: """Decide whether the sub-agent may emit a root span, or must quarantine. The convention permits parentless roots; correctness does not, for a delegatee whose envelope carried a traceparent. This function enforces the invariant before export so the fork never reaches the stitcher. """ if not env.is_delegatee: # Genuine top-level entry point: a root span is correct. return {"parent_span_id": None, "root": True, "quarantined": False} parent_supplied = env.traceparent is not None parent_resolved = env.extracted_parent_span_id is not None if parent_supplied and not parent_resolved: # Envelope carried a traceparent but the propagator never read it. # Emitting a clean root here is the silent fork. raise TraceForkError( f"delegatee {env.delegation_id}: traceparent present in envelope " f"but no parent span resolved; refusing to emit root span. " f"Quarantine with delegation.parent_unresolved=true." ) if not parent_supplied: # No parent context at all: orchestrator-side protocol defect. # Emit as orphan candidate, not a clean root. return { "parent_span_id": None, "root": True, "quarantined": True, "attributes": {"delegation.orphan_candidate": True, "delegation.logical_id": env.logical_delegation_id}, } return {"parent_span_id": env.extracted_parent_span_id, "root": False, "quarantined": False} def stitch_trace(roots: list[dict], logical_delegation_id: str) -> dict: """Stitcher-side gate: exactly one causally-parented root per logical delegation. Two roots under one logical delegation is a fork.""" if len(roots) > 1: raise TraceForkError( f"logical delegation {logical_delegation_id} produced {len(roots)} " f"root spans; causal fork detected (retry reused delegation identity " f"or duplicate execution). Refusing to stitch a fabricated diamond." ) root = roots[0] if root.get("quarantined"): raise TraceForkError( f"logical delegation {logical_delegation_id}: root span is an " f"orphan candidate with no resolved parent; causal edge missing." ) return root ```