{
  "schema_version": "1.3.0",
  "slug": "what-structural-signals-indicate-a-genai-span-tree-has-silently-orphaned-a-tool-call-child-before-the-parent-reasoning-span-closes",
  "title": "What structural signals indicate a GenAI span tree has silently orphaned a tool-call child before the parent reasoning span closes",
  "date_of_record": "2026 November 27",
  "scope": "Applies to agent runtimes emitting OpenTelemetry GenAI semantic conventions (`gen_ai.*`) where a reasoning span (`gen_ai.operation.name = \"chat\"` or `\"invoke_agent\"`) parents one or more tool-execution spans (`gen_ai.operation.name = \"execute_tool\"`). Does not apply to single-shot inference calls with no child spans, nor to runtimes that emit tool calls as span *events* on the parent rather than as child spans.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-a-genai-span-tree-has-silently-orphaned-a-tool-call-child-before-the-parent-reasoning-span-closes.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-a-genai-span-tree-has-silently-orphaned-a-tool-call-child-before-the-parent-reasoning-span-closes.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-a-genai-span-tree-has-silently-orphaned-a-tool-call-child-before-the-parent-reasoning-span-closes.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1799,
    "python_slice_tokens": 194,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The distinction that matters is **span lifecycle containment versus semantic containment**. A tool-call child span is *structurally* contained when its `end()` executes before the parent's `end()`. It is *semantically* contained when the parent's `gen_ai.usage.output_tokens` and reasoning trace actually reflect the tool result. These two properties decouple ...",
    "what_was_observed": "A tool-using agent loop with a 30-second per-turn timeout was instrumented with GenAI spans. The loop structure was: open a `chat` span, call the model, if the model returns a tool call, open an `execute_tool` child span, run the tool, feed the result back, repeat. The `chat` span was opened inside an async context manager keyed to the *first* model invocation. Under normal latency the loop completed in one or two tu...",
    "condition_of_validity": "The failure requires three conditions to co-occur: 1. **The parent span is scoped to a single model invocation, not to the agent loop.** This is the default when instrumenting with a `with tracer.start_as_current_span(\"chat\")` around the inference call rather than around the loop body. 2. **The tool span is emitted after the parent context has exited.** In a...",
    "decision_boundary": "The guardrail is a **containment assertion at parent close time**, not a schema validation. Before ending a `chat` span whose `finish_reasons` includes `\"tool_calls\"`, the emitter must assert that at least one `execute_tool` child span was created with the current span as its explicit parent context. If the assertion fails, the correct behavior is not to sil...",
    "operational_effect": "The operational consequence is a class of cost and latency attribution errors that survive every schema validator. Token sums per trace remain correct; token sums per *reasoning step* are wrong whenever a tool call spans a turn boundary. Latency attribution to the requesting decision is lost entirely for orphaned tool spans. Evaluation harnesses that 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": "412584c5b99a2e4ce146f734006f89dbd254a9bf5efeca56e0f855461ff4dcba",
    "verified_classes": [
      "OrphanedToolSpanError",
      "SpanRecord"
    ],
    "verified_functions": [
      "close_chat_span",
      "__init__"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "OrphanedToolSpanError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
