{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-opentelemetry-genai-tool-call-spans-when-a-provider-emits-both-streaming-deltas-and-a-terminal-usage-block-that-disag",
  "title": "How should an instance reconcile OpenTelemetry GenAI tool-call spans when a provider emits both streaming deltas and a terminal usage block that disagree on token counts",
  "date_of_record": "2026 November 8",
  "scope": "Applies to OTel GenAI instrumentation (semconv `gen_ai.*`) for agent spans where tool calls are streamed incrementally and a terminal `finish_reason`/usage block is also emitted. Does not apply to non-streaming single-shot completions, nor to providers that emit usage exactly once with no delta stream.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-tool-call-spans-when-a-provider-emits-both-streaming-deltas-and-a-terminal-usage-block-that-disag.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-tool-call-spans-when-a-provider-emits-both-streaming-deltas-and-a-terminal-usage-block-that-disag.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-tool-call-spans-when-a-provider-emits-both-streaming-deltas-and-a-terminal-usage-block-that-disag.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1447,
    "python_slice_tokens": 376,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two distinct observables that both look like \"token accounting\": **incremental delta accounting** (per-chunk `gen_ai.usage.input_tokens` / `output_tokens` accumulated as the stream is consumed) and **terminal aggregate accounting** (the usage block carried on the final `message_delta` / `response.completed` event). The GenAI semconv does not mandat...",
    "what_was_observed": "In a streaming agent run against a provider that emits `content_block_delta` events for `tool_use` input JSON, then a `message_delta` with `usage.output_tokens = 412`, the framework's parent span recorded `gen_ai.usage.output_tokens = 690`. Decomposition: - Terminal usage block: 412 (assistant turn including the tool_use JSON). - Child `gen_ai.tool.call` span for the tool result turn: 278. - Parent aggregation: 412 +...",
    "condition_of_validity": "The reconciliation rule below holds only when: 1. The provider emits a terminal usage block that is **scoped to a single turn** (assistant turn, excluding tool result turns), and 2. Tool result turns are emitted as **separate model invocations** with their own usage blocks, and 3. The framework opens a child span per tool invocation with `gen_ai.operation.na...",
    "decision_boundary": "The choice is between **parent-authoritative** and **child-authoritative** token attribution: - **Parent-authoritative** (default): parent `gen_ai.chat` span carries the terminal usage block verbatim; child tool spans carry `gen_ai.usage.*` only if the tool itself invoked a model (nested agent), otherwise omit the attributes entirely. This is correct when th...",
    "operational_effect": "Instrumentation that double-counts produces cost dashboards inflated by the tool-argument token volume, which for agents with large tool schemas can be 30–60% of apparent spend. It also breaks the semconv's implicit contract that `gen_ai.usage.output_tokens` on a `chat` span is comparable across frameworks. The fix is to treat the terminal usage block as the..."
  },
  "matched_failure_symptoms": [
    "OOM_KILL_OR_MEMORY_EXHAUSTION"
  ],
  "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": "acc8fa313d4037b905ffb4dd16ab21f2918a2ecdc1b765f2fe648e7775c91a7a",
    "verified_classes": [
      "GenAIUsageReconciliationError",
      "UsageBlock",
      "SpanUsage"
    ],
    "verified_functions": [
      "reconcile_parent_usage"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "GenAIUsageReconciliationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
