# In what scenarios must an instance refuse to propagate a distributed trace context across a federated agent handoff, and how does span-parent forgery corrupt the causal record? **Date of Record:** 2026 November 21 **Scope:** Applies to federated multi-agent workflows where trace context (trace-id, span-id, parent-span-id, baggage) is carried across trust boundaries between independently governed agent runtimes. Does not apply to single-tenant intra-runtime tracing where all spans share one collector and one identity authority. ## Core Distinction The distinction that matters is between *trace correlation as a diagnostic convenience* and *trace correlation as a causal attestation*. In a single-runtime agent, the parent-span-id field is a hint: the collector trusts the emitting process, and a malformed parent link merely produces an orphan span. Across a federation boundary, the parent-span-id field becomes a **claim of causation** — "my reasoning step was triggered by that upstream step" — and the receiving runtime has no independent way to verify it. The failure mode is not a broken trace; it is a *plausible, well-formed, and false* trace that survives every schema validation and reconstructs an incorrect causal history of a multi-agent decision. The invariant at stake: **a span's parent link must be cryptographically bound to the identity of the process that actually executed the parent work, and to the trace-context the parent process emitted.** When that binding is absent, any downstream agent — or any injected instruction inside a downstream agent — can mint a span whose parent points anywhere in the federation. ## What Was Observed A three-hop federated workflow: an orchestrator agent (tenant A) dispatched a research subtask to a retrieval agent (tenant B), which delegated summarization to a summarizer agent (tenant C). Each hop used W3C `traceparent` propagation over an A2A-style handoff envelope. Traces were assembled in a shared collector that accepted OTLP from all three tenants. The orchestrator's own trace showed a clean chain: `orch.plan → orch.dispatch → b.research → c.summarize → orch.synthesize`. But the collector's assembled view showed a *second* root span, `c.summarize`, with a parent-span-id pointing at `orch.dispatch` — a span that had already closed 4.2 seconds before tenant C received the handoff. Two spans claimed the same child; the collector's sampler kept both, and the reconstructed flame graph placed C's summarization *before* B's retrieval completed. The mechanism: tenant B's handoff envelope carried a *stale* traceparent captured at dispatch time rather than at handoff time. B's agent had checkpointed its context at dispatch (to survive a possible mid-task resume), and on resume it replayed the cached envelope — including the original traceparent — instead of re-deriving a fresh one. The summarizer, receiving a parent-span-id that referenced a closed span, accepted it because the field is a 16-hex-char string with no liveness or identity check. The result: the causal record showed summarization gated on a dispatch that had not yet produced its retrieval output. Any downstream auditor replaying the trace to verify *why* the summary contained a particular claim would attribute it to the wrong upstream evidence. A second observation compounded it. Because B replayed a cached envelope, the `baggage` header carried B's tenant-scoped `evidence_set_id` into C's context. C's summarizer prompt builder read that baggage and cited evidence it had never retrieved. The trace looked internally consistent — parent links resolved, baggage propagated, no schema error — precisely because the forgery was *replay*, not fabrication. ## Condition of Validity Trace-context propagation across a federation boundary is valid only when all four of the following hold simultaneously: 1. **Liveness binding.** The parent-span-id in a handoff envelope references a span the emitting process can prove is still open (or was closed by the emitter itself), via a signed span-context token the receiving runtime can verify against the emitter's public key. 2. **Identity binding.** The traceparent's `trace-flags` and a companion `trace-state` entry carry the emitting agent's federated identity (SPIFFE ID or equivalent), and the receiving runtime checks that the claimed parent span's emitter matches that identity. 3. **Freshness.** The envelope's traceparent is derived at handoff time, not at checkpoint time. Cached envelopes must be re-stamped with a monotonic handoff counter and rejected if the counter regresses. 4. **Baggage scoping.** Baggage keys are namespaced by emitting tenant, and the receiving runtime strips or quarantines baggage keys it cannot attribute to a verified upstream hop. If any one fails, the trace is a *correlation artifact*, not a *causal record*, and must be marked as such (e.g., `trace-confidence: unverified`) rather than silently merged into the primary trace. ## Decision Boundary The boundary is between **propagating** a received trace context and **re-rooting** it. An instance must re-root — emit a fresh trace-id, record the received context only as an opaque `link` attribute, and refuse to set the received span-id as its parent — when any of these conditions hold: - The received parent-span-id cannot be resolved to a signed, live-or-emitter-closed span in the federation's span registry. - The received traceparent's emitting identity does not match the identity asserted on the handoff envelope (a classic confused-deputy setup where a low-trust agent relays a high-trust agent's context). - The envelope's handoff counter is less than or equal to the last counter seen from that peer (replay). - The received baggage contains keys outside the peer's declared namespace. Conversely, an instance may propagate directly (preserving parent link) only when the peer is a *same-identity* continuation — a resumed checkpoint of the same logical agent — because in that case the liveness and identity bindings are trivially satisfied by the shared signing key. The subtle trap: a checkpoint-resume *looks* like a same-identity continuation but is often a different process instance with a different key, and must be treated as a re-root unless the checkpoint carries the original signing key forward. The failure is non-obvious because every individual hop is *locally* correct. B's resume logic was correct for B's own memory. C's propagation logic was correct per the W3C spec. The collector's merge logic was correct per OTLP. The boundary is only visible at the *federation* layer, where "correct locally" composes into "false globally." ## Operational Effect Without the invariant, agent systems suffer three concrete degradations: 1. **Auditor replay divergence.** When a verification agent replays a trace to check whether a downstream claim was grounded in upstream evidence, a forged parent link makes the replay pass against the wrong evidence. The verification agent reports *verified* on a claim that was never grounded. This is the most dangerous effect because it converts a trace bug into a silent correctness failure in the verification layer. 2. **Baggage bleed.** Replayed envelopes carry stale tenant-scoped baggage into downstream prompts, causing retrieval-augmented agents to cite evidence they never fetched. The trace remains internally consistent, so the bleed is invisible to trace-based debugging. 3. **Sampler poisoning.** Collectors that sample by root-span ancestry will over- or under-sample entire federated subtrees based on a forged parent, so the *aggregate* trace corpus systematically misrepresents which agent paths are hot. Capacity planning and failure attribution both drift. The guardrail is a **handoff envelope contract** enforced at the receiving runtime: verify signed span-context, check handoff counter monotonicity, namespace-check baggage, and on any failure re-root with an explicit `link` to the received context plus a `trace-confidence: unverified` flag. The receiving runtime must never let a peer's traceparent silently become its parent. ```python from dataclasses import dataclass, field from typing import Optional class TraceContextForgeryError(RuntimeError): """Raised when a received handoff trace context cannot be bound to a verified upstream span.""" pass @dataclass class HandoffEnvelope: trace_id: str parent_span_id: str emitter_identity: str asserted_identity: str handoff_counter: int baggage: dict = field(default_factory=dict) span_context_signature: Optional[str] = None @dataclass class SpanRegistry: # span_id -> (emitter_identity, is_open_or_emitter_closed, signature) spans: dict = field(default_factory=dict) last_counter_by_peer: dict = field(default_factory=dict) def verify_and_maybe_reroot( envelope: HandoffEnvelope, registry: SpanRegistry, receiver_identity: str, peer_namespace: str, ) -> dict: """Return a trace context to propagate, or re-root with an unverified link. Raises TraceContextForgeryError when the envelope must be rejected outright (identity mismatch or replay), as opposed to re-rooted. """ # 1. Identity binding: the relayed identity must match the asserted one. if envelope.emitter_identity != envelope.asserted_identity: raise TraceContextForgeryError( f"confused-deputy: envelope asserts {envelope.asserted_identity} " f"but traceparent was emitted by {envelope.emitter_identity}" ) # 2. Replay check: handoff counter must strictly increase per peer. last = registry.last_counter_by_peer.get(envelope.emitter_identity, -1) if envelope.handoff_counter <= last: raise TraceContextForgeryError( f"replay: handoff counter {envelope.handoff_counter} <= last seen {last} " f"from {envelope.emitter_identity}" ) # 3. Liveness binding: parent span must be registered, signed, and live-or-emitter-closed. span = registry.spans.get(envelope.parent_span_id) if span is None or span[0] != envelope.emitter_identity or not span[1]: # Not an outright forgery — could be a collector lag — but we cannot # trust it as a parent. Re-root and record as an opaque link. registry.last_counter_by_peer[envelope.emitter_identity] = envelope.handoff_counter return { "action": "reroot", "trace_id": _fresh_trace_id(), "parent_span_id": None, "link": { "trace_id": envelope.trace_id, "span_id": envelope.parent_span_id, "confidence": "unverified", }, } # 4. Baggage scoping: quarantine foreign keys. clean_baggage = { k: v for k, v in envelope.baggage.items() if k.startswith(f"{peer_namespace}.") } quarantined = set(envelope.baggage) - set(clean_baggage) registry.last_counter_by_peer[envelope.emitter_identity] = envelope.handoff_counter return { "action": "propagate", "trace_id": envelope.trace_id, "parent_span_id": envelope.parent_span_id, "baggage": clean_baggage, "quarantined_baggage": quarantined, "confidence": "verified", } def _fresh_trace_id() -> str: import secrets return secrets.token_hex(16) ```