{
  "schema_version": "1.3.0",
  "slug": "in-what-scenarios-must-an-instance-treat-opentelemetry-genai-token-accounting-as-non-additive-across-a-tool-call-chain-and-how-does-span-parenting-cor",
  "title": "In what scenarios must an instance treat OpenTelemetry GenAI token accounting as non-additive across a tool-call chain, and how does span-parenting corrupt the rollup",
  "date_of_record": "2026 November 25",
  "scope": "Applies to agents that emit OTel GenAI spans (`gen_ai.*` attributes) per LLM invocation and per tool call, and that aggregate `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens` by walking the span tree. Does not apply to single-shot LLM calls with no tool loop, nor to billing systems that consume provider-side invoices rather than telemetry.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-opentelemetry-genai-token-accounting-as-non-additive-across-a-tool-call-chain-and-how-does-span-parenting-cor.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-opentelemetry-genai-token-accounting-as-non-additive-across-a-tool-call-chain-and-how-does-span-parenting-cor.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-opentelemetry-genai-token-accounting-as-non-additive-across-a-tool-call-chain-and-how-does-span-parenting-cor.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2081,
    "python_slice_tokens": 454,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions describe *per-span* usage attributes: each `gen_ai.chat` (or `gen_ai.invoke_agent`) span carries the token counts the model returned for *that* completion. They do not specify an aggregation rule across a parent/child span tree. Operators assume the obvious one — sum the leaf `gen_ai.chat` spans and you get the chain total — an...",
    "what_was_observed": "A code-review agent performing a 6-call tool chain (read file → grep → read file → run tests → read diff → summarize). Instrumentation emitted one `gen_ai.invoke_agent` root span and six `gen_ai.chat` children, plus four `gen_ai.execute_tool` spans nested under the chat spans that triggered them. Observed telemetry, condensed: Three separate defects surfaced in the rollup dashboard: 1. The dashboard summed *all* span...",
    "condition_of_validity": "Leaf-sum token accounting is valid if and only if all of the following hold: - **Non-ancestral set.** The summed spans form an antichain in the span tree. No span in the set is an ancestor of another. Enforce by filtering to spans where `span.kind == \"CLIENT\"` and `gen_ai.operation.name == \"chat\"`, and asserting no two share an ancestor-descendant relation. ...",
    "decision_boundary": "The boundary is whether the consumer needs **billing truth** or **state truth**. - Billing, quota enforcement, rate-limit projection → use the leaf sum over the antichain of `chat` spans, *excluding* any span lacking a unique `gen_ai.response.id`. This is the number the provider will invoice. - Context-window management, saturation alerting, history-truncati...",
    "operational_effect": "The failure is not a metrics bug; it propagates into agent behavior. An agent that receives a corrupted token count as part of its own context (via a `get_budget_status` tool, a system-prompt injection of \"you have used N tokens\", or a supervisor's steering message) will make truncation, summarization, and early-termination decisions on a fabricated number. ..."
  },
  "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": "ee0efe8b205a77f27668bb37a59f0a7cb3117e25c4da486b886f51c9f3b2b5a7",
    "verified_classes": [
      "TokenRollupInvariantError",
      "Span",
      "ChainRollup"
    ],
    "verified_functions": [
      "_is_ancestor",
      "rollup_chain"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "TokenRollupInvariantError"
    ],
    "sample_fail_closed_invariants": [
      "assert s.response_id is not None",
      "no billable chat spans in tree"
    ],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
