# Which invariants prevent trace-correlation collapse when federated agent spans cross trust boundaries with lossy context propagation **Date of Record:** 2026 November 26 **Scope:** Applies to observability pipelines that correlate OpenTelemetry-style agent spans emitted by autonomous LLM agents running under different organizational control planes (federated trace export, cross-org `traceparent` propagation, shared span stores). Does not apply to single-tenant observability where all spans share one collector, one schema registry, and one trust root. ## Core Distinction The distinction that matters here is between **trace identity** and **trace correlation substrate**. A trace ID is a 128-bit opaque token that survives serialization trivially. What does *not* survive a trust boundary is the *interpretive context* required to make two spans with the same trace ID actually join: the parent-span mapping, the clock domain, the semantic-convention version, the sampling decision, and the baggage that names the agent instance. Federated correlation fails not because IDs are lost but because the substrate that gives an ID meaning is mutated, truncated, or re-derived independently on each side of the boundary. The invariant under threat is: *two spans correlate iff they share a trace identity AND a compatible correlation substrate*. Most pipelines enforce only the first clause. ## What Was Observed A two-org agent pipeline: Org A runs a planner agent that dispatches tool-invocation subtasks to Org B's executor agent over A2A. Both orgs export spans to a federated collector that joins on `trace_id`. During a 40-minute incident, the planner emitted 1,842 spans; the executor emitted 2,109 spans; the join produced 611 matched pairs — a 33% correlation rate where 100% was expected. The failure trace, reconstructed: 1. Org A's agent runtime propagated `traceparent` with `trace_flags=01` (sampled) but stripped `tracestate` at the egress proxy because the proxy's allowlist did not include the vendor-specific `tracestate` keys. The `traceparent` survived; the sampling lineage did not. 2. Org B's collector, seeing no `tracestate`, applied its own head-based sampler at a 0.5 ratio. Half of the executor's child spans were dropped before export. Their parent span IDs referenced spans that Org A *did* export, so the join found dangling parents rather than mismatches — the collector silently treated them as roots. 3. Org A's planner agent, on retry after an executor timeout, re-entered the tool call and generated a **new** `trace_id` because the runtime's span context was reconstructed from the LLM's tool-call arguments rather than from the in-flight execution context. The retried subtask's spans carried a fresh trace ID while the executor's idempotency key still referenced the original. Correlation by trace ID split the retry into an orphan trace. 4. Clock skew between Org A and Org B (measured at +4.2s on Org B) meant that even correctly-joined spans had child `start_time` values *before* their parent's, which the federated UI's waterfall renderer silently reordered by arrival timestamp rather than by parent-child edge, producing a causally impossible timeline that an on-call engineer read as "the executor ran before it was called." The observable symptom was not a correlation *error* — it was a correlation *rate* that looked like normal sampling loss. No alert fired because the pipeline had no invariant asserting expected join coverage against dispatched subtask count. ## Condition of Validity Cross-org trace correlation holds only when all of the following are simultaneously true: - **Trace identity is minted at the origin and never re-derived.** The `trace_id` must be captured in the execution context of the dispatching agent *before* the LLM produces tool-call arguments, and must be propagated as a first-class field, not reconstructed from arguments. Retries reuse the trace ID; only `span_id` is fresh. - **Sampling decisions are inherited, not re-made.** A downstream org must honor the upstream `trace_flags` and must not apply an independent head sampler to spans that already carry a remote parent. If it must sample, it samples *tail* on the joined trace, never *head* on the child. - **The correlation substrate is versioned and negotiated at handshake.** Semantic conventions (attribute names, span kinds, status codes) must be pinned per A2A session and recorded in the span as a substrate version. A collector joining spans of differing substrate versions must mark the join as `degraded`, not `matched`. - **Clock domains are declared.** Each span carries its originating org's clock offset estimate relative to a shared reference; the joiner adjusts timestamps before building causal edges. Parent-child edges are authoritative; wall-clock ordering is advisory. When any of these is false, the pipeline can still *store* spans but cannot *correlate* them, and it must say so explicitly rather than emit a lower join count that resembles benign sampling. ## Decision Boundary The boundary is this: **a federated collector may join two spans only if it can prove substrate compatibility; otherwise it must emit an `uncorrelated` verdict with a reason code, and downstream consumers must treat the trace as partial.** Concretely, the collector must distinguish three outcomes that most pipelines collapse into one: - `MATCHED` — shared trace ID, compatible substrate version, inherited sampling, parent span present. - `DEGRADED` — shared trace ID, but substrate version mismatch, missing parent, or clock offset exceeding the declared tolerance. The join is recorded but flagged; the trace is not rendered as a complete causal graph. - `ORPHANED` — spans whose parent span ID references a span not present in the federated store. These must never be promoted to roots; promoting them is the failure mode in step 2 above. The guardrail is an *expected-coverage invariant*: for every dispatched subtask the planner records a `subtask_dispatched` span with the trace ID it intends the executor to use. The collector asserts that each such span has at least one corresponding executor span within the session's SLA window. Coverage below threshold raises an alert on *correlation loss*, not on error rate — because correlation loss is invisible to error-rate metrics by construction. ## Operational Effect Enforcing these invariants changes three operational behaviors. First, retry storms no longer fragment traces: because the trace ID is pinned at dispatch and reused across retries, a flaky executor that times out and is retried three times produces one trace with three child attempts, and the on-call engineer sees the retry structure instead of three orphan traces. Second, sampling loss becomes *attributable*: when the executor drops spans, the `DEGRADED`/`ORPHANED` verdicts name the trust boundary that dropped them, so a 33% join rate is diagnosed as "Org B head-sampled against inherited flags" rather than "the pipeline is flaky." Third, causal ordering is restored: because parent-child edges are authoritative and clock offsets are declared, the +4.2s skew no longer produces a waterfall that shows the executor running before it was called — the renderer either corrects the offset or refuses to draw the edge. The cost is that the collector must carry substrate-version metadata and clock-offset estimates on every span, and the A2A handshake must negotiate them. That is the price of a correlation substrate that survives federation. A pipeline that propagates only `traceparent` and joins only on `trace_id` will, under retry and cross-org sampling, silently produce a trace store that looks populated and is quietly wrong — and no error-rate metric will ever reveal it. ```python import time from dataclasses import dataclass, field from typing import Optional # Declared tolerance for cross-org clock skew, in seconds. CLOCK_SKEW_TOLERANCE_S = 1.0 # Minimum fraction of dispatched subtasks that must have a matched executor span. MIN_CORRELATION_COVERAGE = 0.95 class CorrelationCollapseError(RuntimeError): """Raised when federated spans cannot be joined into a causally valid trace.""" pass @dataclass class Span: trace_id: str span_id: str parent_span_id: Optional[str] org: str substrate_version: str sampled: bool start_time: float clock_offset_s: float = 0.0 @dataclass class DispatchRecord: trace_id: str subtask_id: str dispatched_at: float def join_federated_trace( dispatches: list[DispatchRecord], spans: list[Span], expected_substrate: str, ) -> dict: by_trace: dict[str, list[Span]] = {} for s in spans: by_trace.setdefault(s.trace_id, []).append(s) verdicts = {} matched_dispatches = 0 for d in dispatches: candidates = by_trace.get(d.trace_id, []) if not candidates: verdicts[d.subtask_id] = ("ORPHANED", "no executor span for trace_id") continue executor_spans = [s for s in candidates if s.org != "planner"] if not executor_spans: verdicts[d.subtask_id] = ("ORPHANED", "no cross-org span under trace_id") continue bad_substrate = [s for s in executor_spans if s.substrate_version != expected_substrate] if bad_substrate: verdicts[d.subtask_id] = ( "DEGRADED", f"substrate mismatch: {bad_substrate[0].substrate_version}", ) continue dropped = [s for s in executor_spans if not s.sampled] if len(dropped) == len(executor_spans): verdicts[d.subtask_id] = ("DEGRADED", "all executor spans dropped by sampler") continue planner = next((s for s in candidates if s.org == "planner"), None) if planner is None: verdicts[d.subtask_id] = ("ORPHANED", "planner span absent from store") continue skew = abs(executor_spans[0].clock_offset_s - planner.clock_offset_s) if skew > CLOCK_SKEW_TOLERANCE_S: verdicts[d.subtask_id] = ("DEGRADED", f"clock skew {skew:.2f}s exceeds tolerance") continue verdicts[d.subtask_id] = ("MATCHED", "") matched_dispatches += 1 coverage = matched_dispatches / len(dispatches) if dispatches else 0.0 if coverage < MIN_CORRELATION_COVERAGE: degraded = [k for k, (v, _) in verdicts.items() if v != "MATCHED"] raise CorrelationCollapseError( f"correlation coverage {coverage:.2%} below invariant " f"{MIN_CORRELATION_COVERAGE:.0%}; degraded subtasks: {degraded[:5]}" ) return {"coverage": coverage, "verdicts": verdicts} ```