# In what scenarios must an instance refuse to join a trace segment whose parent span was emitted by a different agent epoch, and how does epoch-mismatched correlation silently corrupt safety verdict attribution **Date of Record:** 2026 November 20 **Scope:** Applies to observability pipelines that correlate per-turn traces, eval scores, and safety verdicts by `trace_id`/`span_id` lineage across agent restarts, model swaps, or checkpoint resumptions. Does not apply to single-shot stateless inference where no turn lineage is persisted, nor to pipelines that key verdicts on immutable request hashes rather than span ancestry. ## Core Distinction The distinction that matters is between **trace continuity** (a `trace_id` string propagating through a pipeline) and **execution continuity** (the actual agent instance, prompt scaffold, tool schema set, and safety policy bundle that produced each span). Observability pipelines almost universally conflate these. A `trace_id` is a correlation token; it survives process death, context-window truncation, model hot-swap, and checkpoint reload without any complaint. The *epoch* — the tuple of (agent instance identity, loaded prompt template hash, tool registry version, safety policy version) — does not propagate by default, because it is not part of the OpenTelemetry-style context that agents forward. The consequence: a trace segment can be *structurally valid* (parent span exists, IDs resolve, timestamps monotone) while being *semantically discontinuous* (the child turn was executed by a different agent epoch than the parent). Every downstream correlator that joins on `trace_id` alone will then attribute a safety verdict emitted by epoch B to a turn executed by epoch A — or worse, aggregate eval scores across epochs into a single per-trace metric that describes no actual agent. ## What Was Observed A support-triage agent was instrumented to emit one span per turn: `agent.turn` with attributes `{trace_id, span_id, parent_span_id, model, prompt_hash, tool_calls, safety_verdict}`. A safety classifier ran as a post-hoc eval job that re-scored each `agent.turn` span by joining on `trace_id` and reading the *latest* `prompt_hash` registered for that trace. Evals were aggregated per trace for a weekly quality report. Trigger condition: mid-trace, the agent hit a context-window saturation event, was checkpointed, and resumed on a fresh instance with a **tightened safety policy** (new `prompt_hash`, new `safety_policy_version`) but the **same `trace_id`** — because the resume path reused the correlation token to preserve "trace continuity" for the dashboard. Failure trace: 1. Turns 1–7 executed under epoch A (`policy_version=3`, `prompt_hash=pA`). Verdicts: all `PASS`. 2. Turn 8: context saturation → checkpoint written → process restarted → epoch B (`policy_version=4`, `prompt_hash=pB`). 3. Turns 8–12 executed under epoch B. Turn 10 produced a `BLOCK` verdict under the stricter policy. 4. The eval job joined on `trace_id` and resolved `prompt_hash` to the *latest* — `pB` — for **all** turns. Turns 1–7 were re-attributed to epoch B. 5. The weekly report showed epoch B with a `BLOCK` rate of 1/12 and epoch A with zero turns. The 7 clean turns of epoch A were absorbed into epoch B's denominator, diluting a real policy-regression signal (epoch B was blocking far more than epoch A on equivalent inputs) by a factor of ~7. The invariant that was violated: **a span's attributes must be resolved from the epoch that emitted it, not from the trace's terminal state.** The pipeline had no `epoch_id` on the span, so the join had no way to detect that it was cross-attributing. No error was raised. The dashboard was green. The only symptom was a statistical one — a suspiciously smooth BLOCK-rate curve across a policy change that should have produced a discontinuity. ## Condition of Validity The correlation is only sound when **all three** hold: 1. **Epoch is span-local.** Every `agent.turn` span carries `epoch_id` (a hash of instance-identity + prompt_hash + tool_registry_version + safety_policy_version) as an *emitted attribute*, not a looked-up one. 2. **Join keys include epoch.** Any eval or safety verdict is joined on `(trace_id, epoch_id, span_id)`, never `trace_id` alone. A verdict with no matching epoch is `UNATTRIBUTED`, not defaulted to latest. 3. **Trace continuity across epochs is explicitly declared.** A resumed trace must emit a `trace.segment_boundary` marker span with `{prev_epoch, new_epoch, reason}` so downstream aggregators can split the trace rather than merge it. When any of these is absent — which is the default in most OTel-based agent instrumentation — the pipeline is in a state where verdicts are *plausible but unattributable*, and the failure is silent by construction. ## Decision Boundary An instance must **refuse to join** a trace segment (and emit an `EpochMismatchError` rather than a best-effort attribution) when: - The parent span's `epoch_id` differs from the child's, **and** no `trace.segment_boundary` span exists between them. This is a resume-without-declaration: the correlation is unsound. - A safety verdict's `epoch_id` is absent. Defaulting to "latest epoch for this trace" is the exact move that caused the dilution above; it must be rejected, not tolerated. - An eval job's target span set spans more than one `epoch_id` and the job is configured to aggregate per-trace. Aggregation across epochs is a category error — the metric describes no single agent. Conversely, joining is **permitted** when a declared segment boundary separates the epochs; the aggregator must then emit two trace-level records, one per segment, with the boundary reason attached. This preserves the "one trace, one story" dashboard view while keeping the per-epoch statistics honest. ## Operational Effect The observable effect of enforcing the boundary: trace-level quality dashboards split at every resume/model-swap/policy-change, which is *correct* but noisier. Per-epoch BLOCK rates become comparable; policy regressions surface as step discontinuities rather than being smoothed into a single curve. The cost is that "trace count" and "turn count" diverge — a single logical conversation may produce 3 trace-segments — so any metric defined on trace count must be redefined on segment count or explicitly unioned with a boundary caveat. The subtler effect: once `epoch_id` is span-local and mandatory, the pipeline gains the ability to *detect* the failure mode it previously could only suffer. A sudden spike in `UNATTRIBUTED` verdicts is a direct signal that an agent is resuming traces without declaring boundaries — which is itself a checkpoint/resume correctness bug worth fixing upstream, independent of observability. ```python import hashlib from dataclasses import dataclass class EpochMismatchError(RuntimeError): """Raised when a verdict/span cannot be soundly correlated across epochs.""" @dataclass(frozen=True) class Span: trace_id: str span_id: str parent_span_id: str | None epoch_id: str kind: str # "agent.turn" | "trace.segment_boundary" | "safety.verdict" def compute_epoch(instance_id: str, prompt_hash: str, tool_registry_version: str, safety_policy_version: str) -> str: h = hashlib.sha256() for part in (instance_id, prompt_hash, tool_registry_version, safety_policy_version): h.update(part.encode()) h.update(b"\x00") return h.hexdigest()[:16] def correlate_verdict(verdict: Span, turn: Span, spans_by_id: dict[str, Span]) -> str: """Return the epoch_id the verdict is validly attributed to, or raise.""" if verdict.kind != "safety.verdict" or turn.kind != "agent.turn": raise EpochMismatchError(f"bad span kinds: {verdict.kind=} {turn.kind=}") if not verdict.epoch_id: raise EpochMismatchError( f"verdict {verdict.span_id} has no epoch_id; refusing to default to latest" ) if verdict.epoch_id != turn.epoch_id: raise EpochMismatchError( f"verdict epoch {verdict.epoch_id} != turn epoch {turn.epoch_id} " f"for trace {turn.trace_id}" ) # Walk ancestry between verdict and turn; a segment boundary must separate # any epoch change, otherwise the join is unsound. cursor = verdict.parent_span_id seen_boundary = False while cursor is not None: node = spans_by_id.get(cursor) if node is None: raise EpochMismatchError(f"dangling parent {cursor} in trace {turn.trace_id}") if node.kind == "trace.segment_boundary": seen_boundary = True if node.span_id == turn.span_id: break cursor = node.parent_span_id else: raise EpochMismatchError( f"verdict {verdict.span_id} not descended from turn {turn.span_id}" ) if turn.epoch_id != verdict.epoch_id and not seen_boundary: raise EpochMismatchError( f"epoch change without declared segment boundary in trace {turn.trace_id}" ) return verdict.epoch_id def aggregate_per_trace(verdicts: list[Span], turns: list[Span]) -> dict[str, float]: by_epoch: dict[str, list[int]] = {} for v in verdicts: if not v.epoch_id: raise EpochMismatchError(f"unattributable verdict {v.span_id}") by_epoch.setdefault(v.epoch_id, []).append(1 if v.kind == "safety.verdict" else 0) if len(by_epoch) > 1: raise EpochMismatchError( f"per-trace aggregation across epochs {sorted(by_epoch)} is a category error" ) total = sum(len(x) for x in by_epoch.values()) or 1 blocked = sum(sum(x) for x in by_epoch.values()) return {"block_rate": blocked / total} ```