feat: hybrid endpoint fallback — try cloudcode-pa + daily-cloudcode-pa on 429
This commit is contained in:
@@ -5071,7 +5071,10 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
|||||||
|
|
||||||
_allow_staging = os.environ.get("ALLOW_ANTIGRAVITY_STAGING", "0") == "1"
|
_allow_staging = os.environ.get("ALLOW_ANTIGRAVITY_STAGING", "0") == "1"
|
||||||
if OAUTH_PROVIDER == "google-antigravity":
|
if OAUTH_PROVIDER == "google-antigravity":
|
||||||
_antigravity_endpoints = ["https://cloudcode-pa.googleapis.com"]
|
_antigravity_endpoints = [
|
||||||
|
"https://cloudcode-pa.googleapis.com",
|
||||||
|
"https://daily-cloudcode-pa.googleapis.com",
|
||||||
|
]
|
||||||
if _allow_staging:
|
if _allow_staging:
|
||||||
_antigravity_endpoints.extend([
|
_antigravity_endpoints.extend([
|
||||||
"https://daily-cloudcode-pa.sandbox.googleapis.com",
|
"https://daily-cloudcode-pa.sandbox.googleapis.com",
|
||||||
@@ -5128,14 +5131,16 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
|||||||
if e.code == 403 and "SERVICE_DISABLED" in err_body[:500] and ep != endpoints[-1]:
|
if e.code == 403 and "SERVICE_DISABLED" in err_body[:500] and ep != endpoints[-1]:
|
||||||
print(f"[{self._session_id}] {ep} SERVICE_DISABLED, trying next endpoint", file=sys.stderr)
|
print(f"[{self._session_id}] {ep} SERVICE_DISABLED, trying next endpoint", file=sys.stderr)
|
||||||
continue
|
continue
|
||||||
if e.code == 429 and ep != endpoints[-1] and _allow_staging:
|
if e.code == 429 and OAUTH_PROVIDER.startswith("google"):
|
||||||
print(f"[{self._session_id}] {ep} HTTP 429, trying next endpoint", file=sys.stderr)
|
print(f"[{self._session_id}] 429 from {ep}, body: {err_body[:300]}", file=sys.stderr)
|
||||||
continue
|
if ep != endpoints[-1]:
|
||||||
if e.code == 429:
|
print(f"[{self._session_id}] {ep} HTTP 429, trying fallback endpoint", file=sys.stderr)
|
||||||
|
continue
|
||||||
pool = _google_antigravity_pool if OAUTH_PROVIDER == "google-antigravity" else _google_cli_pool
|
pool = _google_antigravity_pool if OAUTH_PROVIDER == "google-antigravity" else _google_cli_pool
|
||||||
_, acct = _get_google_account(OAUTH_PROVIDER)
|
_, acct = _get_google_account(OAUTH_PROVIDER)
|
||||||
if acct:
|
if acct:
|
||||||
pool.mark_rate_limited(acct, 60)
|
pool.mark_rate_limited(acct, 60)
|
||||||
|
print(f"[{self._session_id}] all endpoints returned 429", file=sys.stderr)
|
||||||
return self.send_json(e.code, {"error": {"type": "upstream_error", "message": _sanitize_err_body(err_body)}})
|
return self.send_json(e.code, {"error": {"type": "upstream_error", "message": _sanitize_err_body(err_body)}})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if ep == endpoints[-1]:
|
if ep == endpoints[-1]:
|
||||||
|
|||||||
Reference in New Issue
Block a user