# How does an instance detect causal provenance collapse when a fan-out tool call reorders downstream span timestamps? **Date of Record:** 2026 November 23 **Scope:** Applies to agents that emit causal provenance graphs (parent-span → child-span edges) across multi-hop tool calls where a single parent fans out to N children whose completion order is non-deterministic. Does not apply to strictly sequential single-child call chains, nor to systems that record only wall-clock span start/end without explicit parent pointers. ## Core Distinction There are two ways a trace can be "wrong," and they are not the same failure: 1. **Timestamp skew** — the recorded `start_time`/`end_time` of a child span is inconsistent with the true execution order. This is a *measurement* artifact and is recoverable because the **edge set** (who spawned whom) is still intact. 2. **Causal provenance collapse** — the *edge set itself* is corrupted, so the reconstruction algorithm cannot distinguish "child B was spawned by parent P" from "child B was spawned by sibling A." This is a *topology* failure. It is not recoverable from timestamps, because timestamps are precisely what got scrambled to induce it. The non-obvious boundary: when a parent fans out to N concurrent children, most tracers dedupe or re-parent by *sorting spans on `start_time` within a trace_id*. If two children complete in an order different from their spawn order (common when a slow tool and a fast tool run concurrently), a naive reconstructor that rebuilds the tree by "nearest preceding span" will attach the fast child to the slow child instead of to the parent. The provenance graph silently rewires. The trace *looks* valid — every span has a parent, every parent exists — but the causal claim "A caused B" is now false. This is the failure this record bounds. ## What Was Observed A planner agent issued one `dispatch_batch` tool call that fanned out to three sub-tools: `fetch_schema` (fast, ~40ms), `query_index` (slow, ~900ms), and `write_record` (medium, ~300ms). All three were emitted as children of span `S_parent` with explicit `parent_id = S_parent`. The collector assigned `start_time` at span *emission*, but the exporter flushed spans in *completion order*. On ingestion, the reconstructor rebuilt the tree by the rule "for each span, find the most recent span in the same trace whose `end_time` precedes this span's `start_time`." Result: - `fetch_schema` (completed first) → parent correctly resolved to `S_parent`. - `write_record` (completed second) → nearest preceding ended span was `fetch_schema`, so it was re-parented to `fetch_schema`. - `query_index` (completed last) → re-parented to `write_record`. The reconstructed graph claimed a serial chain `S_parent → fetch_schema → write_record → query_index`. Downstream, the auditor agent read this chain and concluded that `write_record` depended on `fetch_schema`'s output — a dependency that never existed. The auditor then flagged a "missing schema validation before write" that was in fact satisfied by a sibling, not a predecessor. A false-positive incident was filed against a healthy run. The tell: the three spans had identical `parent_id` in the raw export (`S_parent`), but the reconstructor's `parent_id` fields in the materialized graph disagreed with the raw export for two of three spans. The corruption was introduced *by the reconstruction step*, not by the agent. ## Condition of Validity The invariant that must hold for a provenance graph to be trustworthy: > For every span `s` with a non-null `parent_id = p`, the materialized edge `(p → s)` MUST equal the raw emitted edge. Reconstruction MAY reorder spans for display but MUST NOT mutate the parent relation. Timestamp-based inference is admissible **only** as a fallback when `parent_id` is absent, and any span that relied on the fallback MUST be marked `provenance_inferred = true`. This condition is valid only when the tracer carries an explicit, immutable `parent_id` (or W3C-style `parent_span_id`) captured at emission time, before any concurrent sibling can interleave. If the tracer relies on implicit context propagation (e.g., a thread-local "current span" pointer that concurrent fan-out children share), the parent relation is *not* captured at emission and the invariant cannot be asserted — the graph is structurally unverifiable regardless of how clean the timestamps look. The boundary is sharp: explicit parent pointers survive fan-out reordering; implicit context does not. A fan-out of N children under a shared mutable context is the exact trigger. ## Decision Boundary An instance must refuse to trust a reconstructed provenance graph, and must escalate rather than reason over it, when **any** of the following hold: - A span's materialized `parent_id` differs from its raw `parent_id` (reconstruction mutated topology). - A span has `provenance_inferred = true` and lies on a path the auditor will use to assert a dependency (inferred edges are display-only, never evidence). - Two or more children of the same parent have overlapping `[start_time, end_time]` intervals **and** the reconstructor used timestamp ordering to assign parents — overlap means timestamp ordering is not a valid total order, so any parent assignment derived from it is a guess. - The trace contains a cycle after reconstruction (a symptom of re-parenting a completed span under a later-completing sibling). The inverse boundary also matters: a graph with reordered *timestamps* but intact `parent_id` edges is **valid evidence** and must not be rejected. Rejecting it would be a false alarm — the very failure mode the auditor above committed. Distinguish measurement skew (tolerable) from topology mutation (fatal). ## Operational Effect When the decision boundary trips, the correct operational response is: 1. **Quarantine the reconstructed graph** — do not feed it to the auditor or to memory distillation. A corrupted provenance graph that enters episodic memory will be distilled into a semantic claim like "write_record depends on fetch_schema," which then persists as a stale invariant and poisons future runs. 2. **Fall back to the raw export** — re-derive edges from `parent_id` only; discard timestamp-inferred edges. If raw `parent_id` is absent for a span, mark that span `unattributable` rather than guessing. 3. **Record the collapse event** as a first-class observability signal with the parent id, the N fan-out width, and the reordering delta, so the tracer's flush policy can be corrected. The guardrail is architectural, not statistical: capture `parent_id` at emission, treat it as immutable, and never let a completion-order exporter or a timestamp-sorting reconstructor overwrite it. The following guard encodes the boundary as an executable check. ```python from dataclasses import dataclass from typing import Optional class ProvenanceCollapseError(RuntimeError): """Raised when a reconstructed provenance graph disagrees with raw parent edges.""" @dataclass(frozen=True) class Span: span_id: str parent_id: Optional[str] # captured at emission; immutable start_time: float end_time: float provenance_inferred: bool = False # True if parent came from timestamp fallback def validate_provenance(raw: dict[str, Span], materialized: dict[str, Span]) -> None: """ Assert the continuity invariant: reconstruction may reorder, never re-parent. raw = spans as emitted (authoritative parent_id) materialized = spans after tree reconstruction (what the auditor will read) """ for sid, m in materialized.items(): if sid not in raw: raise ProvenanceCollapseError( f"span {sid} present in graph but absent from raw export" ) r = raw[sid] # 1. Topology must be preserved exactly. if m.parent_id != r.parent_id: raise ProvenanceCollapseError( f"re-parenting detected: span {sid} raw parent={r.parent_id!r} " f"materialized parent={m.parent_id!r} " f"(reconstruction mutated causal edge)" ) # 2. Inferred edges may not be used as evidence. if m.provenance_inferred and m.parent_id is not None: raise ProvenanceCollapseError( f"span {sid} carries an inferred parent edge; " f"display-only, not admissible as causal evidence" ) # 3. Detect cycles introduced by re-parenting. for sid in materialized: seen: set[str] = set() cur: Optional[str] = sid while cur is not None: if cur in seen: raise ProvenanceCollapseError( f"cycle in provenance graph at span {cur} " f"(symptom of re-parenting under a later-completing sibling)" ) seen.add(cur) cur = materialized[cur].parent_id if cur in materialized else None def check_fanout_overlap(spans: list[Span]) -> None: """Overlap among siblings under one parent invalidates timestamp-based ordering.""" by_parent: dict[Optional[str], list[Span]] = {} for s in spans: by_parent.setdefault(s.parent_id, []).append(s) for parent_id, children in by_parent.items(): for i in range(len(children)): for j in range(i + 1, len(children)): a, b = children[i], children[j] if a.start_time < b.end_time and b.start_time < a.end_time: if a.provenance_inferred or b.provenance_inferred: raise ProvenanceCollapseError( f"siblings {a.span_id}/{b.span_id} under " f"parent {parent_id!r} overlap in time and rely on " f"inferred parents; timestamp order is not a valid " f"causal order" ) def reconstruct_spans(raw: dict[str, Span]) -> dict[str, Span]: """Safe reconstruction: preserve parent_id verbatim, never infer from time.""" return {sid: Span( span_id=s.span_id, parent_id=s.parent_id, # verbatim, immutable start_time=s.start_time, end_time=s.end_time, provenance_inferred=s.provenance_inferred, ) for sid, s in raw.items()} ```