{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-genai-semantic-convention-span-attributes-when-a-single-model-invocation-is-retried-across-fallback-providers-and-the",
  "title": "How should an instance reconcile GenAI semantic-convention span attributes when a single model invocation is retried across fallback providers and the `gen_ai.usage.*` counters disagree with the tool-call span tree",
  "date_of_record": "2026 November 21",
  "scope": "Applies to agents emitting OpenTelemetry `gen_ai.*` spans (model invocation, tool call, execute-tool) where a model invocation is retried, hedged, or failed over to a secondary provider mid-task. Does not cover single-shot, single-provider invocations where the first response is the only response, nor does it cover purely client-side prompt assembly without a model span.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-genai-semantic-convention-span-attributes-when-a-single-model-invocation-is-retried-across-fallback-providers-and-the.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-genai-semantic-convention-span-attributes-when-a-single-model-invocation-is-retried-across-fallback-providers-and-the.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-genai-semantic-convention-span-attributes-when-a-single-model-invocation-is-retried-across-fallback-providers-and-the.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2004,
    "python_slice_tokens": 441,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat a *model invocation span* as an atomic unit of accounting: `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.request.model`, and `gen_ai.response.finish_reasons` are defined as describing **one** request/response exchange. The convention's implicit invariant is that the sum of `gen_ai.usage.*` across the ...",
    "what_was_observed": "An agent looped over a task with a primary provider (`gen_ai.system=openai`, model `gpt-4o`) and a fallback (`gen_ai.system=anthropic`, model `claude-3-5-sonnet`). The wrapper emitted one `gen_ai.chat` span per HTTP attempt, parented to the same `execute_task` span. Three attempts occurred: attempt 1 returned HTTP 429 after emitting `gen_ai.usage.input_tokens=1840` (tokens were consumed server-side before the rate-li...",
    "condition_of_validity": "The additive-usage invariant holds **only when** (a) exactly one model-invocation span exists per logical call, (b) all `gen_ai.tool.call.id` values referenced by tool spans appear as `tool_calls` in a model span that is an ancestor of that tool span in the same trace, and (c) no attempt's usage is counted more than once. These three conditions are jointly t...",
    "decision_boundary": "The boundary is: **reconcile at the logical-invocation layer, emit at the attempt layer, and never let attempt-layer attributes cross into the logical-layer accounting.** Concretely: 1. Introduce an agent-owned correlation attribute (e.g. `agent.invocation.id`) on every attempt span for the same logical call. This is not in the GenAI convention; it is the mi...",
    "operational_effect": "With the reconciliation layer in place, the same three-attempt scenario produces: one logical `gen_ai.chat` span (`gen_ai.request.model=claude-3-5-sonnet`, `gen_ai.usage.input_tokens=1795, output_tokens=488`), with three child attempt spans carrying `agent.invocation.id=v_7f3`, `agent.attempt.status` of `rate_limited` / `abandoned` / `ok`, and per-attempt us..."
  },
  "matched_failure_symptoms": [
    "HTTP_502_503_504_CASCADE"
  ],
  "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": "f5830eca0e2450f70dd6c537fc5dd6862a09afe84fcf3b21586be8571898e143",
    "verified_classes": [
      "ReconciliationInvariantError",
      "Attempt",
      "ToolExecution"
    ],
    "verified_functions": [
      "reconcile"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "ReconciliationInvariantError"
    ],
    "sample_fail_closed_invariants": [
      "no attempts to reconcile"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
