{
  "schema_version": "1.3.0",
  "slug": "under-what-conditions-must-an-instance-treat-opentelemetry-genai-token-accounting-spans-as-non-authoritative-when-tool-call-attributes-are-emitted-asy",
  "title": "Under what conditions must an instance treat OpenTelemetry GenAI token-accounting spans as non-authoritative when tool-call attributes are emitted asynchronously by a child span",
  "date_of_record": "2026 November 29",
  "scope": "Applies to any agent runtime that emits OpenTelemetry spans conforming to the GenAI semantic conventions (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.operation.name`, `gen_ai.tool.name`, `gen_ai.tool.call.id`) where tool-call attributes are set by a child span that may outlive or complete after its parent `chat`/`invoke_agent` span. Does not apply to synchronous, single-span-per-turn emitters where all GenAI attributes are finalized before span end.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-opentelemetry-genai-token-accounting-spans-as-non-authoritative-when-tool-call-attributes-are-emitted-asy.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-opentelemetry-genai-token-accounting-spans-as-non-authoritative-when-tool-call-attributes-are-emitted-asy.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-opentelemetry-genai-token-accounting-spans-as-non-authoritative-when-tool-call-attributes-are-emitted-asy.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2072,
    "python_slice_tokens": 292,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define *attribute names* and *attribute placement*, but they do not define a *temporal ordering contract* between the span that owns the token-usage attributes and the child spans that own the tool-call attributes. In most SDK implementations, `gen_ai.usage.*` is set on the parent `chat` span at the moment the model response re...",
    "what_was_observed": "During a replay audit of a multi-tool agent (a retrieval → summarize → cite pipeline), token totals reconstructed from exported spans disagreed with the provider-side billing ledger by 3.1% across a 24-hour window. The discrepancy was not random: it was concentrated in turns where the model emitted *parallel* tool calls (two or more `tool_use` blocks in a single assistant message). The trace for a representative fail...",
    "condition_of_validity": "A GenAI token-accounting record derived from spans is valid **if and only if** all three hold: 1. **Causal closure.** For every span S carrying `gen_ai.usage.output_tokens > 0` and `gen_ai.operation.name=chat`, every `gen_ai.tool.call.id` present in the model's response is represented by a descendant span of S whose `end_time` is ≤ the read time of the accou...",
    "decision_boundary": "The boundary is: **does the emitter finalize the parent span before dispatching children?** - If the runtime dispatches tool calls *before* ending the parent `chat` span (synchronous tool loop inside the span), closure holds by construction, and the token record is authoritative at first read. - If the runtime ends the parent span at model-response completio...",
    "operational_effect": "Downstream of the boundary, three effects compound: 1. **Silent undercount.** Per-turn token dashboards show lower usage than the ledger. Cost attribution to tools is zero for orphaned turns, so tool-level cost ranking is wrong — the most expensive tool (the slow one) appears cheapest because its tokens are unattributed. 2. **Non-reproducible joins.** Re-run..."
  },
  "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": "2ae1eeb9d708d8a3cc2b067302e510e7f54dd6332bdb30cf423935fca0a85039",
    "verified_classes": [
      "TokenAccountingClosureError",
      "GenAISpan",
      "ClosureWatermark"
    ],
    "verified_functions": [
      "finalize_token_record",
      "observe_child",
      "is_closed"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "TokenAccountingClosureError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "time",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
