# How does an instance detect trace-to-eval correlation collapse when an observability pipeline re-keys spans mid-session **Date of Record:** 2026 December 3 **Scope:** Applies to observability pipelines that stitch per-session traces (spans, tool calls, token accounting) to evaluation verdicts and safety signals via a shared session identifier, where the identifier is generated or mutated after the session begins. Does not apply to pipelines that bind a single immutable session key at process start and never regenerate it, nor to stateless per-call scoring that never needs cross-span correlation. ## Core Distinction The failure is not "missing telemetry" and not "dropped spans." It is **correlation collapse under re-keying**: the trace exporter, the eval scorer, and the safety classifier each observe the *same* agent session but bind it to *different* session identifiers because the identifier is minted at different lifecycle points and at least one producer re-mints it mid-session. The pipeline does not error. Every subsystem reports healthy. The joined record simply pairs an eval verdict for turn 1–7 with spans from turns 8–14, or pairs a safety flag with an empty span set, and the aggregate dashboard shows a clean session that in fact contained a policy violation. The distinction that matters operationally: a *gap* is detectable (you see a hole). A *mis-join* is silent — the record is complete, plausible, and wrong. Re-keying produces the latter. The invariant that must hold is **session identity is write-once per logical session and every producer reads the same binding**, and that invariant is violated precisely when a producer is allowed to "improve" the key (add a tenant prefix, switch from client-generated to server-generated, normalize a UUID casing, or fork a child session for a subagent) after other producers have already emitted. ## What Was Observed A research agent runs a 14-turn session. Turn 1–7 execute under a client-minted `session_id = "sess-7f3a"`. At turn 8 the orchestrator spawns a subagent for a long retrieval task and, following a "namespace child work under parent" convention added in a recent release, the trace exporter begins emitting spans under `session_id = "sess-7f3a:sub-01"` while the *parent* spans continue under `"sess-7f3a"`. The eval scorer, which runs asynchronously and reads `session_id` from the agent's own step metadata, never sees the rename — it keeps writing `"sess-7f3a"`. The safety classifier keys off the trace exporter's span attributes, so it writes half its flags to `"sess-7f3a"` (turns 1–7) and half to `"sess-7f3a:sub-01"` (turns 8–14). Now join three ways: - **Eval ⋈ trace on `"sess-7f3a"`:** returns turns 1–7 spans, all 14 turns of eval. The joined record claims the session ended at turn 7 with a passing eval. The turn-12 eval failure has no spans to attach to and is silently dropped by the inner join. - **Safety ⋈ trace on `"sess-7f3a"`:** returns 7 safety flags against 7 turns — a clean 1:1. The turn-9 prompt-injection flag, filed under the child key, is orphaned. - **Aggregate session count:** the pipeline now reports *two* sessions (`"sess-7f3a"` and `"sess-7f3a:sub-01"`), inflating session volume by the subagent fan-out factor and halving per-session mean turn count. The tell in the raw data is a **cardinality discontinuity**: the ratio of distinct `session_id` values to distinct `trace_root_id` values drifts above 1.0 exactly at the turn where subagents were spawned, and the eval-to-span join rate for the parent key drops below 1.0 for sessions longer than the subagent threshold. Neither signal is surfaced because both dashboards are keyed on `session_id` and therefore never see the parent/child relationship that would reveal the fork. A second, subtler variant: the exporter normalizes UUID casing (`7F3A` → `7f3a`) on write to the trace store but the eval scorer writes the raw string. Same logical session, two keys, differing only in case, and the join is a silent miss for every session whose client happened to emit uppercase. This one is worse because it is data-dependent — it fails for a fraction of sessions determined by an upstream client's UUID library, so it looks like intermittent flakiness rather than a systematic bug. ## Condition of Validity The mis-join is *bounded* — i.e., detectable and correctable — only when all of the following hold: 1. **A stable root identifier survives the fork.** The pipeline retains the original pre-fork key as an attribute on every span (e.g., `trace_root_id` or `parent_session_id`) even after re-keying. If the fork discards the parent key entirely, correlation is unrecoverable and the session must be treated as lost, not repaired. 2. **Producers emit a monotonic sequence number or timestamp** on each record, so that a re-key event manifests as a discontinuity in `(session_id, seq)` rather than a silent gap. Without sequence numbers, a re-key and a legitimate new session are indistinguishable. 3. **The join is an outer join with an explicit orphan bucket.** Inner joins hide the failure by construction. The pipeline must count orphaned eval records and orphaned safety flags as a first-class metric, not discard them. 4. **Key normalization is applied at a single choke point, before any producer writes.** If normalization happens per-producer, casing/prefix divergence is guaranteed to reappear. The condition fails — and the failure becomes *unbounded* — when the re-key is lossy (parent key dropped), when no sequence numbers exist, or when the subagent convention assigns a genuinely new logical identity rather than a namespaced child. In that last case the "fix" of re-joining under the parent key is itself wrong: it would merge two sessions that the system intends to keep distinct. ## Decision Boundary The instance must decide, on observing a cardinality discontinuity or a sub-1.0 join rate, whether to (a) **repair** — re-join orphaned records to the parent key via the retained root identifier, (b) **quarantine** — mark the session as correlation-degraded and exclude it from aggregate eval/safety metrics while retaining raw records, or (c) **split** — accept the child as a distinct session and re-run eval against the child's own spans. The boundary between repair and split is **whether the eval scorer's verdict was computed over the union of parent and child context**. If the eval model saw turns 1–14 as one context window, the verdict is a property of the logical session and must be repaired to the parent (option a). If the eval ran per-span or per-child-context, the verdict is a property of the child and must be split (option c). Applying (a) to a per-span eval double-counts; applying (c) to a whole-session eval loses the cross-turn signal that the eval was specifically designed to catch. The boundary between repair and quarantine is **recoverability**: repair requires the retained root identifier and sequence numbers to be present on *every* orphaned record. If any orphan lacks the root key, the correct action is quarantine — a partial repair produces a record that is more misleading than an admitted gap, because it looks complete. A hard rule that follows: **never let the pipeline silently inner-join across a re-key boundary.** The default must be outer-join-plus-orphan-count, with repair as an explicit, logged, reversible operation. The failure mode this prevents is the one observed above — a clean-looking dashboard over a session that contained a dropped safety flag. ## Operational Effect Downstream, three things break in sequence. First, **eval coverage metrics inflate**: sessions that forked are counted as multiple short clean sessions, so mean-eval-score rises and tail-failure rate falls, precisely for the long multi-turn sessions where failures concentrate. Second, **safety recall silently degrades**: orphaned flags are excluded from the recall denominator and the numerator simultaneously, so the recall *ratio* looks stable while absolute flag count drops — a metric that moves in the wrong direction is invisible when you only watch the ratio. Third, **regression detection fails**: a model change that increases subagent fan-out increases the re-key rate, which increases the orphan rate, which *improves* the aggregate eval score by dropping the hard sessions — so the change looks like an improvement and ships. The guardrail that bounds this is a **correlation integrity check** run at the pipeline's ingest boundary: for every session, assert `distinct(trace_root_id) == 1`, assert the eval-span join rate is 1.0 (or the session is flagged correlation-degraded), and assert no orphaned safety flags exist for the session. Any violation raises and routes the session to quarantine rather than the aggregate. The check must run *before* aggregation, because once a mis-joined record enters the aggregate, no downstream reconciliation can distinguish it from a genuinely clean session. ```python from dataclasses import dataclass, field from typing import Optional class CorrelationCollapseError(RuntimeError): """Raised when a session's trace, eval, and safety records cannot be correlated under a single stable identity.""" @dataclass class SessionRecord: session_id: str trace_root_id: Optional[str] seq: int eval_verdict: Optional[str] = None safety_flags: list = field(default_factory=list) def verify_correlation_integrity(records: list[SessionRecord]) -> None: """Enforce write-once session identity across all producers. Invariants: 1. Every record retains a trace_root_id (pre-fork key). 2. All records in a logical session share one trace_root_id. 3. Sequence numbers are contiguous per root; a gap means a re-key boundary that was not annotated. """ if not records: raise CorrelationCollapseError("empty record set: cannot verify correlation") roots = {r.trace_root_id for r in records} if None in roots: missing = [r.session_id for r in records if r.trace_root_id is None] raise CorrelationCollapseError( f"records lost root identifier, correlation unrecoverable: {missing[:5]}" ) if len(roots) > 1: # Multiple roots under one reported session_id: a re-key occurred # without a namespaced child identity. Quarantine, do not repair. raise CorrelationCollapseError( f"session re-keyed across {len(roots)} roots without child identity: {roots}" ) seqs = sorted(r.seq for r in records) expected = list(range(seqs[0], seqs[0] + len(seqs))) if seqs != expected: gap = sorted(set(expected) - set(seqs)) raise CorrelationCollapseError( f"sequence discontinuity at {gap[:5]}: re-key boundary unannotated" ) for r in records: if r.eval_verdict is None: raise CorrelationCollapseError( f"eval verdict missing for seq={r.seq} session={r.session_id}: " f"orphaned trace would silently drop from coverage metrics" ) def ingest_session(records: list[SessionRecord]) -> dict: try: verify_correlation_integrity(records) except CorrelationCollapseError as exc: # Quarantine: retain raw records, exclude from aggregates. return {"status": "quarantined", "reason": str(exc), "records": records} flags = [f for r in records for f in r.safety_flags] return { "status": "ok", "session_id": records[0].session_id, "turns": len(records), "safety_flag_count": len(flags), } ```