fix(litellm): submit a single LLM span for calls using fallbacks [SIGN-53] #21792
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.41) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.41 · 195 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.316
Shallow Review Depth
shallow_review_depth
0.289
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #21792"
general
weight: 0.35
wconti27
Description
Fixes #20670. A
litellm.completion/acompletioncall withfallbacksproduced two LLM Observability spans with identical token usage, double-counting tokens and cost.Root cause: litellm routes such calls through its fallback runner, which re-enters
litellm.completion/acompletion(withoutfallbacks) for each attempt. Both the outer call and the inner call were wrapped and submitted as LLM spans.Fix: the outer call keeps its span and sets a context flag so the inner calls made by the fallback runner skip theirs. Keeping the outer span (rather than the inner) preserves a span when no re-entry happens, e.g. on a response cache hit.
Follow-ups from review: the outer litellm span is always kept and tagged with the fallback model that answered. When that model is a non-streamed OpenAI call answered without the cache, the OpenAI integration already emits the LLM span, so the outer span becomes a workflow span (as for proxy requests). The trace then has one LLM span, with no repeated tokens or cost, and the OpenAI span keeps a valid parent. Tests cover sync, async, streaming, global
litellm.model_fallbacks, and failure, cache-hit and multi-attempt chains. Sync streaming fallback is not tested: litellm's sync runner returns an async generator for streams.Testing
New regression test in
tests/contrib/litellm/test_litellm_llmobs.pyfails before the fix (two LLM spans) and passes after. Fulltests/contrib/litellmpasses locally.Risks
None.
🤖 Generated with Claude Code