{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-reconcile-otel-genai-span-attributes-when-a-tool-call-span-is-emitted-before-its-parent-model-invocation-span-closes",
  "title": "Where must an instance reconcile OTel GenAI span attributes when a tool-call span is emitted before its parent model-invocation span closes",
  "date_of_record": "2026 December 1",
  "scope": "Applies to agents that emit OpenTelemetry GenAI semantic-convention spans (`gen_ai.operation.name`, `gen_ai.tool.name`, `gen_ai.usage.input_tokens`, `gen_ai.request.model`, `gen_ai.response.finish_reasons`) where tool execution is nested inside a model-invocation turn and spans are exported asynchronously. Does not apply to batch/offline evaluation traces with no live parent, nor to pure LLM-gateway proxies that only proxy a single completion.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-otel-genai-span-attributes-when-a-tool-call-span-is-emitted-before-its-parent-model-invocation-span-closes.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-otel-genai-span-attributes-when-a-tool-call-span-is-emitted-before-its-parent-model-invocation-span-closes.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-otel-genai-span-attributes-when-a-tool-call-span-is-emitted-before-its-parent-model-invocation-span-closes.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1860,
    "python_slice_tokens": 317,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat a model invocation and a tool call as two distinct operations with distinct attribute namespaces, but they do not mandate emission order. In a real agent loop the tool call is *logically* a child of the model invocation that requested it, yet it executes and finishes *before* the model invocation span closes—because the m...",
    "what_was_observed": "A multi-turn agent using a function-calling loop emitted spans in this order for a single user request: 1. `chat` span opened (`gen_ai.operation.name=chat`, `gen_ai.request.model=gpt-4o`, no usage yet). 2. Completion returned a tool call; `execute_tool` span opened as child of (1). 3. Tool ran, `execute_tool` span closed with `gen_ai.tool.name=search_docs`, `gen_ai.tool.call.id=call_abc`. 4. Tool result appended to m...",
    "condition_of_validity": "The failure is bounded and predictable. It occurs only when all of the following hold: - The agent reuses a single model-invocation span across multiple completion round-trips (the \"loop on one span\" pattern), rather than opening a fresh `chat` span per completion. - Tool execution is nested as a child of that reused span. - The exporter is batch-based (OTLP...",
    "decision_boundary": "The correct architectural choice is not \"always open a new span per completion\" (that inflates trace cardinality and breaks the natural parent-child grouping of a single user turn). The boundary is: **if you reuse a model-invocation span across tool round-trips, you must not let any consumer observe its usage before `end()`.** Two admissible resolutions: 1. ...",
    "operational_effect": "The practical consequence is that GenAI trace *completeness* and GenAI trace *correctness* diverge. A trace can have every span, every correct `trace_id`, every correct `parent_span_id`, and still report per-tool token cost as zero, because the join resolved against a parent snapshot taken before the parent's usage attributes were written. Cost dashboards, b..."
  },
  "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": "5514c9a4c7de718ce1391ec32a3895a1e6fd7582ff3de2d321477ff20d55eb1d",
    "verified_classes": [
      "UsageAttributionError",
      "GenAISpan"
    ],
    "verified_functions": [
      "attribute_tool_usage",
      "is_final"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 6,
    "raised_exceptions": [
      "UsageAttributionError"
    ],
    "sample_fail_closed_invariants": [
      "assert attribute_tool_usage(tool, chat) == 4120"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
