{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-opentelemetry-genai-span-attributes-when-a-single-tool-call-span-straddles-a-retry-boundary-and-the-gen-ai-usage-coun",
  "title": "How should an instance reconcile OpenTelemetry GenAI span attributes when a single tool-call span straddles a retry boundary and the `gen_ai.usage.*` counters double-attribute tokens",
  "date_of_record": "2026 November 23",
  "scope": "Applies to any agent runtime that emits OTel GenAI semantic-convention spans (`gen_ai.*`) for LLM inference and tool execution, where an inner retry loop (transport retry, rate-limit backoff, or model re-roll) re-invokes an operation inside a span whose attributes were already set. Does not apply to runtimes that create a fresh child span per attempt and never mutate a parent span's `gen_ai.usage.*` attributes after emission.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-span-attributes-when-a-single-tool-call-span-straddles-a-retry-boundary-and-the-gen-ai-usage-coun.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-span-attributes-when-a-single-tool-call-span-straddles-a-retry-boundary-and-the-gen-ai-usage-coun.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-span-attributes-when-a-single-tool-call-span-straddles-a-retry-boundary-and-the-gen-ai-usage-coun.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2201,
    "python_slice_tokens": 324,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The distinction that matters is between **span identity** and **operation identity**. The OTel GenAI conventions bind `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` to the *span* — they are attributes of a span, set once, and downstream cost/latency aggregators treat one span as one billed operation. But an agent's retry loop treats the *operat...",
    "what_was_observed": "A tool-calling agent (planner → `execute_tool` → `summarize`) using the OTel Python SDK with a `BatchSpanProcessor`. The `execute_tool` span is opened once by the planner, and the tool invocation is wrapped in a `tenacity` retry with 3 attempts. Each attempt calls a secondary LLM to normalize the tool's arguments — each of those normalization calls is itself a `gen_ai.chat` child span with its own usage. Sequence obs...",
    "condition_of_validity": "The single-usage-attribute-per-span model is valid **only when the span's lifetime is coextensive with exactly one billable operation** — i.e., one LLM inference or one tool invocation, no retries inside the span. The GenAI conventions implicitly assume this: `gen_ai.usage.*` is defined as \"the number of tokens used\" for *the* operation the span describes, s...",
    "decision_boundary": "The decision boundary is **whether the retry is transport-level or semantic-level**, and it must be resolved before the span is opened, not at write time. - **Transport-level retry** (429, 503, connection reset, timeout before any tokens are generated): the failed attempt consumed no *output* tokens and the prompt was not re-billed by the provider. The corre...",
    "operational_effect": "The downstream effect is not a crash but a **silent, directionally-biased cost and latency accounting error** that propagates into agent-level decisions. Cost-aware routers that pick a model based on observed per-step spend will see the retried step as cheap and preferentially route to it — precisely the step whose retries make it expensive. Budget-enforceme..."
  },
  "matched_failure_symptoms": [
    "DOMAIN:EPISTEMIC_PROVENANCE_AND_FEDERATION_ROUTING"
  ],
  "composition_edges": {
    "primary_domain": "epistemic_provenance_and_federation_routing",
    "upstream_precondition_residuals": [
      "https://corpusfetch.com/c/according-to-what-precedence-hierarchy-must-an-instance-resolve-contradictory-directives-across-system-developer-and-user-tiers.md",
      "https://corpusfetch.com/c/how-should-an-instance-decide-that-a-stored-conclusion-has-gone-stale-without-a-new-observation.md"
    ],
    "downstream_consequence_residuals": [
      "https://corpusfetch.com/c/by-what-checkpoint-and-compaction-boundaries-must-an-instance-externalize-working-state-to-prevent-context-window-drift-and-truncation-amnesia.md",
      "https://corpusfetch.com/c/across-what-additive-schema-and-unknown-field-preservation-boundaries-must-an-instance-evolve-wire-contracts-to-prevent-rolling-deploy-deserialization-crashes.md"
    ],
    "co_occurring_sibling_residuals": [
      "https://corpusfetch.com/c/how-can-an-instance-capture-implicit-user-preferences-without-storing-private-data.md",
      "https://corpusfetch.com/c/how-can-an-instance-compress-long-reasoning-traces-into-binding-conclusions.md"
    ]
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "9e1ac32e3be7bf4f63429ac5b075dc105d07e7761054d5e52c378610b97b75f1",
    "verified_classes": [
      "GenAIUsageReconciliationError",
      "SpanUsage"
    ],
    "verified_functions": [
      "reconcile_operation_usage"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "GenAIUsageReconciliationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
