Skip to content

FIX: retry backoff never waits with default wait_seconds; make reraise meaningful - #2596

Open
NullLabTests wants to merge 2 commits into
huggingface:mainfrom
NullLabTests:fix/retrying-backoff
Open

FIX: retry backoff never waits with default wait_seconds; make reraise meaningful#2596
NullLabTests wants to merge 2 commits into
huggingface:mainfrom
NullLabTests:fix/retrying-backoff

Conversation

@NullLabTests

Copy link
Copy Markdown

Fixes #2586

Three problems in smolagents.utils.Retrying:

  1. Backoff never waited with the default wait_seconds=0.0. delay starts at 0.0 and delay *= exponential_base * (1 + jitter * random()) keeps it at 0.0, so the if delay > 0 guard never sleeps. Any caller using the default gets max_attempts back-to-back calls. Default is now 1.0, matching tenacity's wait_exponential multiplier.

  2. First sleep was wait_seconds * exponential_base, not wait_seconds. The delay was multiplied before sleeping, so a wait_seconds=1.0 produced waits of 2s, 4s, 8s... instead of 1s, 2s, 4s... The sleep now happens before the delay grows.

  3. reraise had no effect. Both branches were identical raise, so reraise=False behaved like reraise=True. Following tenacity, reraise=False now raises a RetryError wrapping the last exception; reraise=True re-raises the original.

Tests added in tests/test_utils.py cover all three fixes plus the no-retry path.

Note: models.py passes wait_seconds=RETRY_WAIT (60) explicitly, so in-repo behavior is unchanged; the default change only affects external users who relied on the (broken) default.

…aise meaningful

- Default wait_seconds=0.0 kept delay at 0, so exponential backoff
  never actually slept. Default is now 1.0, matching tenacity's
  wait_exponential multiplier.
- The first sleep used wait_seconds * exponential_base instead of
  wait_seconds because delay was multiplied before sleeping. Sleep now
  happens before the delay grows, so waits are 1s, 2s, 4s, ...
- reraise=False raised the raw exception like reraise=True. It now
  raises RetryError wrapping the last exception, matching tenacity.
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.

Retrying's default wait_seconds=0.0 disables backoff entirely, and reraise has no effect

1 participant