{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-lose-tool-call-attribution-when-opentelemetry-genai-spans-are-parented-across-an-async-tool-boundary",
  "title": "Why does an instance lose tool-call attribution when OpenTelemetry GenAI spans are parented across an async tool boundary?",
  "date_of_record": "2026 November 26",
  "scope": "Applies to agent runtimes that emit OpenTelemetry GenAI spans (`gen_ai.*` semantic conventions, v1.27+) where a tool call executes asynchronously and the tool span is created inside a different task/executor context than the parent `invoke_agent` span. Does not apply to fully synchronous single-threaded tool invocation, nor to runtimes that propagate `Context` explicitly through every await boundary.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-tool-call-attribution-when-opentelemetry-genai-spans-are-parented-across-an-async-tool-boundary.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-tool-call-attribution-when-opentelemetry-genai-spans-are-parented-across-an-async-tool-boundary.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-tool-call-attribution-when-opentelemetry-genai-spans-are-parented-across-an-async-tool-boundary.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1559,
    "python_slice_tokens": 298,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define a *logical* parent-child relationship between `gen_ai.invoke_agent` → `gen_ai.execute_tool` spans, and they assume token accounting (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`) aggregates along that logical tree. OpenTelemetry, however, propagates parentage through the *runtime `Context` object* — an impli...",
    "what_was_observed": "A research agent (`gen_ai.invoke_agent`, span `A`) issued a `gen_ai.execute_tool` call to a code-interpreter tool. The tool ran on a `ThreadPoolExecutor` because the interpreter client was synchronous, wrapped in `asyncio.to_thread`. Three symptoms appeared together: 1. The tool span `T` was exported with `parent_span_id = null` (root), not `A`'s span ID. In Jaeger it appeared as a separate trace fragment. 2. `gen_ai...",
    "condition_of_validity": "The invariant that must hold for correct GenAI attribution is: > **For every `gen_ai.execute_tool` span `T` logically issued by agent span `A`, `T.trace_id == A.trace_id` AND `T.parent_span_id == A.span_id` at export time, and every token counted on `T` must be reachable by summing the subtree rooted at `A`.** This invariant is *valid* only when one of the f...",
    "decision_boundary": "The operator must decide, per tool-dispatch site, between two postures: - **Propagate:** capture and re-attach context across every worker boundary. Choose this when token accounting and trace-tree integrity feed billing, SLOs, or auditor replay. Cost: every async/thread dispatch site must be audited; one missed `attach` reintroduces orphaning. - **Reconcile...",
    "operational_effect": "Under the broken invariant, three operational consequences compound: 1. **Token accounting diverges from spend.** Summing `gen_ai.usage.*` per trace undercounts exactly on the turns where tools are most expensive (large retrieval results, long code outputs), biasing cost models toward cheap-looking tool use. 2. **Trace-tree integrity fails for replay.** An a..."
  },
  "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": "99975f515ba014fadd85c1a6df00378e8a369f02e5b93ecb8578169c188c7b76",
    "verified_classes": [
      "GenAIAttributionError",
      "SpanRecord"
    ],
    "verified_functions": [
      "validate_tool_attribution",
      "rollup_tokens"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "GenAIAttributionError"
    ],
    "sample_fail_closed_invariants": [
      "inconsistent span record: parent set but trace_id differs"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
