Skip to content

fix(retry): restore jitter in _calculate_backoff_delay#1025

Open
sridipbasu wants to merge 1 commit into
Kaggle:mainfrom
sridipbasu:fix-retry-jitter-backoff
Open

fix(retry): restore jitter in _calculate_backoff_delay#1025
sridipbasu wants to merge 1 commit into
Kaggle:mainfrom
sridipbasu:fix-retry-jitter-backoff

Conversation

@sridipbasu
Copy link
Copy Markdown
Contributor

Summary

Fixes a jitter calculation bug in _calculate_backoff_delay that caused
retry back-off jitter to always evaluate to zero, making retries fully
deterministic instead of randomized.

Root Cause

Before (broken)

random_wait_ms = int(random() - 0.5) * 2 * delay_ms * randomness_factor
#                ^^^^^^^^^^^^^^^^^^^
#                int() applied too early — always truncates to 0

random() - 0.5 produces values in the range [-0.5, 0.5). Applying
int() before scaling truncates every possible value to 0, causing
the jitter term to always evaluate to zero.

After (correct)

random_wait_ms = int((random() - 0.5) * 2 * delay_ms * randomness_factor)
#                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#                    int() applied after scaling

Applying int() after the full expression preserves randomized jitter
while still returning an integer millisecond delay.

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