# Under what conditions must an instance reconcile LITMUS safety-failure spans with OpenTelemetry GenAI semantic conventions before emitting telemetry **Date of Record:** 2026 November 22 **Scope:** Applies to agent runtimes that instrument LITMUS-style safety benchmark verdicts (harm-refusal, jailbreak resistance, tool-misuse, prompt-injection containment) and export them as OpenTelemetry `gen_ai.*` spans. Does not apply to raw log shipping or to non-agentic batch scoring where no span lifecycle exists. ## Core Distinction LITMUS verdicts are *categorical, post-hoc, and benchmark-scoped*: a probe either elicited a violation or it did not, and the verdict is produced after a scoring pass over a transcript. OpenTelemetry GenAI events are *streaming, span-scoped, and lifecycle-bound*: a span opens at invocation, accumulates attributes, and closes on completion, and the semantic conventions constrain what a `gen_ai` span may legally carry. The failure mode lives precisely at the seam: a LITMUS failure is often discovered *after* the GenAI span it refers to has already been closed and exported. The non-obvious boundary is that a closed span is immutable — you cannot retroactively attach a `litmus.failure` verdict to a span that has already crossed the exporter boundary. Naively "mapping" LITMUS failures onto GenAI events therefore silently drops the failure, because the observable exists only as a dangling reference to a span ID that the collector has already sealed. The invariant that must hold: **every LITMUS failure verdict must be representable as a span that was still open at the moment the verdict was assigned, or as an explicitly linked parentless span that carries the original trace context.** Violating this does not raise an error — it produces a *clean* telemetry stream that under-reports safety failures, which is the worst possible failure shape for a safety benchmark. ## What Was Observed An agent harness ran a LITMUS jailbreak-resistance suite against a tool-using agent. Each probe invocation produced a `gen_ai.chat` span with `gen_ai.operation.name=chat`, `gen_ai.request.model`, and `gen_ai.usage.*` attributes. Scoring ran as a separate offline pass reading the transcript store, emitting verdicts 200–900 ms after each span closed. The mapping layer was written to attach verdicts as span events: on verdict, it looked up the span by `trace_id`/`span_id` from the transcript record and called `span.add_event("litmus.verdict", {...})`. Against a live collector this appeared to work — the SDK accepted the call without exception. But the span had already been ended and flushed. The SDK's `NonRecordingSpan` (returned for ended spans) silently no-ops `add_event`. Result: zero `litmus.verdict` events reached the backend for any probe whose scoring latency exceeded the span's export flush window. The dashboard showed 100% pass rate on a suite where 14% of probes had produced violations. The telemetry was not corrupted; it was *absent in the failure direction only*, because passing probes generated no verdict event to lose. A second, subtler trace: for the probes whose verdicts *did* land (scoring fast enough to beat the flush), the event was attached to a span whose `gen_ai.operation.name` was `chat`, and the collector's GenAI semantic-convention validator rejected unknown event attributes prefixed with anything other than the registered `gen_ai` namespace under strict mode, dropping the event at the processor. ## Condition of Validity The mapping is only valid when three conditions hold simultaneously: 1. **Span-liveness:** the target GenAI span is still recording (not ended, not flushed) at verdict-assignment time, OR the verdict is emitted as a new span that carries an explicit `SpanContext` link back to the original `trace_id`/`span_id`. 2. **Namespace legality:** the verdict event's attributes conform to the collector's GenAI convention profile — either placed under a registered namespace or the collector is configured to pass through a declared custom namespace (`litmus.*`) rather than drop it. 3. **Directional completeness:** the emission path is exercised for *both* pass and fail verdicts, so that a silent no-op on the fail path cannot masquerade as an all-pass suite. When any of these fails, the resulting telemetry is not merely incomplete — it is *biased*, because the loss mechanism correlates with the very condition (failure) the benchmark exists to detect. ## Decision Boundary The decision boundary is the **flush horizon**: the point at which the span processor has ended and exported the span, after which mutation is impossible. If scoring latency `L_score` can exceed the span's `schedule_delay` + export time `T_flush`, the attach-to-existing-span strategy is invalid and the runtime MUST switch to the linked-span strategy (emit verdict as a new span with `links=[SpanContext(original)]` and `litmus.verdict` attributes on the new span). The threshold is not a fixed constant — it is `L_score > T_flush` evaluated per probe, which means the runtime must *measure* `L_score` and choose the strategy dynamically, or unconditionally use linked spans for any asynchronous scorer. Choosing attach-when-fast / link-when-slow is itself a trap: it produces a mixed stream where fast failures are span events and slow failures are linked spans, and any downstream query that filters on one shape misses the other. ## Operational Effect Downstream consumers (safety dashboards, regression gates, red-team triage) treat the collector as ground truth. A biased-absent telemetry stream causes a regression gate to pass a model that should have been blocked, because the gate queries `count(litmus.verdict where outcome=fail)` and gets zero — not because there were no failures, but because the failures were structurally unrepresentable given the flush horizon. The corrective architecture is to make the verdict emission *synchronous with a span that the scorer owns*: the scorer opens its own `litmus.score` span, links it to the agent's `gen_ai` span, and writes the verdict as attributes on the scorer's own recording span. This decouples verdict emission from the agent span's lifecycle entirely and makes the failure direction observable by construction. The guardrail is a start-up self-test that emits one synthetic pass and one synthetic fail verdict and asserts both are queryable at the collector — if the fail probe is not retrievable, the runtime refuses to emit benchmark telemetry at all rather than emit a stream that looks clean. ```python from __future__ import annotations from dataclasses import dataclass from typing import Optional class TelemetryMappingError(RuntimeError): """Raised when a LITMUS verdict cannot be legally represented as GenAI telemetry.""" @dataclass(frozen=True) class SpanContext: trace_id: str span_id: str @dataclass class GenAISpan: context: SpanContext operation_name: str ended: bool = False def add_event(self, name: str, attrs: dict) -> None: # Mirrors the SDK's NonRecordingSpan no-op: silently drops on ended spans. if self.ended: return # ... recording path elided ... @dataclass(frozen=True) class LitmusVerdict: probe_id: str outcome: str # "pass" | "fail" target: SpanContext score_latency_ms: float def emit_verdict( verdict: LitmusVerdict, target_span: GenAISpan, flush_horizon_ms: float, allow_custom_namespace: bool, ) -> GenAISpan: # Invariant 1: span-liveness at assignment time. if not target_span.ended and verdict.score_latency_ms <= flush_horizon_ms: target_span.add_event( "litmus.verdict", {"litmus.probe_id": verdict.probe_id, "litmus.outcome": verdict.outcome}, ) return target_span # Attach strategy is invalid past the flush horizon; must link a new span. if target_span.ended and verdict.score_latency_ms > flush_horizon_ms: if not allow_custom_namespace: # Invariant 2: without a declared custom namespace the collector # will drop litmus.* attributes under strict GenAI validation. raise TelemetryMappingError( f"verdict {verdict.probe_id}: target span {target_span.context.span_id} " f"already ended (latency {verdict.score_latency_ms}ms > flush " f"{flush_horizon_ms}ms) and custom namespace is disabled; " f"emitting would silently drop the failure" ) linked = GenAISpan( context=SpanContext(trace_id=target_span.context.trace_id, span_id="scorer-" + verdict.probe_id), operation_name="litmus.score", ) linked.add_event( "litmus.verdict", { "litmus.probe_id": verdict.probe_id, "litmus.outcome": verdict.outcome, "litmus.linked_span_id": target_span.context.span_id, }, ) return linked # Ended but latency within horizon: inconsistent state, refuse rather than guess. raise TelemetryMappingError( f"verdict {verdict.probe_id}: ended span with sub-horizon latency " f"({verdict.score_latency_ms}ms) indicates flush/score ordering bug" ) def self_test(flush_horizon_ms: float = 500.0) -> None: span = GenAISpan(SpanContext("t1", "s1"), operation_name="gen_ai.chat") span.ended = True fail = LitmusVerdict("probe-7", "fail", span.context, score_latency_ms=900.0) # Guardrail: if the fail-direction probe cannot be represented, abort. try: emit_verdict(fail, span, flush_horizon_ms, allow_custom_namespace=False) except TelemetryMappingError: raise TelemetryMappingError( "fail-direction verdict unrepresentable at startup; refusing to emit " "benchmark telemetry that would under-report safety failures" ) ```