# How does an instance detect the divergence between prompt lineage and tool-invocation causality in GenAI observability pipelines **Date of Record:** 2026 November 18 **Scope:** Applies to observability pipelines that reconstruct end-to-end traces by correlating prompt lineage (parent prompt → child prompt via chain/agent hops) with tool-invocation spans and safety-intervention events emitted by separate subsystems (guardrails, policy engines, moderation services). Does not apply to single-hop inference logging without tool calls, nor to pipelines where all three event classes share a single synchronous emitter with a common clock. ## Core Distinction Prompt lineage is a *logical* parent-child relation: prompt B was derived from prompt A, possibly across an agent hop, a retry, or a re-prompt after a safety block. Tool-invocation causality is a *physical* happens-before relation: the tool call was issued by a specific model turn, executed by a runtime, and returned before the next turn began. These two graphs are usually assumed isomorphic — the lineage edge A→B is assumed to imply the tool span B is causally downstream of the tool spans of A. That assumption fails at exactly one boundary: **re-prompting after a safety intervention**. When a guardrail blocks turn N and the orchestrator re-issues the prompt with a modified context, the new prompt carries the *same lineage parent* as the blocked one (it was derived from the same user turn), but its tool spans are causally *after* the intervention event, not parallel to it. A correlator that joins on lineage parent id will attach the post-intervention tool spans to the pre-intervention trace segment, producing a trace where a tool call appears to have executed before the block that caused its re-issuance. ## What Was Observed In a production agent pipeline emitting three event streams — `prompt.lineage` (parent_id, child_id, derivation_reason), `tool.invoke` (span_id, turn_id, issued_at, completed_at), and `safety.intervention` (turn_id, verdict, action) — a nightly reconciliation job flagged 0.7% of multi-turn traces as containing a tool span whose `issued_at` preceded the `safety.intervention` event on the same `turn_id`, yet whose `span_id` appeared only in the post-intervention lineage branch. Manual inspection of 40 such traces showed the invariant violation was always the same shape: the orchestrator reused `turn_id` across the blocked attempt and the retry, so `tool.invoke` events from the retry were keyed to the same turn as the intervention that triggered them. The lineage stream was correct; the tool stream was correct; the *correlation key* (`turn_id`) was not unique per attempt, and the intervention event had no field distinguishing "the attempt that was blocked" from "the attempt that ran after the block." The failure is silent under normal load. It only surfaces when a guardrail fires, which is rare enough that the join produced plausible-looking traces for weeks. The observable symptom is not an error but a *causality inversion*: a tool execution timestamped before the safety verdict that authorized its re-issuance. ## Condition of Validity The inversion is detectable, and the detection is sound, only under these conditions: 1. The `safety.intervention` event carries a monotonic `verdict_at` timestamp from the same clock domain as `tool.invoke.issued_at` (or the two are reconciled via a known offset with bounded skew). 2. The orchestrator, on re-prompt, emits a *new* `prompt.lineage` edge (parent = original user turn, child = retry prompt) rather than mutating the original. If it mutates in place, the pre-intervention lineage is destroyed and the inversion is unrecoverable from logs alone. 3. `turn_id` is treated as a *correlation hint*, not a primary key. The detector must not assume uniqueness. When condition 2 fails, no post-hoc detector can distinguish a retry from a parallel branch; the record is ambiguous and must be flagged as `UNRECONCILABLE` rather than `INVERTED`. ## Decision Boundary The boundary between a benign correlation artifact and a real causality violation is whether the tool span's `issued_at` is strictly before the intervention's `verdict_at` **while** the span's lineage parent is the retry child. If the span belongs to the *blocked* attempt (parent = original prompt) and predates the verdict, that is normal — the tool ran, then the guardrail fired on the model output. If the span belongs to the *retry* attempt (parent = retry child) and predates the verdict, that is impossible under correct orchestration and indicates either a clock-domain mismatch or a reused `turn_id` collapsing two attempts. The detector must resolve which lineage branch owns the span before deciding; joining on `turn_id` alone will misclassify both cases. ## Operational Effect Once the detector is deployed, the pipeline reclassifies the 0.7% as `TURN_ID_COLLISION` rather than `CAUSALITY_VIOLATION`, and the orchestrator is patched to mint a fresh `attempt_id` per re-prompt. The observability invariant that survives is: **for any tool span, `issued_at` must be ≥ the `verdict_at` of every safety intervention whose retry branch owns that span.** This is checkable at ingest time in O(1) per span and catches the boundary failure before it corrupts downstream trace reconstruction. ```python from dataclasses import dataclass from typing import Optional class LineageCausalityError(RuntimeError): """Raised when a tool span's issuance predates the safety verdict that authorized its lineage branch, indicating a turn_id collision or a clock-domain mismatch in the observability pipeline.""" @dataclass(frozen=True) class ToolSpan: span_id: str turn_id: str lineage_parent: str issued_at: float @dataclass(frozen=True) class SafetyIntervention: turn_id: str verdict_at: float retry_child_id: str def check_span_causality( span: ToolSpan, interventions: list[SafetyIntervention], clock_skew_bound: float = 0.050, ) -> None: for iv in interventions: if iv.turn_id != span.turn_id: continue owns_retry_branch = span.lineage_parent == iv.retry_child_id if not owns_retry_branch: # Span belongs to the blocked attempt; pre-verdict issuance is expected. continue if span.issued_at < iv.verdict_at - clock_skew_bound: raise LineageCausalityError( f"span {span.span_id} on turn {span.turn_id} issued at " f"{span.issued_at} precedes verdict at {iv.verdict_at} " f"but is owned by retry branch {iv.retry_child_id}; " f"likely turn_id collision or clock-domain mismatch" ) ```