Fix fallback for native LLM provider errors - #120
Conversation
|
Warning Review limit reached
Next review available in: 13 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe AnyLLM adapter centralizes completion error normalization, preserves validation, serialization, and protocol errors, broadens completion message types, and enables request-error normalization through the provider factory. Tests cover native failures, fallback switching, and exception context. ChangesNative Error Normalization
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant PrimaryClient
participant AnyLLMStructuredProvider
participant FallbackLLMProvider
PrimaryClient->>AnyLLMStructuredProvider: completion request
AnyLLMStructuredProvider->>AnyLLMStructuredProvider: normalize provider request error
AnyLLMStructuredProvider->>FallbackLLMProvider: raise LLMRequestError
FallbackLLMProvider->>FallbackLLMProvider: switch to fallback provider
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #120 +/- ##
=======================================
Coverage 99.86% 99.86%
=======================================
Files 115 115
Lines 12154 12239 +85
Branches 729 730 +1
=======================================
+ Hits 12137 12222 +85
Misses 12 12
Partials 5 5 ☔ View full report in Codecov by Harness. |
|
/agentic_review |
Code Review by Qodo
Context used✅ Compliance rules (platform):
46 rules 1.
|
|
/agentic_review |
|
Code review by qodo was updated up to the latest commit 26d5701 |
|
/agentic_review |
|
Code review by qodo was updated up to the latest commit 1ebc5f5 |
|
/agentic_review |
|
Code review by qodo was updated up to the latest commit 681514f |
|
/agentic_review |
|
Code review by qodo was updated up to the latest commit d7ebed6 |
|
/agentic_review |
|
Code review by qodo was updated up to the latest commit 4da2b82 |
|
/agentic_review |
|
Code review by qodo was updated up to the latest commit 4da2b82 |
|
/agentic_review |
|
Code review by qodo was updated up to the latest commit a051749 |
PR Summary by QodoFix AnyLLM native provider errors to preserve fallback routing
AI Description
Diagram
High-Level Assessment
Files changed (5)
|
|
Code review by qodo was updated up to the latest commit a051749 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
weather_briefing/llm/any_llm.py (1)
155-169: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract a shared completion-call helper to remove triplicated boilerplate.
summarize,assess_notification, andtranslate_service_statusall repeat the same "build messages → wrapacompletionin_normalize_request_errors+api_call_context→ catchLengthFinishReasonError" shape; consolidating this avoids the three call sites drifting apart when normalization or logging logic changes.
weather_briefing/llm/any_llm.py#L155-L169: factor the_normalize_request_errors/api_call_context/acompletionwrapping used here into a shared private helper (e.g._complete(...)) parameterized by message text, messages, response_format, temperature, and max_tokens.weather_briefing/llm/any_llm.py#L195-L212: routeassess_notification's completion call through the same shared helper instead of repeating the wrapping.weather_briefing/llm/any_llm.py#L243-L267: routetranslate_service_status's completion call through the same shared helper instead of repeating the wrapping.♻️ Sketch of a shared helper
async def _complete( self, message: str, messages: list[dict[str, Any] | ChatCompletionMessage], *, response_format: type[BaseModel], temperature: float, max_tokens: int, limit_message: str, ) -> object: try: with ( _normalize_request_errors(message, normalize_native_errors=self._normalize_native_errors), api_call_context(self._provider, "chat-completions"), ): return await self._client.acompletion( model=self._model, messages=messages, response_format=response_format, temperature=temperature, max_tokens=max_tokens, ) except LengthFinishReasonError as exc: _LOGGER.warning("%s: provider=%s model=%r error_type=%s", limit_message, self._provider, self._model, type(exc).__name__) raise LLMOutputLimitError(limit_message) from exc🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@weather_briefing/llm/any_llm.py` around lines 155 - 169, In weather_briefing/llm/any_llm.py at lines 155-169, extract the shared completion flow into a private _complete helper accepting the request message, messages, response format, temperature, max_tokens, and limit message, while preserving error normalization, api_call_context, LengthFinishReasonError logging, and LLMOutputLimitError conversion; update assess_notification at lines 195-212 and translate_service_status at lines 243-267 to call this helper instead of duplicating the wrapper and exception handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@weather_briefing/llm/any_llm.py`:
- Around line 155-169: In weather_briefing/llm/any_llm.py at lines 155-169,
extract the shared completion flow into a private _complete helper accepting the
request message, messages, response format, temperature, max_tokens, and limit
message, while preserving error normalization, api_call_context,
LengthFinishReasonError logging, and LLMOutputLimitError conversion; update
assess_notification at lines 195-212 and translate_service_status at lines
243-267 to call this helper instead of duplicating the wrapper and exception
handling.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: e9c38705-d6b3-40be-9c73-9f2f235772bf
📒 Files selected for processing (5)
docs/notes.mdtests/test_any_llm_provider.pytests/test_llm.pytests/test_llm_fallback.pyweather_briefing/llm/any_llm.py
|
Code review by qodo was updated up to the latest commit b9daec8 |
|
Code review by qodo was updated up to the latest commit e9f8a36 |
|
Code review by qodo was updated up to the latest commit 99e4751 |
|
@coderabbitai review |
✅ Action performedReview finished.
|
Summary
Root cause
AnyLLM can propagate a provider SDK exception directly. The adapter only recognized
AnyLLMError, so the configured fallback provider was bypassed when the primary returned a native SDK error such as an OpenAI-compatible HTTP 400.Validation
prek run --all-filesuv run --with pytest --with pytest-cov -- pytest --cov --cov-branch --cov-report=xmlmasterSummary by CodeRabbit
Bug Fixes
LLMRequestError.Documentation