From 33e4c521cfcdddf1ccba0f202d5c7cd5ee83929c Mon Sep 17 00:00:00 2001 From: Harjoth Khara Date: Mon, 18 Aug 2025 17:42:31 -0700 Subject: [PATCH] fix: correct jitter comment to reflect 25% scaling --- src/openai/_base_client.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/openai/_base_client.py b/src/openai/_base_client.py index f71e00f51f..5883919ecb 100644 --- a/src/openai/_base_client.py +++ b/src/openai/_base_client.py @@ -742,12 +742,11 @@ def _calculate_retry_timeout( # Apply exponential backoff, but not more than the max. sleep_seconds = min(INITIAL_RETRY_DELAY * pow(2.0, nb_retries), MAX_RETRY_DELAY) - # Apply some jitter, plus-or-minus half a second. + # Apply jitter by scaling the delay down by up to 25% to spread retries and avoid thundering-herd effects. jitter = 1 - 0.25 * random() timeout = sleep_seconds * jitter return timeout if timeout >= 0 else 0 - - def _should_retry(self, response: httpx.Response) -> bool: +# def _should_retry(self, response: httpx.Response) -> bool: # Note: this is not a standard header should_retry_header = response.headers.get("x-should-retry")