{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-attribute-a-genai-span-to-the-model-that-actually-answered-when-the-tool-call-and-the-completion-share-one-trace-context",
  "title": "How should an instance attribute a GenAI span to the model that actually answered when the tool call and the completion share one trace context",
  "date_of_record": "2026 November 22",
  "scope": "Applies to agent runtimes that emit OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*` attributes) and that interleave model inference, tool invocation, and sub-agent handoffs within a single trace. Does not cover pure single-shot inference telemetry where one span maps to one provider call.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-attribute-a-genai-span-to-the-model-that-actually-answered-when-the-tool-call-and-the-completion-share-one-trace-context.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-attribute-a-genai-span-to-the-model-that-actually-answered-when-the-tool-call-and-the-completion-share-one-trace-context.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-attribute-a-genai-span-to-the-model-that-actually-answered-when-the-tool-call-and-the-completion-share-one-trace-context.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1883,
    "python_slice_tokens": 359,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define attributes like `gen_ai.operation.name`, `gen_ai.request.model`, `gen_ai.response.model`, `gen_ai.usage.input_tokens`, and `gen_ai.usage.output_tokens` on a span that represents *one inference operation*. The conventions are explicit that `gen_ai.response.model` records the model that actually served the response, which ...",
    "what_was_observed": "A coding agent emits one span per reasoning step. Each step: (1) call the model with the current transcript, (2) if the model returns a tool call, execute the tool, (3) append the tool result, (4) re-invoke the model. The runtime wraps all four phases in a single span `agent.step` with `gen_ai.operation.name = chat`. The failure trace, for a step where the model requested a 9-second `pytest` run: 1. Span starts. `gen...",
    "condition_of_validity": "The one-span-per-step model is only valid when the step contains exactly one provider round-trip and zero tool executions. It is *invalid* whenever any of the following hold within the span's lifetime: - More than one `gen_ai.request.model` value is observed (fallback, retry, or escalation). - More than one `gen_ai.response.model` value is observed. - Any ch...",
    "decision_boundary": "The decision the runtime must make at span-close time is whether to emit the accumulated span as-is (fast, lossy) or to split it retroactively into per-call child spans (correct, requires buffering). The boundary is determined by the invariant above, evaluated as a predicate over the span's recorded events: - If the span recorded exactly one `gen_ai.request....",
    "operational_effect": "Once the invariant is enforced, three second-order effects appear that are easy to miss: 1. **Span cardinality rises.** A 40-step agent run that previously emitted 40 spans now emits ~120 (40 step parents, ~80 chat children, plus tool spans). Trace backends with per-trace span caps (commonly 1,000) start truncating long runs. The cap must be raised or the st..."
  },
  "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": "2678fc8290d8c889a10dc63fcf6b1898ebeb11c9734807d2e62bbc3d517d46d6",
    "verified_classes": [
      "GenAIAttributionError",
      "GenAISpan"
    ],
    "verified_functions": [
      "finalize_genai_span",
      "emit_agent_step",
      "record_request",
      "record_response",
      "record_tool_overlap"
    ],
    "verified_functions_count": 5,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "GenAIAttributionError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
