Skip to content

Commit 73a2395

Browse files
committed
refactor(providers): 🔨 improve error handling and reduce debug logging in antigravity provider
- Add specific handling for 429 HTTP status errors to prevent unnecessary fallback URL retries, as quota exhaustion is credential-bound - Separate HTTP errors from network errors in exception handling for more intelligent retry logic - Comment out verbose debug logging for function grouping operations to reduce noise - Fix code style formatting for commented URLs and quota group configuration - Enable claude model quota group for production use The changes improve the provider's resilience by distinguishing between errors that benefit from URL fallback (network issues, server errors) versus those that don't (rate limits). Debug log reduction improves terminal readability while maintaining error logging in failures.log.
1 parent 640efbf commit 73a2395

File tree

1 file changed

+40
-17
lines changed

1 file changed

+40
-17
lines changed

‎src/rotator_library/providers/antigravity_provider.py‎

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
# Priority: daily (sandbox) → autopush (sandbox) → production
5151
BASE_URLS = [
5252
"https://daily-cloudcode-pa.sandbox.googleapis.com/v1internal",
53-
#"https://autopush-cloudcode-pa.sandbox.googleapis.com/v1internal",
53+
# "https://autopush-cloudcode-pa.sandbox.googleapis.com/v1internal",
5454
"https://cloudcode-pa.googleapis.com/v1internal", # Production fallback
5555
]
5656

@@ -541,7 +541,7 @@ class AntigravityProvider(AntigravityAuthBase, ProviderInterface):
541541
# Model quota groups (can be overridden via QUOTA_GROUPS_ANTIGRAVITY_CLAUDE)
542542
# Models in the same group share quota - when one is exhausted, all are
543543
model_quota_groups: QuotaGroupMap = {
544-
#"claude": ["claude-sonnet-4-5", "claude-opus-4-5"], - commented out for later use if needed
544+
"claude": ["claude-sonnet-4-5", "claude-opus-4-5"],
545545
}
546546

547547
# Model usage weights for grouped usage calculation
@@ -2559,9 +2559,9 @@ def _fix_tool_response_grouping(
25592559
f"Ignoring duplicate - this may indicate malformed conversation history."
25602560
)
25612561
continue
2562-
lib_logger.debug(
2563-
f"[Grouping] Collected response for ID: {resp_id}"
2564-
)
2562+
#lib_logger.debug(
2563+
# f"[Grouping] Collected response for ID: {resp_id}"
2564+
#)
25652565
collected_responses[resp_id] = resp
25662566

25672567
# Try to satisfy pending groups (newest first)
@@ -2576,10 +2576,10 @@ def _fix_tool_response_grouping(
25762576
collected_responses.pop(gid) for gid in group_ids
25772577
]
25782578
new_contents.append({"parts": group_responses, "role": "user"})
2579-
lib_logger.debug(
2580-
f"[Grouping] Satisfied group with {len(group_responses)} responses: "
2581-
f"ids={group_ids}"
2582-
)
2579+
#lib_logger.debug(
2580+
# f"[Grouping] Satisfied group with {len(group_responses)} responses: "
2581+
# f"ids={group_ids}"
2582+
#)
25832583
pending_groups.pop(i)
25842584
break
25852585
continue
@@ -2599,10 +2599,10 @@ def _fix_tool_response_grouping(
25992599
]
26002600

26012601
if call_ids:
2602-
lib_logger.debug(
2603-
f"[Grouping] Created pending group expecting {len(call_ids)} responses: "
2604-
f"ids={call_ids}, names={func_names}"
2605-
)
2602+
#lib_logger.debug(
2603+
# f"[Grouping] Created pending group expecting {len(call_ids)} responses: "
2604+
# f"ids={call_ids}, names={func_names}"
2605+
#)
26062606
pending_groups.append(
26072607
{
26082608
"ids": call_ids,
@@ -3634,7 +3634,28 @@ async def acompletion(
36343634
return await self._handle_non_streaming(
36353635
client, url, headers, payload, model, file_logger
36363636
)
3637+
except httpx.HTTPStatusError as e:
3638+
# 429 = Rate limit/quota exhausted - tied to credential, not URL
3639+
# Do NOT retry on different URL, just raise immediately
3640+
if e.response.status_code == 429:
3641+
lib_logger.debug(f"429 quota error - not retrying on fallback URL: {e}")
3642+
raise
3643+
3644+
# For other HTTP errors (403, 500, etc.), try fallback URL
3645+
if self._try_next_base_url():
3646+
lib_logger.warning(f"Retrying with fallback URL: {e}")
3647+
url = f"{self._get_base_url()}{endpoint}"
3648+
if stream:
3649+
return self._handle_streaming(
3650+
client, url, headers, payload, model, file_logger
3651+
)
3652+
else:
3653+
return await self._handle_non_streaming(
3654+
client, url, headers, payload, model, file_logger
3655+
)
3656+
raise
36373657
except Exception as e:
3658+
# Non-HTTP errors (network issues, timeouts, etc.) - try fallback URL
36383659
if self._try_next_base_url():
36393660
lib_logger.warning(f"Retrying with fallback URL: {e}")
36403661
url = f"{self._get_base_url()}{endpoint}"
@@ -3718,11 +3739,13 @@ async def _handle_streaming(
37183739
"POST", url, headers=headers, json=payload, timeout=600.0
37193740
) as response:
37203741
if response.status_code >= 400:
3742+
# Read error body for raise_for_status to include in exception
3743+
# Terminal logging commented out - errors are logged in failures.log
37213744
try:
3722-
error_body = await response.aread()
3723-
lib_logger.error(
3724-
f"API error {response.status_code}: {error_body.decode()}"
3725-
)
3745+
await response.aread()
3746+
# lib_logger.error(
3747+
# f"API error {response.status_code}: {error_body.decode()}"
3748+
# )
37263749
except Exception:
37273750
pass
37283751

0 commit comments

Comments
 (0)