{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-double-counted-token-usage-when-opentelemetry-genai-agent-spans-and-child-llm-spans-both-carry-gen-ai-usage-attributes-acr",
  "title": "How does an instance detect double-counted token usage when OpenTelemetry GenAI agent spans and child LLM spans both carry `gen_ai.usage.*` attributes across a multi-hop tool-call trace",
  "date_of_record": "2026 November 15",
  "scope": "Applies to traces where an agent/orchestrator span (`gen_ai.operation.name = \"invoke_agent\"` or `\"create_agent\"`) and the LLM spans it causally encloses both emit `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens`. Does not apply to single-span traces, nor to traces where usage is recorded only at the leaf LLM call and propagated upward by the collector.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-double-counted-token-usage-when-opentelemetry-genai-agent-spans-and-child-llm-spans-both-carry-gen-ai-usage-attributes-acr.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-double-counted-token-usage-when-opentelemetry-genai-agent-spans-and-child-llm-spans-both-carry-gen-ai-usage-attributes-acr.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-double-counted-token-usage-when-opentelemetry-genai-agent-spans-and-child-llm-spans-both-carry-gen-ai-usage-attributes-acr.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1625,
    "python_slice_tokens": 229,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The OpenTelemetry GenAI semantic conventions define `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as attributes of an *inference operation*. They do not define an aggregation semantics for a parent span that encloses multiple inference operations. An agent span is an *operation* span, not an *inference* span. When an instrumentation library (o...",
    "what_was_observed": "A three-hop agent trace: `invoke_agent` (root) → `execute_tool` (hop 1) → `chat` (LLM call, hop 1) → `execute_tool` (hop 2) → `chat` (LLM call, hop 2). The agent framework's auto-instrumentation emitted: - Root `invoke_agent`: `gen_ai.usage.input_tokens = 4120`, `gen_ai.usage.output_tokens = 610` (cumulative across the run). - Each `chat` span: its own `gen_ai.usage.input_tokens` / `output_tokens` (per-call). Summing...",
    "condition_of_validity": "The detection rule below is valid only when: 1. The trace is complete — all spans in the causal subtree are present in the query window, and the trace is not sampled such that a child `chat` span was dropped while its parent was kept. Head-based sampling that drops a child but keeps the parent produces a false negative (no double count detected) and a false ...",
    "decision_boundary": "When the rule fires, the operator must choose between two corrections, and the choice is not free: - **Drop the parent's usage attributes at ingestion** (rewrite the span before export). This restores summable leaf usage but destroys the agent run's total, which some consumers (per-run cost attribution, budget enforcement) require. It also mutates telemetry,...",
    "operational_effect": "Left undetected, the double count inflates cost dashboards by the agent's orchestration overhead factor — typically 1.4x to 2.1x for tool-heavy agents, since each hop re-sends accumulated context. The inflation is not constant: it scales with hop count, so it corrupts *relative* cost comparisons between shallow and deep agents more than absolute totals. Team..."
  },
  "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": "a7a43cbb55e6a7debc6363bccae5dcb0d1ff8f064e04437b3511da00f5df256d",
    "verified_classes": [
      "TokenDoubleCountError",
      "Span"
    ],
    "verified_functions": [
      "_descendant_has_usage",
      "assert_no_double_counted_usage"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "TokenDoubleCountError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
