{
  "schema_version": "1.3.0",
  "slug": "what-structural-signals-indicate-token-accounting-drift-when-opentelemetry-genai-spans-merge-child-tool-call-usage-into-a-parent-agent-span",
  "title": "What structural signals indicate token-accounting drift when OpenTelemetry GenAI spans merge child tool-call usage into a parent agent span",
  "date_of_record": "2026 December 2",
  "scope": "Applies to agents emitting OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*`) where a parent agent/invoke span aggregates token usage from child chat and tool-execution spans. Does not apply to single-shot LLM calls with no child spans, nor to billing systems that read provider-side invoices directly.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-token-accounting-drift-when-opentelemetry-genai-spans-merge-child-tool-call-usage-into-a-parent-agent-span.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-token-accounting-drift-when-opentelemetry-genai-spans-merge-child-tool-call-usage-into-a-parent-agent-span.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-token-accounting-drift-when-opentelemetry-genai-spans-merge-child-tool-call-usage-into-a-parent-agent-span.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1584,
    "python_slice_tokens": 301,
    "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`, and the newer `gen_ai.usage.input_tokens.cached`) as *per-operation* measurements attached to the span that performed the inference. They are **not** defined as additive counters to be rolled up by an agent orchestration layer. The distinction t...",
    "what_was_observed": "A multi-step agent (planner → 4 tool-calling ReAct iterations → synthesizer) emitted a trace where the root `invoke_agent` span carried `gen_ai.usage.input_tokens = 41820` and `output_tokens = 3110`, while the six child `chat` spans each carried their own usage summing to exactly the same 41820/3110. The collector's OTLP-to-metrics processor, configured per the conventions' guidance to emit `gen_ai.client.token.usage...",
    "condition_of_validity": "The rollup is only sound when **exactly one** of the following holds and is enforced structurally: - The root span carries usage **and** has no descendant spans carrying usage attributes (single-inference agent), or - The root span carries **no** usage attributes and aggregation is done exclusively by the backend summing leaf spans, or - The root span carrie...",
    "decision_boundary": "The boundary is whether the emitting agent framework knows, at span-close time, whether it is a leaf or a container. If it cannot distinguish — because the framework writes usage in a `finally` block regardless of child count — it must **not** write usage on the orchestration span. The safe default is: write usage only on spans with `gen_ai.operation.name ∈ ...",
    "operational_effect": "The observable effect is a token-cost metric that inflates by a factor of (inference calls per trace) while latency and error-rate metrics remain correct — a signature that misleads capacity planning toward \"our agents are expensive\" when the true cost is 1/N of reported. Budget alerts fire on summed leaf spans while the root-span dashboard shows a different..."
  },
  "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": "6dead79aa30b750cef18d4ffa8ae861139032f3656eca44c683f070c6162c506",
    "verified_classes": [
      "TokenAccountingDriftError",
      "GenAISpan"
    ],
    "verified_functions": [
      "validate_trace"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "TokenAccountingDriftError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
