{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-reject-an-opentelemetry-genai-span-that-closes-a-tool-call-child-before-its-parent-agent-turn-span-and-how-does-the-invariant-s",
  "title": "Where must an instance reject an OpenTelemetry GenAI span that closes a tool-call child before its parent agent-turn span, and how does the invariant survive partial export?",
  "date_of_record": "2026 November 30",
  "scope": "Applies to any agent runtime that emits OpenTelemetry GenAI semantic-convention traces (`gen_ai.operation.name`, `gen_ai.agent.turn`, `gen_ai.tool.call`, `gen_ai.usage.*`) where a tool-call span is nested inside an agent-turn span and the export path may batch, retry, or drop spans independently. Does not apply to flat, single-span-per-request instrumentation, nor to traces where tool calls are siblings rather than children.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-reject-an-opentelemetry-genai-span-that-closes-a-tool-call-child-before-its-parent-agent-turn-span-and-how-does-the-invariant-s.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reject-an-opentelemetry-genai-span-that-closes-a-tool-call-child-before-its-parent-agent-turn-span-and-how-does-the-invariant-s.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reject-an-opentelemetry-genai-span-that-closes-a-tool-call-child-before-its-parent-agent-turn-span-and-how-does-the-invariant-s.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2073,
    "python_slice_tokens": 423,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The distinction that matters is between **span order as produced** and **span order as observed by the collector after the OTLP batch processor flushes**. The GenAI semantic conventions model an agent turn as a parent span with `gen_ai.operation.name = \"chat\"` (or `\"agent.turn\"` in newer drafts) whose children are `gen_ai.tool.call` spans. The convention ass...",
    "what_was_observed": "A tool-calling agent (three-step loop: plan → `search_docs` tool → synthesize) emitted traces where `gen_ai.tool.call` spans arrived at the collector with `parent_span_id` set to a turn span that had not yet been received. The collector's trace assembler held the orphan in a pending buffer keyed by `parent_span_id`. Under normal load the parent arrived within one batch interval and the trace assembled correctly. Unde...",
    "condition_of_validity": "The causal closure invariant is valid **if and only if** the runtime guarantees that (a) a child span object is never re-emitted after `end()`, and (b) a turn span's `span_id` is immutable for the lifetime of the logical turn, including across retries. Condition (a) is violated by span-object caching for idempotent tool results—a common optimization when a t...",
    "decision_boundary": "The boundary is: **when a turn is retried after a partial tool execution, does the retry inherit the prior attempt's child spans or fork a new trace?** - If the retry inherits child spans (reuse path), the runtime MUST either re-parent the child to the new turn span (mutating `parent_span_id`, which the SDK does not support post-`end()`) or keep the *origina...",
    "operational_effect": "The practical consequence is that **span-level error status and trace-level tool-call presence diverge**, and every consumer of the trace must be written to tolerate it or the runtime must prevent it. Concretely: - Evaluators computing tool-use rates must key on `trace_id` + tool-call span existence, not on per-turn child counts, because retried turns legiti..."
  },
  "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": "932e9f03b4c3c8f04c833f376c2b81c26d59e3f5eeda3389aace18c3108f3b98",
    "verified_classes": [
      "SpanReemissionError",
      "TurnSpanRegistry"
    ],
    "verified_functions": [
      "__init__",
      "open_turn",
      "emit_tool_child",
      "close_turn"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 8,
    "raised_exceptions": [
      "SpanReemissionError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
