feat(ai_provider): add retry handling, exponential backoff, and timeout resilience#245
Open
Harshit-Maurya838 wants to merge 3 commits into
Conversation
…imeout-retry-handling-203
Author
|
@imDarshanGK Conflicts has been resolved and all points in issue has been implemented. Please review it. |
Author
|
@imDarshanGK Please review this PR i resolved the issue and resolve the merge conflicts also |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #203
Description
This PR improves the reliability and observability of LLM integrations in
ai_provider.pyby introducing configurable retry handling, exponential backoff, structured logging, and comprehensive timeout/error handling while maintaining backward compatibility.Key Improvements
Retry & Backoff Support
Added configurable retry handling for:
Implemented exponential backoff using:
Improved Logging & Observability
Replaced print-based logging with structured logging
Added provider-level observability including:
Better Error Handling
Added granular handling for:
httpx.HTTPStatusErrorhttpx.RequestErrorPrevented retries for invalid client-side requests (400/401)
Preserved graceful fallback behavior and offline compatibility
Configuration Updates
Added new environment variables:
LLM_MAX_RETRIESLLM_RETRY_BACKOFFUpdated:
backend/app/config.py.env.exampleDocumentation
Unit Tests
Added comprehensive test coverage in:
backend/tests/test_ai_provider.pyTest scenarios include:
Type of Change
Verification
Test Results
7 passed in 0.58sNotes
call_llm()return signature (str | None) was intentionally preserved to avoid breaking changes.LLM_BASE_URLto keep configuration minimal and backward-compatible.