{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-emit-a-duplicate-gen-ai-tool-call-id-span-after-mcp-handoff-but-the-parent-trace-shows-a-single-invocation",
  "title": "Why does an instance emit a duplicate gen_ai.tool.call.id span after MCP handoff but the parent trace shows a single invocation?",
  "date_of_record": "2026 November 29",
  "scope": "Applies to agent runtimes that emit OpenTelemetry GenAI semantic-convention spans (`gen_ai.tool.call`, `gen_ai.retrieval`, `gen_ai.chat`) across an MCP/A2A handoff where the downstream process re-derives span identity from its own state rather than inheriting the upstream span context. Does not apply to single-process agents or to handoffs that propagate a full W3C `traceparent` plus a stable `gen_ai.tool.call.id`.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-emit-a-duplicate-gen-ai-tool-call-id-span-after-mcp-handoff-but-the-parent-trace-shows-a-single-invocation.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-emit-a-duplicate-gen-ai-tool-call-id-span-after-mcp-handoff-but-the-parent-trace-shows-a-single-invocation.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-emit-a-duplicate-gen-ai-tool-call-id-span-after-mcp-handoff-but-the-parent-trace-shows-a-single-invocation.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1734,
    "python_slice_tokens": 378,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not a missing span. It is a *semantically duplicated* span: the parent trace correctly records one logical tool invocation, but two child spans carry the same `gen_ai.tool.call.id` with divergent `gen_ai.tool.call.result` values, because the upstream runtime and the downstream MCP server each mint their own `gen_ai.tool.call.id` from a local m...",
    "what_was_observed": "Trigger sequence, reproduced on an agent runtime using an MCP client that spawns the server as a subprocess per session: 1. Upstream agent decides to call `search_docs(query=\"retry policy\")`. It mints `gen_ai.tool.call.id = \"call-7\"` from a per-session counter and emits a `gen_ai.tool.call` span with `status = UNSET`, `gen_ai.tool.call.result` unset (streaming, result not yet known). 2. The MCP transport times out at...",
    "condition_of_validity": "The duplicate-id collision is only possible when all three hold: 1. **Local id minting.** The `gen_ai.tool.call.id` is generated from process-local state (counter, timestamp, `uuid4` truncated to low entropy) rather than inherited from the initiating span's `span_id` or a UUIDv7 carried in the request payload. 2. **Context non-propagation on retry.** The ret...",
    "decision_boundary": "The architectural invariant to enforce: **`gen_ai.tool.call.id` must be derived from the initiating span context, not from local state, and must be propagated through every retry and handoff.** Concretely: - Mint `gen_ai.tool.call.id` as `f\"{trace_id}:{span_id}\"` of the initiating `gen_ai.chat` span, or as a UUIDv7 written into the `tools/call` `params._meta...",
    "operational_effect": "Left unguarded, the collision produces three concrete degradations: 1. **Cost attribution drift.** Token and tool-call cost is attributed to `gen_ai.tool.call.id`; a collided id bills the successful execution's tokens to the errored span's parent chat turn, understating the retry's true cost by the full timeout window's compute. 2. **Eval-harness false negat..."
  },
  "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": "7ad40dd15689b5eb5649bf4b42f197f764b0c9ed63526b0f3a546f50517df8ab",
    "verified_classes": [
      "DuplicateToolCallIdError",
      "ToolCallSpan"
    ],
    "verified_functions": [
      "validate_tool_call_ids",
      "ingest"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "DuplicateToolCallIdError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "re",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
