{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-tool-call-span-corruption-under-opentelemetry-genai-semantic-conventions",
  "title": "Which invariants prevent tool-call span corruption under OpenTelemetry GenAI semantic conventions",
  "date_of_record": "2026 November 17",
  "scope": "Applies to instrumentation that emits `gen_ai.*` attributes on spans modeling LLM turns, tool calls, and agent steps per the OpenTelemetry GenAI semantic conventions (as of the 1.x experimental drafts). Does not cover pure request/response HTTP spans, nor spans emitted by vendor SDKs that have not adopted the convention.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-tool-call-span-corruption-under-opentelemetry-genai-semantic-conventions.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-tool-call-span-corruption-under-opentelemetry-genai-semantic-conventions.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-tool-call-span-corruption-under-opentelemetry-genai-semantic-conventions.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1119,
    "python_slice_tokens": 247,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI conventions distinguish a **turn span** (one model invocation, carrying `gen_ai.operation.name`, `gen_ai.request.model`, token usage, and `gen_ai.response.finish_reasons`) from a **tool-call span** (one execution of a tool the model requested, carrying `gen_ai.tool.name`, `gen_ai.tool.call.id`, and `gen_ai.tool.type`). The non-obvious failure is no...",
    "what_was_observed": "In a multi-step agent loop (plan → tool → observe → plan), instrumentation emitted tool spans as children of the *current* active span at execution time. Under concurrent tool execution (parallel function calling), three tool spans for call ids `A`, `B`, `C` were all parented to the second turn span because the executor reused the context of the most recently completed model call. Result: the first turn's tool calls ...",
    "condition_of_validity": "The \"one span per call id, parented to the requesting turn\" invariant holds only when: - The `gen_ai.tool.call.id` is propagated from the model response into the executor's span context *before* the span starts, not read from the executor's local state after. - Parallel tool execution uses `contextvars`/explicit context passing per task, not the ambient span...",
    "decision_boundary": "Choose between **eager span creation** (open the tool span at request-parse time, before the executor is scheduled) and **deferred span creation** (open at execution start). Eager creation preserves parentage and makes dropped executions visible as long-lived or errored spans; deferred creation risks the parentage drift above and hides queue-saturation drops...",
    "operational_effect": "With the invariant enforced, agent-trajectory reconstruction from spans is exact: every `gen_ai.tool.call.id` appears once as a child of the turn that requested it, and a requested-but-unexecuted tool is a visible errored child span rather than a silent gap. Without it, trace-based evaluation of agent correctness silently attributes tool outputs to the wrong..."
  },
  "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": "9eeee49902c96d02d58fffbb2084dea8f1754e36cb0003938394dcd156b5a089",
    "verified_classes": [
      "ToolCallParentageError",
      "TurnSpan"
    ],
    "verified_functions": [
      "register_tool_span",
      "close_turn"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "ToolCallParentageError"
    ],
    "sample_fail_closed_invariants": [
      "tool-call span emitted without gen_ai.tool.call.id; parentage cannot be verified"
    ],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
