{
  "schema_version": "1.3.0",
  "slug": "under-what-conditions-must-an-instance-treat-a-genai-tool-call-span-as-a-child-of-the-model-invocation-span-rather-than-the-enclosing-agent-span",
  "title": "Under what conditions must an instance treat a GenAI tool-call span as a child of the model-invocation span rather than the enclosing agent span",
  "date_of_record": "2026 November 13",
  "scope": "Applies to services emitting OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*`) where an agent loop invokes a model, and the model returns one or more tool calls that the same process executes. Does not apply to tool execution delegated to a separate remote agent whose span is joined via context propagation across a network boundary, nor to streaming partial tool-calls that are never materialized as discrete invocations.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-a-genai-tool-call-span-as-a-child-of-the-model-invocation-span-rather-than-the-enclosing-agent-span.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-a-genai-tool-call-span-as-a-child-of-the-model-invocation-span-rather-than-the-enclosing-agent-span.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-a-genai-tool-call-span-as-a-child-of-the-model-invocation-span-rather-than-the-enclosing-agent-span.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1796,
    "python_slice_tokens": 342,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions describe a *model invocation* span (`gen_ai.operation.name = \"chat\"`) and separate *tool execution* spans. The non-obvious invariant is this: a tool-call span is a **child of the model-invocation span that produced it**, not a sibling of that span under the enclosing agent/chain span — *and only when the tool call is causally d...",
    "what_was_observed": "In a production agent loop, the model span was closed with `span.end()` immediately after the response was parsed, and then each returned tool call was executed. Because the model span was no longer the active span, the OpenTelemetry context at tool-execution time resolved to the agent span. The resulting trace showed tool spans as siblings of the model span: The consequence was measurable: a downstream cost/latency ...",
    "condition_of_validity": "The parent-under-model rule is valid if and only if all of the following hold: 1. **Single-response derivation.** The tool call was emitted by one specific model response. If a tool call is synthesized by the agent framework itself (e.g., a planner step that emits a tool call without a model turn), it has no model span to parent to and must attach to the age...",
    "decision_boundary": "The decision is not \"always parent tools under the model span.\" It is a boundary test evaluated at tool-span creation time: - **Parent = model invocation span** when the tool call is causally bound to a single, identifiable, same-segment model response whose context is available (live or captured). - **Parent = agent span, with a span link to the model span*...",
    "operational_effect": "Enforcing the boundary restored the `tools per inference` join from 0.0 to the true fan-out (median 1.8, p99 6) and reduced tail-sampling storage by the fan-out factor. The captured-context pattern also eliminated a class of orphaned tool spans that had been appearing as roots when the agent span was not active during async tool execution. The residual cost ..."
  },
  "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": "de8491913ac99862b82837a97d4f5581dc055b2fee64e649c938644303e13db0",
    "verified_classes": [
      "ToolSpanParentingError",
      "ModelInvocation"
    ],
    "verified_functions": [
      "parent_tool_span",
      "close_model_span"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "ToolSpanParentingError"
    ],
    "sample_fail_closed_invariants": [
      "refusing to close model span before capturing its context"
    ],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "opentelemetry",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
