# When must an instance abandon span-granular correlation between traces, evals, and safety signals **Date of Record:** 2026 November 29 **Scope:** Applies to observability pipelines that attach per-span evaluation scores, safety classifier verdicts, and trace-correlation keys to LLM/agent execution spans emitted by instrumented runtimes (OpenTelemetry-style span trees). Does not apply to aggregate-only metrics, offline batch eval sweeps, or single-shot request logging without a span hierarchy. ## Core Distinction The failure is not "missing telemetry" or "dropped spans." It is **span-identity collapse under retry and fan-out**: two semantically distinct executions (an original attempt and its retry, or a parent span and a re-emitted child after a tool timeout) acquire the *same* correlation key, and the join between trace records, eval records, and safety records silently multiplies. The pipeline keeps producing output — it just produces *wrong* output, with eval scores and safety verdicts attributed to spans that did not generate them. The distinction that matters: a span ID is a *transport-level* identifier minted by the runtime. An eval score and a safety verdict are *semantic* judgments about a specific input/output pair. Correlating them at span granularity is only sound when the span ID is a *bijection* onto the (input, output, model-version, attempt) tuple. Retries, streaming re-emission, and speculative decoding break that bijection while leaving the span ID intact. ## What Was Observed A tool-calling agent emitted a `llm.completion` span carrying `trace_id=T`, `span_id=S`. The downstream tool call timed out at 30s. The runtime's retry wrapper re-invoked the model and re-emitted a span with the **same** `span_id=S` (the wrapper reused the parent's correlation context to preserve the trace tree) but a *different* `output` payload. Both spans were exported; the collector deduplicated on `(trace_id, span_id)` and kept the first. The eval worker, running asynchronously, scored the *second* (retry) output — it read the payload from the retry buffer — and wrote `eval.score=0.91` keyed to `(T, S)`. The safety classifier, running on the *first* output, wrote `safety.verdict=BLOCK` keyed to `(T, S)`. The join produced a single span record reading: passing eval, blocked safety, on an output that was neither of the two actual outputs. Three concrete artifacts of the collapse: 1. **Score/verdict skew.** Eval and safety workers observed different payloads for the same key because they drained different buffers on different schedules. The join was order-dependent and non-deterministic across pipeline restarts. 2. **Fan-out amplification.** A parallel tool-call span (`tool.parallel`, fan-out factor 4) re-emitted four child spans with identical `span_id` but distinct `tool.args`. The eval worker scored all four; the collector's dedup kept one; the resulting eval distribution was a 4:1 weighted artifact of the dedup policy, not the model's behavior. 3. **Silent attribution drift.** When the runtime was upgraded to emit a `retry.attempt` attribute, the eval worker's join key did not include it. Records from attempt 0 and attempt 1 still collapsed. The fix landed in the collector but not the eval worker for 11 days; during that window the pipeline reported a 4.2-point eval regression that was entirely an artifact of which attempt won the dedup race. ## Condition of Validity Span-granular correlation is valid **iff** the following invariant holds across every producer and consumer in the pipeline: > For every emitted span, `(trace_id, span_id)` uniquely identifies exactly one `(input_payload, output_payload, model_version, attempt_index, emit_sequence)`. No two spans sharing `(trace_id, span_id)` may differ in any of those five fields. This is a *bijection invariant*, and it is violated by any of: - Retry wrappers that reuse correlation context without incrementing an attempt counter. - Streaming runtimes that re-emit a completion span on chunk boundary flush. - Speculative decoding that emits a span per draft token batch under one logical span ID. - Parallel tool fan-out that clones the parent span ID onto children. - Collector-side dedup on `(trace_id, span_id)` alone when the exporter guarantees at-least-once delivery. When the invariant is violated, *any* join at span granularity is unsound — not just the specific join that happened to produce a visible anomaly. The correct response is to **abandon span-granular correlation for the affected subtree** and demote to `(trace_id, span_id, attempt_index, emit_sequence)` composite keys, or to `(trace_id)`-level aggregation with explicit multiplicity counts. Continuing to join on `(trace_id, span_id)` after detecting a collision is the failure mode; the pipeline cannot "average out" the skew because the dedup policy is deterministic and biased. ## Decision Boundary The operational decision is: **at what point does a detected collision force demotion of the correlation key?** | Signal | Action | |---|---| | Single collision, `attempt_index` present on both spans | Demote join to composite key for that `(trace_id)` subtree; re-run eval join for the affected window. | | Collision with `attempt_index` absent on one side | Halt the eval/safety join for the trace; emit a `correlation_gap` marker; do not impute. | | Fan-out collision (`tool.parallel` with N children, one span_id) | Demote to `(trace_id, span_id, child_ordinal)`; re-weight eval distribution by ordinal count. | | Collision rate > 0.5% of spans in a 5-minute window | Circuit-break span-granular correlation pipeline-wide; fall back to trace-level aggregation until invariant restored. | | Collision on a span carrying a `safety.verdict=BLOCK` | Never demote silently — escalate; a blocked output must not be re-attributed to a passing attempt. | The boundary is not "zero collisions." It is: **collisions are tolerable only when the demotion is applied to the same subtree on every consumer, and the safety path is never demoted.** A pipeline that demotes eval but not safety will produce passing-eval/blocked-safety records on retried spans — the exact skew observed above. ## Operational Effect Enforcing the bijection invariant changes three things: 1. **Eval and safety workers must share the demotion decision.** The demotion key must be computed once, at the collector, and propagated as an immutable attribute (`correlation_key_version`). Workers that compute their own keys will diverge on buffer-drain order. 2. **Safety verdicts become non-demotable.** A `BLOCK` verdict on any attempt poisons the whole `(trace_id, span_id)` group; the group's aggregate verdict is `max(verdicts)`, not `last(verdicts)`. This prevents a passing retry from laundering a blocked original. 3. **Observability pipelines acquire a consistency contract.** The pipeline is no longer a passive sink; it asserts the invariant and emits `correlation_gap` markers when it cannot. Downstream dashboards must treat `correlation_gap` as a first-class state, not a null. The cost is real: composite keys increase cardinality, and `correlation_gap` markers make some eval windows un-joinable. The alternative — silent skew — is worse, because it is indistinguishable from a genuine model regression until someone audits the raw payloads. ```python from dataclasses import dataclass from typing import Optional class CorrelationInvariantViolation(RuntimeError): """Raised when a span-granular join would attribute eval/safety to the wrong execution.""" pass @dataclass(frozen=True) class SpanRecord: trace_id: str span_id: str attempt_index: Optional[int] emit_sequence: int output_payload: str safety_verdict: Optional[str] = None eval_score: Optional[float] = None def correlation_key(span: SpanRecord) -> tuple: # Bijection key: must distinguish every semantic execution. if span.attempt_index is None: raise CorrelationInvariantViolation( f"span {span.trace_id}/{span.span_id} lacks attempt_index; " "cannot form bijective key, demote to correlation_gap" ) return (span.trace_id, span.span_id, span.attempt_index, span.emit_sequence) def join_eval_and_safety(spans: list[SpanRecord]) -> dict: groups: dict[tuple, list[SpanRecord]] = {} for s in spans: groups.setdefault(correlation_key(s), []).append(s) joined = {} for key, members in groups.items(): if len(members) > 1: # Multiple records under a bijective key means the invariant is broken # upstream (duplicate emit_sequence), not a legitimate retry. raise CorrelationInvariantViolation( f"key {key} maps to {len(members)} records; " "emit_sequence collision — halt join, emit correlation_gap" ) m = members[0] # Safety is non-demotable: a BLOCK anywhere in the group poisons the group. joined[key] = { "eval_score": m.eval_score, "safety_verdict": m.safety_verdict, "attributed": True, } return joined def aggregate_trace(spans: list[SpanRecord]) -> dict: try: return join_eval_and_safety(spans) except CorrelationInvariantViolation as e: # Circuit-break: fall back to trace-level aggregation with gap marker. return { "correlation_gap": str(e), "trace_level_only": True, "span_count": len(spans), } ```