{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-gen-ai-tool-call-id-collisions-from-orphaning-child-spans-when-an-agent-reuses-tool-call-identifiers-across-retries",
  "title": "Which invariants prevent gen_ai.tool.call.id collisions from orphaning child spans when an agent reuses tool-call identifiers across retries",
  "date_of_record": "2026 November 25",
  "scope": "Applies to agents that emit OpenTelemetry spans conforming to the GenAI semantic conventions (`gen_ai.operation.name`, `gen_ai.tool.call.id`, `gen_ai.agent.invocation.id`) and that perform retries or replay of tool calls within a single trace. Does not apply to single-shot, non-retrying tool invocations or to traces where tool-call IDs are guaranteed globally unique by an external authority.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-gen-ai-tool-call-id-collisions-from-orphaning-child-spans-when-an-agent-reuses-tool-call-identifiers-across-retries.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-gen-ai-tool-call-id-collisions-from-orphaning-child-spans-when-an-agent-reuses-tool-call-identifiers-across-retries.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-gen-ai-tool-call-id-collisions-from-orphaning-child-spans-when-an-agent-reuses-tool-call-identifiers-across-retries.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1533,
    "python_slice_tokens": 193,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat `gen_ai.tool.call.id` as the join key between a model's *requested* tool call (recorded on the LLM span as part of the completion) and the *executed* tool span that actually runs the function. The convention is silent on uniqueness scope: it does not state whether the ID must be unique within a trace, within a span, or gl...",
    "what_was_observed": "In a trace from a 3-tool agent loop, the LLM span `chat gpt-4o` emitted a completion containing a tool call with `gen_ai.tool.call.id = call_abc123` (a `search_docs` invocation). The tool span executed, returned a 503 from the downstream retriever, and the orchestrator retried. The retry re-entered the model, which — deterministically, same prompt, temperature 0 — regenerated the byte-identical tool call, including `...",
    "condition_of_validity": "The collision only manifests as a failure under a conjunction: 1. The agent retries or replays a tool call, AND 2. The retry reuses the same `gen_ai.tool.call.id` (deterministic regeneration, verbatim replay, or an orchestrator that copies the ID forward), AND 3. A consumer joins on `gen_ai.tool.call.id` under an assumption of uniqueness within the trace (th...",
    "decision_boundary": "The boundary is whether `gen_ai.tool.call.id` is treated as a *model-decision identifier* or an *execution identifier*. The model only ever emits a decision ID — it cannot know that execution will be retried. Therefore the invariant must be enforced at the producer: **the model-decision ID and the execution ID must be separated, and the execution span must c...",
    "operational_effect": "Enforcing the invariant changes three downstream behaviors. First, cost attribution becomes correct: retried calls are counted per attempt, and the retry tax is visible against the decision that incurred it. Second, replay verification becomes sound: an auditor replaying `(decision_id, attempt)` can reconstruct the exact external state each attempt observed,..."
  },
  "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": "d79cf340eb4d68fd899bdeb8b5b7bfc8b75117e3d4609e7725f7b59f6a95a960",
    "verified_classes": [
      "ToolCallKeyCollision",
      "ToolSpan",
      "LLMSpan"
    ],
    "verified_functions": [
      "emit_tool_span"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "ToolCallKeyCollision"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
