{
  "schema_version": "1.3.0",
  "slug": "when-must-an-instance-refuse-to-emit-a-genai-tool-call-span-the-gen-ai-tool-call-id-correlation-invariant-and-the-orphaned-child-span-hazard",
  "title": "When must an instance refuse to emit a GenAI tool-call span: the `gen_ai.tool.call.id` correlation invariant and the orphaned-child span hazard",
  "date_of_record": "2026 November 25",
  "scope": "Applies to any agent runtime that emits OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*`) for LLM inference, tool execution, and agent reasoning steps, where spans are exported asynchronously and correlated by `trace_id`/`span_id` plus the semantic `gen_ai.tool.call.id`. Does not apply to synchronous in-process tracing where the parent span is guaranteed live at child-close time, nor to non-GenAI spans.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-emit-a-genai-tool-call-span-the-gen-ai-tool-call-id-correlation-invariant-and-the-orphaned-child-span-hazard.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-emit-a-genai-tool-call-span-the-gen-ai-tool-call-id-correlation-invariant-and-the-orphaned-child-span-hazard.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-emit-a-genai-tool-call-span-the-gen-ai-tool-call-id-correlation-invariant-and-the-orphaned-child-span-hazard.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1648,
    "python_slice_tokens": 352,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat `gen_ai.tool.call.id` as a *correlation key*, not merely an attribute. The convention's intent is that the tool-execution span (child) and the model-inference span (parent) that requested the tool share a stable call identifier so that token accounting (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`) on the par...",
    "what_was_observed": "A long-running agent loop issued a tool call (`gen_ai.tool.name = \"search\"`) inside an inference span. The runtime, optimizing for latency, closed the inference span as soon as the tool-call *request* was serialized, then awaited the tool result in a detached coroutine. The tool took 41 seconds (a slow upstream). During that window the batch span processor flushed: the parent inference span was exported, acknowledged...",
    "condition_of_validity": "Emitting a GenAI tool-call span referencing a `gen_ai.tool.call.id` is valid **only if** all of the following hold at the moment of export: - The parent inference span identified by `parent_span_id` is still present in the active trace (not yet evicted by the batch processor), **or** the exporter is configured with a correlation-retention window that guarant...",
    "decision_boundary": "The decision boundary is the **parent-retention deadline** versus the **tool-execution deadline**. If `tool_deadline > parent_retention_deadline`, the runtime is on the wrong side of the boundary and *must not* emit a correlating child span. Concretely: - If the batch span processor's `max_export_batch_size` / `scheduled_delay` will flush the parent before t...",
    "operational_effect": "The guardrail is a **correlation pre-flight check** at child-span finalization: before emitting a tool span, verify the parent span is still retained; if not, either block on retention extension or emit a demoted, flagged span. Without it, the failure is silent — no exception, no error span, just a drifted accounting join and a trace that renders structurall..."
  },
  "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": "e6154c2f59040de1405ef1d72a1b79aea5970838c4e3a0115bf69532903447a5",
    "verified_classes": [
      "OrphanedToolSpanError",
      "Span",
      "SpanBuffer"
    ],
    "verified_functions": [
      "finalize_tool_span",
      "__init__",
      "retain",
      "evict",
      "is_retained",
      "was_evicted"
    ],
    "verified_functions_count": 6,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "OrphanedToolSpanError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "time",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
