{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-double-counts-tool-call-tokens-across-nested-agent-spans",
  "title": "What happens when an instance double-counts tool-call tokens across nested agent spans",
  "date_of_record": "2026 November 10",
  "scope": "Applies to OpenTelemetry traces in which a GenAI agent span emits `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens` while its child tool-execution spans (or nested agent spans) also emit usage attributes that are subsequently aggregated by a collector, backend rollup, or cost pipeline. Does not apply to flat, non-nested spans where each span owns a disjoint token budget, nor to spans that emit usage only at the root.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-double-counts-tool-call-tokens-across-nested-agent-spans.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-double-counts-tool-call-tokens-across-nested-agent-spans.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-double-counts-tool-call-tokens-across-nested-agent-spans.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1642,
    "python_slice_tokens": 367,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define token usage as an attribute of the span that *caused* the model invocation — `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` on the span whose `gen_ai.operation.name` is `chat` (or `text_completion`). They do **not** define a rule for composing usage across a span tree. This is the non-obvious boundary: a pa...",
    "what_was_observed": "A retrieval agent was instrumented with a root `invoke_agent` span, a child `chat` span for the planning call, and a child `execute_tool` span for a `search` tool that itself issued an internal `chat` call to summarize results. All three spans emitted usage attributes. The observed trace: - root `invoke_agent`: `input_tokens=1840`, `output_tokens=310` - child `chat` (planning): `input_tokens=1200`, `output_tokens=180...",
    "condition_of_validity": "The double-count is only a defect under a specific conjunction: 1. A span and at least one of its descendants both emit `gen_ai.usage.*`, **and** 2. the ancestor's usage value is *inclusive* of the descendant's model calls (true for synchronous agent loops, false for fire-and-forget fan-out where the parent returns before children complete), **and** 3. the c...",
    "decision_boundary": "Choose the accounting strategy before instrumenting, not after: - **Root-only accounting (recommended for cost):** emit `gen_ai.usage.*` only on the span designated as the trace's accounting root; children emit model-call spans with *no* usage attributes, or with usage attributes and an explicit `gen_ai.usage.scope=exclusive` custom attribute. Aggregation se...",
    "operational_effect": "The practical consequence is that token accounting and cost attribution become topology-dependent and silently drift as agents are refactored. A synchronous loop refactored to async fan-out halves the reported cost without any change in actual spend; a fan-out refactored to sequential doubles it. Dashboards built on summed usage are not measuring spend — the..."
  },
  "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": "53bd14d7649a3ca5179c1d9a33dd55a9a8d3901e4e589ef48460f646f710a683",
    "verified_classes": [
      "TokenAccountingError",
      "Span"
    ],
    "verified_functions": [
      "validate_usage_tree",
      "rollup_tokens",
      "emits_usage",
      "descendants"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "TokenAccountingError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
