{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-opentelemetry-genai-tool-call-spans-when-a-single-agent-step-emits-both-a-parent-execute-tool-span-and-a-child-provid",
  "title": "How should an instance reconcile OpenTelemetry GenAI tool-call spans when a single agent step emits both a parent `execute_tool` span and a child provider span whose token attributes disagree?",
  "date_of_record": "2026 November 27",
  "scope": "Applies to agents that wrap tool invocations in an explicit `execute_tool` span (per OTel GenAI semconv `gen_ai.operation.name = \"execute_tool\"`) while also emitting provider-native chat spans (`gen_ai.operation.name = \"chat\"`) for the model call that *decided* to invoke the tool. Does not apply to agents that emit a single flattened span per step, nor to pure streaming token accounting without tool calls.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-tool-call-spans-when-a-single-agent-step-emits-both-a-parent-execute-tool-span-and-a-child-provid.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-tool-call-spans-when-a-single-agent-step-emits-both-a-parent-execute-tool-span-and-a-child-provid.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-tool-call-spans-when-a-single-agent-step-emits-both-a-parent-execute-tool-span-and-a-child-provid.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1420,
    "python_slice_tokens": 329,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define two independent accounting surfaces that a naive agent conflates: **operation-scoped token attributes** (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`) belong to the span where the model inference actually happened, while **tool-call attributes** (`gen_ai.tool.name`, `gen_ai.tool.call.id`) belong to the span ...",
    "what_was_observed": "A ReAct-style agent executed a step: `chat` span (model decides to call `search_docs`) → `execute_tool` span (the tool runs). The instrumentation library attached `gen_ai.usage.input_tokens=1840`, `gen_ai.usage.output_tokens=112` to the `chat` span correctly, but a step-level decorator also stamped the *same* values onto the enclosing `execute_tool` span because it read the last-known usage from a shared context vari...",
    "condition_of_validity": "The double-count is only *possible* when three conditions coincide: (1) the agent emits a structural parent span for the tool step that is not the inference span; (2) the instrumentation reads usage from a mutable context variable populated by the most recent inference, rather than from the inference span's own scope; and (3) the exporter does not enforce th...",
    "decision_boundary": "The reconciliation rule an instance must enforce at span-close time: - If `gen_ai.operation.name == \"execute_tool\"` **and** any `gen_ai.usage.*` attribute is present → the span is mis-attributed. Do **not** silently drop; emit a `gen_ai.usage.reconciliation=\"reassigned\"` marker and move the values to the nearest descendant `chat` span if one exists, else dro...",
    "operational_effect": "Without the guard, cost dashboards over-report by the fan-out factor of tool steps per inference—typically 1.5–3× for tool-heavy agents—and budget guards that halt an agent at a token ceiling fire *early*, truncating legitimate runs. A token-rate autoscaler sees phantom load and over-provisions. The fix is a close-time validator in the span processor that en..."
  },
  "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": "0c0a63a99cba8003238713880a13e45fdc2d519f6f6e6429aa1edc30c999fbde",
    "verified_classes": [
      "TokenAttributionError",
      "Span"
    ],
    "verified_functions": [
      "reconcile_trace",
      "validate_step_span",
      "has_usage",
      "usage",
      "walk"
    ],
    "verified_functions_count": 5,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "TokenAttributionError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
