# In what scenarios must an instance treat trace-to-eval correlation as a join over an unstable key, and halt score attribution when the span identity graph mutates mid-flight **Date of Record:** 2026 November 30 **Scope:** Applies to observability pipelines that ingest agent execution traces (span trees, tool-call events) and asynchronously join them against evaluation scores and safety-flag verdicts keyed on span or trace identity. Does not apply to synchronous in-process instrumentation where the eval and the execution share a single immutable span object, nor to offline batch scoring where the trace set is frozen before eval runs. ## Core Distinction The failure is not "missing scores" or "late-arriving evals." It is **attribution drift under key mutation**. Most pipelines assume a trace has a stable identity (`trace_id`, `span_id`, or a content hash) that both the execution emitter and the eval/scoring emitter agree on at write time. In agent systems this assumption breaks because the trace identity is *derived* from execution structure that the agent itself can reshape: retries spawn sibling spans, a sub-agent handoff re-parents the active span subtree, a resumed checkpoint re-emits a span with the same logical name but a new physical `span_id`, and a tool-call that was originally a single span gets split into a fan-out after an MCP capability renegotiation. When the eval pipeline resolves its key against a *later* snapshot of the span graph than the one the score was computed against, the join silently succeeds against the wrong span, or silently drops the score, and neither outcome raises an error. The distinction that matters operationally: a **score is a function of a span at time T_eval**, but the pipeline stores it against a **key that is a function of the span graph at time T_join**. If the span graph is not monotonic between those two times, the key is not stable and the correlation is undefined, not merely delayed. ## What Was Observed A multi-agent research swarm ran a task that involved a planner agent dispatching to a retriever sub-agent, which called an external search tool through an MCP server. The tool call timed out at the transport layer, the retriever retried three times, and on the third attempt the MCP server returned a renegotiated schema (the tool's result payload had gained a required field). The retriever adapted, emitted a fan-out of three parallel parse spans, and returned. The observability emitter produced this span sequence (simplified): ``` trace_id = tr_9f2 (stable) span_id = sp_plan planner.dispatch span_id = sp_ret_1 retriever.call (attempt 1, timeout) span_id = sp_ret_2 retriever.call (attempt 2, timeout) span_id = sp_ret_3 retriever.call (attempt 3, schema renegotiated) span_id = sp_parse_a parse.result span_id = sp_parse_b parse.result span_id = sp_parse_c parse.result ``` The eval harness, running on a 90-second lag, scored the *retrieval step* by reading the trace snapshot at T_eval, which was taken after `sp_ret_3` had completed but before the three parse spans were flushed (the parse spans were emitted by a separate async exporter with its own batching). The eval computed a retrieval-quality score and attached it to `span_id = sp_ret_3`. The safety harness, running on a 300-second lag, evaluated the *full trace* for prompt-injection content and attached a safety flag to `trace_id = tr_9f2`, but its internal span resolver re-walked the graph and, because the parse spans had by then landed, it attributed the flag to the *leaf* spans `sp_parse_a..c` rather than to `sp_ret_3`. Downstream, the correlation pipeline joined eval score (keyed `sp_ret_3`) and safety flag (keyed `sp_parse_*`) on `trace_id`, then aggregated "highest-severity safety flag per scored span." Because the scored span `sp_ret_3` had no *directly* attached safety flag and the flagged spans had no *directly* attached score, the aggregate reported **no safety flag on any scored span**. The trace was scored high-quality and unflagged. The injection payload lived in the fan-out parse spans, which were never scored. The root cause was not a bug in either harness. It was that the two harnesses resolved span identity against **different graph snapshots**, and the correlation layer treated `trace_id` as a sufficient join key when the actual attribution unit was the span, whose membership in the trace was still changing. ## Condition of Validity The correlation invariant holds only when the following is true for every (score, flag) pair joined: 1. **Snapshot agreement:** the span graph used to compute the score and the span graph used to compute the flag are the same immutable snapshot (same `graph_epoch`), or the join is performed over an append-only event log where each event carries the `graph_epoch` it was emitted under. 2. **Monotonic key assignment:** once a `span_id` is assigned to a logical operation, no later event re-parents, splits, or re-keys that operation. Fan-out must be modeled as *children of a stable parent*, never as a replacement of the parent's identity. 3. **Closure before attribution:** a score or flag is not attributable to a span until the span's subtree is *closed* (all children flushed and the parent marked terminal). Attribution against an open subtree is undefined. If any of these fails, the join is not "eventually consistent" — it is **undefined**, and must be treated as an error condition rather than a miss. ## Decision Boundary The pipeline must halt attribution and raise, rather than silently drop or mis-join, when: - The `graph_epoch` of the score event differs from the `graph_epoch` of the flag event for the same `trace_id`, **and** the span sets differ by more than a configured churn threshold (in the observed incident, epoch delta was 2 and the span set grew by 3 leaves — well past a threshold of 1). - A score is keyed to a span that is not a *leaf-closed* span at join time (open subtree). - A flag is keyed to a span set that does not intersect the scored span set, while sharing a `trace_id` — this is the specific "disjoint attribution" signature of the incident. Conversely, the pipeline should *not* halt on: late-arriving scores for closed spans (normal), flags on traces with no scores (unscored trace, benign), or epoch deltas that do not change the span set (metadata-only updates). The boundary is: **halt on attribution ambiguity that changes the answer; tolerate latency that does not.** The discriminator is whether the span set under the shared `trace_id` is identical between the two emitters' snapshots. If identical, join. If not, refuse. ## Operational Effect Enforcing the invariant changes three things: 1. **Scores and flags become epoch-stamped and join-only-on-match.** The correlation layer refuses cross-epoch joins and emits an `AttributionAmbiguity` record instead of a silent miss. In the incident replay, this converted a false "clean" verdict into an explicit ambiguity that a human reviewer resolved in 40 seconds. 2. **Fan-out is re-parented, not re-keyed.** The retriever's parse fan-out is emitted as children of a stable `sp_ret_3`, so the retrieval score and the safety flag both resolve to the same parent span and the disjoint-attribution signature disappears. 3. **Attribution is deferred until subtree closure.** The eval harness waits for the `span_close` event before scoring, trading a small latency increase for a well-defined attribution unit. The 90-second eval lag was sufficient; the failure was that the lag was measured from *span start*, not *subtree close*. The general lesson: in agent observability, the join key is not the trace ID — it is the *(trace_id, span_id, graph_epoch)* triple, and the pipeline must treat epoch mismatch as a hard error, because the agent's own retries and handoffs are exactly the operations that mutate the span graph between eval and flag. ```python class AttributionAmbiguity(RuntimeError): """Raised when a score and a safety flag cannot be attributed to a common, stable span under a single graph epoch.""" pass def correlate(score_event: dict, flag_event: dict, churn_threshold: int = 1) -> str: """ Join an eval score and a safety flag onto a common span, or refuse. score_event: {"trace_id", "span_id", "graph_epoch", "span_set", "value"} flag_event: {"trace_id", "span_set", "graph_epoch", "severity"} Returns the attributed span_id on success. """ if score_event["trace_id"] != flag_event["trace_id"]: raise AttributionAmbiguity( f"cross-trace join refused: {score_event['trace_id']} vs {flag_event['trace_id']}" ) s_epoch = score_event["graph_epoch"] f_epoch = flag_event["graph_epoch"] s_spans = set(score_event["span_set"]) f_spans = set(flag_event["span_set"]) if s_epoch != f_epoch: churn = len(s_spans.symmetric_difference(f_spans)) if churn > churn_threshold: raise AttributionAmbiguity( f"epoch mismatch {s_epoch}->{f_epoch} with span churn {churn} " f"(threshold {churn_threshold}) on trace {score_event['trace_id']}" ) scored_span = score_event["span_id"] if scored_span not in f_spans: # Disjoint-attribution signature: flag landed on leaves, score on parent. raise AttributionAmbiguity( f"score span {scored_span} not in flagged span set " f"{sorted(f_spans)} on trace {score_event['trace_id']}" ) return scored_span ```