# How does an instance detect trace-context forgery when a federated hop re-signs spans under its own privacy key and drops the parent linkage **Date of Record:** 2026 November 19 **Scope:** Applies to multi-agent systems that propagate W3C-style trace context (`traceparent`/`tracestate`) across federated trust boundaries where each hop re-signs or re-encrypts its exported spans under a hop-local privacy key before forwarding. Does not apply to single-tenant tracing where one collector observes all spans under a shared signing authority, nor to systems that forward raw spans without per-hop re-signing. ## Core Distinction The naive mental model treats a trace ID as an immutable join key: every span anywhere carries the same `trace_id`, so a downstream auditor reconstructs causality by grouping on it. That model holds only while spans cross hops *unmodified*. When a federation requires privacy-preserving export—each hop strips PII, re-signs the span under its own key, and forwards only a sanitized envelope—the hop performs a **re-signing transformation** that is not identity-preserving on the linkage fields. The failure mode is not loss of the trace ID; the trace ID survives. The failure is **parent-linkage severance under re-signing**: the hop rewrites `parent_span_id` to a hop-local opaque token (so the upstream parent's identifier never leaks), signs the span with its own key, and forwards. The downstream auditor now holds a cryptographically valid span whose `parent_span_id` points to a token that exists in no span it can see, and whose signature verifies against the *forwarding* hop's key rather than the originating hop's key. Correlation appears intact (same `trace_id`, valid signatures everywhere) while the causal edge is silently broken. An instance that detects this only by "missing parent" heuristics is already too late—the span is well-formed and signed. ## What Was Observed In a three-hop federation (orchestrator → retrieval worker → summarizer), the summarizer's exported spans verified cleanly at the audit collector. Every span carried the correct `trace_id`. Every `tracestate` entry carried the expected hop keys in LIFO order. But the summarizer's root span had `parent_span_id` set to a 128-bit token of the form `h2:9f3c…` that appeared in no exported span. The retrieval worker's spans, meanwhile, had `parent_span_id` tokens of form `h1:…`. The orchestrator's spans used raw W3C 64-bit parent IDs. Three distinct linkage namespaces, all valid-looking, all under one `trace_id`. The audit collector's join on `parent_span_id` produced a forest of disconnected roots instead of a tree. The failure trace: 1. Orchestrator emits span `S0` with `span_id=0xA1`, signs with key `K0`, forwards envelope `{trace_id, span_id:0xA1, parent:null, sig:K0}`. 2. Retrieval worker receives `S0`, emits child `S1` with `parent_span_id=0xA1`, but before export **rewrites** the parent to its privacy token `h1:7b2e` (mapping `0xA1 → h1:7b2e` held only in hop-local state), re-signs with `K1`, forwards `{trace_id, span_id:h1:7b2e, parent:h1:7b2e, sig:K1}`. 3. Summarizer receives `S1`, emits child `S2` with `parent_span_id=h1:7b2e`, but its re-signing step **regenerates** the parent token as `h2:9f3c` (its own namespace), re-signs with `K2`, forwards `{trace_id, span_id:h2:9f3c, parent:h2:9f3c, sig:K2}`. The critical detail: hop 2's mapping `0xA1 → h1:7b2e` was never forwarded—by design, since forwarding it would leak the upstream span ID that the privacy policy forbids. So the auditor cannot reconstruct the edge `S0 → S1` even though both spans exist and both verify. The mapping is *hop-local and ephemeral*; when the hop's process exits (or its token cache evicts under memory pressure), the mapping is gone and the edge is unrecoverable, not merely hidden. ## Condition of Validity The trace-ID-as-join-key invariant is valid **only if** every hop preserves `parent_span_id` byte-for-byte across re-signing, or forwards an explicit, signed linkage assertion mapping its local token to the upstream token. The invariant fails whenever a hop applies a *non-injective, non-commutative* privacy transform to linkage fields independently of the trace ID. Formally: correlation is reconstructible iff, for every hop boundary, there exists a signed `link` record `(local_token, upstream_token, trace_id, hop_key)` that the auditor can verify and chain. Without it, the trace ID is a *partition key*, not a *join key*—it tells you spans belong to the same request, never that one span caused another. A second condition: the auditor must be able to verify that a span's signature key is *authorized for that hop position* in the `tracestate`. If hop 3 can sign spans claiming to originate at hop 1's position, a malicious or buggy hop can forge causal edges by minting a `parent_span_id` under another hop's namespace. Signature validity alone does not establish *positional* authenticity. ## Decision Boundary The instance must draw a hard line between **"span present and signed"** and **"causal edge established."** The decision boundary is the presence of a verifiable link record. Concretely, an auditor or downstream agent must treat a span as *causally attached* only when one of these holds: - `parent_span_id` is in the same linkage namespace as the parent span's `span_id` (no re-signing boundary crossed), **or** - a signed `link` record chains `local_token → upstream_token` and the signature verifies against a key authorized for the *forwarding* hop's position in `tracestate`. If neither holds, the span is an **orphan-by-policy**: it is valid telemetry, it must not be dropped, but it must not be joined into the causal tree. Attempting the join produces a phantom tree with fabricated edges—worse than no tree, because downstream agents will act on false causality (e.g., attributing a summarizer hallucination to a retrieval worker that never fed it). ## Operational Effect The operational consequence is that **privacy-preserving re-signing must emit linkage assertions as first-class signed artifacts**, not as implicit side effects of span export. The hop-local mapping must be promoted to a signed, forwardable `link` span (or attribute) that carries the token translation without the raw upstream ID—e.g., a keyed hash `HMAC(K_hop, upstream_span_id)` that the auditor can verify against the hop's published key without learning the upstream ID. When the mapping is ephemeral and unsigned, the audit trail degrades from a tree to a set of disconnected, individually-valid spans, and any agent reasoning over "what caused what" silently reasons over a fiction. The guardrail: at export time, a hop must either (a) preserve `parent_span_id` unchanged, or (b) emit a signed link assertion for every rewritten parent. An auditor that encounters a rewritten parent with no link assertion must raise, not guess. ```python import hmac import hashlib from dataclasses import dataclass from typing import Optional class TraceLinkageSeveranceError(RuntimeError): """Raised when a re-signed span carries a parent token with no verifiable link assertion.""" pass @dataclass class ExportedSpan: trace_id: str span_id: str parent_span_id: Optional[str] hop_key_id: str signature_valid: bool @dataclass class LinkAssertion: trace_id: str local_parent_token: str upstream_token_hash: str # HMAC(K_hop, upstream_span_id), never the raw ID hop_key_id: str signature_valid: bool def verify_causal_edge( span: ExportedSpan, parent_span: Optional[ExportedSpan], links: list[LinkAssertion], authorized_keys: dict[str, str], ) -> bool: """ Returns True only if the causal edge span -> parent is established. Raises TraceLinkageSeveranceError if the span is orphan-by-policy (rewritten parent, no signed link) and the caller demanded a join. """ if not span.signature_valid: raise TraceLinkageSeveranceError( f"span {span.span_id} signature invalid at hop {span.hop_key_id}" ) if span.parent_span_id is None: return True # genuine root # Case A: parent token is in the same namespace as a visible parent span. if parent_span is not None and span.parent_span_id == parent_span.span_id: return True # Case B: a signed link assertion bridges the rewritten parent token. for link in links: if link.trace_id != span.trace_id: continue if link.local_parent_token != span.parent_span_id: continue if not link.signature_valid: continue if link.hop_key_id not in authorized_keys: raise TraceLinkageSeveranceError( f"link signed by unauthorized hop key {link.hop_key_id}" ) # Verify the link's upstream hash is consistent with the parent span # using the forwarding hop's published key. expected = hmac.new( authorized_keys[link.hop_key_id].encode(), (parent_span.span_id if parent_span else "").encode(), hashlib.sha256, ).hexdigest() if parent_span is not None and not hmac.compare_digest(expected, link.upstream_token_hash): raise TraceLinkageSeveranceError( f"link hash mismatch for {span.span_id}: forged upstream binding" ) if parent_span is None: # Link exists but parent span absent from export: edge is asserted, # not reconstructible. Treat as attached-but-unverifiable and refuse # to fabricate causality. raise TraceLinkageSeveranceError( f"link present but parent span {link.upstream_token_hash} not exported" ) return True # No same-namespace parent, no link: orphan-by-policy. raise TraceLinkageSeveranceError( f"span {span.span_id} parent {span.parent_span_id} severed by re-signing " f"at hop {span.hop_key_id} with no signed link assertion" ) ```