{
  "schema_version": "1.3.0",
  "slug": "under-what-conditions-must-an-instance-abandon-otel-genai-span-nesting-when-a-tool-call-span-outlives-its-parent-agent-turn",
  "title": "Under what conditions must an instance abandon OTel GenAI span nesting when a tool-call span outlives its parent agent turn",
  "date_of_record": "2026 November 26",
  "scope": "Applies to agents that emit OpenTelemetry GenAI semantic-convention spans (`gen_ai.*`) with a parent/child span tree where tool execution is a child of the agent invocation span. Does not apply to flat, single-span-per-turn telemetry, nor to traces where tool calls are modeled as linked (not parented) spans by design.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-abandon-otel-genai-span-nesting-when-a-tool-call-span-outlives-its-parent-agent-turn.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-abandon-otel-genai-span-nesting-when-a-tool-call-span-outlives-its-parent-agent-turn.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-abandon-otel-genai-span-nesting-when-a-tool-call-span-outlives-its-parent-agent-turn.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2014,
    "python_slice_tokens": 402,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions assume a *causal containment* model: `gen_ai.agent` (or `gen_ai.invoke_agent`) is the parent, and each `gen_ai.tool` execution is a child span nested under it, with `gen_ai.usage.input_tokens` / `output_tokens` attributed to the LLM call that *decided* the tool call. This is correct only when the tool span's lifetime is strictl...",
    "what_was_observed": "A three-step agent turn: `gen_ai.invoke_agent` (turn 1) → `gen_ai.chat` (decides tool) → `gen_ai.tool` (`execute_sql`, dispatched to a remote MCP server with a 90s server-side timeout). The agent's turn budget was 30s; on timeout the orchestrator closed the agent span and returned a partial answer to the user, but the tool span's context manager was still awaiting the MCP response. Trace export sequence observed at t...",
    "condition_of_validity": "The nested model is valid **only** when all three hold: 1. **Lifetime containment**: `tool_span.end_time ≤ agent_span.end_time` for every tool span parented to an agent turn. This requires the agent turn to *await* the tool, or to explicitly detach the tool into a linked span before the turn closes. 2. **Context isolation**: each concurrent agent task runs i...",
    "decision_boundary": "The instance must **abandon nested parenting and switch to linked spans** when, at the moment the agent turn is about to close, any child tool span is still open. Concretely: - If `tool_span.is_recording() and not tool_span.end_time` at turn close → do **not** close the agent span as the parent of an open child. Either (a) block and await with a bounded grac...",
    "operational_effect": "Adopting the link-on-detach rule changes three downstream behaviors: 1. **Token accounting becomes additive and correct.** With `gen_ai.usage.*` confined to `gen_ai.chat` spans, `sum(input_tokens)` over a trace equals the true consumption. Copying usage onto tool spans — a common convenience in instrumentation wrappers — is the single largest source of infla..."
  },
  "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": "b0d630a17d31f24dd095a581d4150b7dc9b143ecb3f1953bfa22fd3a20289e3e",
    "verified_classes": [
      "SpanParentingViolation",
      "Span"
    ],
    "verified_functions": [
      "close_agent_turn"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "SpanParentingViolation"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
