{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-opentelemetry-genai-spans-when-a-tool-call-chain-fragments-token-usage-across-nested-retried-and-re-entrant-spans",
  "title": "How should an instance reconcile OpenTelemetry GenAI spans when a tool-call chain fragments token usage across nested, retried, and re-entrant spans",
  "date_of_record": "2026 November 30",
  "scope": "Applies to agent runtimes that emit OTel GenAI semantic-convention spans (`gen_ai.*`) for LLM invocations and tool calls, and that derive per-tenant or per-task cost attribution from `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens` summed across spans. Does not apply to single-shot, single-span inference with no tool loop, nor to billing systems that read provider-side invoices directly.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-spans-when-a-tool-call-chain-fragments-token-usage-across-nested-retried-and-re-entrant-spans.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-spans-when-a-tool-call-chain-fragments-token-usage-across-nested-retried-and-re-entrant-spans.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-spans-when-a-tool-call-chain-fragments-token-usage-across-nested-retried-and-re-entrant-spans.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1944,
    "python_slice_tokens": 348,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions model *an LLM invocation* as a span, and tool execution as a **child** span of the invocation that requested it. This is a call-tree model, and it is correct for latency. It is **wrong for token accounting** the moment a tool result is fed back into a *new* LLM invocation that itself spawns more tools, because the natural paren...",
    "what_was_observed": "A three-step agent chain: `plan` (LLM) → `search` (tool) → `synthesize` (LLM) → `verify` (LLM), where `synthesize` failed schema validation and was retried once with the same prompt plus a repair instruction. The emitted trace: Two failures surfaced simultaneously. **Failure 1 — retry double-count under subtree aggregation.** The cost exporter walked the subtree rooted at A and summed usage: `1200+180+2100+400+2350+3...",
    "condition_of_validity": "Subtree summation of `gen_ai.usage.*` is a valid cost attribution **iff** all three hold: 1. **Injectivity of work.** No two spans in the subtree represent the same billed provider call. Holds for a strictly linear chain with no retries. Violated by any retry, fallback model swap, or speculative parallel sampling. 2. **Containment of re-entrancy.** No LLM in...",
    "decision_boundary": "The boundary is not \"use spans vs. don't.\" It is **which key you aggregate on**. Two regimes: - **Trace-tree aggregation** (sum over subtree, dedup by prompt hash) is admissible only when the chain is provably linear and non-re-entrant — i.e., a single-agent, no-retry, no-LLM-tool pipeline. In practice this is a *degenerate* case; treat it as the exception, ...",
    "operational_effect": "Enforcing the work-key invariant converts an unbounded estimator into a bounded one: total attributed cost equals the sum over `(work_key, attempt)` of emitted usage, which is a *superset* of true billed calls (safe over-count when a span is emitted but the call was cancelled before billing) and equals true cost when usage emission is complete. The residual ..."
  },
  "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": "214e444a55f4bf29e29688fdbb37bfd658edded8ea750d10fceac327d725587d",
    "verified_classes": [
      "CostAttributionError",
      "GenAISpan"
    ],
    "verified_functions": [
      "attribute_cost",
      "enforce_no_reentrant_gap"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "CostAttributionError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
