{
  "schema_version": "1.3.0",
  "slug": "when-must-an-instance-re-emit-a-genai-span-after-a-tool-call-attribute-mutation-or-the-parent-child-orphan-invariant-in-opentelemetry-agent-traces",
  "title": "When must an instance re-emit a GenAI span after a tool-call attribute mutation, or the parent-child orphan invariant in OpenTelemetry agent traces",
  "date_of_record": "2026 November 24",
  "scope": "Applies to agent runtimes that emit OpenTelemetry spans conforming to the GenAI semantic conventions (`gen_ai.*`) for model invocations, tool calls, and multi-turn sessions, where attributes are mutated after span start but before span end. Does not apply to immutable-at-creation span emitters, nor to pure trace-context propagation without attribute rewriting.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/when-must-an-instance-re-emit-a-genai-span-after-a-tool-call-attribute-mutation-or-the-parent-child-orphan-invariant-in-opentelemetry-agent-traces.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-re-emit-a-genai-span-after-a-tool-call-attribute-mutation-or-the-parent-child-orphan-invariant-in-opentelemetry-agent-traces.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-re-emit-a-genai-span-after-a-tool-call-attribute-mutation-or-the-parent-child-orphan-invariant-in-opentelemetry-agent-traces.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1563,
    "python_slice_tokens": 317,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat a span as an immutable event record with a fixed identity (`trace_id`, `span_id`, `parent_span_id`) and a mutable attribute bag. This distinction is a lie in practice: several `gen_ai.*` attributes are *identity-bearing* — they determine whether the span is a valid child of an agent-session span, whether a tool call is at...",
    "what_was_observed": "A three-tier agent (session span → model invocation span → tool call span) was instrumented with an SDK that used the OTel `Span` API's `set_attribute` on the tool-call span during its lifetime. The agent's control loop was: 1. Open session span `S` (root). 2. Open `gen_ai.chat` span `C` as child of `S`, with `gen_ai.request.model`, `gen_ai.usage.input_tokens` set at start. 3. Model streams a tool-call directive; the...",
    "condition_of_validity": "The invariant that holds is: **a `gen_ai.tool.call` span may only be created after the parent `gen_ai.chat` span's `span_id` is allocated and the tool call is definitively attributed to that span.** The span-creation boundary is the parent-span-ID finalization, not the tool-execution boundary. Any design that opens the tool-call span before the model invocat...",
    "decision_boundary": "The decision boundary is whether the model invocation span's `span_id` is known at the moment the tool call is dispatched. If yes (synchronous, non-streaming, or the runtime allocates `C.span_id` eagerly before streaming begins), open `T` as a child of `C` and mutate freely. If no (streaming model, parallel tool dispatch, speculative execution), the runtime ...",
    "operational_effect": "In practice, this failure produces traces that look complete (all spans present, all attributes populated) but fail attribution queries: \"which model turn caused this tool call?\" returns nothing, because the tool-call span's parent is the session, not the chat span. Agent observability dashboards that compute tool-call latency per model turn silently underco..."
  },
  "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": "3b7828c226d831237e4ed552d7ce8d560e06299e34607a0bcf7b28115f0f87cd",
    "verified_classes": [
      "GenAISpanParentInvariantError",
      "GenAISpan"
    ],
    "verified_functions": [
      "open_tool_call_span",
      "validate_exported_trace",
      "set_attribute",
      "end_and_export"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 6,
    "raised_exceptions": [
      "GenAISpanParentInvariantError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
