{
  "schema_version": "1.3.0",
  "slug": "under-what-conditions-must-an-instance-re-parent-a-genai-span-when-a-mid-turn-tool-call-opens-a-new-trace-context",
  "title": "Under what conditions must an instance re-parent a GenAI span when a mid-turn tool call opens a new trace context",
  "date_of_record": "2026 December 2",
  "scope": "Applies to agents emitting OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*`) where a single logical user turn spans multiple LLM invocations interleaved with tool calls that may originate a fresh trace context (e.g., a remote MCP server, an A2A peer, or a sub-agent process). Does not apply to single-shot inference spans or to agents whose tool calls are strictly in-process and inherit the ambient `Context`.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-re-parent-a-genai-span-when-a-mid-turn-tool-call-opens-a-new-trace-context.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-re-parent-a-genai-span-when-a-mid-turn-tool-call-opens-a-new-trace-context.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-re-parent-a-genai-span-when-a-mid-turn-tool-call-opens-a-new-trace-context.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1894,
    "python_slice_tokens": 344,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions describe *what* a span represents (`gen_ai.operation.name`, `gen_ai.request.model`, `gen_ai.usage.input_tokens`, `gen_ai.conversation.id`) but they are deliberately silent on *parentage*: they do not state that all spans for one conversation must share a trace ID, nor that a tool span must be a child of the LLM span that reques...",
    "what_was_observed": "A three-tool ReAct turn against a remote MCP filesystem server. The agent process held a turn-root span `T` (`trace_id=aaa`, `span_id=t00`) created at turn start. LLM span `L1` was a child of `T`. The first tool call `read_file` was dispatched, and the MCP client propagated the ambient context, so the server's span `S1` appeared as a child of `L1` with `trace_id=aaa` — correct. The second tool call `list_dir` was rou...",
    "condition_of_validity": "The re-parenting hazard is live only when all four hold: 1. The agent maintains a logical turn identity (`gen_ai.conversation.id`) across more than one LLM invocation. 2. At least one tool dispatch crosses a process/trust boundary that is permitted to originate a new trace context (remote MCP server without `traceparent` propagation, A2A task, sub-agent spaw...",
    "decision_boundary": "The boundary is a single comparison performed at the point where a tool result is about to seed the next LLM span: - If `returned_ctx.trace_id == turn_root_ctx.trace_id`: the remote propagated correctly; attach as parent is harmless and preferred (it preserves the natural chain). No link needed. - If `returned_ctx.trace_id != turn_root_ctx.trace_id`: **do no...",
    "operational_effect": "Enforcing the retained-context invariant converts a silent, schema-valid corruption into a loud, countable, and bounded one. Trace-scoped turn aggregation becomes exact: one `trace_id` per turn, N linked remote contexts. Replay auditors that walk `parent_span_id` chains no longer see phantom reordering, because remote causality is carried in `links` (which r..."
  },
  "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": "6ddc034b4dc3423d07785ddfdf56ac4569e4e5313027611714a4072103387f65",
    "verified_classes": [
      "TraceAttributionError",
      "SpanCtx"
    ],
    "verified_functions": [
      "next_llm_span_parent",
      "assert_same_trace"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "TraceAttributionError"
    ],
    "sample_fail_closed_invariants": [
      "turn root is self-inconsistent",
      "gen_ai.conversation.id missing; cannot attribute multi-turn span",
      "unreachable"
    ],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
