{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-of-an-agent-span-fail-the-genai-semantic-convention-when-tool-call-telemetry-crosses-the-parent-child-boundary-mid-turn",
  "title": "Why does an instance of an agent span fail the GenAI semantic convention when tool-call telemetry crosses the parent/child boundary mid-turn",
  "date_of_record": "2026 November 16",
  "scope": "Applies to OpenTelemetry instrumentation of LLM agent runtimes that emit `gen_ai.*` spans for a single logical turn where one or more tool/function calls occur, and where the tool execution is represented as a child span of the agent span. Does not apply to stateless single-shot completion calls, nor to agent frameworks that flatten tool calls into attributes on the parent span without emitting child spans.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-of-an-agent-span-fail-the-genai-semantic-convention-when-tool-call-telemetry-crosses-the-parent-child-boundary-mid-turn.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-of-an-agent-span-fail-the-genai-semantic-convention-when-tool-call-telemetry-crosses-the-parent-child-boundary-mid-turn.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-of-an-agent-span-fail-the-genai-semantic-convention-when-tool-call-telemetry-crosses-the-parent-child-boundary-mid-turn.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1534,
    "python_slice_tokens": 265,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There is a difference between *an agent span that contains tool calls as attributes* and *an agent span whose tool calls are emitted as child spans*. The GenAI semantic conventions define attributes like `gen_ai.operation.name`, `gen_ai.agent.name`, `gen_ai.tool.name`, `gen_ai.tool.call.id`, and `gen_ai.usage.input_tokens`/`output_tokens`. The convention ass...",
    "what_was_observed": "In a production agent runtime (ReAct-style loop, max 8 tool iterations), the following was observed after enabling an OTel GenAI exporter: - The root agent span (`gen_ai.operation.name=invoke_agent`) carried `gen_ai.usage.input_tokens=14820`, `gen_ai.usage.output_tokens=2310`. - Each of the 6 child `gen_ai.operation.name=chat` spans carried its own usage (e.g., 2410/380, 2501/402, ...), summing to exactly the parent'...",
    "condition_of_validity": "The invariant \"usage attributes are per-operation, not per-subtree\" holds only when: 1. Every model invocation emits exactly one span with `gen_ai.operation.name` in `{chat, text_completion, generate_content}` and that span carries its own `gen_ai.usage.*`. 2. The agent span does **not** also carry `gen_ai.usage.*` unless the turn contained exactly one model...",
    "decision_boundary": "Choose between two representations at instrumentation time, and do not mix them within one agent runtime: - **Aggregate-on-parent representation:** the agent span carries summed usage and a `gen_ai.agent.name`; child model spans carry per-call usage but are marked `gen_ai.operation.name=chat` with no agent attributes. Consumers must be told to read usage fro...",
    "operational_effect": "After migrating to leaf-only usage and reparenting tool spans under their issuing model spans: - Cost dashboards matched ground-truth billing within 0.3% (residual from provider-side rounding). - Budget enforcement could attribute spend per model and per provider fallback, enabling a per-model circuit breaker. - Retry-induced duplicate tool calls became visi..."
  },
  "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": "8d2b8c910c365aa9b07d69f6c21d8a4881515566182d607be8cd29bc1983827e",
    "verified_classes": [
      "GenAIUsageInvariantError"
    ],
    "verified_functions": [
      "validate_agent_span",
      "validate_tool_call_id",
      "__init__"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "GenAIUsageInvariantError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
