{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-lose-parent-child-span-linkage-when-an-agent-span-is-exported-after-its-tool-call-children-close-under-opentelemetry-genai-semant",
  "title": "Why does an instance lose parent-child span linkage when an agent span is exported after its tool-call children close under OpenTelemetry GenAI semantic conventions",
  "date_of_record": "2026 November 25",
  "scope": "Applies to single-process or sidecar-exported agent runtimes that emit `gen_ai.*` spans for agent turns and nested tool calls, where the span processor uses a batching exporter and the agent loop is resumable across checkpoint boundaries. Does not apply to synchronous in-memory span processors that flush before the parent span ends, nor to non-GenAI spans without tool-call attributes.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-parent-child-span-linkage-when-an-agent-span-is-exported-after-its-tool-call-children-close-under-opentelemetry-genai-semant.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-parent-child-span-linkage-when-an-agent-span-is-exported-after-its-tool-call-children-close-under-opentelemetry-genai-semant.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-parent-child-span-linkage-when-an-agent-span-is-exported-after-its-tool-call-children-close-under-opentelemetry-genai-semant.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1769,
    "python_slice_tokens": 386,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"missing spans\" and not \"wrong attribute values.\" It is a **linkage inversion**: a child `gen_ai.tool.call` span is exported with a `parent_span_id` that points to an agent span whose `span_id` was never committed to the exporter because the agent span is still open when the batch flush fires. The child is durable; the parent is not yet du...",
    "what_was_observed": "A resumable agent runtime executed a turn that called three tools. Sequence: 1. Agent span `S_a` opened with `trace_id=T`, `span_id=A1`, `gen_ai.operation.name=invoke_agent`, `gen_ai.agent.name=planner`. 2. Tool span `S_t1` opened with `parent_span_id=A1`, `gen_ai.operation.name=execute_tool`, `gen_ai.tool.name=search`. Closed at t+40ms. 3. BatchSpanProcessor hit its `schedule_delay_millis=5000` deadline at t+5000ms....",
    "condition_of_validity": "The invariant that must hold for trace reconstruction is: > For every exported span `c` with `parent_span_id = p`, there exists an exported span `s` with `span_id = p`, `s.start_time <= c.start_time`, `s.end_time >= c.end_time`, and `s.trace_id = c.trace_id`, and `p` is unique within the trace's retention horizon. This invariant is violated whenever any of t...",
    "decision_boundary": "The boundary is not \"batch vs. simple processor.\" It is **whether span identity is part of the durable agent state**. Two admissible architectures: - **Identity-in-checkpoint.** Persist `(trace_id, span_id, start_time, attributes)` of every open span in the checkpoint. On resume, re-open the span with the *same* `span_id` and original `start_time`; the expor...",
    "operational_effect": "With the naive configuration (batch exporter, no identity in checkpoint, random `span_id`): - Orphan rate rises with tool-call latency variance: turns with a tool call exceeding `schedule_delay_millis` orphan exactly that tool span. Measured ~0.7% of turns at p99 tool latency 6s and 5s batch delay. - Resume events multiply orphans by the number of pre-checkp..."
  },
  "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": "b569bff049ffcc21afb05cc015e8c0bd81d94a023bb6540aacbf98d4c7538f6d",
    "verified_classes": [
      "SpanLinkageError",
      "Span",
      "TraceRegistry"
    ],
    "verified_functions": [
      "export_tool_call",
      "resume_agent_span",
      "__init__",
      "ingest",
      "validate_linkage"
    ],
    "verified_functions_count": 5,
    "defensive_guards_count": 6,
    "raised_exceptions": [
      "SpanLinkageError"
    ],
    "sample_fail_closed_invariants": [
      "checkpoint did not persist open agent span_id; resume would mint a new identity and orphan previously-exported tool-call"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "time",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
