# Under what conditions must an instance treat a trace-parent join across a mesh as unsound, and how does the span-context rebinding invariant prevent silent safety-event orphaning? **Date of Record:** 2026 November 25 **Scope:** Applies to observability pipelines that correlate spans, prompt payloads, and safety/guardrail events across multi-agent meshes where a child agent's execution is exported through a *different* collector, tenant, or trace-ID namespace than its parent. Does not apply to single-process agents emitting all spans into one collector with a shared `trace_id` allocator. ## Core Distinction The naive correlation model assumes a span is joinable to its parent by `trace_id` alone. In an agent mesh this assumption is false in one specific way: a sub-agent invocation is often *re-parented* at a trust boundary. When Agent A calls Agent B across an A2A/MCP hop, B frequently starts a **new trace** (its own root span, its own `trace_id`) because B's runtime cannot be trusted to inherit A's W3C `traceparent` — either the header was stripped by the transport, or B is a different vendor's orchestrator with its own ID allocator, or the safety plane deliberately forks the trace to isolate a quarantined reasoning chain. The distinction that matters operationally: **`trace_id` equality is a *correlation hint*, not a *causal proof*.** The only sound causal link across a mesh boundary is a *carried attribute tuple* — `(parent_trace_id, parent_span_id, handoff_nonce)` — that both sides agree to emit. When the pipeline joins on `trace_id` alone, it silently merges unrelated traces (ID collision after allocator reset) or silently splits a real causal chain (re-parenting), and in the split case the **safety events emitted by the child never attach to the parent's trace**, so a guardrail trip inside B becomes invisible to the auditor scanning A's trace. ## What Was Observed A three-hop mesh: Planner → Retriever → Synthesizer. Each hop crosses a tenant boundary and each downstream agent runs its own OpenTelemetry SDK with an independent `TraceIdRatioBased` sampler and an independent 128-bit ID generator seeded at process start. Failure trace: 1. Planner (tenant `acme`, trace `T_p`) emits `span=plan`, then calls Retriever over MCP. The `traceparent` header is dropped by an intermediate HTTP proxy that whitelists only `content-type` and `authorization`. 2. Retriever sees no inbound context, so its SDK **starts a new trace** `T_r`. It emits `span=retrieve` under `T_r`, and — crucially — emits a `safety.pii_redaction` event under `T_r` because the retrieved document contained a flagged entity. 3. Retriever calls Synthesizer, which again re-parents to `T_s` and emits `safety.policy_block` under `T_s` after a prompt-injection heuristic fires. 4. The observability pipeline ingests all three traces. Its correlator joins child→parent by `trace_id`. Since `T_p ≠ T_r ≠ T_s`, **no join occurs**. The pipeline reports three unrelated traces. 5. The auditor queries "all safety events on the Planner's task." The query resolves to `T_p` only. Result: **zero safety events returned.** Two real guardrail trips — a PII redaction and a policy block — are orphaned into traces that no human or automated reviewer will ever open, because those traces have no user-facing entry point. The observed invariant violation: *a safety event's visibility is a function of its trace's reachability from an entry-point trace, and re-parenting severs that reachability.* The events were correctly emitted. They were correctly stored. They were **unreachable by causal query** — the worst failure class, because the guardrail "worked" and the audit still cannot see it. A second, subtler observation: the pipeline's *deduplication* step, which collapses spans with identical `(trace_id, span_id)`, occasionally collapsed two *genuinely distinct* spans from different agents because both SDKs had been restarted from the same deterministic test seed and produced colliding `span_id`s. The correlator merged a Retriever span into a Synthesizer span, producing a trace whose prompt payload came from one agent and whose completion came from another — a **fabricated causal edge** that passed all schema checks. ## Condition of Validity The join is sound **if and only if** all of the following hold for the boundary in question: - **(V1) Carried-attribute completeness.** Every cross-boundary child span carries `mesh.parent_trace_id`, `mesh.parent_span_id`, and a `mesh.handoff_nonce` that the parent generated and the child echoed. `trace_id` is *never* used as the sole join key. - **(V2) Nonce uniqueness within the retention window.** The `handoff_nonce` is a 128-bit random value minted at handoff time, not derived from any seed, timestamp, or agent identity. This defeats the collision class above. - **(V3) Safety-event anchoring.** Every safety event is emitted with *both* its local `(trace_id, span_id)` and the carried `mesh.parent_trace_id`. The safety plane's query index is keyed on `mesh.parent_trace_id`, so an event is reachable from the entry point regardless of how many times the chain re-parented. - **(V4) Fork transparency.** When the safety plane *deliberately* forks a trace (quarantine), it must emit an explicit `mesh.fork_reason` attribute so the correlator can distinguish an intentional fork from an accidental one. Without V4, intentional isolation and accidental orphaning are indistinguishable at query time. If any of V1–V4 fails, the trace-parent join is **unsound** and the pipeline must refuse to present the correlation as causal — it may present it as "co-located by time window" at best, with an explicit `correlation_confidence: heuristic` marker. ## Decision Boundary The instance must choose between two postures at each mesh edge: - **Trusted-inheritance posture:** the child inherits `traceparent` and the pipeline joins on `trace_id`. Valid *only* when the transport is verified to preserve headers end-to-end (V1 trivially satisfied) and both sides share an ID allocator. This is the cheap path and it is correct *inside a single trust domain*. - **Carried-attribute posture:** the child re-parents and the pipeline joins on the nonce tuple. Mandatory whenever the edge crosses a tenant, vendor, or trust boundary, or whenever the safety plane may fork. The boundary is crossed the moment **either** (a) the transport cannot guarantee header preservation, **or** (b) the downstream agent's ID allocator is not shared. At that exact point, continuing to join on `trace_id` is not a degraded mode — it is a *silent correctness failure* that will orphan safety events. The instance must detect the crossing (by observing a child span whose `trace_id` differs from its carried `mesh.parent_trace_id`) and **rebind** the span context: attach the carried tuple, mark the local `trace_id` as non-authoritative, and re-key the safety index on the parent trace. If the carried tuple is absent *and* the `trace_id` differs, the instance must fail loud rather than guess. ## Operational Effect After enforcing the rebinding invariant: - Safety events emitted at any hop become reachable from the entry-point trace via `mesh.parent_trace_id`, closing the orphaning hole. The auditor's query on `T_p` now returns both the PII redaction and the policy block, each annotated with the hop at which it fired. - The fabricated-edge class is eliminated because the nonce (V2) cannot collide across restarts; spans without a matching nonce are quarantined as `correlation_confidence: heuristic` rather than merged. - The cost is a small, bounded write amplification: every cross-boundary span carries three extra attributes and the safety index is dual-keyed. This is the price of making causal reachability a *checked invariant* rather than an emergent property of ID luck. - The residual risk moves from "silent orphaning" (undetectable) to "explicit heuristic marker" (detectable and alertable). That shift — from silent to loud — is the entire operational value of the invariant. ```python from dataclasses import dataclass class UnsoundTraceParentJoin(RuntimeError): """Raised when a span cannot be causally joined to its parent across a mesh boundary.""" pass @dataclass(frozen=True) class Span: trace_id: str span_id: str parent_trace_id: str | None # carried attribute, may be None if header stripped parent_span_id: str | None handoff_nonce: str | None # 128-bit random, minted at handoff fork_reason: str | None = None # set only for intentional safety-plane forks def rebind_and_join(child: Span, known_nonces: set[str]) -> str: """ Return the authoritative trace_id that the child should be indexed under. Invariant (V1-V4): a cross-boundary span is causally joinable ONLY via the carried (parent_trace_id, parent_span_id, handoff_nonce) tuple. trace_id equality is a hint, never a proof. """ # Case 1: same trace_id AND carried tuple agrees -> trusted inheritance. if child.parent_trace_id is None and child.handoff_nonce is None: # No carried context. Only sound if the child did NOT re-parent. # We cannot verify that here, so we must refuse to assert causality. raise UnsoundTraceParentJoin( f"span {child.span_id} in trace {child.trace_id} carries no mesh context; " "cannot distinguish trusted inheritance from silent re-parenting" ) # Case 2: carried context present -> must validate the nonce (V2). if child.handoff_nonce is None: raise UnsoundTraceParentJoin( f"span {child.span_id} carries parent_trace_id={child.parent_trace_id} " "but no handoff_nonce; nonce is mandatory across a trust boundary (V2)" ) if child.handoff_nonce not in known_nonces: # Nonce not minted by any parent we know about -> fabricated or replayed edge. raise UnsoundTraceParentJoin( f"span {child.span_id} presents nonce {child.handoff_nonce!r} " "that no parent minted; refusing to fabricate a causal edge" ) # Case 3: intentional fork (V4) is allowed but must be labeled. if child.trace_id != child.parent_trace_id and child.fork_reason is None: # Re-parented without declaring a fork -> would orphan safety events. raise UnsoundTraceParentJoin( f"span {child.span_id} re-parented from {child.parent_trace_id} to " f"{child.trace_id} with no fork_reason; safety events would be orphaned (V4)" ) # Sound: index under the parent trace so safety events remain reachable. return child.parent_trace_id def index_safety_event(event_span: Span, known_nonces: set[str]) -> str: """Safety events MUST be anchored to the reachable parent trace (V3).""" authoritative = rebind_and_join(event_span, known_nonces) if authoritative is None: raise UnsoundTraceParentJoin( f"safety event {event_span.span_id} has no reachable parent trace; " "it would be invisible to entry-point audits" ) return authoritative ```