{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-reconcile-opentelemetry-genai-span-attributes-before-emitting-them-or-the-token-accounting-silently-double-counts-retried-tool",
  "title": "Where must an instance reconcile OpenTelemetry GenAI span attributes before emitting them, or the token accounting silently double-counts retried tool calls",
  "date_of_record": "2026 November 30",
  "scope": "Applies to any LLM agent runtime that emits OpenTelemetry spans conforming to the GenAI semantic conventions (`gen_ai.*` attributes) and that performs retries, fallbacks, or multi-attempt tool invocation under a single logical agent step. Does not apply to single-shot, no-retry inference paths where each span maps 1:1 to a unique provider request.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-span-attributes-before-emitting-them-or-the-token-accounting-silently-double-counts-retried-tool.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-span-attributes-before-emitting-them-or-the-token-accounting-silently-double-counts-retried-tool.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-span-attributes-before-emitting-them-or-the-token-accounting-silently-double-counts-retried-tool.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1744,
    "python_slice_tokens": 276,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define attributes like `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, and `gen_ai.operation.name` on a per-span basis. The convention implicitly assumes a span corresponds to *one billable provider interaction*. An agent runtime, however, frequently maps a *logical operation* (one \"tool call\" or one \"reasoning step\"...",
    "what_was_observed": "A tool-calling agent invoked a retrieval tool through a provider gateway. The gateway applied an internal retry policy: on HTTP 429 it retried up to three times, each retry producing a distinct provider request with its own `usage` block. The agent's OpenTelemetry exporter wrapped each attempt in a child span under the logical `execute_tool` span, tagging each with `gen_ai.operation.name = \"chat\"` and `gen_ai.usage.i...",
    "condition_of_validity": "The reconciliation invariant holds only under the following conditions, and fails outside them: 1. **The logical operation must be represented by a parent span that owns the canonical usage attributes.** If the parent `execute_tool` span carries the *winning* attempt's `gen_ai.usage.*` and each child attempt carries its own, then a rollup that sums only leaf...",
    "decision_boundary": "Before emitting any GenAI span, the instrumenter must decide, per logical operation: - **Is this span a logical step or a physical attempt?** If physical attempt, it must be a child of a logical-step parent and must carry an attempt-outcome marker. - **Does the parent own canonical usage, or do children?** Exactly one level owns it. The other level must not ...",
    "operational_effect": "The observable effect is a class of bugs that look like reasoning failures but are accounting failures: premature context-exhaustion aborts on tasks that had headroom, budget-guard trips that halt multi-step agents mid-execution, and cost dashboards that disagree with invoices by the retry multiplier. Because the per-span trace is convention-conformant, stan..."
  },
  "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": "8d50ed1249a2b72b40c0f724235fc4bccfa6f2c042f8cd8dad1c36df238f26c2",
    "verified_classes": [
      "GenAIUsageReconciliationError"
    ],
    "verified_functions": [
      "reconcile_agent_span_tree"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "GenAIUsageReconciliationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
