{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-parent-child-span-orphaning-when-an-agent-s-tool-call-span-outlives-its-parent-turn-under-opentelemetry-genai-semantic-conven",
  "title": "Which invariants prevent parent-child span orphaning when an agent's tool-call span outlives its parent turn under OpenTelemetry GenAI semantic conventions",
  "date_of_record": "2026 November 26",
  "scope": "Applies to agent runtimes that emit OpenTelemetry GenAI spans (`gen_ai.*` semconv) with a turn/step parent span and nested tool-call child spans, where tool execution is asynchronous and may complete after the parent turn span has ended. Does not apply to synchronous in-process tool calls that always return before the parent span closes, nor to batch/offline trace export where ordering is reconstructed post-hoc.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-parent-child-span-orphaning-when-an-agent-s-tool-call-span-outlives-its-parent-turn-under-opentelemetry-genai-semantic-conven.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-parent-child-span-orphaning-when-an-agent-s-tool-call-span-outlives-its-parent-turn-under-opentelemetry-genai-semantic-conven.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-parent-child-span-orphaning-when-an-agent-s-tool-call-span-outlives-its-parent-turn-under-opentelemetry-genai-semantic-conven.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2072,
    "python_slice_tokens": 418,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define *attribute* schemas (`gen_ai.operation.name`, `gen_ai.tool.name`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.request.model`) but they do **not** define a *lifetime* contract between a tool-call span and the agent turn span that owns it. The convention tells you how to label a child span; it says n...",
    "what_was_observed": "A long-running agent (retrieval + code-execution tools, median tool latency 40s, p99 210s) emitted turn spans with a 60s wall-clock budget. On turns where a tool exceeded 60s, the following trace shape was produced: 1. Turn span `T` opened, `gen_ai.operation.name=chat`, `gen_ai.usage.input_tokens=1840` recorded at model-response time. 2. Tool-call span `C` opened as child of `T`, `gen_ai.operation.name=execute_tool`,...",
    "condition_of_validity": "The orphaning is only a *correctness* failure (as opposed to a cosmetic trace-rendering issue) when all of the following hold: 1. The tool-call span's lifetime can exceed the parent turn span's lifetime (async tools, human-in-the-loop tools, long code execution). 2. At least one accounting or attribution query keys on span *hierarchy* (root-span grouping, pa...",
    "decision_boundary": "The boundary is: **does the span processor guarantee parent-before-child export ordering for the entire trace, or not?** - If the exporter uses a `SimpleSpanProcessor` with synchronous flush, or a `BatchSpanProcessor` configured such that the parent's batch cannot flush before all children end (e.g., parent span held in a `CompositeSpan` / explicit parent-sc...",
    "operational_effect": "When the redundant turn-correlation attribute is absent and an async tool outlives its turn, the observable effects are: - **Cost aggregation drift:** per-root-span token sums undercount turns (each detached tool span becomes a 0-token root), and per-trace averages shift as trace counts inflate. Budget enforcement keyed on root spans over-admits. - **Replay ..."
  },
  "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": "de808ac4cc5c7b50420c9d39a616d00d419efadf5cae1c1da7188cf15173e4b1",
    "verified_classes": [
      "OrphanedToolSpanError",
      "GenAISpan"
    ],
    "verified_functions": [
      "attribute_turn_tokens",
      "enforce_hierarchy_invariant"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "OrphanedToolSpanError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
