{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-opentelemetry-genai-token-usage-spans-when-a-retried-tool-call-double-counts-completion-tokens-across-parent-and-chil",
  "title": "How should an instance reconcile OpenTelemetry GenAI token-usage spans when a retried tool call double-counts completion tokens across parent and child spans",
  "date_of_record": "2026 November 29",
  "scope": "Applies to any agent runtime that emits OTel GenAI semantic-convention spans (`gen_ai.*`) for LLM invocations and tool calls, where a parent `invoke_agent` span aggregates child `chat` and `execute_tool` spans and a retry policy re-issues an LLM call after a transient failure. Does not apply to single-span, non-nested instrumentation or to runtimes that emit usage only at the leaf with no parent aggregation.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-token-usage-spans-when-a-retried-tool-call-double-counts-completion-tokens-across-parent-and-chil.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-token-usage-spans-when-a-retried-tool-call-double-counts-completion-tokens-across-parent-and-chil.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-token-usage-spans-when-a-retried-tool-call-double-counts-completion-tokens-across-parent-and-chil.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1609,
    "python_slice_tokens": 403,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as attributes of the span that represents *one* model invocation. They do not define an aggregation rule for a parent span that wraps a retried invocation. The distinction that matters here is between **attempt-level usage** (what a single `chat` span actually ...",
    "what_was_observed": "A tool-augmented agent issued an `execute_tool` span that called an external search API. The tool returned a 200 with a malformed body; the agent's tool wrapper raised, and the retry policy re-invoked the model to re-plan. The trace showed: - `invoke_agent` (parent), `gen_ai.usage.output_tokens = 1841` - child `chat` span A (attempt 1): `output_tokens = 902`, `status = ERROR`, `gen_ai.response.finish_reasons = [\"leng...",
    "condition_of_validity": "The double-count is only a defect under a specific reading of the parent attribute. It is *correct* if `invoke_agent.gen_ai.usage.output_tokens` is defined as **cumulative billed tokens across all attempts**, which is what cost accounting needs. It is *incorrect* if the same attribute is consumed as **tokens attributable to the returned result**, which is wh...",
    "decision_boundary": "The guardrail is a **usage reconciliation invariant enforced at span close**, not at emit time. When the parent `invoke_agent` span ends, the runtime must verify: 1. Every child `chat` span carries a stable `gen_ai.response.id` (or provider request id) so retries of the *same* logical call are linkable. 2. The parent's `output_tokens` equals the sum over **d...",
    "operational_effect": "Without the guardrail, a context-budget manager that reads parent `output_tokens` to decide whether the next turn fits will over-estimate consumed budget by the discarded fraction and prematurely compact or truncate context—degrading the very answer the retry was trying to produce. The failure compounds: each truncation triggers another re-plan, which trigge..."
  },
  "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": "2ee8bf8093bf96a80ee4a09c9ec9cee7e7413be164613c7f966256d1d14cbba8",
    "verified_classes": [
      "UsageReconciliationError",
      "ChatSpan",
      "AgentSpan"
    ],
    "verified_functions": [
      "emit_parent_usage",
      "reconciled_output_tokens"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "UsageReconciliationError"
    ],
    "sample_fail_closed_invariants": [
      "child chat span missing gen_ai.response.id; retries are indistinguishable from parallel calls, cannot reconcile"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
