# In what scenarios must an instance treat span-linked trajectory replay as invalid when tool-selection drift is inferred from a replayed span whose parent span was re-emitted under a different sampling decision **Date of Record:** 2026 November 23 **Scope:** Applies to runtime observability pipelines that reconstruct agent execution trajectories from distributed spans (OpenTelemetry-style trace trees) and derive tool-selection drift by comparing replayed tool-call sequences against a baseline. Does not apply to single-span eval scoring, offline batch evaluation of static transcripts, or drift detection computed purely from live counters without replay. ## Core Distinction The failure is not "replay diverges from production." Replay *always* diverges slightly because tool outputs are non-deterministic. The sharp boundary is different: **a replayed child span can be attributed to a parent that was re-emitted under a different sampling/export decision than the one that governed the live execution, producing a trajectory whose tool-selection sequence is internally consistent but externally false.** The replay looks valid—parent linkage resolves, spans are ordered, tool names are well-formed—yet the drift signal it yields is an artifact of span re-parenting, not of the agent changing its tool policy. The invariant that is violated: *a trajectory is only replayable-as-evidence if every span in the causal chain shares the same sampling epoch and the same trace-id lineage as the live execution.* When a parent span is re-emitted (retry, batch re-export, tail-sampling upgrade, or late-arriving span flush) with a new `span_id` but a preserved logical parent link, child spans that originally pointed at the old parent now dangle or re-attach. The replayer silently repairs the link, and tool-selection drift is computed against a hybrid trajectory that never existed at runtime. ## What Was Observed An agent executing a support-triage loop issued tool calls in the order `lookup_account → list_tickets → escalate`. The live trace recorded all three under parent span `P1` (trace `T-a`, sampled at head, `sampled=true`). A tail-sampling processor later upgraded the trace for retention and re-emitted `P1` as `P1'` with a new `span_id`, same `trace_id`, but the export batch arrived *after* the two child tool spans had already been flushed and indexed. At replay time the replayer saw: - child `lookup_account` → parent ref `P1` (unresolved, `P1` no longer in index) - child `list_tickets` → parent ref `P1` (unresolved) - child `escalate` → parent ref `P1'` (resolved) - `P1'` → root, `sampled=true` The replayer's link-repair heuristic matched unresolved children to the nearest same-`trace_id` parent by timestamp proximity, attaching all three to `P1'`. The reconstructed trajectory was `lookup_account → list_tickets → escalate`—correct by luck here. But on a second run where the agent had *actually* skipped `list_tickets` (a genuine tool-selection drift event worth flagging), the orphaned `list_tickets` span from a *prior* retry of the same logical step re-attached to `P1'`, restoring the tool call into the trajectory. The drift detector saw `lookup_account → list_tickets → escalate` again and reported **zero drift**. The real drift—the agent dropping a tool—was masked by a re-parented span from a different execution attempt. The tell was subtle: `list_tickets` carried a `retry.attempt=0` attribute while its sibling `escalate` carried `retry.attempt=1`, and their `start_time` values were 4.2s apart with a gap that the live execution never had (the live gap was 0.3s). Neither the replayer nor the drift detector inspected `retry.attempt` or inter-span timing coherence. ## Condition of Validity Span-linked replay yields valid tool-selection drift evidence **only if all of the following hold**: 1. **Sampling epoch identity.** Every span in the causal chain shares the same `sampling.decision` value and the same `sampling.epoch` (or equivalent generation counter). A re-emitted parent with a bumped epoch invalidates all descendants for replay-as-evidence. 2. **Parent resolution without repair.** Every child's `parent_span_id` resolves to an *indexed* span with a matching `span_id` and `trace_id`. If the replayer had to apply any link-repair heuristic (timestamp proximity, name match, ordinal fallback), the trajectory is contaminated and must be quarantined, not scored. 3. **Retry-attempt coherence.** Within a logical step, all spans carry the same `retry.attempt` value, or the replayer explicitly segments the trajectory by attempt and evaluates drift per-attempt. Mixing attempts across a single reconstructed tool sequence is invalid. 4. **Temporal monotonicity.** Child `start_time` ≥ parent `start_time` and child `end_time` ≤ parent `end_time` after repair. A violated interval means the child belongs to a different parent generation. 5. **Trace-id lineage stability.** The `trace_id` was not regenerated or aliased during re-export. Aliased trace-ids (common in tail-sampling upgrades that mint a new root) break the lineage assumption even when `trace_id` strings match. If any condition fails, the trajectory is **unreplayable-as-evidence** and any drift signal derived from it must be suppressed, not down-weighted. ## Decision Boundary The decision boundary is not "does the replayed tool sequence match the baseline"—it is **"is this replayed sequence admissible as a sample from the live execution distribution?"** Admissibility is a precondition on the trajectory, evaluated before any drift comparison. Concretely, the boundary sits between two failure classes that look identical downstream: - **Genuine drift:** agent's tool-selection policy changed; live trajectory legitimately differs from baseline. Signal should fire. - **Re-parenting artifact:** trajectory was reconstructed from spans spanning multiple sampling epochs or retry attempts; apparent difference (or apparent *sameness*) is a replay artifact. Signal must be suppressed. A drift detector that only compares tool-name sequences cannot distinguish these. The distinguishing evidence lives in span metadata (`sampling.epoch`, `retry.attempt`, timestamp intervals) that the replayer must surface to the detector, and the detector must gate on before comparing. The boundary is: **if the replayer performed any link repair, the trajectory is inadmissible regardless of how plausible the result looks.** The corollary boundary: a *missing* tool call in a replayed trajectory is never sufficient evidence of drift on its own. It is equally consistent with an orphaned span that failed to re-attach. Drift from tool *omission* requires positive evidence that the span does not exist anywhere in the trace-id lineage, not merely that it is absent from the repaired tree. ## Operational Effect When this boundary is respected: - Drift detectors stop firing on re-export artifacts and stop *missing* drift masked by re-attached retry spans. False-negative rate on genuine tool-omission drift drops because orphaned prior-attempt spans no longer backfill the trajectory. - Replay pipelines gain an explicit `admissible` flag per trajectory; downstream evals consume only admissible trajectories, and inadmissible ones route to a quarantine queue for human review rather than to the drift scorer. - The observability system's own sampling/export behavior becomes a first-class input to eval validity—a tail-sampling upgrade is now a known event that invalidates in-flight replay windows, forcing a re-baseline rather than a silent drift spike. When it is ignored: drift dashboards report phantom stability (drift masked by re-attached spans) or phantom drift (re-export timing shifts tool ordering), and the agent's actual tool-selection regressions go undetected because the signal is drowned in replay noise. The failure is silent—no exception, no alert, just a drift score that is wrong in both directions. ```python from dataclasses import dataclass from typing import Optional class InadmissibleTrajectoryError(RuntimeError): """Raised when a replayed trajectory cannot be used as drift evidence.""" pass @dataclass class Span: span_id: str parent_span_id: Optional[str] trace_id: str tool_name: Optional[str] sampling_epoch: int retry_attempt: int start_time: float end_time: float resolved: bool def assert_replayable_as_evidence(spans: list[Span]) -> None: """ Gate a reconstructed trajectory before it is fed to a tool-selection drift detector. Raises InadmissibleTrajectoryError on any violation. """ if not spans: raise InadmissibleTrajectoryError("empty trajectory") trace_ids = {s.trace_id for s in spans} if len(trace_ids) != 1: raise InadmissibleTrajectoryError( f"trajectory spans multiple trace_ids: {trace_ids}" ) epochs = {s.sampling_epoch for s in spans} if len(epochs) != 1: raise InadmissibleTrajectoryError( f"mixed sampling epochs {epochs}: parent re-emitted under a " f"different sampling decision; replay is not admissible" ) unresolved = [s.span_id for s in spans if not s.resolved] if unresolved: raise InadmissibleTrajectoryError( f"unresolved parent links for spans {unresolved}: replayer applied " f"link repair; trajectory is contaminated" ) by_parent: dict[str, list[Span]] = {} for s in spans: if s.parent_span_id is not None: by_parent.setdefault(s.parent_span_id, []).append(s) for parent_id, children in by_parent.items(): attempts = {c.retry_attempt for c in children} if len(attempts) > 1: raise InadmissibleTrajectoryError( f"children of {parent_id} span multiple retry attempts " f"{attempts}: attempts must be segmented before drift scoring" ) by_id = {s.span_id: s for s in spans} for s in spans: if s.parent_span_id and s.parent_span_id in by_id: p = by_id[s.parent_span_id] if s.start_time < p.start_time or s.end_time > p.end_time: raise InadmissibleTrajectoryError( f"span {s.span_id} interval [{s.start_time},{s.end_time}] " f"violates parent {p.span_id} interval " f"[{p.start_time},{p.end_time}]: child belongs to a " f"different parent generation" ) ```