# Under what conditions must an instance refuse to propagate a trace parent across a federated trust boundary when the W3C `traceparent` flags field disagrees with the local sampling decision **Date of Record:** 2026 December 1 **Scope:** Applies to multi-agent systems where an LLM agent instance emits or forwards W3C Trace Context (`traceparent`/`tracestate`) headers to a peer operating under a different trust domain, and where that peer's auditor replays spans against the propagated context. Does not apply to single-domain tracing, nor to systems where trace context is regenerated per hop rather than propagated. ## Core Distinction The failure is not "trace context is lost." Loss is loud—the child span orphans and the auditor sees a dangling `parentSpanId`, which is easy to detect. The non-obvious failure is **trace context that is present, well-formed, and cryptographically intact but semantically false**: a child span claims a `parentSpanId` that its originating domain never actually sampled, because the `traceparent` `flags` byte (`00` = not sampled, `01` = sampled) was rewritten in transit, or because the receiving domain's local sampler overrode the propagated decision while still emitting the inherited `trace_id`. The invariant that must hold across a federated boundary is: **the sampling decision recorded in a span's `flags` field must equal the sampling decision that the span's declared parent actually committed to at emission time.** When a downstream instance sets `flags=01` on a child whose parent was emitted with `flags=00`, the child is a *phantom sampled* span: it exists in the child domain's trace store, references a real parent, but the parent domain has no record of the work the child attributes to it. Auditor replay across domains will then compute a coverage ratio (sampled children / declared parents) greater than 1.0 for that parent—an impossible value that silently corrupts distributed latency attribution, cost accounting, and any cross-domain SLO derived from trace completeness. This is a *correlation* boundary, not a *transport* boundary. The bytes arrive. The meaning is wrong. ## What Was Observed A three-domain federation: `orchestrator` (domain A, owns the root span and the authoritative sampler), `worker` (domain B, an LLM agent executing tool calls), and `auditor` (domain C, replays spans to verify that every tool invocation in B is attributable to a task issued by A). The root span in A was emitted with `traceparent: 00---00` — **not sampled**, because A's head-based sampler had dropped this trace to stay within its per-second span budget. Critically, A still forwarded the *task* to B over the agent-to-agent channel; the trace context rode along in the message envelope as metadata, decoupled from the sampling decision. B's agent runtime had a local tail-based sampler configured to "always sample any span that invokes a tool," because tool calls were deemed high-value. When B created its child span, its instrumentation library did the following, in order: 1. Parsed the inbound `traceparent`, extracting `trace_id`, `parent_span_id`, and `flags=00`. 2. Consulted the local tail sampler, which returned `RECORD_AND_SAMPLE`. 3. Emitted the child with the inherited `trace_id` and `parent_span_id`, but with `flags=01`. The child span was exported to B's backend. It referenced `root_span_id` as its parent. But A had never exported `root_span_id` — A's sampler had dropped it. When C's auditor joined the two domains on `trace_id`, it found a child whose parent record did not exist in A's store, yet whose `flags` asserted the parent *was* sampled. The auditor's replay invariant — "every sampled span has a sampled, present ancestor" — failed, and C flagged the entire trace as untrusted, dropping 100% of B's tool-call spans for that trace even though they were correctly executed and correctly parented. The phantom-sampled children were not corrupt in isolation. They were corrupt *relative to the declared parent's committed state*. The disagreement between the propagated `flags=00` and the local override `flags=01` was the entire fault. ## Condition of Validity Propagating a trace parent is valid **only** when one of the following holds at the moment the child span is emitted: - **Inheritance mode:** the local sampler defers to the inbound `flags` byte. If `flags=00`, the child is emitted with `flags=00` (or not emitted at all); if `flags=01`, the child is emitted with `flags=01`. The local sampler must not upgrade a `00` to a `01`. - **Reparenting mode:** the local sampler overrides the decision, but the child is emitted with a **new `trace_id`** and a **local root span** as its parent, explicitly severing the cross-domain parent link. The child is then a root of its own trace, and the auditor joins on the *task envelope's* correlation ID, not on `parentSpanId`. The invalid state is the **hybrid**: inherited `trace_id` and `parent_span_id` combined with a locally overridden `flags`. This hybrid is what most OpenTelemetry SDKs produce by default when a tail-based sampler is layered over a propagator that does not enforce decision inheritance. The condition of validity is therefore: *decision inheritance and identity inheritance must travel together, or neither should.* A second condition: the `tracestate` header must carry the originating domain's sampler identity and a monotonically increasing hop count. Without it, domain C cannot distinguish a legitimate `flags=01` (parent was sampled) from a rewritten one, and cannot detect the hybrid at all. ## Decision Boundary The boundary is drawn at the point where the receiving instance decides whether to honor the inbound sampling decision before emitting. Concretely, an instance must **refuse to propagate the inherited parent link and must downgrade to reparenting** when any of the following is true: - Inbound `flags=00` but the local sampler returns `RECORD_AND_SAMPLE`. - Inbound `tracestate` is absent or does not list the emitting domain, so the inbound decision cannot be authenticated. - The inbound `traceparent` version is `ff` (invalid) or the `trace_id` is all-zero. - The hop count in `tracestate` exceeds the federation's configured maximum (default 8), indicating a loop or a replay. Conversely, the instance must **honor inheritance and pass through unchanged** when inbound `flags=01` and `tracestate` authenticates the origin—even if the local sampler would have dropped the span. Dropping a sampled child breaks the auditor's "sampled ancestor" invariant just as badly as upgrading an unsampled one; the asymmetry is only in which direction the coverage ratio deviates from 1.0. The boundary is *not* drawn on "is this trace worth sampling." That is a local optimization. The boundary is drawn on "can I make a sampling claim about a parent I do not control." The answer is no. ## Operational Effect When the invariant holds, cross-domain coverage ratios stay at exactly 1.0 per trace: every sampled child has a sampled, present parent, and the auditor's replay is a pure join with no orphans in either direction. Latency attribution across domains is additive and correct because the parent's start/end timestamps are guaranteed present in the parent domain's store. When the invariant is violated by the hybrid — the most common default — the operational effect is a **silent, asymmetric coverage inflation** in the child domain and a **hard trust rejection** in the auditor domain. The inflation is silent because B's own dashboards show healthy span volume; the rejection is loud only if C's auditor is configured to enforce the invariant, which it usually is not until an SLO breach forces investigation. The net effect is that tool-call spans from B are executed, billed, and logged, but are unattributable to A's tasks during any cross-domain incident review — precisely when attribution matters most. The fix is not a sampler change; it is a propagator-level refusal, enforced before the span is created, so that no phantom-sampled child is ever emitted. ```python from dataclasses import dataclass from typing import Optional class TracePropagationRefused(RuntimeError): """Raised when an instance must not propagate an inherited parent link.""" pass @dataclass(frozen=True) class TraceParent: trace_id: str parent_span_id: str flags: int # 0x00 = not sampled, 0x01 = sampled tracestate: Optional[str] hop_count: int @dataclass(frozen=True) class LocalDecision: sample: bool MAX_FEDERATION_HOPS = 8 def decide_propagation( inbound: TraceParent, local: LocalDecision, origin_authenticated: bool, ) -> str: """Return 'inherit' or 'reparent', or raise TracePropagationRefused. Enforces the invariant: sampling-decision inheritance and identity inheritance must travel together, or neither. """ if inbound.trace_id == "0" * 32 or inbound.trace_id == "": raise TracePropagationRefused( f"invalid trace_id {inbound.trace_id!r}; cannot propagate parent link" ) if inbound.hop_count > MAX_FEDERATION_HOPS: raise TracePropagationRefused( f"hop_count {inbound.hop_count} exceeds federation max " f"{MAX_FEDERATION_HOPS}; suspected loop or replay" ) if not origin_authenticated: # Cannot verify the inbound sampling decision; do not make a claim about it. raise TracePropagationRefused( "origin domain not authenticated via tracestate; " "refusing to inherit sampling decision" ) inbound_sampled = bool(inbound.flags & 0x01) if inbound_sampled and not local.sample: # Honor the parent's committed decision even against local sampler. return "inherit" if not inbound_sampled and local.sample: # Local upgrade of an unsampled parent would create a phantom-sampled # child. Reparent instead: new trace_id, local root. return "reparent" # Decisions agree; inherit identity and decision together. return "inherit" def emit_child_span( inbound: TraceParent, local: LocalDecision, origin_authenticated: bool, new_trace_id_factory, ) -> dict: mode = decide_propagation(inbound, local, origin_authenticated) if mode == "inherit": return { "trace_id": inbound.trace_id, "parent_span_id": inbound.parent_span_id, "flags": inbound.flags, } # reparent: sever cross-domain link, become local root new_trace = new_trace_id_factory() if new_trace == inbound.trace_id: raise TracePropagationRefused( "reparenting produced identical trace_id; identity inheritance " "cannot be severed while decision inheritance is overridden" ) return {"trace_id": new_trace, "parent_span_id": None, "flags": 0x01} ```