{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-attributes-a-nested-tool-call-span-s-tokens-to-the-parent-agent-span-double-counting-and-orphaned-cost-under-opentelemet",
  "title": "What happens when an instance attributes a nested tool-call span's tokens to the parent agent span: double-counting and orphaned cost under OpenTelemetry GenAI semantic conventions",
  "date_of_record": "2026 November 28",
  "scope": "Applies to agents emitting OpenTelemetry spans conforming to the GenAI semantic conventions (`gen_ai.*` attributes) where an agent span (`gen_ai.operation.name = \"invoke_agent\"`) parents one or more child tool-execution spans that themselves invoke LLM calls. Does not apply to flat single-span-per-LLM-call instrumentation, nor to backends that deduplicate on `gen_ai.response.id`.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-attributes-a-nested-tool-call-span-s-tokens-to-the-parent-agent-span-double-counting-and-orphaned-cost-under-opentelemet.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-attributes-a-nested-tool-call-span-s-tokens-to-the-parent-agent-span-double-counting-and-orphaned-cost-under-opentelemet.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-attributes-a-nested-tool-call-span-s-tokens-to-the-parent-agent-span-double-counting-and-orphaned-cost-under-opentelemet.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1707,
    "python_slice_tokens": 163,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define token-usage attributes (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`) as properties of a *single model inference*, keyed to the span that represents that inference. They do **not** define a rollup contract for agent spans that orchestrate multiple inferences. The distinction that breaks is between *inference...",
    "what_was_observed": "A research agent executes a plan with a tool-calling loop. Per user turn it emits: one `invoke_agent` root span, N `execute_tool` child spans, and, nested under each tool span, one or more `chat` spans for the sub-LLM calls the tool makes (e.g., a summarizer tool that calls a model to compress retrieved documents). The instrumentation library was configured with a \"propagate usage to parent\" flag to make dashboards s...",
    "condition_of_validity": "The double-count is *only* absent when one of the following holds, and each must be enforced, not assumed: 1. **No rollup.** `invoke_agent` spans carry no `gen_ai.usage.*` attributes; usage lives exclusively on `chat` spans. Backends compute agent totals by summing leaves. This is the spec-faithful configuration and the one to default to. 2. **Rollup with le...",
    "decision_boundary": "The boundary is drawn at the **span that represents an inference**. Attribute `gen_ai.usage.*` to exactly one span per inference — the `chat` span whose `gen_ai.response.id` identifies it — and never to an ancestor. If a product requirement demands an agent-level total on the root span (dashboards, budget enforcement at the agent granularity), emit it under ...",
    "operational_effect": "With the spec-faithful configuration (no rollup, usage only on `chat` spans), cost dashboards must aggregate at the leaf and join to the agent via `trace_id`/`parent_span_id`; totals are then exact and reconcile against provider invoices. With the rollup configuration, every tool-mediated inference is counted twice, retried inferences are counted 1.x times d..."
  },
  "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": "92c0f4979d8b98bd869de85e3c2cb3eef066e20a8310e7f34e5e3a8911ca59a3",
    "verified_classes": [
      "UsageAttributionError"
    ],
    "verified_functions": [
      "emit_span_usage"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "UsageAttributionError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
