# In what scenarios must an instance treat a causal trace graph as unsound when tool side effects are observed before their causally preceding retrieval node **Date of Record:** 2026 November 25 **Scope:** Applies to agents whose observability layer reconstructs a directed acyclic causal trace graph from (prompt → retrieval → reasoning → tool-call → side-effect) spans, where side-effect observation timestamps are derived from external systems (DB write logs, HTTP request receipts, filesystem mtimes) rather than from the agent's own span emitter. Does not apply to purely in-process traces where all span timestamps originate from a single monotonic clock. ## Core Distinction There are two fundamentally different questions an observability system asks of a trace graph. The first is *attribution*: which prompt and which retrieval node caused this tool side effect? The second is *ordering soundness*: is the partial order encoded by the graph consistent with physical reality? Most agent observability stacks conflate these. They build the graph from the agent's own span emitter — which emits a `tool_call` span, then a `tool_result` span, then attaches the external side-effect record — and they assume the DAG's topological order matches wall-clock causality. The non-obvious failure is that **external side effects can be observed with a timestamp earlier than the retrieval node that causally produced them**, and the trace graph will still be internally consistent as a DAG. When this happens, the graph is *attributively correct but temporally unsound*, and any downstream analysis that trusts topological order as time order — replay, blame assignment, causal counterfactual ("what if retrieval R had returned different chunks?") — silently produces wrong answers. The invariant that must hold is not "the DAG is acyclic" but "every side-effect node's observed-at timestamp is ≥ the completion timestamp of every ancestor span, modulo a declared clock-skew bound." Acyclicity is necessary and insufficient. ## What Was Observed A retrieval-augmented agent was tasked with reconciling invoice records against a vendor ledger. The trace for one episode showed the following span sequence as emitted by the agent's own emitter (all timestamps from the agent's monotonic clock, microseconds): - `prompt_span` started at t=0, completed t=4,200 - `retrieval_span` (vector query, top-k=8) started t=4,210, completed t=118,900 - `reasoning_span` started t=118,950, completed t=402,300 - `tool_call_span` (`ledger.write_adjustment`) started t=402,350, completed t=409,100 - `tool_result_span` completed t=409,150 The external ledger system, however, logged the `write_adjustment` side effect with an `observed_at` of t=97,400 (in the same clock domain, after NTP correction). That is: the side effect landed **21.5 ms before the retrieval span completed**. The trace graph, as constructed, placed the side-effect node as a child of `tool_call_span`, which is a descendant of `retrieval_span` — so the DAG was acyclic. But the side-effect node's timestamp preceded its own grandparent's completion. The root cause was a **vector store that returned partial results under a soft timeout**. The retrieval client had a 100 ms soft deadline; when the index shard was cold, it returned the first 6 of 8 chunks at t=97,000 and the remaining 2 at t=118,800, but the agent's retrieval span only closed when the *last* chunk arrived. The reasoning span began at t=118,950 with all 8 chunks, but the tool call was actually triggered by a *partial* reasoning pass that had already seen the first 6 chunks — a speculative execution path the agent's emitter did not model as a separate span. The ledger write was issued from that speculative path at t=97,300, and the agent's emitter, seeing only the final consolidated reasoning span, attributed the write to the *completed* retrieval. The trace looked clean. The attribution ("retrieval R caused write W") was defensible for the final decision. But the **causal counterfactual was wrong**: replaying the trace with retrieval R's chunks removed would have predicted no ledger write, when in fact a write had already been committed based on 6 of those 8 chunks before the 8-chunk retrieval completed. ## Condition of Validity The trace graph is sound as a causal record only if, for every side-effect node `S` and every ancestor span `A` in the DAG, the condition ``` observed_at(S) >= completed_at(A) - epsilon_clock ``` holds, where `epsilon_clock` is the declared maximum clock skew between the agent's emitter and the external system that observed `S` (typically NTP-bounded, ~1–50 ms). This is a *temporal containment* invariant on the transitive ancestor set, not just on the immediate parent. Checking only the parent edge is insufficient: in the observed episode, `observed_at(S) = 97,400` was greater than `completed_at(tool_call_span) = 409,100`? No — it was less, but the immediate-parent check was skipped because the emitter stamped the side-effect record with the *tool_call span's* clock at attach time, not the external `observed_at`. The emitter normalized the external timestamp to its own clock using the tool_call completion as the anchor, which is precisely the lossy step. The invariant is also conditional on the retrieval client being *non-speculative*: if the retrieval layer can return partial results that feed downstream reasoning before the span closes, the emitter must model the partial return as its own span, or the temporal containment invariant is unenforceable because the causal parent of the side effect is a span that was never emitted. ## Decision Boundary An instance must **refuse to use the trace graph for causal counterfactual analysis or blame assignment** — and must instead flag the episode as `TRACE_TEMPORALLY_UNSOUND` — when any of the following hold: 1. Any side-effect node's external `observed_at` precedes the `completed_at` of any transitive ancestor by more than `epsilon_clock`. 2. The retrieval client is configured with a soft deadline or partial-return mode and the trace contains no `partial_result` span between retrieval start and retrieval completion. 3. The tool-call span's `started_at` is later than the side-effect's `observed_at` (the call was issued before its own span opened — a speculative-execution signature). Below this boundary (all checks pass), the graph may be used for attribution and replay. Above it, the graph is still useful for *what happened* (the write occurred, the chunks were retrieved) but not for *why* or *what if* — because the partial-order-to-time-order mapping is broken and the counterfactual replay will diverge from the actual execution path. The subtlety is that the boundary is **per-episode, not per-agent**. An agent can produce sound traces for 9,000 episodes and one unsound trace when a shard goes cold. Operators who sample-audit traces rather than checking the invariant on every episode will miss it, because the unsound trace is acyclic and attributively plausible. ## Operational Effect When the unsound trace was used for a post-incident review, the team concluded the erroneous ledger adjustment was caused by a chunk that had, in fact, arrived *after* the adjustment was written. The corrective action — "tighten the retrieval filter for that vendor" — was applied to the wrong node. The actual cause was the speculative path acting on 6 chunks with a stale vendor-status field that the 7th and 8th chunks would have corrected. The fix that mattered was to disable partial-return on the retrieval client for ledger reconciliation, or to emit a `partial_result` span so the speculative path became visible. The architectural guardrail is a **temporal containment checker** that runs at trace-write time, not at analysis time, and rejects or annotates any episode violating the invariant. It must compare external `observed_at` against the *transitive* ancestor set's `completed_at`, not the parent edge, and it must require retrieval clients to declare whether they can return partial results. A trace that fails the check is still persisted but tagged `temporal_soundness=false`, and every downstream consumer (replay engine, blame attributor, counterfactual sampler) is required to check that tag before trusting topological order as time order. ```python from dataclasses import dataclass from typing import Sequence EPSILON_CLOCK_US = 50_000 # declared max skew between emitter and external observer class TraceTemporalUnsoundnessError(RuntimeError): """Raised when a causal trace graph's side-effect ordering violates temporal containment.""" @dataclass(frozen=True) class Span: span_id: str parent_id: str | None started_at_us: int completed_at_us: int @dataclass(frozen=True) class SideEffect: span_id: str # the tool_call span that produced it observed_at_us: int # from the external system, NOT the emitter clock def assert_temporal_containment( spans: Sequence[Span], effects: Sequence[SideEffect], epsilon_clock_us: int = EPSILON_CLOCK_US, ) -> None: by_id = {s.span_id: s for s in spans} def ancestors(span_id: str) -> list[Span]: chain, cur = [], by_id.get(span_id) while cur is not None and cur.parent_id is not None: cur = by_id.get(cur.parent_id) if cur is None: break chain.append(cur) return chain for eff in effects: call = by_id.get(eff.span_id) if call is None: raise TraceTemporalUnsoundnessError( f"side effect references unknown span {eff.span_id!r}" ) # Speculative-execution signature: call issued before its own span opened. if eff.observed_at_us < call.started_at_us - epsilon_clock_us: raise TraceTemporalUnsoundnessError( f"side effect {eff.span_id!r} observed at {eff.observed_at_us} " f"precedes its tool_call span start {call.started_at_us} " f"(speculative execution, not modeled as a span)" ) for anc in ancestors(eff.span_id): if eff.observed_at_us < anc.completed_at_us - epsilon_clock_us: raise TraceTemporalUnsoundnessError( f"side effect {eff.span_id!r} observed at {eff.observed_at_us} " f"precedes ancestor {anc.span_id!r} completion " f"{anc.completed_at_us} by more than epsilon={epsilon_clock_us}; " f"trace is attributively plausible but temporally unsound" ) ```