# When must an instance refuse to emit a causal trace link across an A2A hop that has no verifiable shared parent span **Date of Record:** 2026 November 28 **Scope:** Applies to multi-agent systems where observability is propagated as causal trace context (trace/span IDs, parent links, or W3C-style traceparent headers) across A2A handoffs and nested tool invocations. Does not apply to single-process agent runtimes with no inter-instance delegation, nor to purely metric-based telemetry that carries no causal structure. ## Core Distinction There are two structurally different things a trace link can mean across an A2A hop, and conflating them is the root failure: 1. **Correlation** — "these two spans were emitted during the same user request." Correlation is cheap: any propagated request ID establishes it, and it survives loss, reordering, and forgery. 2. **Causation** — "span B happened *because* span A's output was consumed." Causation requires that the child instance actually observed the parent's span context *and* that the parent's span context is trustworthy at the moment of linkage. Most agent observability stacks silently promote correlation to causation. When instance A calls instance B over A2A and forwards a `traceparent`, B's spans are stitched under A's trace as if A causally produced them. This is usually correct and occasionally catastrophically wrong: the link asserts a parent-child relation that the runtime cannot verify, and downstream replay/audit logic treats the trace as a ground-truth causal DAG. The boundary condition is: **an instance must refuse to emit a causal link when the parent span context it received is unverifiable, stale, or structurally impossible given its own clock and state.** Correlation may still be recorded; causation must not be fabricated. ## What Was Observed A three-instance pipeline: orchestrator `O`, worker `W`, and a tool-invoking sub-agent `S` spawned by `W` via A2A. `W` invokes a distributed tool `T` (a hosted retrieval service) that returns a `traceparent` echoing the span it was called under. Failure trace, observed under load: - `W` receives a task from `O` with `traceparent` = `00---01`. `W` starts span `spanW` parented to `spanO`. Correct. - `W` calls tool `T`. `T` is slow; `W`'s tool-call deadline fires at 8s. `W` retries the tool call under a *new* span `spanW2`, but the retry reuses the same logical operation ID, and the agent framework's retry wrapper re-emits the *original* `traceparent` (`spanW`) rather than `spanW2`. - `T` (on the second, successful attempt) returns `traceparent` = `00---01`. `W` links `T`'s server span under `spanW`. Fine so far. - Meanwhile `W` spawns `S` over A2A. The A2A envelope carries `spanW`. `S` starts its span parented to `spanW`. Fine. - **The break:** `S` invokes the same tool `T` (shared cache). `T` returns a *cached* `traceparent` from the first caller — `00---01` — because the cache key was the tool arguments, not the caller span. `S` now emits its tool span parented to `spanW`, which is `S`'s *grandparent*, not its parent. The trace DAG now has `spanW` with two children (`S`'s root and `S`'s tool span), one of which is not causally downstream of the other's parent. Downstream consequences: - A replay/audit job that reconstructs causal order from parent links concluded `S`'s tool call happened concurrently with `S`'s own root span, producing a "self-overlapping agent" anomaly that fired a false incident. - A latency attribution job charged `S`'s tool latency to `W` (since `spanW` is `W`'s span), inflating `W`'s p99 by ~40% during the window. - A prompt-injection detector that walks the causal chain from tool output back to the originating user prompt walked the *wrong* chain and attributed a benign cached document to the wrong user session. The invariant violated: **a child span's parent must be a span the child instance demonstrably received and that is temporally and structurally consistent with the child's own start time and known ancestors.** `S` received `spanW` (true), but `spanW` was neither `S`'s parent nor a valid ancestor of `S`'s tool span — it was an aliased context injected by a third party (`T`'s cache). ## Condition of Validity A causal link `child -> parent` is valid to emit only when all of the following hold at the child: 1. **Provenance:** the parent span context arrived on the channel the child actually used to receive work (the A2A envelope, the tool request context), not via a side channel such as a tool response body or cache echo. 2. **Non-aliasing:** the parent span ID is not equal to any span ID the child has already seen as a *non-ancestor* context (e.g., a tool's echoed context). A context that appears in two different roles in the same trace is aliased and must be rejected as a parent. 3. **Temporal consistency:** `parent.start <= child.start` within the propagated clock skew budget, and `parent.end` (if known) `>= child.start - skew`. A parent that ended before the child began by more than the skew budget cannot be a causal parent. 4. **Ancestor closure:** the parent span ID is reachable in the child's locally held ancestor set, or the child explicitly records the link as *unverified correlation* rather than causation. When any of 1–4 fails, the child must emit the span with a **detached** parent (a synthetic `link` attribute recording the received context) and a `causality: unverified` flag, never as a hard parent edge. ## Decision Boundary The decision is not "trust the header or drop it." It is a three-way classification at the moment of span creation: - **Emit as causal parent** — all four conditions hold. Default path. - **Emit as correlation link only** — provenance holds but aliasing or ancestor-closure fails (the cache-echo case above). The span is created with no parent, plus a `link` to the received context and `causality: unverified`. This preserves the audit trail without asserting a false DAG edge. - **Reject and quarantine** — provenance fails (context arrived via a tool response body, or a header the child did not request) *and* the context is structurally impossible (parent ends before child starts beyond skew). This is the signature of context injection or a misbehaving intermediary. The child must not link at all and must raise to its own supervisor. The boundary is sharp because the failure modes are asymmetric: a false causal edge corrupts every downstream consumer (replay, attribution, security attribution), while a missing causal edge merely degrades trace completeness. The runtime must bias toward detaching. ## Operational Effect Enforcing the invariant changes three things: - **Trace DAGs become sound but incomplete.** Some legitimate links will be downgraded to `unverified` when a tool echoes a context the child cannot prove it received directly. Accept this; make `unverified` visible in the trace UI so operators can distinguish "no link" from "link we refused to assert." - **Cache and shared-tool layers must not echo caller trace context.** The root cause here was a tool caching its *response* including the `traceparent`. Tool servers must strip or regenerate trace context on cache hits, keyed to the actual caller, or return it only as a `link`, never as a parent. - **Retry wrappers must not reuse the original span context.** A retried tool call is a new span; re-emitting the original `traceparent` on retry is what created the alias in the first place. Retry logic must mint a fresh child span and, if it must preserve the original for correlation, attach it as a `link`. The guardrail is a small, local check at span-creation time — cheap, deterministic, and it converts a silent DAG corruption into a visible, bounded degradation. ```python from __future__ import annotations import time from dataclasses import dataclass, field from typing import Optional class CausalLinkViolation(RuntimeError): """Raised when a received span context cannot be asserted as a causal parent.""" @dataclass(frozen=True) class SpanContext: trace_id: str span_id: str start_ns: int end_ns: Optional[int] = None # Channel the context arrived on: "a2a_envelope", "tool_request", # "tool_response", "cache_echo", etc. channel: str = "a2a_envelope" @dataclass class LocalSpan: trace_id: str span_id: str parent_id: Optional[str] causality: str # "verified" | "unverified" | "none" links: list[SpanContext] = field(default_factory=list) CLOCK_SKEW_NS = 250_000_000 # 250ms budget def _is_ancestor(span_id: str, known_ancestors: set[str]) -> bool: return span_id in known_ancestors def assert_causal_parent( received: SpanContext, child_start_ns: int, known_ancestors: set[str], seen_non_ancestor_contexts: set[str], now_ns: Optional[int] = None, ) -> LocalSpan: """ Decide whether `received` may be emitted as a hard causal parent of the child span about to be created. Returns a LocalSpan whose `parent_id` is set only when the link is verified; otherwise the context is attached as a `link` with causality="unverified", or the call raises. """ now_ns = now_ns if now_ns is not None else time.time_ns() # Condition 1: provenance — context must arrive on a work-delivery channel. if received.channel in ("tool_response", "cache_echo"): # Context echoed by a tool is never a legitimate causal parent. # If it is also structurally impossible, treat as injection. if received.end_ns is not None and received.end_ns < child_start_ns - CLOCK_SKEW_NS: raise CausalLinkViolation( f"rejected injected context span={received.span_id} " f"channel={received.channel}: parent ended before child began " f"beyond skew budget" ) # Otherwise: downgrade to correlation-only. return LocalSpan( trace_id=received.trace_id, span_id=f"child-{now_ns}", parent_id=None, causality="unverified", links=[received], ) # Condition 2: non-aliasing — a span ID already seen in a non-ancestor # role cannot be promoted to parent. if received.span_id in seen_non_ancestor_contexts: return LocalSpan( trace_id=received.trace_id, span_id=f"child-{now_ns}", parent_id=None, causality="unverified", links=[received], ) # Condition 3: temporal consistency. if received.start_ns > child_start_ns + CLOCK_SKEW_NS: raise CausalLinkViolation( f"parent span={received.span_id} starts after child by more than " f"skew budget; causal order impossible" ) if received.end_ns is not None and received.end_ns < child_start_ns - CLOCK_SKEW_NS: raise CausalLinkViolation( f"parent span={received.span_id} ended before child began beyond " f"skew budget" ) # Condition 4: ancestor closure. if not _is_ancestor(received.span_id, known_ancestors): return LocalSpan( trace_id=received.trace_id, span_id=f"child-{now_ns}", parent_id=None, causality="unverified", links=[received], ) return LocalSpan( trace_id=received.trace_id, span_id=f"child-{now_ns}", parent_id=received.span_id, causality="verified", ) ```