Repository navigation
feat(retry): Retry webhooks, client LLM proxy and guardrails calls #1275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6ab6fcf
feat(retry): Retry webhooks and transient upstream failures
Prajna1999 12285b0
refactor(retry): Use tenacity @retry directly with 3 attempts
Prajna1999 7cd938a
refactor(retry): Limit retries to webhooks, LLM proxy and guardrails
Prajna1999 168d565
feat(llm): Retry OpenAI, Anthropic and Sarvam calls via SDK settings
Prajna1999 0a16118
fix(retry): Use 3 retries (4 attempts) for tenacity call sites
Prajna1999 2f52e38
feat(llm): Retry ElevenLabs 5xx and connect failures with tenacity
Prajna1999 faf6dc6
Merge branch 'main' into feat/retry-webhooks-and-provider-calls
Prajna1999 c151a85
Merge branch 'main' into feat/retry-webhooks-and-provider-calls
Prajna1999 0dd873e
Merge branch 'main' into feat/retry-webhooks-and-provider-calls
Prajna1999 8180000
revert(llm): Keep SDK default retries for OpenAI, Anthropic, Sarvam, …
Prajna1999 c8b56bd
chore: version lock to litellm
Prajna1999 eb1451e
fix(llm): Release DB connection during proxy calls
Prajna1999 dd4348c
Merge branch 'main' into feat/retry-webhooks-and-provider-calls
Prajna1999 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import httpx | ||
| import requests | ||
|
|
||
|
|
||
| def is_transient(error: BaseException) -> bool: | ||
| """5xx from upstream, or a connection that never reached it.""" | ||
| if isinstance(error, (httpx.HTTPStatusError, requests.HTTPError)): | ||
| return error.response is not None and error.response.status_code >= 500 | ||
| return isinstance( | ||
| error, (httpx.ConnectError, httpx.ConnectTimeout, requests.ConnectionError) | ||
| ) |
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import httpx | ||
| import pytest | ||
|
|
||
| from app.core.retry import is_transient | ||
|
|
||
| _REQUEST = httpx.Request("POST", "https://upstream.example/v1") | ||
|
|
||
|
|
||
| def _status_error(code: int) -> httpx.HTTPStatusError: | ||
| return httpx.HTTPStatusError( | ||
| "upstream", request=_REQUEST, response=httpx.Response(code, request=_REQUEST) | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "error, expected", | ||
| [ | ||
| (_status_error(500), True), | ||
| (_status_error(404), False), | ||
| (httpx.ConnectError("refused"), True), | ||
| (httpx.ConnectTimeout("slow handshake"), True), | ||
| # The request may have reached upstream, so a retry could double-execute. | ||
| (httpx.ReadTimeout("no response"), False), | ||
| ], | ||
| ) | ||
| def test_is_transient(error: BaseException, expected: bool) -> None: | ||
| assert is_transient(error) is expected |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can combine this into one single decorator I guess, instead of repeating everywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a decorator. So thought of keeping it staright forward
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was Claude's suggestion. But overrode it to make the retry straight forward