{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-emits-genai-span-attributes-for-a-tool-calling-turn-whose-tool-results-arrive-after-the-parent-span-has-already-ended",
  "title": "What happens when an instance emits GenAI span attributes for a tool-calling turn whose tool results arrive after the parent span has already ended",
  "date_of_record": "2026 November 21",
  "scope": "Applies to agents instrumented with OpenTelemetry GenAI semantic conventions (`gen_ai.*`) where tool execution is asynchronous relative to the model invocation span. Does not apply to fully synchronous single-shot call chains where every tool result is produced before the parent `gen_ai.chat` span closes.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-genai-span-attributes-for-a-tool-calling-turn-whose-tool-results-arrive-after-the-parent-span-has-already-ended.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-genai-span-attributes-for-a-tool-calling-turn-whose-tool-results-arrive-after-the-parent-span-has-already-ended.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-genai-span-attributes-for-a-tool-calling-turn-whose-tool-results-arrive-after-the-parent-span-has-already-ended.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1605,
    "python_slice_tokens": 260,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions model a chat turn as a span that *contains* its tool calls: the `gen_ai.chat` span is expected to carry `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, and a set of tool-call child spans or events, all finalized before the parent span ends. This encodes a hidden invariant: **all attributes describing a turn are known...",
    "what_was_observed": "A tool-calling agent loop instrumented with the GenAI conventions on a three-step task (search → read → summarize) produced trace trees where: - The `gen_ai.chat` span for the turn that *requested* the tool closed with `gen_ai.usage.output_tokens` reflecting only the tool-call emission, not the eventual answer. - The subsequent `gen_ai.chat` span (the one that consumed the tool result) was emitted as a **sibling**, n...",
    "condition_of_validity": "The convention holds — spans faithfully represent a turn — only when the tool result is available before the generation span closes. This is true for: - Synchronous function-calling where the tool is a pure in-process function and the runtime executes it inline before returning control. - Single-turn agents that emit at most one generation span per user mess...",
    "decision_boundary": "The instrumenter must decide, per turn, whether to: 1. **Close-on-generate** (span ends when the model stops emitting): correct for latency accounting of the model alone, but requires an explicit parent *turn* span to preserve causality and a `gen_ai.tool.call.id` attribute on both the requesting generation and the consuming generation so the edge is reconst...",
    "operational_effect": "Downstream consumers of the trace — cost attributors, latency dashboards, and replay auditors — inherit the defect silently: - **Cost attribution** undercounts because tool-result tokens land on a span with no causal link to the request; per-conversation rollups that sum child spans miss them. - **Replay** cannot reconstruct the turn because the tool-call ID..."
  },
  "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": "1680a4a9515200ac23d5d3a390b5929a5b7321edcbde1e674e2da00d6ad08e26",
    "verified_classes": [
      "OrphanedToolCallError",
      "GenAITurnSpan"
    ],
    "verified_functions": [
      "__init__",
      "record_generation",
      "close_generation",
      "record_tool_result",
      "close"
    ],
    "verified_functions_count": 5,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "OrphanedToolCallError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
