Skip to content

Commit 3876001

Browse files
committed
refactor(antigravity): 🔨 clarify empty response retry configuration and logic
Renames `EMPTY_RESPONSE_MAX_RETRIES` to `EMPTY_RESPONSE_MAX_ATTEMPTS` and updates the retry logic to be more intuitive and correct. - Renamed constant to better reflect that it represents total attempts, not retries - Updated environment variable from `ANTIGRAVITY_EMPTY_RESPONSE_RETRIES` to `ANTIGRAVITY_EMPTY_RESPONSE_ATTEMPTS` - Changed default from 3 to 4 attempts with minimum enforcement via `max(1, ...)` - Fixed off-by-one errors in loop conditions: now using `range(EMPTY_RESPONSE_MAX_ATTEMPTS)` instead of `range(EMPTY_RESPONSE_MAX_RETRIES + 1)` - Corrected retry condition from `attempt < EMPTY_RESPONSE_MAX_RETRIES` to `attempt < EMPTY_RESPONSE_MAX_ATTEMPTS - 1` - Removed redundant error logging on final attempt failure (caller handles error logging) - Updated all related comments and log messages to reflect "attempts" terminology - Applied changes consistently to both streaming and non-streaming handlers BREAKING CHANGE: The environment variable `ANTIGRAVITY_EMPTY_RESPONSE_RETRIES` has been renamed to `ANTIGRAVITY_EMPTY_RESPONSE_ATTEMPTS`. Users must update their environment configuration to use the new variable name. The semantic meaning has also changed from "number of retries after initial attempt" to "total number of attempts including the first".
1 parent d5acbd4 commit 3876001

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

‎src/rotator_library/providers/antigravity_provider.py‎

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ def _env_int(key: str, default: int) -> int:
8585

8686
# Empty response retry configuration
8787
# When Antigravity returns an empty response (no content, no tool calls),
88-
# automatically retry up to this many times before giving up
89-
EMPTY_RESPONSE_MAX_RETRIES = _env_int("ANTIGRAVITY_EMPTY_RESPONSE_RETRIES", 3)
88+
# automatically retry up to this many attempts before giving up (minimum 1)
89+
EMPTY_RESPONSE_MAX_ATTEMPTS = max(1, _env_int("ANTIGRAVITY_EMPTY_RESPONSE_ATTEMPTS", 4))
9090
EMPTY_RESPONSE_RETRY_DELAY = _env_int("ANTIGRAVITY_EMPTY_RESPONSE_RETRY_DELAY", 2)
9191

9292
# Model alias mappings (internal ↔ public)
@@ -3258,7 +3258,7 @@ async def acompletion(
32583258
"This may indicate a temporary service issue. Please try again."
32593259
)
32603260

3261-
for attempt in range(EMPTY_RESPONSE_MAX_RETRIES + 1):
3261+
for attempt in range(EMPTY_RESPONSE_MAX_ATTEMPTS):
32623262
result = await self._handle_non_streaming(
32633263
client, url, headers, payload, model, file_logger
32643264
)
@@ -3272,18 +3272,16 @@ async def acompletion(
32723272
got_response = bool(result_dict.get("choices"))
32733273

32743274
if not got_response:
3275-
if attempt < EMPTY_RESPONSE_MAX_RETRIES:
3275+
if attempt < EMPTY_RESPONSE_MAX_ATTEMPTS - 1:
32763276
lib_logger.warning(
32773277
f"[Antigravity] Empty response from {model}, "
3278-
f"attempt {attempt + 1}/{EMPTY_RESPONSE_MAX_RETRIES + 1}. Retrying..."
3278+
f"attempt {attempt + 1}/{EMPTY_RESPONSE_MAX_ATTEMPTS}. Retrying..."
32793279
)
32803280
await asyncio.sleep(EMPTY_RESPONSE_RETRY_DELAY)
32813281
continue
32823282
else:
3283-
lib_logger.error(
3284-
f"[Antigravity] Empty response from {model} after "
3285-
f"{EMPTY_RESPONSE_MAX_RETRIES + 1} attempts. Giving up."
3286-
)
3283+
# Last attempt failed - raise without extra logging
3284+
# (caller will log the error)
32873285
raise EmptyResponseError(
32883286
provider="antigravity",
32893287
model=model,
@@ -3493,14 +3491,14 @@ async def _streaming_with_retry(
34933491
Wrapper around _handle_streaming that retries on empty responses.
34943492
34953493
If the stream yields zero chunks (Antigravity returned nothing),
3496-
retry up to EMPTY_RESPONSE_MAX_RETRIES times before giving up.
3494+
retry up to EMPTY_RESPONSE_MAX_ATTEMPTS times before giving up.
34973495
"""
34983496
error_msg = (
34993497
"The model returned an empty response after multiple attempts. "
35003498
"This may indicate a temporary service issue. Please try again."
35013499
)
35023500

3503-
for attempt in range(EMPTY_RESPONSE_MAX_RETRIES + 1):
3501+
for attempt in range(EMPTY_RESPONSE_MAX_ATTEMPTS):
35043502
chunk_count = 0
35053503

35063504
try:
@@ -3514,18 +3512,16 @@ async def _streaming_with_retry(
35143512
return # Success - we got data
35153513

35163514
# Zero chunks - empty response
3517-
if attempt < EMPTY_RESPONSE_MAX_RETRIES:
3515+
if attempt < EMPTY_RESPONSE_MAX_ATTEMPTS - 1:
35183516
lib_logger.warning(
35193517
f"[Antigravity] Empty stream from {model}, "
3520-
f"attempt {attempt + 1}/{EMPTY_RESPONSE_MAX_RETRIES + 1}. Retrying..."
3518+
f"attempt {attempt + 1}/{EMPTY_RESPONSE_MAX_ATTEMPTS}. Retrying..."
35213519
)
35223520
await asyncio.sleep(EMPTY_RESPONSE_RETRY_DELAY)
35233521
continue
35243522
else:
3525-
lib_logger.error(
3526-
f"[Antigravity] Empty stream from {model} after "
3527-
f"{EMPTY_RESPONSE_MAX_RETRIES + 1} attempts. Giving up."
3528-
)
3523+
# Last attempt failed - raise without extra logging
3524+
# (caller will log the error)
35293525
raise EmptyResponseError(
35303526
provider="antigravity",
35313527
model=model,

0 commit comments

Comments
 (0)