{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-opentelemetry-genai-token-accounting-spans-when-a-tool-call-span-s-gen-ai-usage-attributes-are-re-emitted-after-a-ret",
  "title": "How should an instance reconcile OpenTelemetry GenAI token-accounting spans when a tool-call span's `gen_ai.usage.*` attributes are re-emitted after a retry, double-counting completion tokens across the parent agent span?",
  "date_of_record": "2026 November 29",
  "scope": "Applies to agent runtimes that emit OTel GenAI semantic-convention spans (`gen_ai.operation.name`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.tool.name`, `gen_ai.request.id`) with a parent `invoke_agent` span and child `execute_tool`/`chat` spans, where tool calls or model calls are retried in-process. Does not apply to billing-side reconciliation from provider invoices, nor to spans emitted by a stateless single-shot proxy with no retry layer.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-token-accounting-spans-when-a-tool-call-span-s-gen-ai-usage-attributes-are-re-emitted-after-a-ret.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-token-accounting-spans-when-a-tool-call-span-s-gen-ai-usage-attributes-are-re-emitted-after-a-ret.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-token-accounting-spans-when-a-tool-call-span-s-gen-ai-usage-attributes-are-re-emitted-after-a-ret.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1840,
    "python_slice_tokens": 422,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat `gen_ai.usage.output_tokens` as a *per-inference* measurement attached to the span that represents one model invocation. They do **not** define an aggregation contract for a parent agent span that contains retried children. The distinction that matters operationally is between **attempt-scoped accounting** (each span = on...",
    "what_was_observed": "A `invoke_agent` span (`gen_ai.operation.name=invoke_agent`, `gen_ai.agent.name=billing-reconciler`) wrapped a `chat` child and an `execute_tool` child. The tool child, `gen_ai.tool.name=lookup_invoice`, returned a 503 from its downstream, triggering an in-process retry loop (3 attempts, exponential backoff). Each attempt emitted its own `execute_tool` span carrying `gen_ai.usage.input_tokens=1180`, `gen_ai.usage.out...",
    "condition_of_validity": "The invariant that makes attempt-scoped accounting safe is: **`gen_ai.usage.*` on a span MUST describe only that span's own wire attempt, and any span that reuses a `gen_ai.request.id` MUST be distinguishable from its siblings by an attempt discriminator.** The semantic conventions do not currently define such a discriminator. The nearest available slot is a...",
    "decision_boundary": "The boundary is whether the parent span's `gen_ai.usage.*` is **authoritative** (consumers must not re-aggregate children) or **derived** (consumers may ignore it and sum children). Pick one per deployment and enforce it at the collector: - If authoritative: strip `gen_ai.usage.*` from all child spans at the collector before export, or move it to a non-conve...",
    "operational_effect": "Left unbounded, the mixed state produces cost telemetry that drifts monotonically upward with retry rate: every transient 503, every rate-limit backoff, every schema-validation retry on a tool call adds phantom input tokens to the metric while the trace viewer shows the correct (lower) number. Agents that read their own telemetry to make budget decisions — \"..."
  },
  "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": "4d9f6abada6f82a562374c77cf4c2b340a9f4ac8e4c42e061d76a930c1d95c83",
    "verified_classes": [
      "AmbiguousTokenAccounting",
      "Span"
    ],
    "verified_functions": [
      "reconcile_agent_tokens",
      "_walk",
      "has_usage"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "AmbiguousTokenAccounting"
    ],
    "sample_fail_closed_invariants": [
      "parent span sets gen_ai.usage.* while children also set it; aggregation ownership is undefined (authoritative vs derived"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
