-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Implement fail-fast behavior for non-retryable errors in red team scans #42590
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: slister1001 <[email protected]>
Co-authored-by: slister1001 <[email protected]>
do not fail fast on 400 |
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.
Pull Request Overview
This PR implements fail-fast behavior for non-retryable errors in red team scans to improve efficiency and user experience. When the system encounters errors that won't be resolved by retrying (like authentication failures or bad requests), it now fails immediately instead of wasting time on futile retry attempts.
Key changes:
- Added
NonRetryableError
exception class for immediate failure scenarios - Enhanced error detection logic to identify non-retryable HTTP 4xx errors and configuration issues
- Modified retry logic to raise
NonRetryableError
for non-retryable cases instead of continuing retry attempts
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
File | Description |
---|---|
exception_utils.py |
Added NonRetryableError class and is_non_retryable_error() method with detection logic |
retry_utils.py |
Enhanced RetryManager with fail-fast behavior and non-retryable error checking |
__init__.py |
Exported new NonRetryableError exception class |
_orchestrator_manager.py |
Updated retry decorator to handle and log non-retryable errors appropriately |
sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/red_team/_utils/exception_utils.py
Show resolved
Hide resolved
sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/red_team/_utils/exception_utils.py
Show resolved
Hide resolved
sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/red_team/_utils/retry_utils.py
Show resolved
Hide resolved
return True | ||
|
||
return False | ||
|
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.
This condition is duplicated from line 111 in the same method. Consider extracting this logic to avoid code duplication.
if self._is_non_retryable_status_code(status_code): | |
return True | |
# Specific HTTP status errors that are non-retryable | |
if isinstance(exception, httpx.HTTPStatusError): | |
status_code = exception.response.status_code | |
if self._is_non_retryable_status_code(status_code): | |
return True | |
return False | |
def _is_non_retryable_status_code(self, status_code: int) -> bool: | |
"""Return True if status code is a non-retryable client error (4xx except 429).""" | |
return 400 <= status_code < 500 and status_code != 429 |
Copilot uses AI. Check for mistakes.
Problem
When red team scans encounter non-retryable errors (like authentication failures, bad requests, or configuration issues), the current implementation continues to retry these operations, wasting time and resources before eventually failing. This leads to poor user experience and inefficient resource usage.
Solution
This PR implements fail-fast behavior for non-retryable errors by:
NonRetryableError
exception class - A specialized exception that signals immediate failure for errors that won't be resolved by retryingRetryManager.should_retry_exception()
to immediately raiseNonRetryableError
for non-retryable casesError Categories
Non-retryable (fail fast):
FileNotFoundError
,PermissionError
Retryable (existing behavior unchanged):
Example Behavior Change
Before:
After:
Benefits
Files Changed
azure/ai/evaluation/red_team/_utils/exception_utils.py
- AddedNonRetryableError
class and detection logicazure/ai/evaluation/red_team/_utils/retry_utils.py
- Enhanced retry manager with fail-fast behaviorazure/ai/evaluation/red_team/_orchestrator_manager.py
- Updated retry decorator to handle non-retryable errorsazure/ai/evaluation/red_team/_utils/__init__.py
- Added exports for new exception typeWarning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
pypi.org
/home/REDACTED/work/azure-sdk-for-python/azure-sdk-for-python/.venv/bin/python /home/REDACTED/work/azure-sdk-for-python/azure-sdk-for-python/.venv/lib/python3.9/site-packages/pip/__pip-REDACTED__.py install --ignore-installed --no-user --prefix /tmp/pip-build-env-79zs7crv/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i REDACTED -- setuptools>=40.8.0
(dns block)/home/REDACTED/work/azure-sdk-for-python/azure-sdk-for-python/.venv/bin/python /home/REDACTED/work/azure-sdk-for-python/azure-sdk-for-python/.venv/bin/pip install httpx tenacity
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.