Repository navigation
FIX: Retry only rate limits in OpenAITextEmbedding and raise the original error - #4834
Open
Swaraj Unde (swaraj-unde) wants to merge 1 commit into
Open
Swaraj Unde (swaraj-unde) wants to merge 1 commit into
Swaraj Unde (swaraj-unde) wants to merge 1 commit into
Conversation
…inal error generate_text_embedding_async used a bare tenacity.retry with no retry predicate and no reraise, so every error (401, 400, 404, programming errors) was retried for 3 seconds and surfaced as tenacity.RetryError. Use the shared pyrit_target_retry, which retries only rate limits with exponential backoff and re-raises the original exception.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the shared retry-policy change.
No open issues 🎉
What changed in this PR
Addresses #4833 by replacing embedding-specific retries with PyRIT’s shared retry policy, preserving original exceptions.
Changes:
- Non-rate-limit errors now propagate without outer retries.
- Rate limits use shared backoff and attempt settings.
- Adds regression tests for error propagation and rate-limit recovery.
| File | Description |
|---|---|
tests/unit/embedding/test_openai_text_embedding.py |
Tests immediate failures, retry recovery, and retry exhaustion. |
pyrit/embedding/openai_text_embedding.py |
Replaces the broad Tenacity decorator with pyrit_target_retry. |
Review effort: Balanced
Author
|
@microsoft-github-policy-service agree |
This branch has not been deployed
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.
Description
OpenAITextEmbedding.generate_text_embedding_asyncretried every exception for 3 seconds (about 29 calls) and then raisedtenacity.RetryError, hiding the real error. This switches it to the sharedpyrit_target_retryso permanent errors fail on the first call with their original exception. Fixes #4833.@tenacity.retry(wait_fixed(0.1), stop_after_delay(3))with@pyrit_target_retry, as the OpenAI targets use, and drop thetenacityimport.openai.RateLimitErrorafter the configured attempts instead ofRetryError.tests/unit/embedding/test_openai_text_embedding.py; six of its seven tests fail on the old decorator.Behavior changes to be aware of:
openaiexception instead oftenacity.RetryError. Nothing inpyritcatchesRetryErrorfrom embeddings.