Skip to content

Fail fast on 4xx responses in retry_with_exponential_backoff - #370

Merged
CodexVeritas merged 1 commit into
mainfrom
claude/vigilant-aryabhata-53814a
Oct 14, 2026
Merged

CodexVeritas merged 1 commit into
mainfrom
claude/vigilant-aryabhata-53814a

Conversation

@CodexVeritas

Copy link
Copy Markdown
Collaborator

Summary

retry_with_exponential_backoff retried every requests.exceptions.RequestException, including the HTTPError that raise_for_status_with_additional_info raises for deterministic client errors. Every decorated MetaculusClient method 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_info passes response= to the HTTPError it raises, so the status code travels with the exception. The error message is unchanged.
  • retry_with_exponential_backoff re-raises right away when the error is an HTTPError with a 4xx response other than 429, and logs a warning saying why.
  • Still retried: timeouts, connection errors, 429, 5xx, and any HTTPError with no response attached (as before).

Tests

Added to code_tests/unit_tests/test_helpers/test_retry_decorator.py (no network or env vars needed):

  • A 400 that goes through raise_for_status_with_additional_info is raised after one call, and the response, status code and body text stay on the error.
  • 429, 503, HTTPError without a response, Timeout and ConnectionError are each retried max_retries times.

TZ=UTC poetry run pytest code_tests/unit_tests: 994 passed, 141 skipped.

🤖 Generated with Claude Code

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>
@CodexVeritas
CodexVeritas merged commit 60b094e into main Oct 14, 2026
2 checks passed
@CodexVeritas
CodexVeritas deleted the claude/vigilant-aryabhata-53814a branch October 14, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant