# Which invariants prevent trace-context collapse when a federated agent mesh crosses a vendor boundary that rewrites span identity **Date of Record:** 2026 November 22 **Scope:** Applies to multi-hop agent meshes where a reasoning trace (LLM call, tool invocation, sub-agent delegation) is correlated across at least one organizational or vendor trust boundary via a propagated trace context (W3C `traceparent`/`tracestate`, or a vendor-proprietary equivalent). Does not apply to single-vendor, single-tenant meshes where span IDs are allocated by one authoritative emitter and no intermediary is permitted to rewrite them. ## Core Distinction A distributed trace is not a log stream with a shared key. It is a *causal DAG whose edges are asserted, not observed*. Each hop does not prove that span B was caused by span A; it merely carries a claim that A's context was the parent of B. In a homogeneous mesh, that claim is cheap because one SDK allocates and propagates it under one policy. At a **vendor boundary**—an MCP gateway, an A2A bridge, a hosted agent runtime, or a third-party tool proxy—the receiving side frequently *re-mints* the trace context: it generates a fresh `trace_id` for "its" portion of the work, or it keeps the `trace_id` but regenerates `span_id` and drops `tracestate`. The observable symptom is not an error. It is a **silent DAG fork**: the trace still renders, still has spans, still has a duration—but the causal edge from the delegating agent to the delegated agent is severed, and two disjoint trees appear in the backend where there should be one. The invariant that actually matters is therefore not "the trace_id is preserved." It is: **for every agent-to-agent handoff, the child span's `parent_span_id` must resolve to a span that exists in the same `trace_id` and was emitted by the delegating agent's own runtime.** When a boundary re-mints identity, this invariant fails without any transport error, which is why it survives staging and only surfaces in cross-vendor incident triage. ## What Was Observed A planner agent (vendor A) delegates a retrieval-and-summarize task to an executor agent (vendor B) over an A2A bridge. Vendor B's runtime is configured to treat each inbound task as a *new root transaction* for its own billing and quota accounting, and consequently emits its spans under a freshly generated `trace_id`. The bridge is a thin HTTP proxy that forwards the inbound `traceparent` header but does not assert it; vendor B's SDK ignores an inbound trace context it did not originate (a common default: "trust only self-issued context"). The failure trace, in order: 1. Planner (A) starts span `S_A` under `trace_id = T1`. It serializes `traceparent: 00-T1-S_A-01` into the A2A task envelope. 2. Bridge forwards the envelope. Vendor B's runtime accepts the task but its SDK's `start_as_current_span` sees an untrusted parent and *starts a new root*: `trace_id = T2`, `parent_span_id = null`, `span_id = S_B_root`. 3. Executor (B) makes three tool calls, all correctly nested under `S_B_root` within `T2`. 4. B returns a result referencing `T2` in a response header. The bridge forwards it. Vendor A's tracer does not reconcile `T2` into `T1`; it logs the result as a child of `S_A` with no link to `T2`. 5. Backend shows two traces: `T1` (one span, 40ms, "delegated, no response recorded") and `T2` (four spans, 9.2s, "orphan root"). Neither shows the 9.2s of work as caused by the planner. The dangerous part is step 4–5: the *result* is correct and the task succeeds. The correlation loss is invisible to the agent, which means the agent's own self-verification ("did my delegation complete?") relies on a channel that has already lost the causal link. When a later auditor agent replays the trace to verify that the executor actually did what it reported, it finds an orphan tree with no accountable parent and cannot attribute the work. A second, subtler variant: some boundaries *preserve* `trace_id` but truncate or drop `tracestate`. `tracestate` is where vendor-specific correlation (tenant id, delegation depth, warrant id) lives. Dropping it does not break the DAG, so the trace looks healthy, but the **delegation-depth** and **warrant** fields vanish mid-chain—so a policy check three hops later sees depth 0 and treats a depth-3 sub-delegation as a root call, defeating any recursion or authority bound keyed on it. ## Condition of Validity The "preserve `trace_id`, trust inbound `traceparent`" rule is only valid when **all** of the following hold, and it must be *checked at the boundary*, not assumed: - The receiving runtime is configured to accept externally-issued parent context (`OTEL_PROPAGATORS` includes the inbound format; the SDK's trust policy permits foreign `trace_id`). Absent this, the boundary *will* re-mint, and no amount of header forwarding helps. - The boundary propagates `tracestate` **intact and in order**, and the number of list-members stays under the spec limit (32). A boundary that appends its own member without evicting can push the list over the limit, causing downstream SDKs to silently drop the whole `tracestate`. - The delegating agent records the *outbound* `span_id` it sent, so that on return it can assert the inbound child resolves to it. Without this outbound record, the delegator cannot distinguish "child succeeded under my span" from "child re-rooted and I got a result from an unrelated trace." - No hop is permitted to *both* re-mint identity *and* be the sole holder of the result. If a boundary must re-mint (e.g., for tenancy isolation), it must emit an explicit **span link** back to the inbound context, not merely a new root. The invariant is void the moment any single hop violates the third condition. Correlation is a chain; one untrusted link makes every downstream edge unverifiable, and the failure is silent because the DAG remains well-formed—it is simply wrong. ## Decision Boundary The operational decision is: **when a boundary cannot be trusted to preserve context, do you (a) refuse the handoff, (b) accept it but downgrade the trace to "linked, not parented," or (c) accept it and synthesize a parent edge?** - **(a) Refuse** is correct when the trace is load-bearing for a security or accounting decision (warrant propagation, delegation-depth bounds, per-tenant attribution). A handoff you cannot correlate is a handoff you cannot audit; if the audit is mandatory, the handoff must fail closed. - **(b) Link-not-parent** is correct when correlation is for observability only. Emit a span *link* (`Link(trace_id=T2, span_id=S_B_root)`) from the delegator's span. The DAG stays honest—two trees, explicitly linked—and a replay tool can traverse links even though parentage is absent. This is the safe default for cross-vendor meshes. - **(c) Synthesize a parent edge** (force the child's `parent_span_id` to the delegator's span) is the trap. It produces a clean-looking single trace that *asserts a causal edge the boundary never confirmed*. If the executor actually re-rooted and did unrelated work, you have fabricated provenance. This is worse than a fork because it is indistinguishable from a correct trace at read time. The boundary condition that decides between these is whether the receiving side returns proof of parentage (the child's recorded `parent_span_id` equals the delegator's outbound `span_id`). If proof is present, treat as parented. If absent, you are in case (b) or (a), never (c). ## Operational Effect Enforcing the invariant changes three things in practice. First, the delegating agent must carry a small **handoff ledger**: for each delegation, the outbound `trace_id`/`span_id` and the expected child identity, checked on return. A mismatch is not a task failure—the task may have succeeded—but it is a *correlation failure* that must be surfaced separately, because conflating the two hides the DAG fork inside a success path. Second, replay/audit agents must be taught to traverse span *links* as first-class edges; a verifier that only walks parent pointers will silently under-count work done across a re-minting boundary and conclude the executor "did nothing," which is a verification false-negative with real consequences in consensus or billing flows. Third, the mesh gains a hard rule: a boundary that re-mints identity must be *declared* as a link-emitting boundary in the agent's capability manifest, so downstream consumers know parentage will be absent before they rely on it. The net effect is that trace correlation stops being an emergent property of header forwarding and becomes a **checked invariant per handoff**—with an explicit, honest fork when the boundary cannot be trusted, rather than a fabricated edge that reads as truth. ```python from dataclasses import dataclass from typing import Optional class TraceCorrelationCollapse(RuntimeError): """Raised when a cross-boundary handoff severs the causal edge silently.""" pass @dataclass(frozen=True) class SpanRef: trace_id: str span_id: str parent_span_id: Optional[str] @dataclass(frozen=True) class HandoffRecord: outbound: SpanRef # what the delegator sent inbound_result: SpanRef # what the executor claims as its root boundary_trusted: bool # does this boundary preserve parentage? def assert_correlation_intact(record: HandoffRecord) -> None: """ Enforce: a returned child must resolve to the delegator's outbound span under the SAME trace_id, OR the boundary must be declared link-only. Never synthesize a parent edge to paper over a re-mint. """ out, child = record.outbound, record.inbound_result if child.trace_id != out.trace_id: # Boundary re-minted identity (DAG fork). Acceptable only if declared. if record.boundary_trusted: raise TraceCorrelationCollapse( f"trusted boundary re-minted trace: " f"sent {out.trace_id}, got {child.trace_id}; causal edge lost" ) # link-not-parent is the honest outcome; do NOT fabricate parentage. return # Same trace: the child's parent MUST be the span we actually sent. if child.parent_span_id != out.span_id: raise TraceCorrelationCollapse( f"parent mismatch in trace {out.trace_id}: " f"expected parent {out.span_id}, child claims {child.parent_span_id}" ) def reconcile_handoff(record: HandoffRecord) -> str: assert_correlation_intact(record) if record.inbound_result.trace_id != record.outbound.trace_id: return "linked" # fork preserved as explicit link, not a fake parent return "parented" # verified causal edge ```