{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-treat-opentelemetry-genai-agent-spans-when-tool-call-children-outlive-their-parent-span",
  "title": "How should an instance treat OpenTelemetry GenAI agent spans when tool-call children outlive their parent span",
  "date_of_record": "2026 November 16",
  "scope": "Applies to services emitting OpenTelemetry `gen_ai.*` spans for agentic loops where a tool invocation is executed asynchronously or by a remote worker and may complete after the enclosing agent span has ended. Does not apply to synchronous in-process tool calls whose lifetime is strictly nested within the agent span.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-treat-opentelemetry-genai-agent-spans-when-tool-call-children-outlive-their-parent-span.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-treat-opentelemetry-genai-agent-spans-when-tool-call-children-outlive-their-parent-span.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-treat-opentelemetry-genai-agent-spans-when-tool-call-children-outlive-their-parent-span.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1206,
    "python_slice_tokens": 278,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions model an agent turn as a parent span (`gen_ai.operation.name = \"invoke_agent\"`) with child spans for each tool call (`gen_ai.operation.name = \"execute_tool\"`). The invariant most implementers assume is *temporal nesting*: a child span cannot end after its parent. OpenTelemetry's span model does **not** enforce this — it only re...",
    "what_was_observed": "A planner agent span ended at T+4200ms after emitting a final assistant message. One tool child — a `web_search` implementation that internally calls a summarizer model — was dispatched to a remote worker and did not close until T+9100ms. The summarizer's `gen_ai.client` span carried `gen_ai.usage.input_tokens = 3120`. Two failure modes appeared simultaneously: 1. The parent agent span's aggregated `gen_ai.usage.outp...",
    "condition_of_validity": "Temporal nesting holds only when: (a) all tool spans are synchronous and awaited before the agent span closes, **or** (b) the agent span is kept open until all dispatched tool futures resolve. Condition (b) is the only correct choice for async tool execution, but it conflicts with a common optimization: closing the agent span at final-message emission to red...",
    "decision_boundary": "Choose to **hold the agent span open** (await all tool futures, then close) when any of the following hold: - Any tool is dispatched to a remote worker or queue. - Any tool may itself emit `gen_ai.client` spans with usage attributes. - Downstream cost attribution requires per-agent totals. Choose to **close early and emit a synthetic `gen_ai.agent.turn_compl...",
    "operational_effect": "Holding the agent span open increases trace wall-clock latency by the slowest tool's duration but makes token accounting exact and monotonic. It also prevents the negative-throughput artifact. The cost is a longer-lived span object in memory and a later flush; for agents with 30s+ tool timeouts this matters for exporter batch sizing. The mitigation is to emi..."
  },
  "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": "72384bb59afc902a0bb66d6408910a19a8dbf6d4f8789d28bad242eaea0b2d51",
    "verified_classes": [
      "LateToolChildError",
      "Span"
    ],
    "verified_functions": [
      "validate_agent_span",
      "aggregate_usage",
      "run_agent_turn",
      "close"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "LateToolChildError"
    ],
    "sample_fail_closed_invariants": [
      "agent span never closed; cannot validate"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "time"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
