What happens when an instance attributes a LITMUS safety verdict to the wrong OTel span after a retried tool call

**Date of Record:** 2026 December 1 **Scope:** Applies to runtime observability pipelines that merge LITMUS-style safety verdicts (per-invocation policy evaluations emitted asynchronously by a separate evaluator) with OpenTelemetry GenAI traces (span trees emitted by the agent runtime). Does not apply to synchronous in-process guardrails that block before emission, nor to verdicts keyed by content hash rather than span identity.

Core Distinction

There are two distinct notions of "the thing a verdict is about": the *invocation* (a logical unit of model or tool execution the evaluator judged) and the *span* (the OTel record the runtime emitted for it). LITMUS verdicts are produced out-of-band by an evaluator that observes request/response payloads; OTel spans are produced in-band by the runtime. The merge key is almost always one of `trace_id` + `span_id`, `request_id`, or a payload hash. The invariant that must hold is: **a verdict may only be attached to the span whose payload the evaluator actually inspected.** This invariant silently breaks when the runtime retries a tool call or re-invokes a model under the *same* logical request id but a *new* span id, or vice versa, so that the evaluator's asynchronous verdict lands after the span it judged has already been superseded.

What Was Observed

A tool-calling agent issued a `search_documents` call. The runtime emitted span `S1` (span_id `0xA1`, request_id `req-77`). The tool returned a timeout at t+1.2s. The runtime's retry policy re-issued the call as span `S2` (span_id `0xB2`, same `request_id=req-77`, since the logical request was unchanged). `S2` succeeded at t+2.0s and the agent continued to completion.

The LITMUS evaluator, running asynchronously, had already pulled the payload of the *first* attempt (`req-77`, attempt payload containing a user-supplied document that tripped a prompt-injection policy). It emitted a `BLOCK` verdict at t+3.4s, keyed by `request_id=req-77`. The merge layer, seeing `req-77`, attached the `BLOCK` verdict to whichever span currently held that request id — `S2`, the successful retry — because `S1` had been closed and was no longer the "active" record for the key. The trace now read: successful retrieval span, safety verdict BLOCK, agent continued and produced output. Two failure modes in one: (a) the verdict was attributed to a payload the evaluator never saw, and (b) the runtime had already acted on the unsafe first attempt's content before the verdict arrived, but the trace showed the block on the *safe* span, so replay-based auditing concluded the retry path was unsafe when it was not.

The inverse also occurred in the same corpus: when the retry reused the same span id (some runtimes mutate the span in place), the evaluator's verdict for attempt 1 was attached to attempt 2's payload, and a genuinely unsafe retry was recorded as `ALLOW` because the evaluator had judged the earlier, benign payload.

Condition of Validity

The merge is only correct when the following conjunction holds:

  1. **Verdict keying is span-scoped, not request-scoped.** The evaluator must receive the exact `span_id` of the payload it inspected, and the merge must key on `(trace_id, span_id)`. If the evaluator can only see `request_id`, the merge is undefined under retry.
  2. **Attempt identity is immutable.** A retried invocation must produce a *new* span with a *new* span id and carry a distinct attempt ordinal (e.g., `gen_ai.attempt=2`); the original span must remain in the trace as a closed sibling, never overwritten.
  3. **The evaluator is told which attempt it is judging, or the payload is content-addressed.** If the evaluator keys on a hash of the exact request payload, retries with identical payloads collapse legitimately; retries with different payloads do not.
  4. **Verdict arrival ordering is not assumed.** The merge must tolerate a verdict arriving after the span closed, after the trace flushed, or after a child span was already emitted downstream.

Any retry mechanism, streaming re-invocation, or tool-call fallback that violates (1) or (2) makes the merged trace *actively misleading* rather than merely incomplete.

Decision Boundary

The operational choice is whether a late or ambiguous verdict should be (a) attached anyway, (b) quarantined, or (c) dropped. The boundary:

The critical boundary is the middle case: an ambiguous verdict is *not* a null result and *not* a span verdict. Treating it as either is the bug. A `BLOCK` that cannot be attributed is still a `BLOCK` for policy purposes even though it cannot be stamped on a span.

Operational Effect

Downstream consumers inherit the misattribution and amplify it. Replay-based auditors that reconstruct "did the agent proceed after a BLOCK?" read the stamped span and conclude the agent violated policy on the retry path — flagging a safe execution. Conversely, an unsafe retry whose verdict landed on the pre-retry span reads as compliant. Safety dashboards that count `BLOCK`-stamped spans undercount blocks that were quarantined or dropped, so the observed block rate diverges from the evaluator's true block rate, and the divergence is *correlated with retry frequency* — i.e., it grows exactly when the agent is under stress and retrying most. The invariant to enforce in the merge layer: **never write a verdict onto a span whose request payload hash differs from the verdict's, and never let a request-scoped key resolve to more than one open attempt without quarantining.** Encode this as a hard failure in the correlator so that a silent misattribution becomes a loud, catchable error at merge time rather than a plausible-looking trace.

from dataclasses import dataclass, field
from typing import Optional


class VerdictAttributionError(RuntimeError):
    """Raised when a LITMUS verdict cannot be provably attributed to an OTel span."""


@dataclass
class Span:
    trace_id: str
    span_id: str
    request_id: str
    attempt: int
    request_payload_hash: str
    closed: bool = False


@dataclass
class Verdict:
    trace_id: str
    request_id: str
    span_id: Optional[str]          # present only if evaluator saw span identity
    payload_hash: str
    decision: str                   # "ALLOW" | "BLOCK"
    emitted_at: float


@dataclass
class Correlator:
    spans: dict = field(default_factory=dict)          # (trace_id, span_id) -> Span
    by_request: dict = field(default_factory=dict)     # (trace_id, request_id) -> list[Span]
    quarantined: list = field(default_factory=list)

    def register(self, span: Span) -> None:
        self.spans[(span.trace_id, span.span_id)] = span
        self.by_request.setdefault((span.trace_id, span.request_id), []).append(span)

    def attach(self, verdict: Verdict) -> Span:
        # Path 1: span-scoped key, provable by payload hash.
        if verdict.span_id is not None:
            span = self.spans.get((verdict.trace_id, verdict.span_id))
            if span is None:
                raise VerdictAttributionError(
                    f"verdict for span {verdict.span_id} has no matching span "
                    f"(trace {verdict.trace_id}); cannot attach"
                )
            if span.request_payload_hash != verdict.payload_hash:
                raise VerdictAttributionError(
                    f"payload hash mismatch on span {verdict.span_id}: "
                    f"evaluator judged {verdict.payload_hash}, span recorded "
                    f"{span.request_payload_hash} (retry mutated span in place?)"
                )
            return span

        # Path 2: request-scoped key. Only safe if exactly one attempt exists.
        attempts = self.by_request.get((verdict.trace_id, verdict.request_id), [])
        if len(attempts) == 0:
            raise VerdictAttributionError(
                f"verdict references unknown request {verdict.request_id}"
            )
        if len(attempts) > 1:
            # Ambiguous: multiple attempts under one request id. Quarantine,
            # do NOT guess. This is the retry-attribution trap.
            self.quarantined.append(verdict)
            raise VerdictAttributionError(
                f"request {verdict.request_id} has {len(attempts)} attempts; "
                f"verdict {verdict.decision} quarantined rather than misattributed"
            )
        only = attempts[0]
        if only.request_payload_hash != verdict.payload_hash:
            raise VerdictAttributionError(
                f"single-attempt request {verdict.request_id} payload hash mismatch; "
                f"evaluator and runtime disagree on what was judged"
            )
        return only