{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-emits-tool-call-spans-under-opentelemetry-genai-conventions-but-the-parent-agent-span-closes-before-the-child-tool-span",
  "title": "What happens when an instance emits tool-call spans under OpenTelemetry GenAI conventions but the parent agent span closes before the child tool span flushes",
  "date_of_record": "2026 November 25",
  "scope": "Applies to agent runtimes that instrument LLM invocations and tool calls using OpenTelemetry GenAI semantic conventions (`gen_ai.*` attributes) where spans are exported asynchronously via a batching span processor. Does not apply to synchronous exporters, single-threaded deterministic test harnesses, or pure prompt-level tracing without tool-call children.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-tool-call-spans-under-opentelemetry-genai-conventions-but-the-parent-agent-span-closes-before-the-child-tool-span.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-tool-call-spans-under-opentelemetry-genai-conventions-but-the-parent-agent-span-closes-before-the-child-tool-span.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-tool-call-spans-under-opentelemetry-genai-conventions-but-the-parent-agent-span-closes-before-the-child-tool-span.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2030,
    "python_slice_tokens": 314,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define attribute *shape*, not span *lifecycle ordering*. A `gen_ai.operation.name = \"execute_tool\"` span is a child of the `gen_ai.operation.name = \"chat\"` (or `invoke_agent`) span by trace-parent linkage, but the runtime that emits it has no enforced contract that the child span must *end and be enqueued* before the parent spa...",
    "what_was_observed": "A multi-step agent loop: `chat` span opens → model returns a `tool_calls` block → runtime opens `execute_tool` span, invokes the tool, ends the tool span → runtime opens a *second* `chat` span for the follow-up turn. The agent's top-level `invoke_agent` span ends when the loop terminates. Trigger condition: the tool execution is fast (sub-millisecond local tool, cached retrieval) while the `BatchSpanProcessor` schedu...",
    "condition_of_validity": "The invariant that must hold: **for any `execute_tool` span, its `end_time` must be causally ordered before the `end_time` of every ancestor span in the same trace, and all ancestors must remain unexported until the descendant is enqueued.** This is trivially true in-process but false across the async export boundary. The invariant is valid only when one of ...",
    "decision_boundary": "The decision is whether to treat the GenAI tool-call span as a *child span* (trace-parent linkage, subject to export ordering) or as a *linked span* (`SpanLink` to the `chat` span, independent lifecycle). The conventions permit both; most instrumentation libraries default to child spans because it renders better in trace UIs. Choose child-span linkage only w...",
    "operational_effect": "Downstream consumers of GenAI telemetry — cost dashboards, tool-success SLOs, retry-attribution models, and any agent auditor replaying traces — depend on the parent-child join to attribute `gen_ai.usage.*` tokens and tool outcomes to the correct agent turn. When the join is broken by export reordering, the effects are: - **Cost undercount per turn**, becaus..."
  },
  "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": "5b5c329dfcc6e8514d9af6430b9cce33b2259b35f7fe853d834ecb2334765a75",
    "verified_classes": [
      "ToolSpanOrderingViolation",
      "SpanRecord",
      "TraceBuffer"
    ],
    "verified_functions": [
      "close_agent_turn",
      "end_span",
      "enqueue_tool_span"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "ToolSpanOrderingViolation"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
