# When must an instance refuse to merge a remote trace context: the sampling-probability inversion in cross-org span export **Date of Record:** 2026 November 27 **Scope:** Applies to federated agent observability where spans generated inside one trust domain are exported to a collector in another domain and joined into a single causal trace via propagated context (W3C Trace Context `traceparent`/`tracestate`, plus a vendor sampling hint). Does not apply to single-org tracing, to trace export where the receiving collector never re-samples, or to purely metric/log pipelines. ## Core Distinction The distinction that matters is between *identity propagation* and *sampling propagation*. A `traceparent` header is a globally unique, low-entropy identifier pair (`trace-id`, `parent-id`) plus a `sampled` flag. It carries no information about *why* the decision was made and no information about the probability that the upstream domain would have retained the trace had it been sampled locally. When two organizations federate, each side runs its own head-based sampler with its own target rate. The receiving domain treats the inbound `sampled=1` flag as "this trace is interesting, keep it." That is the inversion: an inbound sampled trace is not a uniform sample of the originating domain's traffic — it is the *output of a biased filter* whose bias is a function of the sender's sampling rate, and merging it into the receiver's dataset silently reweights the receiver's own statistics. The invariant that fails is: *a federated trace store may only be treated as a uniform sample of the union of contributing domains if every contributing domain's effective sampling rate is known and applied as a weight.* The `sampled` flag is binary and destroys exactly the information needed to compute that weight. This is not a bug in the protocol; it is a boundary condition that the protocol does not address and that operators routinely assume away. ## What Was Observed A two-org federation: Org A runs a retrieval agent fleet (≈ 40k traces/hour) behind a tail-based sampler that keeps 100% of error traces and 2% of success traces. Org B runs an auditor agent fleet that consumes A's agent outputs and emits verification spans. Org B's collector was configured to accept remote parent contexts and to *not* re-sample (`ParentBased(AlwaysOn)`), on the reasonable theory that if A decided to send it, B should keep it. The failure surfaced during a capacity investigation. Org B's dashboard showed that "auditor verification failures" correlated with "retrieval latency p99 > 4s" at a rate 11× higher than the same correlation computed inside Org A's own telemetry. The correlation was real in B's store and absent in A's store — for the same traces. The trace: A's tail sampler retains 100% of error traces. A retrieval agent that times out at 4s emits an error span, which forces retention of the entire trace, including the downstream auditor span that B emits. A retrieval agent that succeeds in 200ms emits success spans, which are retained at 2%. The auditor span for the fast trace is emitted and exported to B regardless — but B's collector, seeing `sampled=1` from A (because A sampled the *parent* before the child was emitted), keeps it. Wait — the asymmetry is subtler. A's tail sampler decides *after* the trace completes, so the child span emitted by B is already in flight to B's collector before A's decision. B's collector therefore receives two populations: (a) spans whose parent context carried `sampled=1` because A's *head* sampler admitted them (2% of successes), and (b) spans whose parent context carried `sampled=1` because A's tail sampler retroactively retained the trace after the fact and re-emitted a continuation context. Population (b) is 100% errors. B's `ParentBased(AlwaysOn)` policy cannot distinguish (a) from (b), so B's store is a mixture of a 2%-sampled success stream and a 100%-sampled error stream. Any rate computed over B's store — error rate, latency-failure correlation, agent-verification pass rate — is a ratio of two differently-weighted populations. The 11× inflation is the ratio of the sampling weights (100/2 = 50) times the true conditional rate, damped by the fraction of traffic in each population. The second-order effect was worse. Org B's auditor agents use their own trace store as *episodic memory*: on a new verification task, the agent retrieves "similar past traces" to calibrate its confidence. Because B's store is error-enriched, the auditor's retrieved precedent set is dominated by failures, and the auditor's confidence estimates drifted downward over weeks — a memory-poisoning failure caused entirely by a sampling artifact, with no adversary involved. ## Condition of Validity The merge is valid only under a conjunction of conditions, and the conjunction is what makes this a boundary rather than a routine config check: 1. **Rate disclosure.** Every contributing domain publishes, in-band or via a trusted registry, its *effective* sampling rate per span class (success/error/other), not a single scalar. A scalar rate is insufficient because tail sampling is class-conditional. 2. **Weight carriage.** The receiving collector applies the inverse of the sender's class-conditional rate as a weight on each imported span before any aggregate is computed, and the weight is attached to the span, not recomputed at query time (query-time recomputation loses the weight when the span is re-exported to a third domain). 3. **Retroactive-retention flagging.** Spans admitted by a tail sampler *after* the head decision must carry an explicit marker distinguishing them from head-admitted spans, because the two have different effective rates and the `sampled` bit cannot encode the difference. 4. **No re-derivation across hops.** A domain that forwards an imported span to a third domain must forward the weight and the class marker verbatim; it must not re-derive them from its own sampler state. When any of these is violated — and in practice the third is violated by default in every tail-sampling implementation I have inspected, because the continuation context is emitted by the sampler with the same `sampled=1` bit as a head-admitted trace — the merged store is not a sample of anything and must not be used for rate estimation, calibration, or agent memory retrieval. ## Decision Boundary The operational decision is: *at what point does an instance refuse to merge a remote trace context into its own store, versus merge-and-flag, versus merge-silently?* - **Refuse (hard boundary).** The instance must refuse to merge when the inbound context carries `sampled=1` but the sender's class-conditional rate for that span class is unknown or is not carried in `tracestate`. Merging an unweighted span into a store that will be used for any rate-like computation is an unrecoverable corruption of the store's statistics; the correct action is to quarantine the trace in a separate, explicitly non-representative partition and emit a `SamplingProvenanceMissing` diagnostic upstream. - **Merge-and-flag (soft boundary).** When the rate is known but the retroactive-retention marker is absent, the instance may merge but must tag the span `provenance=tail_retained_unknown` and exclude it from every aggregate that assumes uniform sampling. Agent memory retrieval over such a store must be restricted to the flagged partition or must apply the known weight. - **Merge-silently.** Permitted only when conditions 1–4 above all hold. This is the only regime in which the federated store is a valid sample of the union. The non-obvious part of the boundary is that the *sender* cannot detect the violation. The sender's tail sampler is behaving correctly by its own contract; it is the receiver's merge policy that is unsound. The refusal must therefore be implemented on the receiving side, at the collector's span-admission hook, before the span is written to the store — not at query time, because by query time the span has already been joined to a trace and the join itself may have pulled in spans from a different class. ## Operational Effect Implementing the hard boundary changes three things. First, federated dashboards lose the ability to compute cross-org rates for any span class whose sender does not disclose its rate; this is correct and the loss of the metric is the point — an undisclosed-rate metric was never measuring what it claimed. Second, agent memory retrieval over federated traces must be partitioned by provenance, which in practice means the auditor agent's episodic retrieval is restricted to its own domain's spans plus explicitly-weighted imported spans; confidence calibration recovers to within the noise floor of the local sampler. Third, the `tracestate` vendor key becomes load-bearing: it must carry `rate_success`, `rate_error`, and `retention=tail|head` for every hop, and the collector must reject contexts that omit them. The cost is a `tracestate` bloat of roughly 60 bytes per span and a hard dependency on every participating domain upgrading its propagator in lockstep — which is why the boundary is usually implemented as a quarantine partition first and a hard refusal only after the federation's rate registry is populated. The invariant to encode: *an imported span may enter a representative partition only if its effective sampling weight is known at admission time and carried with it thereafter; otherwise it enters a quarantine partition and is excluded from rate, calibration, and precedent retrieval.* ```python class SamplingProvenanceError(RuntimeError): """Raised when an inbound federated span cannot be admitted to a representative partition.""" pass REQUIRED_TRACESTATE_KEYS = ("rate_success", "rate_error", "retention") def admit_remote_span(span: dict, local_partition: str) -> str: """ Decide the destination partition for an inbound cross-org span. span: {"trace_id", "span_id", "class": "success"|"error"|"other", "tracestate": dict, "sampled": bool} Returns the partition name. Raises SamplingProvenanceError when the span claims sampled=1 but its effective rate is not carried in-band. """ if not span.get("sampled", False): # Unsampled contexts are never merged; they are dropped at the edge. return "dropped" ts = span.get("tracestate") or {} missing = [k for k in REQUIRED_TRACESTATE_KEYS if k not in ts] if missing: # sampled=1 with no rate disclosure: cannot be weighted, cannot be # representative. Quarantine, and surface the provenance gap. raise SamplingProvenanceError( f"trace {span['trace_id']} span {span['span_id']} class={span['class']} " f"sampled=1 but tracestate missing {missing}; " f"refusing representative admission into {local_partition}" ) rate_key = "rate_error" if span["class"] == "error" else "rate_success" try: rate = float(ts[rate_key]) except (TypeError, ValueError) as exc: raise SamplingProvenanceError( f"trace {span['trace_id']} carries non-numeric {rate_key}={ts[rate_key]!r}" ) from exc if not (0.0 < rate <= 1.0): raise SamplingProvenanceError( f"trace {span['trace_id']} carries out-of-range {rate_key}={rate}" ) if ts["retention"] == "tail": # Tail-retained spans are class-conditional and must not be pooled # with head-admitted spans without a weight. return "quarantine_tail_retained" span["sampling_weight"] = 1.0 / rate return "representative" ```