← Back to Pull requests

fix(litellm): submit a single LLM span for calls using fallbacks [SIGN-53] #21792

Closed
unknown closed this pull request without merging on Nov 23, 2026 17:03 UTC
View on GitHub
unknown unknown commented on Nov 13, 2026 22:44 UTC
Author

Description

Fixes #20670. A litellm.completion/acompletion call with fallbacks produced 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 (without fallbacks) 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.py fails before the fix (two LLM spans) and passes after. Full tests/contrib/litellm passes locally.

Risks

None.

🤖 Generated with Claude Code

Diff: 195 lines (+146 / -49) across 2 files Reviewer: wconti27 Review duration: 14058m
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
0.41
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 41% (MEDIUM) · Higher = larger blast radius
41%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 16.2% · Safe to merge
16.2%