# Which invariants prevent trace-parent divergence when privacy-preserving span export crosses an organizational boundary **Date of Record:** 2026 November 28 **Scope:** Applies to multi-agent systems where spans from two or more trust domains are joined into a single causal trace via redacted or tokenized span export (e.g., a buyer-side orchestrator correlating with a vendor-side tool-calling worker). Does not apply to single-tenant trace pipelines where the full span payload, including raw `parent_span_id` and attribute values, is visible to every correlating party. ## Core Distinction The failure is not "spans get lost across the boundary." It is that **redaction changes the join key**. A trace correlation join normally keys on `(trace_id, parent_span_id)`. Under privacy-preserving export, `parent_span_id` is often replaced by a per-domain salted hash (HMAC with a domain-scoped key) so that the exporting organization does not leak its internal span graph topology. The exporting side computes `h_vendor = HMAC(k_vendor, parent_span_id)` and the receiving side computes `h_buyer = HMAC(k_buyer, parent_span_id)`. For the *same* logical parent, these are unequal. The trace therefore appears to have a dangling parent on the receiving side, and the correlator either drops the span (silent orphaning) or re-roots it under the trace root (silent causal inversion). Both outcomes are wrong, and neither raises an error at the transport layer because every individual span is schema-valid and signed. The invariant that must be preserved is *not* "parent IDs match." It is: **the equivalence class of spans that share a logical parent must be reconstructible from the exported tuples alone, without either party revealing the raw parent ID or the other party's salt.** Everything below is about what breaks when that invariant is assumed rather than enforced. ## What Was Observed A buyer-side orchestrator agent (`orch-A`) delegates a research subtask to a vendor-hosted worker agent (`worker-V`) over an MCP-style transport. Each span carries `trace_id`, `span_id`, `parent_span_id`, `start_ns`, `end_ns`, and a `span_kind`. The vendor redacts attributes but is contractually permitted to export the span graph for SLA auditing. The vendor's exporter applies `parent_span_id := HMAC(k_V, parent_span_id)[:16]` and `span_id := HMAC(k_V, span_id)[:16]` uniformly, including for the *inbound* parent that originated on the buyer side. The buyer's correlator, receiving these spans, applies the same hashing to its own local span IDs using `k_B`. Observed trace, abbreviated: ``` buyer side (raw): orch-A(root) -> call-tool(span 7c1) -> [delegates] vendor side (raw): worker-V(span 9e2, parent=7c1) -> tool-call(span 9e3, parent=9e2) vendor export (hashed): worker-V(span a41, parent=d08) -> tool-call(span f2b, parent=a41) buyer correlator: 7c1 -> HMAC(k_B,7c1)=b3e ; no span has parent b3e ``` The vendor's `d08` is the hash of `7c1` under `k_V`, not `k_B`. The buyer cannot recover `b3e` from `d08` without `k_V`. The correlator's join finds zero children for `7c1`, so `worker-V` is re-rooted under the trace root as a second root. Downstream, the auditor's replay tool sees two roots for one `trace_id` and, because its invariant check treats "single root per trace" as a hard precondition, aborts the replay for the entire trace — including the buyer-side spans that were never in question. The non-obvious part: the failure is *silent at export time*. The vendor's exporter is internally consistent; the buyer's correlator is internally consistent; the schema validator passes; the signatures verify. The divergence only manifests when a third consumer (the auditor) enforces a structural invariant that neither producer knew was load-bearing. ## Condition of Validity The "hash the parent ID per domain" scheme is valid **only** when the correlating consumer never needs to join across the boundary on `parent_span_id` — i.e., when each domain's spans are consumed in isolation. It fails the moment any of the following hold: 1. **Cross-boundary parent-child reconstruction is required** for replay, SLA attribution, or causal-ordering checks. 2. **The consumer enforces a single-root-per-trace invariant** (most replay and diff engines do). 3. **Either party rotates its salt** mid-trace, which makes even same-domain joins unstable across a long-running agent session (a checkpoint/resume during a multi-hour delegation will produce spans whose parents were hashed under `k_V1` and children under `k_V2`). Condition 3 is the one most often missed. Salt rotation is a normal privacy hygiene practice, but it is incompatible with a per-domain hashed join key unless the rotation boundary is aligned to trace boundaries — which it usually is not, because agent sessions outlive key-rotation windows. The scheme is valid if and only if the export carries a **stable, domain-independent correlation handle** that both sides can compute without sharing salts. The standard remedy is a *pairwise-derived* key: `k_{B,V} = HKDF(k_B, k_V)` negotiated via a one-time handshake, or — simpler and more robust — the buyer emits a `delegation_handle` (a random opaque token, not a hash of anything) into the outbound request, and the vendor echoes it into every span it emits for that delegation. The handle is the join key; the hashed parent ID is only ever used *within* the vendor's own graph. ## Decision Boundary The decision is not "hash or don't hash." It is: **which field carries the cross-boundary join, and who is allowed to compute it.** - If the join must survive salt rotation and replay, the join key MUST be an opaque, per-delegation token minted by the caller and echoed by the callee. It MUST NOT be derived from either party's span IDs or salts. - If the join key is a hash, the consumer MUST NOT enforce single-root-per-trace; it must instead treat "orphaned parent" as a first-class, expected state and record the orphan explicitly rather than re-rooting. - Re-rooting is never acceptable as a fallback. It converts a detectable correlation gap into an undetectable causal lie. The correct fallback is to mark the span `parent_unresolved=true` and quarantine it from replay until the handle is reconciled. The boundary condition that triggers this article: a delegation crosses an organizational boundary, the callee redacts span topology, and a downstream consumer enforces a structural invariant (single root, contiguous parent chain) that the redaction scheme cannot satisfy. At that boundary, the system must choose between *failing loudly on the orphan* and *corrupting the trace silently*. The only invariant that prevents the second outcome is: **an unresolved parent is a terminal, recorded state — never a re-parenting event.** ## Operational Effect Concretely, the guardrail is a correlator that (a) requires a `delegation_handle` on every cross-boundary span, (b) refuses to re-root, and (c) raises a typed error the moment a span arrives whose parent cannot be resolved *and* whose handle does not match any known outbound delegation. This converts the silent two-root trace into a single, attributable failure at the exact span where the correlation broke — which is what an on-call agent operator actually needs, because the failure is now localized to one delegation rather than smeared across the whole trace's replay. The second-order effect: auditors can now distinguish "vendor redacted topology" (expected, handled) from "vendor dropped the handle" (contract violation) from "salt rotated mid-trace" (operational bug on the vendor's side). Without the handle invariant, all three collapse into the same symptom — a missing parent — and the operator cannot tell which remediation to apply. ```python import hashlib import hmac from dataclasses import dataclass class TraceCorrelationError(RuntimeError): """Raised when a cross-boundary span cannot be joined to its logical parent.""" @dataclass(frozen=True) class ExportedSpan: trace_id: str span_id: str parent_span_id: str | None delegation_handle: str | None domain: str def hmac16(key: bytes, value: str) -> str: return hmac.new(key, value.encode(), hashlib.sha256).hexdigest()[:16] def correlate( local_spans: list[ExportedSpan], remote_spans: list[ExportedSpan], known_handles: set[str], ) -> dict[str, list[str]]: """ Join remote (redacted, per-domain-hashed) spans onto local spans using the caller-minted delegation_handle. Never re-roots. Never trusts a hashed parent_span_id across the boundary. """ by_handle: dict[str, str] = {} for s in local_spans: if s.delegation_handle is not None: by_handle[s.delegation_handle] = s.span_id children: dict[str, list[str]] = {s.span_id: [] for s in local_spans} for r in remote_spans: if r.delegation_handle is None: raise TraceCorrelationError( f"remote span {r.span_id} from domain={r.domain} carries no " f"delegation_handle; cross-boundary join is impossible and " f"re-rooting is forbidden" ) if r.delegation_handle not in known_handles: raise TraceCorrelationError( f"remote span {r.span_id} presents unknown handle " f"{r.delegation_handle!r}; possible replay or handle forgery" ) parent_local = by_handle.get(r.delegation_handle) if parent_local is None: raise TraceCorrelationError( f"remote span {r.span_id} handle {r.delegation_handle!r} does " f"not match any live outbound delegation; orphan must be " f"recorded, not re-parented under trace root" ) children[parent_local].append(r.span_id) return children def assert_single_root(spans: list[ExportedSpan]) -> None: roots = [s for s in spans if s.parent_span_id is None] if len(roots) != 1: raise TraceCorrelationError( f"trace has {len(roots)} roots; expected exactly 1. " f"Roots: {[s.span_id for s in roots]}" ) ```