{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-of-a-genai-agent-span-is-exported-before-its-tool-call-child-spans-are-finalized",
  "title": "What happens when an instance of a GenAI agent span is exported before its tool-call child spans are finalized",
  "date_of_record": "2026 November 12",
  "scope": "Applies to OpenTelemetry SDKs emitting GenAI semantic conventions (`gen_ai.*`) for agent workflows where model invocation spans and tool execution spans are produced by separate instrumentation layers (e.g., an LLM client wrapper and a tool-executor wrapper) and are exported through a batching processor. Does not apply to synchronous single-threaded instrumentation where the parent span is guaranteed to end after all children, nor to exporters that buffer entire traces until root completion (e.g., certain tail-sampling collectors).",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-of-a-genai-agent-span-is-exported-before-its-tool-call-child-spans-are-finalized.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-of-a-genai-agent-span-is-exported-before-its-tool-call-child-spans-are-finalized.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-of-a-genai-agent-span-is-exported-before-its-tool-call-child-spans-are-finalized.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1621,
    "python_slice_tokens": 294,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define two distinct span shapes: the **model invocation span** (`gen_ai.operation.name = \"chat\"` / `\"text_completion\"`, carrying `gen_ai.request.model`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`) and the **tool execution span** (`gen_ai.operation.name = \"execute_tool\"`, carrying `gen_ai.tool.name`, `gen_ai.tool....",
    "what_was_observed": "In a LangChain-style agent runner instrumented with the OpenTelemetry GenAI conventions, the agent invocation span was being ended by the orchestrator as soon as the model returned a `tool_calls` payload, on the assumption that \"the model call is done.\" The tool executor then ran asynchronously and emitted its `execute_tool` span with `parent_span_id` pointing at the already-ended agent span. Symptoms in the exported...",
    "condition_of_validity": "This failure requires the conjunction of: - **Separate instrumentation scopes** for model invocation and tool execution (the common case with framework-level auto-instrumentation plus a user-supplied tool wrapper). - **Parent span ended by the orchestrator before tool dispatch completes** — i.e., the agent span's lifetime is bounded by the model call, not th...",
    "decision_boundary": "Do **not** end the agent-invocation span at model-return when the response contains `tool_calls`. The correct boundary is: the agent span ends only after every tool span it spawned has ended and its result has been appended to the conversation. Concretely: - Treat the model invocation span and each tool span as children of a single agent-turn span whose life...",
    "operational_effect": "After restructuring the agent runner to hold the turn span open across tool execution and to stamp `gen_ai.tool.call.id` at span start, the observed effects were: - Tool spans stopped appearing as orphans; trace-detail views showed the full `chat → execute_tool → chat` chain in 100% of sampled traces (previously ~62%). - The `spanmetrics` connector produced ..."
  },
  "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": "cc49e011f93ef4f35595117242e22801be4a59a8810625c384725224ae8edbb8",
    "verified_classes": [
      "GenAiSpanOrderingError",
      "SpanRecord"
    ],
    "verified_functions": [
      "validate_agent_turn",
      "ancestors"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "GenAiSpanOrderingError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
