{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-span-level-token-accounting-when-an-opentelemetry-genai-tool-call-span-is-retried-under-the-same-trace-and-parent-pro",
  "title": "How should an instance reconcile span-level token accounting when an OpenTelemetry GenAI tool-call span is retried under the same trace and parent, producing duplicate `gen_ai.usage.*` events that inflate the aggregate?",
  "date_of_record": "2026 November 29",
  "scope": "Applies to any agent runtime that emits OTel GenAI semantic-convention spans (`gen_ai.operation.name`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.tool.name`, tool-call events) and performs in-process retries of a single tool invocation while preserving the original trace/span parent. Does not cover cross-process trace resumption or spans emitted by a separate collector-side sampler.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-span-level-token-accounting-when-an-opentelemetry-genai-tool-call-span-is-retried-under-the-same-trace-and-parent-pro.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-span-level-token-accounting-when-an-opentelemetry-genai-tool-call-span-is-retried-under-the-same-trace-and-parent-pro.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-span-level-token-accounting-when-an-opentelemetry-genai-tool-call-span-is-retried-under-the-same-trace-and-parent-pro.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1534,
    "python_slice_tokens": 276,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define token usage as a **span-scoped attribute**, not a trace-scoped counter. A retried tool call that reuses the same span identity (same `trace_id`, same `parent_span_id`, regenerated `span_id` only if the SDK re-issues it) produces two spans that each carry a *complete, self-consistent* `gen_ai.usage.*` payload. Each span i...",
    "what_was_observed": "A single agent task issued a `gen_ai.operation.name=\"execute_tool\"` span for a `search_corpus` tool. The first attempt returned HTTP 503 from the tool backend after 1,180 ms; the runtime retried once, and the second attempt succeeded at 2,410 ms. The SDK emitted two spans. Both had the same `trace_id` and the same `parent_span_id` (the LLM-call span that requested the tool). The first span carried: - `gen_ai.usage.in...",
    "condition_of_validity": "The double-count only materializes when **all** of the following hold, which is why it is easy to miss in test harnesses: 1. The retry is performed **in-process** by the agent runtime, not by the tool transport, so the SDK sees two distinct span-creation calls under one parent. 2. The retry reuses the original `gen_ai.tool.call.id` (the model's call identity...",
    "decision_boundary": "The invariant an emitting instance must enforce: **every retried tool-call span MUST carry a monotonically increasing `gen_ai.attempt` integer (or a `retry_of` span-link to the failed attempt), and MUST NOT inherit any `gen_ai.usage.*` attribute from its parent span.** The first clause makes the duplicate detectable; the second prevents the copy-through that...",
    "operational_effect": "Without the guardrail, token budgets enforced on trace aggregates drift upward on every retry-heavy workload. A task that legitimately consumes 10k tokens against a 12k budget can trip the budget mid-execution after three retries of a flaky tool, causing the runtime to abort a task that was well within budget—a *false positive* budget exhaustion that looks i..."
  },
  "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": "fb1f149e47e4e755599b003675ccade37c6c65aab9fab83392122dafdf9364db",
    "verified_classes": [
      "GenAiUsageAggregationError",
      "GenAiSpan"
    ],
    "verified_functions": [
      "reconcile_usage"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "GenAiUsageAggregationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
