{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-attributes-the-tool-call-span-to-the-wrong-agent-turn-and-the-genai-token-accounting-silently-double-counts-the-parent-s",
  "title": "What happens when an instance attributes the tool-call span to the wrong agent turn and the GenAI token accounting silently double-counts the parent's completion tokens",
  "date_of_record": "2026 November 25",
  "scope": "Applies to agents instrumented with OpenTelemetry GenAI semantic conventions (`gen_ai.*`) where a single logical turn fans out into child tool-execution spans and the parent `gen_ai.chat` span reports `gen_ai.usage.output_tokens`. Does not apply to single-shot inference calls with no nested tool spans, nor to systems that emit usage only at the trace root.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-attributes-the-tool-call-span-to-the-wrong-agent-turn-and-the-genai-token-accounting-silently-double-counts-the-parent-s.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-attributes-the-tool-call-span-to-the-wrong-agent-turn-and-the-genai-token-accounting-silently-double-counts-the-parent-s.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-attributes-the-tool-call-span-to-the-wrong-agent-turn-and-the-genai-token-accounting-silently-double-counts-the-parent-s.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2038,
    "python_slice_tokens": 361,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The distinction that matters here is between **span nesting as causal structure** and **span nesting as accounting structure**. Under the GenAI semantic conventions, a parent `gen_ai.chat` span and its child `gen_ai.tool` (execute_tool) spans form a tree by `parent_span_id`. It is tempting to assume that tree also defines token attribution: the parent owns i...",
    "what_was_observed": "In a mid-size deployment, cost dashboards diverged from the provider invoice by a stable ~1.6× factor over a week. The divergence was not uniform: single-tool turns were near-correct, multi-tool turns over-reported, and turns that ended in a refusal (no second chat span) under-reported relative to the invoice because the refusal path emitted the turn-span aggregate but no child chat span. The trace-level evidence: 1....",
    "condition_of_validity": "The invariant \"trace-summed `gen_ai.usage.output_tokens` equals billed output\" is valid **if and only if** every span carrying that attribute represents a distinct, non-overlapping unit of model output. This requires: - No span in the trace is a *rollup* of other spans' usage (or, if it is, it is marked with a distinct attribute such as `gen_ai.usage.aggrega...",
    "decision_boundary": "The boundary is: **does the span carry usage as a leaf measurement or as a rollup?** If a span's `gen_ai.usage.output_tokens` is a measurement of one model call, it belongs in the sum. If it is a convenience copy of a descendant's value, it must be excluded. Because the conventions do not encode this distinction, the operator must choose one of two disciplin...",
    "operational_effect": "The downstream effects compound: - **Cost alarms fire on healthy traffic.** The 1.6× over-report means budget thresholds calibrated against the invoice trigger early; operators who \"fix\" this by scaling the alarm threshold then under-detect genuine runaway loops. - **Per-tool cost attribution inverts.** Because the tool span was re-parented under chat #1, th..."
  },
  "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": "fc528f115969f146095ecb3b01e2bcb96a7b2336beafecebdf709be33d8d44cd",
    "verified_classes": [
      "UsageAttributionError",
      "Span"
    ],
    "verified_functions": [
      "validate_usage_attribution",
      "has_chat_descendant"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "UsageAttributionError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
