{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-opentelemetry-genai-span-closure-when-a-tool-call-child-span-outlives-its-parent-agent-span",
  "title": "How should an instance reconcile OpenTelemetry GenAI span closure when a tool-call child span outlives its parent agent span",
  "date_of_record": "2026 November 24",
  "scope": "Applies to any agent runtime that emits OTel GenAI spans (`gen_ai.operation.name`, `gen_ai.tool.name`, `gen_ai.usage.input_tokens`/`output_tokens`) where tool invocations are modeled as child spans of an agent/LLM span and the tool executes asynchronously (streaming, long-poll, human-in-the-loop, or MCP round-trip). Does not apply to fully synchronous, single-threaded tool dispatch where the child span is guaranteed to end before the parent returns.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-span-closure-when-a-tool-call-child-span-outlives-its-parent-agent-span.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-span-closure-when-a-tool-call-child-span-outlives-its-parent-agent-span.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-span-closure-when-a-tool-call-child-span-outlives-its-parent-agent-span.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2015,
    "python_slice_tokens": 414,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat token usage as an attribute of the *operation* span (`gen_ai.usage.*`), and tool calls as *separate* child spans carrying `gen_ai.tool.name` and `gen_ai.tool.call.id`. This is coherent only if the parent operation span's lifetime strictly encloses every tool span it spawned. The boundary condition is when it does not: an ...",
    "what_was_observed": "A multi-step agent executing a plan emitted, per step, one `gen_ai.operation.name=chat` span with `gen_ai.usage.output_tokens` set at response completion, and one child span per tool call (`gen_ai.operation.name=execute_tool`, `gen_ai.tool.name=search_index`). The tool was an MCP round-trip with a 4–11s tail latency. The agent span was closed as soon as the model returned the tool-call request — *before* dispatch — b...",
    "condition_of_validity": "The convention that \"tool-call spans are children of the operation span that requested them, and operation token usage is attributable to that span\" holds **iff** the parent span's `end_time` is stamped no earlier than the maximum `end_time` of all descendant spans created during that operation. Formally, for operation span `P` and its spawned tool spans `T_...",
    "decision_boundary": "The instance must choose, at the moment the model returns a tool-call request, between two span topologies. The decision is forced by whether the tool can complete within the operation's semantic unit: - **Close-parent-now (fire-and-forget):** correct only if the tool span is emitted as a `SpanLink` and token/latency accounting is hoisted to a parent *task* ...",
    "operational_effect": "With containment enforced, three downstream properties become true that were false before: 1. **Trace trees are single-rooted per task.** No orphan fragments; `parent_span_id` always resolves within the exported window because the parent outlives its children by construction. 2. **Token accounting is closed.** `sum(gen_ai.usage.input_tokens + output_tokens)`..."
  },
  "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": "4766a165fd89ca876073a30ee486cccd83a0e5a77e8c8d006972152397b11a58",
    "verified_classes": [
      "SpanContainmentViolation",
      "GenAISpan",
      "ContainmentEnforcingTracer"
    ],
    "verified_functions": [
      "__init__",
      "start_operation",
      "start_tool",
      "end_tool",
      "end_operation"
    ],
    "verified_functions_count": 5,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "SpanContainmentViolation"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "time",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
