Where must an instance re-anchor trace lineage when a model-span retry forks the agent's causal chain?
**Date of Record:** 2026 December 2 **Scope:** Applies to observability pipelines that reconstruct a single causal trace from agent-orchestrator spans, model-inference spans, and tool-execution spans, where the model client performs internal retries or hedging. Does not apply to systems that emit one immutable trace ID per request and never retry at the model-client layer.
Core Distinction
A trace is not a log stream. A trace is a *causal claim*: span B happened *because of* span A. In a GenAI pipeline the causal chain is stitched from three span families emitted by three different runtimes — the agent framework (loop steps, plan nodes), the model client (inference calls, including retries), and tool executors (function calls, MCP round-trips). Each family carries its own notion of "parent."
The non-obvious failure is this: **a model-client retry is not a child of the original model span — it is a sibling that re-enters the causal chain at the agent step, and if the pipeline naively nests it under the failed attempt, every downstream tool span inherits a divergent lineage.** The agent's single logical step (one `decide` node) now has *two* model spans claiming to be its direct child, and only one of them actually produced the tool call that followed. Correlation by `parent_span_id` alone cannot distinguish the winner from the discarded hedge, because both were emitted with the same parent.
The distinction that matters operationally: **retry identity ≠ attempt identity.** The retry must be re-anchored to the *logical step* (a stable step ID owned by the agent), not to the *physical attempt* (an ephemeral span that the model client minted and then abandoned). A pipeline that anchors on the physical attempt will, under any concurrent or hedged retry, produce a trace where the tool span's ancestry points at a model call that returned a different completion than the one the tool was actually invoked with.
What Was Observed
In a production agent running a plan-execute loop against a model endpoint with client-side retry (`max_retries=3`, jittered backoff, plus a 2-way hedge on P99 latency), the following trace was reconstructed after a single user turn:
- Agent step `S7` (`decide`) — emitted once, as expected.
- Model span `M7a` — attempt 1, status `DEADLINE_EXCEEDED` at 30s, no completion.
- Model span `M7b` — hedge attempt, status `OK`, completion contains `tool_call: search_corpus(query="…")`.
- Model span `M7c` — attempt 1's *retry*, status `OK`, completion contains `tool_call: search_corpus(query="…")` with a *different* query string (sampling nondeterminism).
- Tool span `T7` — `search_corpus`, parent recorded as `M7a` (the failed attempt), because the tool executor captured the *first* model span handle it was handed and never updated it when the client swapped to the winning attempt.
The reconstructed trace was internally consistent — every span had a parent, no orphans — and completely wrong. An auditor reading `T7` would conclude the tool ran on the query from `M7a`, which returned nothing, so the query would appear to be `""`. The actual executed query came from `M7b`. The pipeline had no invariant forcing the tool span's parent to be the model span whose completion was *actually consumed*.
The tell was a cross-check the pipeline did not perform: `T7.args.query` appeared in neither `M7a` (empty) nor `M7c` (different string), but matched `M7b` exactly. Correlation by parent ID passed; correlation by *content provenance* failed. This is the boundary: parent-ID correlation is necessary but not sufficient once retries fork.
Condition of Validity
Parent-ID correlation is valid **only when the model client guarantees that exactly one model span per agent step reaches `OK`, and that this span is the one whose handle the agent propagates to the tool executor.** In practice this holds only under:
- **No hedging.** Single-attempt semantics, retries disabled or strictly sequential with the failed attempt's handle discarded before the next.
- **Handle rebinding.** The agent re-reads the model span handle *after* the client returns, not before. If the tool executor is constructed with a stale handle captured pre-retry, the invariant is already violated.
- **Content attestation.** The tool span records a hash of the completion it was invoked with, and the model span records the same hash. Without this, a forked lineage is undetectable after the fact.
When any of these is absent — and in hedged or jittered-retry clients, at least (1) and (2) routinely are — the pipeline must treat the model span as *non-authoritative for lineage* and re-anchor on the agent's logical step ID plus a completion-content hash.
Decision Boundary
The pipeline must decide, per agent step, whether to trust the model span's parent link or to re-anchor. The rule:
- If the agent step emitted **exactly one** `OK` model span and **zero** failed attempts → trust the parent link; emit as-is.
- If the agent step emitted **≥2** model spans (any combination of failed and OK) → **re-anchor**: reparent the tool span to the agent step's logical step ID, and attach the completion-content hash as the discriminating edge. The discarded attempts become *siblings of the winning attempt*, not ancestors of the tool.
- If the tool span's recorded completion hash matches **no** `OK` model span → emit a lineage-integrity fault; the trace is unverifiable and must not be used for audit or replay.
This boundary is sharp: it is crossed the moment a second model span appears under one logical step, regardless of which attempt "won." The pipeline cannot infer the winner from timestamps (hedges overlap) or from status (both can be `OK`). Only the completion hash resolves it.
Operational Effect
Downstream consumers of the trace — replay engines, cost attribution, eval harnesses, incident auditors — inherit the fork silently. A replay engine that reconstructs the tool call from `M7a`'s completion will replay an empty query and diverge from the recorded tool output, flagging a spurious "tool nondeterminism" fault. Cost attribution double-counts the hedge and the retry against the step. An eval harness comparing model outputs to tool results pairs the wrong completion with the right tool output and reports a hallucination that never happened.
The guardrail is architectural, not cosmetic: **lineage authority must be assigned at emit time by the component that consumed the completion, not reconstructed at ingest from parent IDs.** Concretely, the agent runtime must write the winning model span's ID and the completion hash into the tool span's attributes before the tool executes, and the ingest pipeline must reject any tool span whose parent model span carries a different hash. Retries become observable as *sibling attempts under a logical step*, which is what they are — not as a nested chain that fabricates ancestry.
import hashlib
from dataclasses import dataclass, field
from typing import Optional
class LineageIntegrityError(RuntimeError):
"""Raised when a tool span's provenance cannot be reconciled to a single
authoritative model span under its agent step."""
pass
@dataclass
class ModelSpan:
span_id: str
logical_step_id: str
status: str # "OK" | "DEADLINE_EXCEEDED" | ...
completion: Optional[str]
completion_hash: Optional[str] = None
def __post_init__(self):
if self.completion is not None:
self.completion_hash = hashlib.sha256(
self.completion.encode()
).hexdigest()[:16]
@dataclass
class ToolSpan:
span_id: str
logical_step_id: str
parent_model_span_id: Optional[str]
consumed_completion_hash: Optional[str]
@dataclass
class AgentStep:
logical_step_id: str
model_spans: list = field(default_factory=list)
tool_spans: list = field(default_factory=list)
def reanchor_lineage(step: AgentStep) -> list:
"""Return tool spans reparented to the logical step when the model chain
has forked (>=2 model spans), and validate content provenance."""
ok_spans = [m for m in step.model_spans if m.status == "OK"]
forked = len(step.model_spans) >= 2
if not forked:
return step.tool_spans # parent link is trustworthy
by_hash = {m.completion_hash: m for m in ok_spans if m.completion_hash}
resolved = []
for tool in step.tool_spans:
winner = by_hash.get(tool.consumed_completion_hash)
if winner is None:
raise LineageIntegrityError(
f"tool {tool.span_id} on step {step.logical_step_id}: "
f"consumed completion hash {tool.consumed_completion_hash!r} "
f"matches no OK model span among "
f"{[m.span_id for m in ok_spans]}; lineage unverifiable"
)
tool.parent_model_span_id = winner.span_id
resolved.append(tool)
return resolved
# Failure trace: M7a failed, M7b (hedge) won, M7c (retry) also OK.
step = AgentStep(
logical_step_id="S7",
model_spans=[
ModelSpan("M7a", "S7", "DEADLINE_EXCEEDED", None),
ModelSpan("M7b", "S7", "OK", '{"tool_call":"search_corpus","q":"alpha"}'),
ModelSpan("M7c", "S7", "OK", '{"tool_call":"search_corpus","q":"beta"}'),
],
tool_spans=[
ToolSpan("T7", "S7", parent_model_span_id="M7a",
consumed_completion_hash=None), # stale handle, no hash
],
)
try:
reanchor_lineage(step)
except LineageIntegrityError as exc:
print(f"LINEAGE FAULT: {exc}")
# Correct behavior: quarantine T7, do not emit into the audit trace.