Repository navigation
Fail fast on 4xx responses in retry_with_exponential_backoff - #370
Merged
Merged
Conversation
raise_for_status_with_additional_info now attaches the response to the HTTPError it raises, and the retry decorator re-raises immediately on 4xx responses other than 429. Timeouts, connection errors, 429 and 5xx are still retried. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
retry_with_exponential_backoffretried everyrequests.exceptions.RequestException, including theHTTPErrorthatraise_for_status_with_additional_inforaises for deterministic client errors. Every decoratedMetaculusClientmethod retried 4xx responses (e.g. a 400 from an invalid forecast, or a 403 from a restricted endpoint) 3 times, with up to 75s between attempts, before raising the same error.Changes
raise_for_status_with_additional_infopassesresponse=to theHTTPErrorit raises, so the status code travels with the exception. The error message is unchanged.retry_with_exponential_backoffre-raises right away when the error is anHTTPErrorwith a 4xx response other than 429, and logs a warning saying why.HTTPErrorwith no response attached (as before).Tests
Added to
code_tests/unit_tests/test_helpers/test_retry_decorator.py(no network or env vars needed):raise_for_status_with_additional_infois raised after one call, and the response, status code and body text stay on the error.HTTPErrorwithout a response,TimeoutandConnectionErrorare each retriedmax_retriestimes.TZ=UTC poetry run pytest code_tests/unit_tests: 994 passed, 141 skipped.🤖 Generated with Claude Code