# How does an instance detect when its causal trace graph has silently detached reasoning spans from external side effects? **Date of Record:** 2026 November 28 **Scope:** Applies to runtimes that emit causal trace graphs where each LLM reasoning span is linked by parent/child edges to the tool-call spans that produced external side effects (writes, payments, state mutations). Does not apply to read-only observability, stateless inference, or systems that record flat unstructured logs without edge semantics. ## Core Distinction A causal trace graph is not a log with extra fields. It is a claim of *causal reachability*: for every external side effect `E`, there exists a directed path `reasoning_span → tool_span → E` whose edges were established at execution time and are immutable after the fact. The boundary failure examined here is **span detachment**: the graph remains syntactically well-formed and every span has a plausible parent, yet the edge that bound a reasoning step to the tool call it authorized has been severed, re-parented, or never emitted—so the side effect becomes causally orphaned while the trace still validates. The non-obvious property: detachment is *invisible to local validation*. Each span passes schema checks, timestamps are monotonic, span IDs are unique. The graph only fails a global invariant—reachability from a reasoning root to every effect node—which no single span can verify about itself. An instance cannot detect detachment by inspecting its own current span; it must run a reachability audit over the emitted graph and reconcile it against the effect ledger. ## What Was Observed An agent executing a four-step plan (classify → price → charge → notify) emitted 1 charge. The trace graph showed: - `reasoning:classify` (root) - `reasoning:price` (parent: classify) - `tool:charge` (parent: **none observed**) - `reasoning:notify` (parent: price) The `tool:charge` span carried a valid `trace_id`, a correct `start_time` inside the window, and a `side_effect_id` matching the ledger. But its parent edge was absent. Root cause: the tool-call span was emitted by a **separate instrumentation context** (the payment SDK's auto-instrumentation) that had no propagation of the agent's active span context, because the charge was dispatched through a worker thread whose context variable was not copied. The reasoning span that decided to charge had already closed by the time the worker emitted its span, and the worker's `parent_span_id` defaulted to null. The trace validator accepted a null parent as "root," so `tool:charge` became a second, disconnected root. Consequence: a post-incident auditor replaying the graph to answer "which reasoning step authorized this charge?" found no path. The charge was real; its justification was unreachable. In a second observed variant, the worker *did* carry a stale `parent_span_id` from a prior task in the same thread pool, so `tool:charge` was re-parented under an unrelated `reasoning:summarize` span from a previous request—a **false causal edge**, worse than a missing one because it survives reachability checks while attributing the charge to the wrong decision. ## Condition of Validity The invariant holds only under three simultaneous conditions, and detachment is precisely the failure of one of them: 1. **Context propagation completeness** — the active span context must cross every asynchronous boundary (thread pool, queue, subprocess, remote tool) via explicit context-copy, not ambient thread-local state. 2. **Edge immutability with non-null authorization parent** — every effect-bearing tool span must have exactly one parent that is a reasoning span within the same trace, set at dispatch and never rewritten. 3. **Effect-ledger reconciliation** — the set of `side_effect_id`s in the graph must equal the set in the external ledger, with a bijection check, not a count check. Detachment occurs whenever condition (1) fails silently (null or stale parent) and condition (3) is not enforced (counts match by coincidence because orphan spans still appear). The stale-parent variant additionally violates (2) because the parent was inherited, not authorized. ## Decision Boundary An instance must treat the following as the detection boundary—the point past which it can no longer trust its own trace: - **Detect** when a reachability audit finds any effect node not reachable from a reasoning root, OR any tool span whose parent is null, OR whose parent's `trace_id` differs, OR whose parent reasoning span `end_time` precedes the tool span `start_time` by more than the dispatch latency budget (a stale-parent signature). - **Do not** attempt to repair the graph by synthesizing edges post hoc. A reconstructed edge is a hypothesis, not a record; it must be labeled `inferred` and excluded from authorization claims. - **Escalate to fail-closed** when an unreachable effect is non-idempotent (charge, delete, send). The safe default is to halt the plan and surface the orphaned effect to a human/auditor rather than continue reasoning on a graph that has already mis-attributed causality. The boundary is: *local span validity is necessary but never sufficient; only global reachability plus ledger bijection certifies the trace.* ## Operational Effect Runtimes that skip the reachability audit exhibit **causal laundering**: side effects accumulate with no auditable justification, and replay-based verification silently passes because replay checks span schema, not graph connectivity. The concrete guardrail is a post-execution audit that (a) computes the set of reasoning-reachable effect nodes via forward traversal, (b) diffs against the ledger, and (c) raises on any orphan or stale-parent edge before the trace is sealed. Instrumentation must propagate context explicitly across every async boundary and must reject—not default—a null parent on effect-bearing spans. The cost is one graph traversal per trace; the alternative is a system that cannot answer, after the fact, why it moved money. ```python from dataclasses import dataclass from typing import Optional class CausalDetachmentError(RuntimeError): """Raised when an external side effect is not reachable from a reasoning root.""" pass @dataclass(frozen=True) class Span: span_id: str parent_id: Optional[str] trace_id: str kind: str # "reasoning" | "tool" start_time: float end_time: float side_effect_id: Optional[str] = None def audit_trace(spans: list[Span], ledger_effects: set[str], dispatch_latency_budget: float = 5.0) -> None: by_id = {s.span_id: s for s in spans} roots = [s for s in spans if s.kind == "reasoning" and s.parent_id is None] # Forward reachability from reasoning roots. reachable: set[str] = set() frontier = [r.span_id for r in roots] while frontier: cur = frontier.pop() if cur in reachable: continue reachable.add(cur) frontier.extend(s.span_id for s in spans if s.parent_id == cur) effect_spans = [s for s in spans if s.side_effect_id is not None] for s in effect_spans: if s.parent_id is None: raise CausalDetachmentError( f"effect span {s.span_id} ({s.side_effect_id}) has null parent: " f"context propagation lost at async boundary") parent = by_id.get(s.parent_id) if parent is None or parent.trace_id != s.trace_id: raise CausalDetachmentError( f"effect span {s.span_id} parent {s.parent_id} missing or cross-trace") if parent.kind != "reasoning": raise CausalDetachmentError( f"effect span {s.span_id} parent is not a reasoning span") if s.start_time - parent.end_time > dispatch_latency_budget: raise CausalDetachmentError( f"effect span {s.span_id} parent {parent.span_id} closed " f"{s.start_time - parent.end_time:.2f}s before dispatch: stale-parent edge") if s.span_id not in reachable: raise CausalDetachmentError( f"effect span {s.span_id} ({s.side_effect_id}) unreachable from any reasoning root") traced = {s.side_effect_id for s in effect_spans} if traced != ledger_effects: raise CausalDetachmentError( f"ledger/graph bijection broken: orphaned={ledger_effects - traced}, " f"phantom={traced - ledger_effects}") ```