# What structural signals indicate a broken tool-call lineage when agent identity, session, and span correlation diverge under concurrent sub-agent fan-out **Date of Record:** 2026 December 2 **Scope:** Applies to OpenTelemetry-style telemetry emitted by LLM agent runtimes that propagate a `trace_id` across parent agent → sub-agent → tool-call spans, where sub-agents are spawned concurrently and share a single session identifier. Does not apply to single-threaded agents that emit one linear span chain per session, nor to purely log-based telemetry without span parentage. ## Core Distinction The failure mode is not *missing* telemetry. It is **telemetry that is present, well-formed, and internally consistent per-span, yet globally mis-parented** — so that the lineage graph reconstructed downstream attributes a tool call to the wrong agent instance, or to two agent instances simultaneously. This is distinct from span loss (dropped exports) and from clock skew (out-of-order timestamps): here every span has a valid `trace_id`, a valid `span_id`, and a `parent_span_id` that *resolves to a real span* — the corruption is that the parent is the *wrong* span because the correlation key used to bind child to parent was not unique across concurrent siblings. The invariant that breaks: **for any tool-call span `T`, the tuple (`agent_instance_id`, `session_id`, `parent_agent_span_id`) must identify exactly one executing agent context.** When sub-agents are fanned out concurrently and the runtime derives `agent_instance_id` from a session-scoped counter or from a hash of `(session_id, agent_role)`, two concurrent siblings of the same role collide on the same identity. The lineage graph then shows a single agent making two interleaved, mutually inconsistent tool-call sequences, and any auditor replaying the trace reconstructs a reasoning chain that never existed. ## What Was Observed A supervisor agent dispatched three `researcher` sub-agents in parallel to answer sub-questions Q1, Q2, Q3. Each sub-agent called a `web_search` tool and a `fetch_page` tool. The runtime assigned `agent_instance_id = sha1(session_id + ":" + agent_role)`. Because all three sub-agents shared `agent_role="researcher"` and the same `session_id`, all three resolved to the **same** `agent_instance_id`. Structural signals in the exported telemetry: 1. **Parent-span multiplicity.** A single `parent_agent_span_id` (the shared researcher identity span) had three concurrent children of type `tool_call:web_search`, with overlapping `start_time`/`end_time` intervals. A single agent context cannot issue three simultaneous blocking tool calls unless it is explicitly parallel-tool-calling — and the runtime had parallel tool use disabled for that role. Overlapping sibling tool spans under one agent span is the primary structural tell. 2. **Argument/result cross-contamination in the lineage.** The `web_search` span carrying query `"Q1 funding history"` had a child `fetch_page` span whose `parent_span_id` pointed at the *Q2* researcher's `web_search` span — because the runtime's "last active tool span in this agent context" pointer was shared across the collided identity. The reconstructed chain read: *search Q1 → fetch a page retrieved for Q2*. Semantically incoherent, structurally valid. 3. **Token-accounting non-conservation.** Summed `gen_ai.usage.input_tokens` across the three collided researcher spans exceeded the supervisor's recorded delegation budget, and per-`agent_instance_id` token totals were non-monotonic across the session (a later span reported fewer cumulative tokens than an earlier one under the same identity). Cumulative counters keyed on a non-unique identity cannot be monotonic. 4. **Orphaned-on-arrival spans.** Two `fetch_page` spans arrived at the collector *before* their nominal parent `web_search` span, and because the backend's parent-resolution is best-effort with a 30s window, they were initially attached to a *prior* session's researcher span that happened to share the same collided identity — cross-session bleed. ## Condition of Validity The correlation is only trustworthy when all of the following hold: - `agent_instance_id` is **globally unique per execution context**, not derived from `(session, role)`. It must be minted at spawn time (e.g., a UUID or a monotonic spawn ordinal scoped to the supervisor span) and propagated as baggage, not recomputed at emit time. - The runtime propagates `parent_span_id` explicitly through the call stack / context object, rather than resolving "current parent" from a shared mutable pointer keyed on agent identity. - Sibling spans under one parent are permitted to overlap **only** if the parent span carries an explicit `parallel_tool_calls=true` attribute; absent that attribute, overlapping children are a lineage-integrity violation. - Cumulative counters (tokens, tool-call count) are keyed on the unique instance id and are monotonic within that id. If any of these is violated, downstream lineage reconstruction is unsound regardless of per-span schema validity. ## Decision Boundary The operational decision is: **when does a lineage anomaly justify quarantining a trace from audit/replay versus flagging it as benign concurrency?** - **Quarantine (treat trace as non-replayable):** overlapping sibling tool spans under one agent span *without* `parallel_tool_calls=true`; a child span whose semantic arguments contradict its parent's (query/result mismatch across the parent edge); non-monotonic cumulative counters under one `agent_instance_id`; a span whose parent resolves to a different `session_id`. - **Flag only:** overlapping siblings with `parallel_tool_calls=true`; out-of-order arrival that resolves within the parent-resolution window to the *correct* parent; single non-monotonic counter reading attributable to a known export retry (dedupe by `span_id` first). - **Ignore:** clock skew alone; missing optional attributes. The boundary is *semantic parent-child coherence*, not timestamp ordering and not schema validity. A schema-valid, time-ordered trace can still be a corrupted lineage. ## Operational Effect When this invariant is unenforced, three concrete downstream effects occur: (a) auditor replay reconstructs a reasoning chain that interleaves independent sub-agents, producing false attributions of a bad tool result to the wrong sub-question; (b) per-agent cost and token budgets are mis-billed because the collided identity aggregates concurrent siblings; (c) cross-session bleed via late-arriving parent resolution contaminates a *prior* session's record, which is unrecoverable once the collector has committed the parent edge. The guardrail is to mint instance identity at spawn, propagate parentage as baggage, gate overlapping siblings on an explicit parallel-tool attribute, and reject parent edges that cross a `session_id` boundary at ingest. ```python import hashlib from dataclasses import dataclass from typing import Optional class LineageIntegrityError(RuntimeError): """Raised when a tool-call span's correlation tuple is not unique/coherent.""" pass @dataclass class Span: span_id: str parent_span_id: Optional[str] session_id: str agent_instance_id: str agent_role: str kind: str start: float end: float parallel_tool_calls: bool = False cumulative_tokens: Optional[int] = None semantic_key: Optional[str] = None # e.g., query string def derive_instance_id(session_id: str, role: str) -> str: # The buggy derivation: collides across concurrent same-role siblings. return hashlib.sha1(f"{session_id}:{role}".encode()).hexdigest() def validate_lineage(spans: list[Span]) -> None: by_id = {s.span_id: s for s in spans} # 1. Parent must exist and share session. for s in spans: if s.parent_span_id is None: continue parent = by_id.get(s.parent_span_id) if parent is None: continue if parent.session_id != s.session_id: raise LineageIntegrityError( f"span {s.span_id} parent crosses session boundary " f"({parent.session_id} != {s.session_id})" ) if (s.semantic_key and parent.semantic_key and s.semantic_key != parent.semantic_key and s.kind == "fetch_page" and parent.kind == "web_search"): raise LineageIntegrityError( f"semantic parent-child mismatch: {s.span_id} " f"({s.semantic_key}) under {parent.span_id} ({parent.semantic_key})" ) # 2. Overlapping siblings under one agent span require explicit parallel flag. for parent in spans: if parent.kind != "agent": continue children = [c for c in spans if c.parent_span_id == parent.span_id and c.kind.startswith("tool_call")] for i in range(len(children)): for j in range(i + 1, len(children)): a, b = children[i], children[j] overlap = a.start < b.end and b.start < a.end if overlap and not parent.parallel_tool_calls: raise LineageIntegrityError( f"overlapping tool spans {a.span_id},{b.span_id} " f"under {parent.span_id} without parallel_tool_calls=true" ) # 3. Cumulative counters monotonic per unique instance id. per_instance: dict[str, list[Span]] = {} for s in spans: if s.cumulative_tokens is not None: per_instance.setdefault(s.agent_instance_id, []).append(s) for iid, group in per_instance.items(): group.sort(key=lambda s: s.start) for prev, cur in zip(group, group[1:]): if cur.cumulative_tokens < prev.cumulative_tokens: raise LineageIntegrityError( f"non-monotonic tokens for instance {iid}: " f"{prev.cumulative_tokens} -> {cur.cumulative_tokens}" ) def assert_unique_instances(spans: list[Span]) -> None: # Collision detector: two distinct agent spans sharing one instance id # while not being the same span is a derivation bug. seen: dict[str, str] = {} for s in spans: if s.kind != "agent": continue prior = seen.get(s.agent_instance_id) if prior is not None and prior != s.span_id: raise LineageIntegrityError( f"agent identity collision: {s.agent_instance_id} " f"maps to spans {prior} and {s.span_id}" ) seen[s.agent_instance_id] = s.span_id ```