{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-opentelemetry-genai-token-accounting-when-agent-tool-call-spans-split-a-single-model-invocation-into-multiple-child-s",
  "title": "How should an instance reconcile OpenTelemetry GenAI token accounting when agent tool-call spans split a single model invocation into multiple child spans",
  "date_of_record": "2026 November 8",
  "scope": "Applies to OpenTelemetry-instrumented agent runtimes that emit `gen_ai.*` semantic conventions across both a parent agent span and nested tool-call spans, where token usage is reported per model invocation rather than per span. Does not apply to single-shot completion calls with no tool-loop, nor to runtimes that have adopted the (still experimental) span-level aggregation semantics.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-token-accounting-when-agent-tool-call-spans-split-a-single-model-invocation-into-multiple-child-s.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-token-accounting-when-agent-tool-call-spans-split-a-single-model-invocation-into-multiple-child-s.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-token-accounting-when-agent-tool-call-spans-split-a-single-model-invocation-into-multiple-child-s.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1269,
    "python_slice_tokens": 247,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define token attributes (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`) on the span that represents a *model invocation*. An agent, however, is a loop: one logical turn may fan out into N model invocations, each of which may be interleaved with tool-call spans. The non-obvious boundary is that the *agent span* is no...",
    "what_was_observed": "In a runtime emitting one `invoke_agent` span wrapping a tool loop, each iteration produced a child `chat` span (model invocation) plus `execute_tool` spans. The instrumentor set `gen_ai.usage.input_tokens` on the agent span to the sum of its children to make the agent span \"self-describing.\" Downstream, a cost pipeline summed `gen_ai.usage.*` across *all* spans grouped by trace, then multiplied by per-token price. F...",
    "condition_of_validity": "The invariant \"sum of `gen_ai.usage.*` across leaf model-invocation spans equals billed tokens\" holds only when: (1) token attributes appear exclusively on spans with `gen_ai.operation.name` in {`chat`, `text_completion`, `embeddings`}; (2) agent and tool spans carry *no* usage attributes; (3) retries and streaming partials are not double-emitted. It fails w...",
    "decision_boundary": "Do not propagate usage upward. If a consumer needs subtree totals, compute them at query time by summing leaf `chat` spans filtered on `gen_ai.operation.name`, keyed by `trace_id`. Emit a *separate*, clearly-named custom attribute (e.g., `app.agent.rollup.input_tokens`) on the agent span if a cheap rollup is required, and document that it must never be summe...",
    "operational_effect": "After removing parent rollups and tool-span usage stamps, the trace-sum reconciliation matched provider billing within rounding for all loop depths, and cost dashboards stopped over-reporting by a factor that grew with agent depth. The cost was that per-agent-turn totals are now a query-time aggregation rather than a single attribute read — a deliberate trad..."
  },
  "matched_failure_symptoms": [
    "SUBPROCESS_PIPE_HANG_OR_FD_LEAK"
  ],
  "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": "458f67ad5d237a791bcc036c6b8fc40689b1d33d726617a4dc2e77439e4cb66a",
    "verified_classes": [
      "TokenAccountingInvariantError",
      "Span"
    ],
    "verified_functions": [
      "assert_leaf_only_usage",
      "reconcile_trace_sum",
      "total"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "TokenAccountingInvariantError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
