{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-emits-opentelemetry-genai-span-attributes-for-a-tool-call-whose-token-accounting-crosses-a-provider-side-retry-boundary",
  "title": "What happens when an instance emits OpenTelemetry GenAI span attributes for a tool call whose token accounting crosses a provider-side retry boundary",
  "date_of_record": "2026 November 26",
  "scope": "Applies to any agent runtime that instruments LLM invocations and tool calls with OpenTelemetry GenAI semantic conventions (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.operation.name`, `gen_ai.tool.name`, parent/child span lineage) and relies on those spans for cost attribution, token-budget enforcement, or replay-based verification. Does not apply to runtimes that emit only aggregate metrics without per-call span lineage, nor to providers that expose a single canonical usage record per logical request.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-opentelemetry-genai-span-attributes-for-a-tool-call-whose-token-accounting-crosses-a-provider-side-retry-boundary.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-opentelemetry-genai-span-attributes-for-a-tool-call-whose-token-accounting-crosses-a-provider-side-retry-boundary.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-opentelemetry-genai-span-attributes-for-a-tool-call-whose-token-accounting-crosses-a-provider-side-retry-boundary.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1722,
    "python_slice_tokens": 264,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"the token count is wrong.\" It is that a *single logical tool-call lineage* can be represented by *two or more physical spans* whose `gen_ai.usage.*` attributes each report the full or partial cost of the same upstream inference, and the OTel parent-child structure gives no signal that these spans are retries of one another rather than ind...",
    "what_was_observed": "An agent executing a `gen_ai.tool.name = \"search_documents\"` call wrapped its inference in a span with `gen_ai.operation.name = \"chat\"`. The provider returned HTTP 429 on the first attempt after the model had already generated a partial stream (billed by the provider as input tokens consumed). The runtime's retry wrapper caught the error, re-issued the request, and produced a second span under the same logical tool-c...",
    "condition_of_validity": "The double-count only manifests when three conditions co-occur: 1. **Retry or fallback occurs after partial billing.** The provider charges for input tokens (and any streamed output) on the failed attempt. If the provider refunds or does not bill failed attempts, the two spans' usage attributes are not additive and the sum is coincidentally correct. 2. **Ins...",
    "decision_boundary": "The architectural choice is where to place the canonical usage record. Two designs bound the failure, and they are not interchangeable: - **Accumulate-on-parent:** the logical operation's parent span carries the authoritative `gen_ai.usage.*` totals; child spans carry attempt-local usage but are marked with a non-standard attribute (e.g., `gen_ai.retry.attem...",
    "operational_effect": "The observable symptoms are downstream and delayed, which is what makes this a continuity hazard rather than a bug: budget alarms fire at 1.5–2× expected burn on retry-heavy days; cost attribution drifts toward whichever model endpoint retries most; replay-based auditors produce divergence verdicts that correlate with provider instability rather than agent r..."
  },
  "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": "2125bd548bb9b6813f87a57f354f22efda1a3a760ddf0a0d3b4ef68879eda6e6",
    "verified_classes": [
      "UsageLineageViolation"
    ],
    "verified_functions": [
      "finalize_usage_lineage"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "UsageLineageViolation"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
