# Where must an instance reconcile OpenTelemetry GenAI span emission with tool-call side effects when a tool invocation succeeds but its span is dropped by a batch exporter **Date of Record:** 2026 November 23 **Scope:** Applies to agent runtimes that emit `gen_ai.*` spans (tool-call spans, model-invocation events, token-usage counters) through an asynchronous batching `SpanProcessor`/`Exporter` and that treat span emission as an observability-only concern separate from the tool executor's control flow. Does not apply to synchronous exporters that block the calling thread until the span is acknowledged, nor to runtimes where span emission is itself a transactional part of the tool contract. ## Core Distinction The failure is not "telemetry is lossy." It is that OpenTelemetry GenAI semantic conventions place a *semantic* obligation on the tool-call span — the span is the canonical record that a tool was invoked, with what arguments, and at what token cost — while the batch exporter places only a *best-effort* delivery obligation on it. When a tool executes successfully but its span is silently dropped (queue overflow, `max_export_batch_size` truncation, exporter backpressure, or process exit before `force_flush`), the agent's own audit trail and its actual state diverge. The runtime then has no authoritative record that the side effect occurred, and any downstream reconciliation — token accounting, replay, checkpoint resume — operates on a state graph that is missing nodes. The non-obvious part: the *tool call succeeded*. The agent's working memory, the external system, and the user all reflect the side effect. Only the span is gone. There is no exception, no retry, no `tool_call.failed` event. The invariant that must hold is: **for every tool side effect that mutates external state, there exists exactly one durable `gen_ai.tool.call` record with `status=OK`, and the absence of that record is itself an error condition — not a benign gap.** ## What Was Observed A planner agent invoked a `write_file` tool against a shared workspace. The tool executor returned success and the agent advanced its plan. The tool-call span was created with the correct attributes: ``` gen_ai.operation.name = "execute_tool" gen_ai.tool.name = "write_file" gen_ai.tool.call.id = "call_8f3a..." gen_ai.usage.input_tokens = 412 gen_ai.usage.output_tokens = 88 ``` The span was handed to a `BatchSpanProcessor` configured with `max_queue_size=2048`, `schedule_delay_millis=5000`. During a burst of 3,000 concurrent sub-agent tool calls, the queue saturated. The processor's documented behavior on a full queue is to **drop the span and increment `dropped_spans`** — it does not block, does not raise, does not signal the caller. The `write_file` tool's side effect committed. The span did not. The failure surfaced 40 minutes later during checkpoint resume. The agent's episodic memory (persisted to a vector store at each step boundary) contained a reference to the file write. The reconstructed span tree from the observability backend contained no `execute_tool` child under the corresponding `invoke_agent` span. A downstream auditor agent, whose job was to verify that every claimed file mutation had a matching tool-call record, flagged the write as **unverified** and halted the pipeline. The side effect was real; the record was not. A second, subtler observation: the `invoke_agent` parent span *did* survive, and its `gen_ai.usage.output_tokens` reflected the model's reasoning about the tool result — because that span was emitted on a lower-traffic path. So the trace showed an agent reasoning about a tool result with no tool call in between. This is the signature of the failure: **a parent span that references a child tool result with no corresponding tool-call span in the trace.** ## Condition of Validity The invariant "every committed tool side effect has a durable span" holds only when the span emission path is causally ordered before the side effect is acknowledged to the agent. This requires one of: 1. **Synchronous acknowledgement:** the tool executor blocks on `span.end()` + `force_flush()` (or an equivalent exporter ack) before returning success to the planner. Cost: latency proportional to exporter RTT; unacceptable for high-fanout swarms. 2. **Two-phase commit with a write-ahead intent record:** the executor writes a durable `tool_call_intent` row (in the agent's own state store, not the telemetry backend) *before* executing, and a `tool_call_complete` row after. The span is emitted asynchronously; reconciliation treats a `complete` row with no matching span as a **telemetry gap** to be backfilled, not as an unverified side effect. This is the recommended pattern. 3. **Span-as-source-of-truth with bounded loss:** the exporter is configured to *never* drop (`max_queue_size` sized to peak fanout, `BlockingQueue` semantics, or a persistent disk-backed queue). This shifts the failure from silent loss to backpressure — the agent stalls rather than losing records. Acceptable only when the agent's own liveness is not on the critical path. The invariant does **not** hold when the runtime treats `BatchSpanProcessor` as fire-and-forget and relies on the observability backend as the audit log. That configuration is valid for latency debugging and invalid for side-effect verification. ## Decision Boundary The boundary is between **observability telemetry** (lossy, sampled, best-effort — appropriate for `gen_ai.client.token.usage` histograms and model-invocation latency events) and **audit records** (durable, exactly-once, causally ordered — required for `gen_ai.tool.call` spans that correspond to external mutations). The GenAI semantic conventions do not distinguish these; they define attribute schemas for both under the same `gen_ai.*` namespace. The runtime must impose the distinction itself. Concretely: a `gen_ai.tool.call` span whose tool is classified `mutating=true` (writes files, sends messages, charges cards, mutates shared state) must be emitted through the durable path. A `gen_ai.tool.call` span whose tool is `mutating=false` (read-only query, search, fetch) may use the lossy batch path. The classification is a property of the tool registration, not of the span. The decision point at runtime: when `tool_executor.execute()` returns success for a `mutating=true` tool, the executor must verify that a durable record exists before returning to the planner. If the durable write fails, the executor must **not** return success — it must either roll back the side effect (if the tool supports it) or raise a `TelemetryCommitError` that the planner treats as a tool failure, even though the side effect committed. This is the uncomfortable part: the agent must be told the tool "failed" when it actually succeeded, because the alternative is an unverifiable side effect. The planner's recovery path must be idempotent (re-invoking `write_file` with the same content is safe; re-invoking `charge_card` is not — hence the tool contract must declare idempotency). ## Operational Effect Without the guardrail, the failure mode compounds. The auditor agent's "unverified" flag causes the planner to re-execute the tool. For idempotent tools, this produces a duplicate span (now two records for one side effect — the opposite error). For non-idempotent tools, it produces a duplicate side effect. Either way, the token accounting drifts: `gen_ai.usage.input_tokens` for the re-execution are counted, the original's are not (span dropped), so the aggregate undercounts by one tool round-trip per dropped span. At 3,000 dropped spans in the observed burst, the token ledger was short by roughly 1.5M input tokens — enough to silently blow a per-tenant budget cap. With the write-ahead intent record, the reconciliation job runs on a schedule: for each `tool_call_complete` row with no matching `gen_ai.tool.call` span (matched by `gen_ai.tool.call.id`), emit a synthetic backfill span with `gen_ai.tool.call.backfilled=true`. The auditor treats backfilled spans as verified-but-late. Token accounting reads from the intent store, not the trace backend, so it is exact regardless of exporter loss. The residual risk is the intent store itself. If the agent's state store and the telemetry backend are the same system (common in single-node deployments), the write-ahead record is subject to the same loss. The invariant requires that the intent store be *more durable* than the telemetry backend — typically a transactional DB or an append-only log with fsync, not a metrics/trace backend with sampling. ```python from dataclasses import dataclass from enum import Enum class ToolMutability(Enum): READ_ONLY = "read_only" MUTATING = "mutating" class TelemetryCommitError(RuntimeError): """Raised when a mutating tool's side effect committed but its durable gen_ai.tool.call record could not be persisted. The planner MUST treat this as a tool failure and follow an idempotent recovery path.""" pass @dataclass class ToolCallIntent: call_id: str tool_name: str mutability: ToolMutability idempotent: bool class DurableToolExecutor: def __init__(self, intent_store, span_exporter, tool_registry): self.intent_store = intent_store # transactional, fsync'd self.span_exporter = span_exporter # may be lossy batch self.tool_registry = tool_registry def execute(self, call_id: str, tool_name: str, args: dict) -> dict: spec = self.tool_registry[tool_name] intent = ToolCallIntent( call_id=call_id, tool_name=tool_name, mutability=spec.mutability, idempotent=spec.idempotent, ) # Phase 1: write-ahead intent for mutating tools, BEFORE side effect. if intent.mutability is ToolMutability.MUTATING: self.intent_store.write_intent(intent) # must fsync # Phase 2: execute. Side effect may commit here. result = spec.invoke(**args) # Phase 3: for mutating tools, the durable completion record is the # authority. Span is emitted best-effort; its loss is backfillable. if intent.mutability is ToolMutability.MUTATING: committed = self.intent_store.write_complete(intent, result) if not committed: # Side effect committed but we cannot prove it durably. # Surface as failure so planner uses idempotent recovery. if not intent.idempotent: raise TelemetryCommitError( f"side effect for {tool_name} (call_id={call_id}) committed " f"but durable record failed; tool is non-idempotent, " f"manual reconciliation required" ) raise TelemetryCommitError( f"side effect for {tool_name} (call_id={call_id}) committed " f"but durable record failed; re-invoke is safe (idempotent)" ) # Span emission is best-effort for all tools; the intent store is the # audit authority for mutating ones. self.span_exporter.emit_tool_call_span(intent, result) return result def reconcile_backfill(intent_store, trace_backend) -> int: """Emit synthetic backfill spans for committed side effects whose original gen_ai.tool.call span was dropped by the batch exporter.""" backfilled = 0 for complete in intent_store.iter_complete(): if not trace_backend.has_span(complete.call_id): trace_backend.emit_backfill_span( call_id=complete.call_id, tool_name=complete.tool_name, attributes={"gen_ai.tool.call.backfilled": True}, ) backfilled += 1 return backfilled ```