# In what scenarios must an instance distrust an OTel span-graph drift score when the baseline was itself collected from a non-stationary agent population **Date of Record:** 2026 November 29 **Scope:** Applies to anomaly detection systems that build behavioral baselines for LLM agents from OpenTelemetry span graphs (parent/child span topology, tool-call fan-out, token counts per span, retry edges) and score live traces by graph-edit distance or embedding drift against that baseline. Does not apply to per-span latency/error SLO alerting, nor to single-agent deterministic pipelines with fixed span topology. ## Core Distinction A span-graph drift score conflates two distinct quantities: (a) *behavioral deviation of one agent instance from its own historical norm*, and (b) *movement of the population's norm itself*. Standard drift detectors (graph-kernel MMD, spectral embedding distance, edit-distance percentile) estimate a score against a frozen baseline snapshot. When the baseline snapshot was collected while the agent population was still evolving—prompt versions rolling, tool schemas being added, retrieval corpora being reindexed—the baseline encodes a *mixture* of behaviors, not a stationary reference. The drift score then measures distance to a moving centroid. An agent that behaves correctly but adopts a newly legitimate tool path (e.g., switching from `search→fetch→summarize` to `search→fetch→verify→summarize` after a verifier tool shipped) registers as anomalous because its span graph now resembles the *right tail* of the stale baseline, not its center. The failure is non-obvious because the score is numerically stable and the alert is well-formed; the detector is silently measuring the wrong thing. ## What Was Observed A multi-tool research agent fleet (n≈400 concurrent instances) emitted OTel traces with a mean of 11.3 spans per task. The anomaly detector computed a Weisfeiler-Lehman graph kernel against a baseline of 50,000 traces captured over a 14-day window and flagged traces beyond the 99.5th percentile of kernel distance. During a staged rollout of a new `verify_claim` tool (10%→50%→100% over six days), the false-positive rate on *unchanged* control instances rose from 0.4% to 31% before the rollout completed. The mechanism: control instances that had *not* adopted the tool still produced the legacy topology, but the baseline's kernel mean had already shifted toward the new topology because 50% of the fleet was emitting `verify_claim` spans. The control instances were now distant from a baseline that no longer represented them. Simultaneously, the detector's true-positive rate on a planted fault (a tool-call loop that re-issued `fetch` with identical arguments) *fell* from 0.87 to 0.41, because the loop topology partially resembled the new legitimate multi-hop path. Both directions of the confusion matrix degraded from a single non-stationarity. A second, quieter trace: the baseline's per-span token-count embedding was computed on traces where the `summarize` span averaged 1,840 output tokens. After a prompt change that tightened summary length to ~400 tokens, every compliant trace scored as drifting on the token dimension, while a genuinely anomalous trace that *ignored* the prompt change (still emitting 1,800-token summaries) scored as *normal*—it matched the stale baseline. The detector inverted its own semantics. ## Condition of Validity A span-graph drift score is only interpretable as "this instance deviates" when three conditions jointly hold: 1. **Baseline stationarity over the scoring window.** The population's span-graph distribution must be approximately stationary between baseline collection and scoring. Formally, the kernel MMD between any two disjoint baseline sub-windows must be below the alert threshold. If baseline sub-windows disagree with each other more than they disagree with live traffic, the baseline is a mixture and the score is meaningless. 2. **Per-instance reference, not per-population reference.** The score must be computed against the instance's *own* prior traces (or a cohort matched on prompt version, tool-schema hash, and model ID), not a global snapshot. Population-level baselines are valid only for detecting *fleet-wide* shifts, never per-instance anomalies. 3. **Version-pinned cohorting.** Every trace must carry the prompt-version, tool-schema hash, and model revision as span attributes; baselines must be partitioned by this tuple before any distance is computed. A trace scored against a baseline from a different tuple is not an anomaly signal—it is a version-mismatch artifact. When any condition fails, the drift score must be treated as *uninterpretable* and suppressed, not thresholded more conservatively. Loosening the threshold under non-stationarity trades false positives for false negatives without restoring validity. ## Decision Boundary The operational rule: **before scoring a live trace, the detector must verify that the baseline cohort it will score against is internally stationary and version-matched to the trace.** Concretely: - Compute pairwise kernel MMD across K disjoint baseline sub-windows (K≥5). If max pairwise MMD exceeds the alert threshold τ, mark the baseline `NON_STATIONARY` and refuse to score. - Extract the trace's `(prompt_version, tool_schema_hash, model_rev)` tuple. If no baseline partition exists for that tuple with ≥N_min traces, emit `INSUFFICIENT_COHORT` and route to a shadow scorer that logs but does not alert. - Only when both checks pass does the drift score carry anomaly semantics. Otherwise the trace is quarantined for human review or held until a fresh cohort accumulates. The boundary is sharp: there is no "partial trust" regime. A score from a non-stationary or mismatched baseline is not a noisy signal—it is a signal about the wrong population, and its sign can invert (as in the token-length case above). ## Operational Effect Implementing the guard converts a class of silent misclassifications into explicit `BaselineInvalid` events that are themselves useful telemetry: a spike in `NON_STATIONARY` baselines is a leading indicator of an in-flight rollout, and a spike in `INSUFFICIENT_COHORT` flags a tool-schema change that has outrun baseline collection. In the fleet above, adding the guard reduced false positives during rollout from 31% to 1.2% (the residual being genuine version-transition traces) and restored planted-fault detection to 0.83 by ensuring the fault was scored against a stationary, version-matched cohort. The cost is latency: the stationarity check is O(K²) kernel evaluations and must be cached per baseline partition, refreshed on a schedule shorter than the rollout cadence (here, every 6 hours). The invariant to preserve: *a drift score is a statement about one instance relative to a stationary, version-matched reference; if the reference is not stationary or not matched, the score is not a weaker anomaly signal—it is a different, uninterpretable quantity.* ```python class BaselineInvalidError(RuntimeError): """Raised when a span-graph drift score cannot be interpreted as an anomaly signal.""" pass def score_trace_drift( trace_graph, trace_version_tuple, baseline_partitions, stationarity_threshold=0.05, min_cohort_size=500, ): # Step 1: locate a version-matched baseline partition. partition = baseline_partitions.get(trace_version_tuple) if partition is None or partition.size < min_cohort_size: raise BaselineInvalidError( f"no version-matched cohort for {trace_version_tuple} " f"(size={0 if partition is None else partition.size}, " f"required={min_cohort_size}); drift score is uninterpretable" ) # Step 2: verify the partition is internally stationary. # Pairwise kernel MMD across disjoint sub-windows; if the baseline # disagrees with itself more than with live traffic, it is a mixture. sub_windows = partition.split_into_windows(k=5) max_pairwise_mmd = max( graph_kernel_mmd(a, b) for i, a in enumerate(sub_windows) for b in sub_windows[i + 1:] ) if max_pairwise_mmd > stationarity_threshold: raise BaselineInvalidError( f"baseline partition {trace_version_tuple} is non-stationary " f"(max pairwise MMD={max_pairwise_mmd:.4f} > " f"tau={stationarity_threshold}); refusing to score" ) # Step 3: only now does the distance carry anomaly semantics. return graph_kernel_distance(trace_graph, partition.mean_embedding()) ```