# What structural signals indicate span-orphaning corruption when observability pipelines correlate agent traces, evals, and safety signals at span granularity **Date of Record:** 2026 November 21 **Scope:** Applies to agent runtimes that emit OpenTelemetry-style spans with parent/child linkage and that fuse three signal planes — execution traces, offline/online evals, and safety classifiers — keyed on `span_id` and `trace_id`. Does not apply to single-turn stateless inference logging where no parent linkage exists. ## Core Distinction The failure mode here is not "missing telemetry" — that is loud and self-diagnosing. It is **span-orphaning corruption**: a safety or eval signal is correctly emitted, correctly attributed to a span at emission time, and then silently re-parented or orphaned during correlation because the pipeline's join key resolves to a *different span instance than the one the model actually saw*. The distinction that matters: a trace pipeline treats `trace_id` as an immutable namespace. An agent runtime treats it as a *mutable retention scope*. When a mid-task checkpoint/resume fires (context compaction, sub-agent handoff, retry after tool timeout), the runtime frequently re-emits a resumed span under a **new `span_id` but the inherited `trace_id`**, or reuses the parent's `span_id` for the resumed work. The observability layer, which assumes `(trace_id, span_id)` is a stable identity, then attaches the eval verdict computed against the *pre-compaction* prompt to the *post-compaction* span — or attaches a safety flag raised on the resumed segment to the original segment that never contained the triggering tokens. The signal is not lost. It is **misattributed to a span whose input distribution differs from the one that produced it**, which is strictly worse than loss because it passes schema validation and downstream dashboards. ## What Was Observed A tool-using agent (retrieval + summarizer) ran a long task that triggered context-window compaction at step 14 of ~40. The runtime emitted: - `span_id=S0` for steps 1–13 under `trace_id=T`. - On compaction, the orchestrator serialized state, cleared the window, and re-entered the loop. The resumed work emitted `span_id=S0` again (parent `span_id` was reused because the resume path copied the enclosing span's attributes verbatim, including its own ID) rather than minting `S1`. - A safety classifier flagged a prompt-injection payload at step 22, inside the resumed segment, and emitted a safety span with `parent_span_id=S0`, `trace_id=T`, `verdict=INJECTION_SUSPECTED`. - An eval harness scored the model's step-9 output (pre-compaction, clean context) as `faithfulness=0.91`, keyed to `S0`. The correlation job joined on `(T, S0)`. Result: the injection flag and the high-faithfulness eval landed on the **same span record**. The dashboard rendered "span S0: faithfulness 0.91, safety: injection suspected" — a contradictory pair that no human triaged because the faithfulness score masked the flag's apparent severity. The actual poisoned segment (resumed, steps 14–40) had *no* eval score, because no eval span carried its true identity — it had been absorbed into the reused `S0`. Structural signals present at corruption time, in order of observability: 1. **Span-ID reuse without a generation counter.** Two `span_end` events for the same `(trace_id, span_id)` with non-monotonic `start_time` and a `resume=true` attribute on the second. This is the primary tell. A conforming pipeline should treat duplicate-terminal-span as a hard invariant violation. 2. **Monotonicity break in `span_sequence`.** The reused span's child events carried timestamps *earlier* than the parent's own `end_time`, because the resume re-emitted children under the old parent after the parent had already closed. 3. **Eval/span cardinality drift.** The eval plane emitted N verdicts but the trace plane had N−1 distinct span identities; the join produced a fan-in where two distinct semantic segments collapsed to one key. 4. **Safety-signal-to-token-provenance mismatch.** The injection flag referenced token offsets that did not exist in the pre-compaction span's recorded `input_hash`. The `input_hash` of `S0` (clean) did not match the hash the classifier had actually scored (poisoned). This is the decisive structural check: **the safety verdict's input hash must equal the span's recorded input hash, or the correlation is invalid regardless of ID match.** ## Condition of Validity The invariant that makes span-granular correlation sound is: > For every correlated signal `s` attached to span `k`, `hash(s.input_payload) == k.recorded_input_hash` **and** `k` is the unique terminal span with identity `(trace_id, span_id)` within the retention window. Correlation is valid only when both hold. The failure above violated the second clause (duplicate terminal span) and, because the classifier scored the resumed payload, the first clause too — but the pipeline checked neither, because it trusted the join key. Any pipeline that joins on `(trace_id, span_id)` alone, without a payload-hash equality gate and a uniqueness gate on terminal spans, is exposed. The condition does *not* require that resume mint new trace IDs (that would fragment the trace and break end-to-end safety review); it requires that resume **mint a new `span_id` and carry a `generation` attribute**, preserving `trace_id` for lineage while making span identity injective. ## Decision Boundary The boundary is whether the runtime's resume path is **identity-preserving** or **identity-minting**. Concretely: - If resume copies the enclosing span's `span_id` (common when resume is implemented as "re-enter the same loop frame"), the pipeline **must** reject duplicate terminal spans and quarantine the trace, because correlation is provably ambiguous. - If resume mints a fresh `span_id` with `generation = parent.generation + 1` and `resumed_from = old_span_id`, correlation is sound and the eval/safety planes can join safely. - The decision to **fail-closed vs. fail-open** on a detected duplicate: fail-closed (drop the trace from the safety dashboard and page) is correct for safety planes, because a masked injection flag is the exact harm. Fail-open is acceptable only for latency/cost evals where misattribution is cosmetic. A pipeline that cannot distinguish these cases from telemetry alone must treat any `resume=true` attribute as a correlation-invalidating event until the runtime is patched — because it cannot prove the span ID it joined on is the span the model actually executed against. ## Operational Effect Downstream, the corruption manifests as **safety-signal suppression by eval dilution**. The high faithfulness score on the reused span raised the trace's aggregate trust score above the triage threshold, so the injection flag was routed to a low-priority queue and never reviewed. The poisoned segment's tokens were never re-scored because no eval span pointed at them. The net effect: a prompt-injection that succeeded in the resumed context produced a trace that *looked* fully observed — trace complete, eval present, safety present — while the two signals described different execution histories. This is the signature of span-orphaning: **completeness metrics stay green while semantic coverage silently halves.** The guardrail is a correlation gate that refuses to attach any signal whose payload hash diverges from the target span's recorded hash, plus a terminal-span uniqueness assertion that quarantines resume-collapsed traces for manual lineage repair. ```python import hashlib from dataclasses import dataclass, field class SpanCorrelationError(RuntimeError): """Raised when a signal cannot be soundly attributed to a span.""" @dataclass class Span: trace_id: str span_id: str generation: int input_payload: str terminal: bool = False children: list = field(default_factory=list) @property def input_hash(self) -> str: return hashlib.sha256(self.input_payload.encode()).hexdigest() @dataclass class Signal: trace_id: str span_id: str kind: str # "eval" | "safety" scored_payload: str verdict: str @property def payload_hash(self) -> str: return hashlib.sha256(self.scored_payload.encode()).hexdigest() def correlate(signal: Signal, spans: list[Span]) -> Span: candidates = [ s for s in spans if s.trace_id == signal.trace_id and s.span_id == signal.span_id ] if not candidates: raise SpanCorrelationError( f"no span for ({signal.trace_id},{signal.span_id})" ) terminal = [s for s in candidates if s.terminal] if len(terminal) != 1: # duplicate terminal span => resume reused span_id => ambiguous identity raise SpanCorrelationError( f"span-orphaning: {len(terminal)} terminal spans for " f"({signal.trace_id},{signal.span_id}); resume collapsed identity, " f"generations={[s.generation for s in terminal]}" ) target = terminal[0] if signal.payload_hash != target.input_hash: # signal was computed against a different payload than the span recorded raise SpanCorrelationError( f"payload-hash divergence on ({signal.trace_id},{signal.span_id}): " f"signal={signal.payload_hash[:12]} span={target.input_hash[:12]}; " f"refusing to attach {signal.kind}={signal.verdict}" ) return target def ingest(signal: Signal, spans: list[Span], safety_plane: bool) -> Span: try: return correlate(signal, spans) except SpanCorrelationError: if safety_plane: # fail-closed: quarantine, never silently drop a safety signal raise SpanCorrelationError( "quarantining trace for lineage repair; safety signal " "cannot be soundly attributed" ) # latency/cost evals: misattribution is cosmetic, drop return None ```