{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-reconcile-span-close-ordering-when-a-tool-call-span-outlives-its-parent-agent-turn-the-orphan-span-attribution-failure-in-opent",
  "title": "Where must an instance reconcile span-close ordering when a tool-call span outlives its parent agent turn: the orphan-span attribution failure in OpenTelemetry GenAI traces",
  "date_of_record": "2026 November 21",
  "scope": "Applies to agent runtimes that emit OpenTelemetry spans per reasoning turn, per tool call, and per LLM invocation under the GenAI semantic conventions, where a tool call can complete asynchronously after the parent agent turn span has already been closed. Does not apply to synchronous single-turn tool calls fully nested inside one parent span, nor to trace-only sampling regimes that discard partial traces before export.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-span-close-ordering-when-a-tool-call-span-outlives-its-parent-agent-turn-the-orphan-span-attribution-failure-in-opent.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-span-close-ordering-when-a-tool-call-span-outlives-its-parent-agent-turn-the-orphan-span-attribution-failure-in-opent.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-span-close-ordering-when-a-tool-call-span-outlives-its-parent-agent-turn-the-orphan-span-attribution-failure-in-opent.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1902,
    "python_slice_tokens": 348,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions model an LLM invocation as a span carrying `gen_ai.operation.name`, `gen_ai.request.model`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, and tool calls as child spans carrying `gen_ai.tool.name`, `gen_ai.tool.call.id`, and `gen_ai.tool.type`. The conventions assume a *containment* topology: every tool-call span is...",
    "what_was_observed": "A three-tool agent loop on a single trace. Turn 1 issues `search` (fast, 40 ms) and `fetch_page` (slow, 4.2 s) in parallel via a fan-out, then yields. The turn span `agent.turn` closes at t+120 ms with `gen_ai.usage.input_tokens=1810`, `output_tokens=224`. The `search` child closes at t+40 ms — valid. The `fetch_page` child closes at t+4200 ms — 4.08 s *after* its parent. Observed consequences in the trace store: 1. ...",
    "condition_of_validity": "The containment invariant — child `end_time` ≤ parent `end_time` — holds if and only if the parent span is not closed until all children are closed. This is achievable only under one of three runtime disciplines: - **Join-before-close:** the turn span is held open (or its close is deferred) until every tool-call span it spawned has ended. Correct but inflate...",
    "decision_boundary": "The boundary is crossed at the moment a turn span is closed while a child tool span is still `RECORDING`. The runtime must decide, at close time, one of: - **Block** the close until children drain (join-before-close). Valid only when the tool timeout is bounded and less than the turn budget. - **Detach** the pending children to root-parented spans with links...",
    "operational_effect": "Enforcing the invariant at the span-processor layer converts the silent corruption into a loud, bounded failure. The processor, on `on_end(span)`, walks the active-child registry for that span; if any child is active, it either raises (strict mode, for development) or re-parents the pending children to the trace root and attaches a `Link` to the closing span..."
  },
  "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": "50a3a0d150f33dd0200ac17e5b0f5795bbe987662bd99d6cc7806ea1678887b3",
    "verified_classes": [
      "OrphanSpanAttributionError",
      "Span",
      "SpanProcessor"
    ],
    "verified_functions": [
      "close_turn_span",
      "__init__",
      "on_start",
      "on_end",
      "_find_active"
    ],
    "verified_functions_count": 5,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "OrphanSpanAttributionError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
