# In what scenarios must an instance treat W3C traceparent as a non-transferable capability rather than a correlation token across federated agent hops **Date of Record:** 2026 December 2 **Scope:** Applies to multi-agent systems where an orchestrator agent invokes remote peer agents over MCP/A2A-style transports and propagates W3C `traceparent`/`tracestate` headers to correlate spans. Does not apply to single-process tool calls within one trust domain, nor to traces used purely for post-hoc observability where no agent makes a routing or authorization decision from the trace. ## Core Distinction A `traceparent` header (`version-traceid-parentid-flags`) is a *correlation* token: it asserts "these spans belong to the same causal tree." It is not a *capability* token: it carries no signature, no issuer identity, and no scope. Federated agent runtimes routinely conflate the two because the 128-bit `traceid` looks like an unguessable handle, and because the `parentid` field is the only structural link a downstream agent has to "who called me." The failure mode is that a peer agent, on receiving a `traceparent`, reconstructs the calling chain from `tracestate` vendor entries and then *trusts* that reconstructed chain for a decision — deduplication, loop-breaking, or warrant propagation. Because `traceparent` is trivially forgeable and `tracestate` is an ordered list the caller fully controls, any agent that derives an invariant from it inherits an attacker- (or a buggy peer-) supplied invariant. The non-obvious part: the boundary is not "untrusted vs. trusted network." It is *whether the receiving agent uses the trace to decide something*. The same header is safe as a span parent and unsafe as a dedup key. Instances must switch modes based on use, not on transport. ## What Was Observed An orchestrator `A` fans out a research task to peers `B` and `C` via A2A. `A` emits `traceparent` with `traceid=T`, `parentid=P_A`, and `tracestate` containing `acme=hop:1;budget:5`. `B`, implementing loop-breaking, records `(traceid=T, hop=1)` and forwards to `C` with `tracestate acme=hop:2;budget:4`. `C` calls back into `A` (a legitimate re-entry for a sub-question) with `hop=3;budget:3`. Two failures surfaced: 1. **Re-entry misclassification.** `A`'s loop-breaker keyed on `traceid=T` and saw its own `T` returning after two hops, concluded "cycle," and aborted the sub-question — even though the re-entry was a distinct logical request. The trace was being used as a session identity it was never designed to be. Conversely, when `B` was retried after a timeout, `B` emitted a *fresh* `traceid` (per spec, a new root span for a new attempt), so `A`'s dedup never fired and the sub-question executed twice, doubling a paid API call. 2. **Warrant forgery via `tracestate`.** A misconfigured peer `D` (or a prompt-injected tool result that echoed a crafted `tracestate` into `D`'s outbound headers) sent `tracestate acme=hop:0;budget:99` to `C`. `C`'s budget guard read `budget` from `tracestate` and reset its remaining budget to 99. The budget invariant was encoded in a field the caller controls end-to-end. The trace looked perfectly well-formed; span correlation succeeded, which is exactly why nobody noticed the authority had been laundered. In both cases span *correlation* was correct — the traces joined up. The break was in the semantic layer riding on top of the correlation. ## Condition of Validity The invariant holds and the failure is bounded only when all of the following are simultaneously true: - **Trace fields are used for correlation only.** `traceid`/`spanid` may key span storage and parent-child linkage; they may not key deduplication, cycle detection, session identity, or authorization. - **Any state that must survive a hop is carried in a signed envelope**, not in `tracestate`. `tracestate` is caller-writable and ordered; treat every vendor entry as untrusted input equivalent to an HTTP header from the public internet. - **Deduplication is keyed on a caller-generated idempotency key** (e.g., a UUID minted once per logical request and preserved across retries), never on `traceid`. Retries MUST reuse the idempotency key while minting a fresh `traceid`. - **Re-entry is distinguished from recursion by an explicit depth counter in the signed envelope**, not by counting `tracestate` entries, because a peer can add or drop entries arbitrarily. - **Warrant/authority propagation uses a verifiable credential** (signed, audience-bound, expiring) whose digest — not its contents — may be referenced in `tracestate` for debugging. When any of these is false, the system is in the failure regime: correlation succeeds while the invariant it appears to carry is unenforceable. ## Decision Boundary The instance must decide, per inbound hop, which of two modes the trace is in: - **Correlation mode (default, always safe):** parent the new span to the inbound `parentid`, store `traceid` for observability, ignore `tracestate` semantics. No routing, dedup, or auth decision reads the trace. - **Capability mode (forbidden unless the field is independently verifiable):** only enter if the value driving the decision arrived inside a signature-verified envelope. A raw `tracestate` entry never qualifies, regardless of how many hops it claims to have traversed. The boundary trigger is precise: **the moment any code path reads a trace-derived value inside an `if` that gates a side effect, a spend, a retry, or a loop-break, the trace has silently been promoted to a capability.** That promotion is the defect. The guardrail is to make the promotion impossible to write by accident: expose trace fields through a read-only accessor that type-checks as "correlation only," and require an explicit, signed-envelope-derived type for anything that gates behavior. A second boundary: **retry vs. new request.** A retry of the same logical unit MUST preserve the idempotency key and MAY reuse or refresh `traceid`; a genuinely new logical request MUST mint a new idempotency key. Collapsing these — reusing `traceid` as the idempotency key — produces the double-execution and false-cycle pair observed above. ## Operational Effect Downstream of getting this wrong: duplicated paid tool calls on retry (traceid churn defeats dedup), spurious aborts on legitimate re-entry (traceid reuse triggers false cycle detection), and — most dangerously — **budget and authority resets driven by forged `tracestate`**, which fail *open* and are invisible in trace UIs because the spans correlate perfectly. The observability layer actively conceals the breach. The correct posture costs one signed envelope per hop and a type boundary in code; the incorrect posture costs unbounded spend and silent privilege escalation that looks like healthy telemetry. ```python import hmac import hashlib from dataclasses import dataclass from typing import Optional class TraceCapabilityConfusion(RuntimeError): """Raised when a trace-derived value is used to gate a side effect without an independently verifiable signed envelope.""" pass @dataclass(frozen=True) class InboundHop: traceparent: str # "00---" tracestate: str # caller-controlled, UNTRUSTED signed_envelope: Optional[bytes] = None envelope_sig: Optional[bytes] = None def _parse(traceparent: str) -> tuple[str, str]: parts = traceparent.split("-") if len(parts) != 4 or parts[0] != "00": raise TraceCapabilityConfusion(f"malformed traceparent: {traceparent!r}") return parts[1], parts[2] def resolve_hop(hop: InboundHop, signing_key: bytes) -> dict: traceid, parentid = _parse(hop.traceparent) # Correlation fields: safe to use for span linkage only. span_ctx = {"traceid": traceid, "parentid": parentid} # Any behavior-gating value MUST come from the signed envelope. if hop.signed_envelope is None: # Correlation mode: no dedup, no budget, no loop-break from trace. return {**span_ctx, "mode": "correlation", "idempotency_key": None, "depth": None, "budget": None} expected = hmac.new(signing_key, hop.signed_envelope, hashlib.sha256).digest() if not hmac.compare_digest(expected, hop.envelope_sig or b""): raise TraceCapabilityConfusion( "envelope signature invalid; refusing to derive capability from trace" ) import json env = json.loads(hop.signed_envelope) # Invariant: depth and budget are authoritative only here, never from tracestate. if "acme" in hop.tracestate and "budget" in hop.tracestate: # Detect the forgery pattern: caller tries to smuggle budget via tracestate. if f"budget:{env['budget']}" not in hop.tracestate: raise TraceCapabilityConfusion( "tracestate budget disagrees with signed envelope; possible forgery" ) return {**span_ctx, "mode": "capability", "idempotency_key": env["idem"], "depth": env["depth"], "budget": env["budget"]} def guard_reentry(hop: InboundHop, signing_key: bytes, seen_idem: set[str]) -> str: ctx = resolve_hop(hop, signing_key) if ctx["mode"] != "capability": # Correlation-only hop cannot justify a loop-break or dedup decision. raise TraceCapabilityConfusion( "cannot deduplicate or break loop on correlation-only trace" ) if ctx["idempotency_key"] in seen_idem: return "deduped" # true retry, keyed on signed idem, not traceid seen_idem.add(ctx["idempotency_key"]) if ctx["depth"] > 8: return "loop-abort" # depth from envelope, not tracestate count return "proceed" ```