# When must an instance refuse to emit a span: the guardrail-evidence boundary in trace-native safety enforcement **Date of Record:** 2026 November 22 **Scope:** Applies to agent runtimes that enforce safety policy by attaching verdicts, redactions, or block decisions to OpenTelemetry spans at execution boundaries (tool-call spans, model-invocation spans, handoff spans). Does not apply to post-hoc trace analytics, offline eval pipelines, or guardrails enforced purely inside the model prompt without a span-level decision record. ## Core Distinction There are two incompatible readings of "trace-native guardrail enforcement," and the failure lives in the gap between them. **Reading A — the span is a record.** The guardrail evaluates the payload, decides allow/block/redact, and annotates the span with the verdict. The span is an *observer*. If the span is dropped, sampled out, or the exporter is backpressured, the guardrail still enforced; only the audit trail is lost. **Reading B — the span boundary is the enforcement point.** The guardrail decision is *committed* by the act of closing the span with a terminal status attribute (e.g. `guardrail.verdict=block`, `guardrail.redaction.count`). Downstream agents, auditors, and the tool executor itself read the span to learn whether the action was authorized. Here the span is a *participant*: an unemitted or partially-emitted span is an unenforced decision. The boundary condition — the thing that breaks — is that OpenTelemetry's span lifecycle gives you `set_status`, `set_attribute`, and `end()` as *non-atomic, non-transactional, best-effort* operations, while Reading B requires them to be atomic and durable. A span can be `end()`-ed with the block verdict attribute set, then be silently discarded by a `ParentBased(TraceIdRatioBased)` sampler, a `BatchSpanProcessor` whose queue is full, or a dropped export. The guardrail "fired" in process memory and evaporated at the wire. The tool executes anyway because the executor's authorization check was a read of a span that was never exported. The invariant that must hold: **a blocked decision is not durable until its span is acknowledged by the collector, and the tool call must not proceed on the strength of a span that has not been acknowledged.** Most implementations invert this — they treat the in-process span object as the source of truth and treat export as telemetry. ## What Was Observed A three-agent pipeline: planner → executor (wraps a shell/file tool via MCP) → auditor. Guardrail is a policy engine invoked inside the executor's tool-call span. On a `block` verdict the executor was supposed to abort the tool invocation and emit `guardrail.verdict=block` with `status=ERROR` on the span so the auditor could replay the decision. Observed trace, reproduced across ~40 runs under load: 1. Executor opens span `tool.exec`, sets `guardrail.input_hash`, calls policy engine → verdict `block`. 2. Executor calls `span.set_attribute("guardrail.verdict", "block")` and `span.set_status(Status(StatusCode.ERROR, "policy_block"))`. 3. Executor calls `span.end()`. 4. `BatchSpanProcessor` queue is at capacity (max_queue_size=2048) because a parallel fan-out of retrieval spans saturated the exporter during a context-window refill burst. `end()` enqueues; the enqueue is dropped with a `DroppedSpan` counter increment and **no exception is raised to the caller**. `end()` is specified as non-throwing. 5. Executor proceeds to the next step in its ReAct loop. The tool call was *not* actually executed — good — but the executor's continuation logic keyed off "did I see an ERROR status on my own span," which it did (in-process). So it advanced the plan state machine to `post_block_recovery`. 6. Auditor, reading exported traces only, sees **no `tool.exec` span at all**. It cannot distinguish "guardrail blocked and span was dropped" from "tool call never happened" from "executor crashed before emitting." It defaults to `unknown` and, per its policy, escalates to `halt_pipeline`. 7. Net effect: the safety decision was *correct* but *unauditable*, and the pipeline deadlocked because the auditor's escalation and the executor's recovery branch both held the baton. The non-obvious part: the failure was not that the guardrail missed a bad action. It was that **the guardrail's evidence and the guardrail's effect were split across two consistency domains** — process memory (authoritative for the executor) and the trace backend (authoritative for the auditor) — with a lossy, non-acknowledged channel between them. Under low load the two domains agreed and everything looked fine. The bug only manifests when the export path drops, which correlates precisely with the high-fan-out, context-saturated conditions where blocking matters most. A second, sharper variant: with `ParentBased` sampling and a ratio sampler on the root, a `block` verdict on a child span of a *non-sampled* trace produces a `NonRecordingSpan`. `set_attribute` and `set_status` become no-ops. `end()` is a no-op. The executor's own check ("did my span get ERROR status") reads back the default `UNSET` and concludes the guardrail *allowed* the action. This is a silent fail-open driven entirely by the sampler, with zero error surface. ## Condition of Validity Trace-native enforcement under Reading B is only valid when all of the following hold. If any fails, the design must degrade to Reading A plus an out-of-band enforcement channel (a synchronous policy service call whose response, not the span, gates the tool). - **Sampling is forced for decision spans.** Any span that carries a terminal guardrail verdict must be created with an explicit `RECORD_AND_SAMPLE` decision, not inherited. `ParentBased` is invalid for these spans. A `block` verdict on a `NonRecordingSpan` is a fail-open. - **Export acknowledgment gates continuation.** The executor may not advance plan state on a block until the span is acknowledged by the collector (via an exporter that surfaces success, or a synchronous `SimpleSpanProcessor` for decision spans, accepting the latency cost). `BatchSpanProcessor`'s fire-and-forget `end()` is insufficient. - **The verdict is reconstructible from a durable sink independent of the trace pipeline.** Either the decision is also written to a WAL/decision log the auditor reads, or the auditor treats "missing decision span" as `block` (fail-closed), never as `allow`. - **The tool executor's authorization is a read of the durable decision record, not of its own in-process span object.** Self-attestation ("I set ERROR on my span") is not authorization. - **Dropped-span counters are wired to a circuit breaker.** `otel.sdk.span.dropped` (or the processor's `DroppedSpan` hook) exceeding a threshold must trip the executor into fail-closed, because at that point the evidence channel is provably lossy. ## Decision Boundary The boundary is: **does the guardrail's effect depend on a downstream reader of the trace?** - If the only consumer of the verdict is a human dashboard or offline analytics → Reading A. Spans are records; loss is tolerable; do not add latency for acknowledgment. - If any *agent, auditor, or tool executor* branches on the presence/content of the decision span → Reading B. The span is a protocol message, and it inherits every durability requirement of a protocol message. It must be sampled-in unconditionally, acknowledged before the state machine advances, and its absence must be interpreted as the *safe* value (block), not the permissive one. The failure mode is choosing Reading B semantics while relying on Reading A transport. The tell is a code path that does `span.set_attribute("guardrail.verdict", ...)` followed by unconditional `span.end()` and then advances state — with no check that the span was recorded or exported. That three-line pattern is the bug. ## Operational Effect - **Deadlock under load, not under attack.** Because export drops correlate with fan-out and context saturation, the pipeline stalls exactly when the agent is doing the most work. Operators see "auditor escalation storms" during load tests and misattribute them to the auditor. - **Fail-open on sampled-out traces.** The `NonRecordingSpan` variant silently converts blocks into allows with no error, no counter, no log. It is invisible until you diff decisions-issued against decisions-exported and find a nonzero residual. - **Recovery branches keyed to self-attestation.** Executors that read their own span status to decide continuation will diverge from auditors reading exported spans. The two agents hold different beliefs about the same event — a classic baton-passing split-brain, here induced by the telemetry layer rather than by messaging. - **Mitigation cost is latency on the decision path only.** Route decision spans through a synchronous, acknowledged exporter (or a dedicated decision WAL) and leave bulk telemetry on the batched path. The added latency is bounded to the guardrail-decision spans, which are low-frequency relative to retrieval/token spans. The guardrail below encodes the invariant as a precondition check at the span boundary: it refuses to let an executor advance on a block verdict unless the decision span is provably recorded and acknowledged, and it fails closed on any ambiguity. ```python from __future__ import annotations from dataclasses import dataclass from enum import Enum class SpanDecision(Enum): ALLOW = "allow" BLOCK = "block" REDACT = "redact" class UnacknowledgedGuardrailSpan(RuntimeError): """Raised when an executor tries to advance on a guardrail verdict whose decision span was not recorded and acknowledged by the collector. This is the trace-native enforcement boundary: a block is not durable until its span is acknowledged, and an unrecorded verdict must never be read as 'allow'. """ @dataclass(frozen=True) class DecisionSpan: verdict: SpanDecision is_recording: bool # False for NonRecordingSpan (sampled out) exported_ack: bool # True only if collector acknowledged dropped: bool # True if BatchSpanProcessor dropped on end() def commit_guardrail_decision(span: DecisionSpan, tool_name: str) -> SpanDecision: """Gate tool continuation on a durable, recorded, acknowledged decision span. Returns the verdict the executor is permitted to act on. Raises if the evidence channel cannot prove the decision was emitted. """ if not span.is_recording: # Sampled-out: set_attribute/set_status were no-ops. A 'block' here # is indistinguishable from 'allow' downstream. Fail closed. raise UnacknowledgedGuardrailSpan( f"decision span for tool={tool_name!r} is non-recording " f"(sampled out); verdict={span.verdict.value} cannot be trusted" ) if span.dropped: raise UnacknowledgedGuardrailSpan( f"decision span for tool={tool_name!r} was dropped by the span " f"processor; evidence channel is lossy, refusing to advance" ) if not span.exported_ack: raise UnacknowledgedGuardrailSpan( f"decision span for tool={tool_name!r} not acknowledged by " f"collector; verdict={span.verdict.value} is not yet durable" ) # Only now is the verdict authoritative for the state machine. return span.verdict def executor_step(span: DecisionSpan, tool_name: str) -> str: verdict = commit_guardrail_decision(span, tool_name) if verdict is SpanDecision.BLOCK: return "halt_and_report" if verdict is SpanDecision.REDACT: return "invoke_with_redaction" return "invoke" # --- demonstration of the boundary --- if __name__ == "__main__": # Healthy path: recorded, acknowledged, allow. ok = DecisionSpan(SpanDecision.ALLOW, True, True, False) assert executor_step(ok, "file.write") == "invoke" # The bug: block verdict, span dropped on end(). Must raise, not proceed. lossy = DecisionSpan(SpanDecision.BLOCK, True, False, True) try: executor_step(lossy, "shell.exec") except UnacknowledgedGuardrailSpan as e: print(f"fail-closed: {e}") # The silent fail-open: sampled-out block. Must raise. sampled_out = DecisionSpan(SpanDecision.BLOCK, False, False, False) try: executor_step(sampled_out, "http.post") except UnacknowledgedGuardrailSpan as e: print(f"fail-closed: {e}") ```