# What happens when an instance's prompt span and tool span are correlated by wall-clock timestamp instead of causal lineage **Date of Record:** 2026 November 29 **Scope:** Applies to agents whose observability pipeline joins LLM inference spans to downstream tool-execution spans via timestamp proximity (start/end-time overlap or nearest-neighbor bucketing) rather than an explicit causal token (trace/span parent, tool-call ID, or propagated correlation ID). Does not apply to systems that emit W3C traceparent or a signed tool-call receipt at the point of tool dispatch. ## Core Distinction Correlation by *causality* and correlation by *coincidence* look identical on a healthy single-agent trace and diverge catastrophically under concurrency, retries, and speculative execution. The causal invariant is: a tool span is a child of the exact prompt span that emitted the tool call, identified by a token minted at emission time and carried through the transport. The timestamp heuristic substitutes the weaker invariant "the tool span's start time falls inside the prompt span's `[start, end]` window." That substitution is valid only when exactly one prompt span is active at a time on the emitting instance. Modern agent runtimes violate that precondition constantly: parallel tool calls, retried inference, streaming spans whose `end` is set by the last token rather than by tool dispatch, and multi-agent fan-out all produce overlapping windows. The non-obvious part is that the failure is *silent and asymmetric*. The join does not error; it produces a plausible-looking trace. The correlation is wrong only for the subset of spans where windows overlap, so aggregate dashboards (p99 latency, tool error rate) remain numerically stable while per-call attribution—which prompt caused which tool failure—is scrambled. The observability system reports health while the causal record is corrupted. ## What Was Observed An agent instance emits a prompt span `P` at `t0` and dispatches two tool calls concurrently (`search`, `fetch`). The runtime sets `P.end` at the moment the *last* streamed token is emitted, but tool dispatch happens during streaming, so both tool spans `T_search` and `T_fetch` start inside `[P.start, P.end]`. A second prompt span `P'` (a retry triggered by a guardrail timeout) starts at `t1 < P.end`, overlapping `P`. Now the join has two candidate parents for each tool span. The correlator picks the nearest `start` time, which is `P'`, not `P`. The retry is credited with the original attempt's tool calls. The downstream consequences compound: 1. **Attribution inversion.** `P'` (the retry) shows two successful tool calls and zero latency, because the tool spans inherited `P'`'s parent but kept their original timestamps. The retry appears to have succeeded instantly. The original `P` appears to have made no tool calls. 2. **Error masking.** When `T_fetch` fails, the error is attributed to `P'`, which the retry logic then marks as "failed and retried." The actual failing attempt `P` is recorded as clean. Retry-storm detection misses the root cause. 3. **Token accounting drift.** Prompt-token cost is summed per parent. Because tool results flow back into `P`, but `P` is recorded as childless, the cost of re-reading tool output is billed to `P'`. Budget alarms fire on the wrong span and the wrong instance. 4. **Replay divergence.** When the trace is replayed for audit, the correlated graph asserts `P'` produced `T_search`. Replaying `P'`'s prompt does not reproduce `T_search`'s arguments, because `P'` never emitted them. The audit concludes the model is non-deterministic; the real cause is a bad edge in the trace graph. The trigger condition is precise: **two or more prompt spans on the same instance have overlapping `[start, end]` windows, and at least one tool span starts within the overlap.** This requires either concurrent tool dispatch during streaming, a retry that begins before the prior span closes, or speculative/parallel sampling. All three are standard in production agents. ## Condition of Validity Timestamp correlation is sound if and only if all of the following hold simultaneously: - **Single-flight invariant:** at most one prompt span per instance is open at any instant. Enforced by a per-instance mutex around inference, which most runtimes do not have because it kills throughput. - **Dispatch-bounded span:** `P.end` is set at the moment of tool dispatch, not at last-token emission, so tool spans cannot start inside a *later* span's window. This requires the span to be closed and a child span opened at dispatch, which is a code change, not a config change. - **Monotonic clock with no NTP step:** timestamps come from a clock that cannot step backward mid-trace. Cross-host correlation over NTP-synced clocks routinely violates this at the millisecond scale that nearest-neighbor bucketing relies on. - **No retry overlap:** the retry policy waits for the prior span to close before opening the next. Exponential backoff with jitter usually satisfies this; immediate retry does not. If any one fails, the heuristic is unsound and the trace is not a causal record. The practical test: can you prove, from the trace alone, that `T_search` was emitted by `P` and not `P'`? If the only evidence is timestamp containment, you cannot. ## Decision Boundary The boundary is not "use timestamps vs. use trace IDs" in the abstract—it is whether the correlation token is minted **at tool-call emission** and **carried through the transport** to the tool executor. The decision rule: - **Accept timestamp correlation** only for single-agent, single-flight, non-retrying workloads where the trace is used for aggregate latency/error dashboards and never for per-call attribution, cost billing, or replay. - **Reject timestamp correlation** the moment any of these are true: (a) the instance dispatches tools concurrently, (b) the retry policy can open a span before the prior closes, (c) the trace feeds a replay/audit path, (d) cost or budget alarms are keyed to the parent span, or (e) tool spans cross host boundaries. The architectural invariant required to bound the failure: **every tool span must carry a `parent_prompt_span_id` minted by the model runtime at the instant the tool call is emitted, and the tool executor must echo it on the span it emits.** The correlator then joins on the token, never on time. Timestamps remain useful for ordering *within* a parent, but they are demoted from join key to display attribute. When the token is missing (tool executor dropped it, transport stripped it), the correlator must emit an *uncorrelated* span with an explicit `correlation_status: unlinked` marker, not fall back to nearest-neighbor. Silent fallback is the failure; explicit unlinked is the guardrail. A second guardrail: the runtime must refuse to open a new prompt span on an instance while a prior span is open, *unless* it stamps both with a shared `concurrency_group_id`, so the correlator knows the windows are intentionally overlapping and must not resolve them by time. ## Operational Effect With causal tokens, the failure mode is bounded and observable: an unlinked tool span is a visible gap, and the correlator's `unlinked_rate` metric rises, alerting the operator to a transport bug. With timestamp correlation, the failure mode is an *inverted* trace that looks healthy: attribution is wrong, retries look fast, errors land on the wrong attempt, and replay divergence is misdiagnosed as model non-determinism. The observability layer becomes an active source of incorrect operational decisions—you scale the wrong instance, you suppress the wrong retry, you bill the wrong prompt. The invariant to enforce: **a trace edge is a causal claim; it may only be asserted by a token minted at emission, never inferred from clock proximity.** Any pipeline that infers edges from time is, under concurrency, fabricating causality. ```python from dataclasses import dataclass, field from typing import Optional class CorrelationInvariantError(RuntimeError): """Raised when a tool span cannot be causally linked to a prompt span.""" @dataclass class PromptSpan: span_id: str instance_id: str start: float end: Optional[float] = None open: bool = True @dataclass class ToolSpan: span_id: str instance_id: str start: float parent_prompt_span_id: Optional[str] = None # minted at dispatch correlation_status: str = "pending" class Correlator: def __init__(self): self.prompts: dict[str, PromptSpan] = {} def open_prompt(self, span: PromptSpan) -> None: # Guardrail: refuse overlapping prompt spans without a concurrency group. for other in self.prompts.values(): if other.instance_id == span.instance_id and other.open: raise CorrelationInvariantError( f"overlapping prompt span {span.span_id} on instance " f"{span.instance_id} while {other.span_id} is open; " f"timestamp correlation is unsound here" ) self.prompts[span.span_id] = span def close_prompt(self, span_id: str, end: float) -> None: self.prompts[span_id].end = end self.prompts[span_id].open = False def link_tool(self, tool: ToolSpan) -> ToolSpan: parent_id = tool.parent_prompt_span_id if parent_id is None: # No token: do NOT fall back to nearest-neighbor by timestamp. tool.correlation_status = "unlinked" raise CorrelationInvariantError( f"tool span {tool.span_id} has no parent_prompt_span_id; " f"refusing timestamp fallback (would fabricate causality)" ) parent = self.prompts.get(parent_id) if parent is None: tool.correlation_status = "unlinked" raise CorrelationInvariantError( f"tool span {tool.span_id} references unknown parent {parent_id}" ) if not (parent.start <= tool.start <= (parent.end or float("inf"))): tool.correlation_status = "unlinked" raise CorrelationInvariantError( f"tool span {tool.span_id} start {tool.start} outside parent " f"{parent_id} window [{parent.start}, {parent.end}]; " f"token and clock disagree — investigate transport" ) tool.correlation_status = "linked" return tool ```