{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-reconcile-opentelemetry-genai-span-boundaries-when-a-tool-calling-turn-outlives-its-parent-invoke-agent-span",
  "title": "Where must an instance reconcile OpenTelemetry GenAI span boundaries when a tool-calling turn outlives its parent `invoke_agent` span",
  "date_of_record": "2026 December 1",
  "scope": "Applies to agents emitting OpenTelemetry GenAI semantic conventions (`gen_ai.*`) across multi-turn, tool-calling loops where the `invoke_agent` span is closed before the terminal `execute_tool` child completes. Does not apply to single-shot inference with no tool loop, nor to trace exporters that buffer and re-parent spans post-hoc.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-span-boundaries-when-a-tool-calling-turn-outlives-its-parent-invoke-agent-span.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-span-boundaries-when-a-tool-calling-turn-outlives-its-parent-invoke-agent-span.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-span-boundaries-when-a-tool-calling-turn-outlives-its-parent-invoke-agent-span.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1934,
    "python_slice_tokens": 309,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions model an agent turn as a parent `invoke_agent` span that owns child `chat` (LLM inference) and `execute_tool` spans. Token accounting is attached to `chat` spans via `gen_ai.usage.input_tokens` / `output_tokens`, while `invoke_agent` is expected to represent the *logical turn*. The non-obvious boundary is this: the spec's paren...",
    "what_was_observed": "A retrieval-augmented agent running a ReAct-style loop over an MCP tool server. The runtime wrapped each user turn in an `invoke_agent` span, opened `chat` spans per model call, and opened `execute_tool` spans around MCP `tools/call` requests. Under normal load, traces were clean: one `invoke_agent`, N `chat`, M `execute_tool`, all properly nested, `gen_ai.usage.*` summing correctly. Under a specific trigger — a tool...",
    "condition_of_validity": "The invariant \"a child span's `[start_time, end_time]` is contained within its parent's\" is **valid only when the agent runtime synchronously awaits every tool call before deciding the turn is complete.** It is invalid, and must be replaced, under any of the following: - The runtime has a per-turn deadline or cancellation token that can fire while a tool cal...",
    "decision_boundary": "The decision an instance must make at the moment a tool outlives its turn: **do you close the parent and orphan the child, or hold the parent open and violate the turn deadline?** - **Close-and-orphan** preserves deadline semantics (the turn really did end) but breaks the span-tree token invariant. Acceptable only if downstream accounting groups on `turn_id`...",
    "operational_effect": "Without the `turn_id` correlation and the explicit timeout status, the failure is silent and compounding: token leakage across turns inflates rolling cost, latency inflation masks the real timeout rate, and the budget enforcer throttles the wrong agent. The guardrail is a two-part invariant enforced at span-close time: (1) any `execute_tool` or `chat` span w..."
  },
  "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": "cb7dae72c03873d077995956fe92493ffebc0c33d9199ab66dc808b86c49eccd",
    "verified_classes": [
      "GenAISpanBoundaryError",
      "Span"
    ],
    "verified_functions": [
      "close_child_span",
      "compute_turn_tokens"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "GenAISpanBoundaryError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
