Under what conditions must an instance treat a semantic trace span as authoritative when its parent span was re-emitted after a retry, and how does causal-link collapse corrupt safety attribution?
**Date of Record:** 2026 December 2 **Scope:** Applies to runtime observability pipelines that reconstruct causal chains across prompt → retrieval → tool invocation → safety decision using span IDs, parent IDs, and trace IDs emitted by instrumented agent instances. Does not apply to single-turn, single-span inference calls with no retry, no fan-out, and no safety gate downstream of the tool layer.
Core Distinction
There are two distinct meanings of "the same operation" in a semantic trace, and conflating them is the root of the failure:
- **Logical operation identity** — the agent's intent to invoke a tool, retrieve a document, or evaluate a safety policy exactly once, as reasoned about by the planner.
- **Physical span identity** — the emitted telemetry record, which is regenerated every time the runtime retries, resumes from a checkpoint, or replays a tool call after a timeout.
A trace backend that keys causal reconstruction on *span ID* rather than on a stable *logical operation ID* will silently collapse two or more physical spans into one causal node whenever a retry re-emits a span with the same parent. The surviving span carries the *last* emitted safety decision, not the decision that actually gated the tool output that reached the user. The trace looks complete. It is causally wrong.
The invariant that must hold: **for every span that gates an externally observable effect (tool side effect, user-visible output, safety block), exactly one span in the trace must be marked `effect_committed=true`, and every re-emitted sibling must be marked `superseded=true` with a monotonic `attempt_index`.** Absent this, causal attribution is non-deterministic and safety decisions detach from the effects they were supposed to authorize.
What Was Observed
A retrieval-augmented agent was instrumented with OpenTelemetry-style spans: `prompt.build` → `retrieval.query` → `tool.invoke` → `safety.evaluate` → `response.emit`. The tool layer (`tool.invoke`) had a 3-second deadline; on timeout the runtime re-issued the call with the *same* `parent_span_id` (the `retrieval.query` span) but a *new* `span_id`, because the instrumentation library generated span IDs at call time.
During a load test, `retrieval.query` exceeded its budget and the agent retried the downstream chain. The trace backend (Jaeger-compatible, keyed by `(trace_id, span_id)`) ingested:
- Attempt 0: `tool.invoke` span `A0`, `safety.evaluate` span `S0` → decision `ALLOW`.
- Attempt 1: `tool.invoke` span `A1`, `safety.evaluate` span `S1` → decision `BLOCK` (the retried retrieval returned a document containing an injected instruction; the safety classifier caught it on the second pass).
Both `S0` and `S1` share parent `A0`/`A1` which share parent `retrieval.query`. The backend's causal-chain view, when queried by "what safety decision gated the response for trace T," returned the *first* matching descendant (`S0`, `ALLOW`) because it sorted by ingestion timestamp and the retry was ingested later but the query joined on the earliest child. The response that actually reached the user was gated by `S1` (`BLOCK`) — the tool output was suppressed. The trace, however, asserted `ALLOW`. An auditor replaying the trace reconstructed a causal chain in which a blocked tool output was attributed as allowed.
The failure is not "the trace is incomplete." The trace contained every span. The failure is that **the causal edge `retrieval.query → tool.invoke → safety.evaluate → response.emit` is a DAG in the logical model but a multigraph in the physical model, and the backend projected it to a simple path by dropping parallel edges.** The dropped edge carried the safety decision that mattered.
A second-order observation: `safety.evaluate` spans `S0` and `S1` had *different* inputs (different retrieved document) but *identical* `parent_span_id` semantics from the backend's perspective, because the backend did not carry the retrieval content hash forward. There was no field on the span that said "this safety evaluation saw document D1, not D0." The safety decision was therefore unattributable to its actual input.
Condition of Validity
The failure requires all of the following to co-occur:
- **Retry with parent reuse.** The runtime re-emits a downstream span under an unchanged parent, rather than emitting a new parent (`retrieval.query.retry`) that owns the retried children. This is the default behavior of most auto-instrumentation SDKs, which treat retries as transport-level concerns invisible to the span tree.
- **Non-idempotent downstream decision.** The retried operation produces a *different* safety decision than the original. If both attempts yield `ALLOW`, collapse is harmless. The failure is only observable when the decision diverges — which is precisely when observability matters.
- **Causal reconstruction by span-ID join.** The backend or query layer reconstructs causality by joining `parent_span_id = span_id` and does not carry a logical-operation discriminator. This is the default for most trace UIs.
- **No content-hash linkage.** The safety span does not record a hash of the input it evaluated, so the backend cannot detect that `S0` and `S1` evaluated different payloads.
If any one condition is absent, the trace remains causally faithful. The dangerous configuration is the *default* configuration: retries are transparent, span IDs are call-scoped, joins are ID-based, and safety spans record only their verdict.
Decision Boundary
The boundary is not "should we retry" — retries are necessary. The boundary is **at what point does a re-emitted span stop being a sibling and start being a superseding attempt that must invalidate its predecessor's causal authority.**
The rule an instance must apply:
- If a span is re-emitted under an unchanged parent *and* the downstream effect is committed (tool side effect, user-visible output), the prior span MUST be marked `superseded=true` and the new span MUST carry `attempt_index = prior.attempt_index + 1` and `effect_committed=true`.
- If a span is re-emitted under an unchanged parent *and* the downstream effect is NOT committed (pure read, no side effect), the spans may remain siblings, but the causal query MUST aggregate them as a set, not pick one.
- A safety decision span MUST carry `input_hash` of the exact payload it evaluated. Two safety spans with different `input_hash` under the same logical operation are not interchangeable; the backend MUST refuse to answer "what decision gated this effect" with a single span unless exactly one span has `effect_committed=true`.
The boundary case that breaks naive implementations: **the retry that flips the verdict.** When attempt 0 is `ALLOW` and attempt 1 is `BLOCK`, and the effect was committed on attempt 1's gating, the trace must show a single committed path ending in `BLOCK`, with attempt 0 explicitly superseded. If the backend cannot represent supersession, it must fail closed — refuse to attribute — rather than attribute to the first-ingested span.
Operational Effect
When the invariant is violated, three concrete operational failures follow:
- **Safety attribution inversion.** Auditors replay the trace and conclude a blocked output was allowed (or vice versa). Post-incident review reconstructs a causal chain that never executed. The trace is not merely lossy; it is *actively misleading*, which is worse than absence.
- **Replay divergence.** Deterministic replay from the trace produces a different execution than the original, because the replay engine follows the collapsed edge to `S0` (`ALLOW`) and proceeds past a gate that actually halted. Replay-based regression testing silently loses the safety case.
- **Metric poisoning.** "Safety block rate" computed from trace spans undercounts blocks by the retry-flip rate, because the collapsed span reports the first verdict. The metric drifts toward apparent permissiveness exactly when the system is catching more.
The guardrail is a **logical operation ID** minted at the planner layer, propagated unchanged across all retries, and required on every span that participates in an effect-gating chain. The trace backend must join on `logical_op_id` and enforce the single-committed-span invariant before answering any causal query. Instrumentation that mints span IDs at call time without a logical-op discriminator cannot satisfy this and must be treated as non-authoritative for safety attribution.
from dataclasses import dataclass, field
from typing import Optional
class CausalAttributionError(RuntimeError):
"""Raised when a semantic trace cannot yield a single authoritative
safety decision for a committed effect."""
pass
@dataclass
class Span:
span_id: str
parent_span_id: Optional[str]
logical_op_id: str
attempt_index: int = 0
superseded: bool = False
effect_committed: bool = False
input_hash: Optional[str] = None
verdict: Optional[str] = None
def resolve_gating_decision(spans: list[Span], logical_op_id: str) -> Span:
"""Return the single span that authoritatively gated the committed effect
for a logical operation. Fail closed on ambiguity."""
candidates = [s for s in spans if s.logical_op_id == logical_op_id]
if not candidates:
raise CausalAttributionError(
f"no spans for logical_op_id={logical_op_id!r}; trace is incomplete"
)
committed = [s for s in candidates if s.effect_committed and not s.superseded]
if len(committed) == 0:
raise CausalAttributionError(
f"logical_op_id={logical_op_id!r} has no committed, non-superseded span; "
f"causal chain is unattributable (retry collapse suspected)"
)
if len(committed) > 1:
raise CausalAttributionError(
f"logical_op_id={logical_op_id!r} has {len(committed)} committed spans; "
f"supersession invariant violated"
)
winner = committed[0]
# Verify no superseded sibling carries a divergent verdict without a
# distinguishing input_hash — that is the retry-flip collapse signature.
for s in candidates:
if s is winner:
continue
if s.verdict is not None and s.verdict != winner.verdict:
if s.input_hash is None or winner.input_hash is None:
raise CausalAttributionError(
f"verdict divergence between span {s.span_id} ({s.verdict}) and "
f"committed span {winner.span_id} ({winner.verdict}) without "
f"input_hash linkage; cannot prove which payload was gated"
)
if s.input_hash == winner.input_hash:
raise CausalAttributionError(
f"same input_hash but divergent verdicts across attempts for "
f"logical_op_id={logical_op_id!r}; non-deterministic safety gate"
)
return winner