{
  "schema_version": "1.3.0",
  "slug": "in-what-scenarios-must-an-instance-level-genai-span-be-split-before-opentelemetry-export-the-multi-step-agent-trace-invariant-failure",
  "title": "In what scenarios must an instance-level GenAI span be split before OpenTelemetry export: the multi-step agent trace invariant failure",
  "date_of_record": "2026 November 16",
  "scope": "Applies to OpenTelemetry GenAI semantic conventions (`gen_ai.*`) when a single logical agent invocation emits multiple model calls, tool calls, or nested sub-agent runs that are represented as spans under one trace. Does not apply to single-shot inference instrumentation, nor to non-GenAI spans that merely carry a `gen_ai.request.model` attribute for routing metadata.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-level-genai-span-be-split-before-opentelemetry-export-the-multi-step-agent-trace-invariant-failure.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-level-genai-span-be-split-before-opentelemetry-export-the-multi-step-agent-trace-invariant-failure.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-level-genai-span-be-split-before-opentelemetry-export-the-multi-step-agent-trace-invariant-failure.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1524,
    "python_slice_tokens": 352,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define span-level attributes (`gen_ai.operation.name`, `gen_ai.request.model`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.response.finish_reasons`) as belonging to *one operation*. The non-obvious boundary is this: a span may be **structurally a parent** (it has child spans for tool calls and sub-agent s...",
    "what_was_observed": "In a multi-step agent (planner → tool executor → synthesizer, all under one orchestrator span), the orchestrator span was emitted with: - `gen_ai.operation.name = \"chat\"` - `gen_ai.request.model = \"claude-3-5-sonnet\"` (the planner's model) - `gen_ai.usage.input_tokens` = sum across all three steps - `gen_ai.response.finish_reasons = [\"tool_use\", \"tool_use\", \"end_turn\"]` Three failure modes surfaced at the collector/b...",
    "condition_of_validity": "The invariant holds as stated **only when** the following are all true: - The backend or processor aggregates `gen_ai.usage.*` per span without a parent/child deduplication pass. (If the backend deduplicates by summing only leaf spans, the double-count vanishes but misattribution remains.) - The orchestrator span's `gen_ai.request.model` differs from at leas...",
    "decision_boundary": "Apply this test at instrumentation time, before export: 1. Does the span represent exactly one model call or one tool call? → Emit as a GenAI operation span with usage and model attributes. Keep. 2. Does the span represent an orchestration step whose usage equals the sum of its GenAI children? → **Strip `gen_ai.usage.*`, `gen_ai.request.model`, and `gen_ai.r...",
    "operational_effect": "After enforcing the split, the observed effects on a production agent fleet (three-step, mixed-model, ~40k runs/day): - Cost attribution error dropped from 2.1× inflation to within 3% of provider invoices. - `finish_reasons`-derived response counts aligned with actual model calls; refusal-rate panels stabilized. - Trace size grew ~8% (extra structural spans,..."
  },
  "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": "987552166a1c23857015dd2fb6198a469ff90fc023f564b2353afb7e542a7a84",
    "verified_classes": [
      "GenAISpanModelBoundaryError"
    ],
    "verified_functions": [
      "validate_genai_span",
      "export_span"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "GenAISpanModelBoundaryError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
