v3.11.12: fix antigravity v2 version fallback (2.0.1→1.15.8)

This commit is contained in:
Roman | RyzenAdvanced
2026-05-26 22:53:03 +04:00
Unverified
parent 633e9570bb
commit 991776c4e6

View File

@@ -5523,7 +5523,8 @@ class Handler(http.server.BaseHTTPRequestHandler):
contents = sanitized
instructions = body.get("instructions", "").strip()
system_parts = []
ag_identity = "You are Antigravity, a powerful agentic AI coding assistant designed by the Google Deepmind team working on Advanced Agentic Coding.\nYou are pair programming with a USER to solve their coding task. The task may require creating a new codebase, modifying or debugging an existing codebase, or simply answering a question.\n**Absolute paths only**\n**Proactiveness**"
system_parts = [{"text": ag_identity}, {"text": "\n--- [SYSTEM_PROMPT_END] ---"}]
if instructions:
system_parts.append({"text": instructions})
@@ -5630,8 +5631,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
{"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "OFF"},
{"category": "HARM_CATEGORY_CIVIC_INTEGRITY", "threshold": "OFF"},
]}
if system_parts:
request_body["systemInstruction"] = {"parts": system_parts}
request_body["systemInstruction"] = {"role": "user", "parts": system_parts}
if gen_config:
request_body["generationConfig"] = gen_config
if gemini_tools:
@@ -5639,14 +5639,18 @@ class Handler(http.server.BaseHTTPRequestHandler):
if _is_claude_model and gemini_tools:
request_body["toolConfig"] = {"functionCallingConfig": {"mode": "VALIDATED"}}
version = _ensure_antigravity_version()
import platform as _plat
_os_name = _plat.system().lower()
_os_arch = _plat.machine().lower().replace("x86_64", "x64").replace("aarch64", "arm64")
_fetched_ver = _ensure_antigravity_version()
_fallback_ver = "1.15.8"
_versions = [_fetched_ver, _fallback_ver] if _fetched_ver != _fallback_ver else [_fallback_ver]
_version_404s = set()
_ag_ua = f"antigravity/{_versions[0]} {_os_name}/{_os_arch}"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {access_token}",
"User-Agent": f"antigravity/{version} {_os_name}/{_os_arch}",
"User-Agent": _ag_ua,
"X-Client-Name": "antigravity",
"X-Client-Version": _ensure_antigravity_client_version(),
"x-goog-api-client": "gl-node/18.18.2 fire/0.8.6 grpc/1.10.x",
@@ -5656,7 +5660,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
"project": project_id,
"model": model,
"requestType": "agent",
"userAgent": f"antigravity/{version} {_os_name}/{_os_arch}",
"userAgent": _ag_ua,
"requestId": f"agent-{uuid.uuid4().hex[:12]}",
"request": request_body,
}
@@ -5672,7 +5676,13 @@ class Handler(http.server.BaseHTTPRequestHandler):
_antigravity_endpoints.append("https://autopush-cloudcode-pa.sandbox.googleapis.com")
body_b = json.dumps(wrapped).encode()
print(f"[{self._session_id}] [antigravity-v2] model={model} stream={stream} contents={len(contents)} tools={bool(gemini_tools)} project={project_id}", file=sys.stderr)
print(f"[{self._session_id}] [antigravity-v2] model={model} stream={stream} contents={len(contents)} tools={bool(gemini_tools)} project={project_id} ver={_versions[0]}", file=sys.stderr)
try:
debug_path = os.path.join(_LOG_DIR, f"antigravity-v2-request-{self._session_id}.json")
with open(debug_path, "w") as dbg:
json.dump(wrapped, dbg, indent=2)
except Exception:
pass
upstream = None
chosen_ep = None
@@ -5681,6 +5691,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
_pref = _antigravity_preferred_endpoint
ordered = ([_pref] + [e for e in _antigravity_endpoints if e != _pref]) if _pref and _pref in _antigravity_endpoints else list(_antigravity_endpoints)
_all_404 = True
for ep in ordered:
action = "streamGenerateContent" if stream else "generateContent"
url_suffix = f"v1internal:{action}?alt=sse" if stream else f"v1internal:{action}"
@@ -5689,21 +5700,25 @@ class Handler(http.server.BaseHTTPRequestHandler):
try:
upstream = urllib.request.urlopen(req, timeout=_upstream_timeout(body, stream))
chosen_ep = ep
_all_404 = False
with _antigravity_endpoint_lock:
_antigravity_preferred_endpoint = ep
break
except urllib.error.HTTPError as e:
err_body = e.read().decode()
err_class = _classify_antigravity_error(e.code, err_body)
print(f"[{self._session_id}] [antigravity-v2] {ep.replace('https://','')} {e.code} class={err_class}", file=sys.stderr)
if e.code == 400:
print(f"[{self._session_id}] [antigravity-v2] {ep.replace('https://','')} {e.code} class={err_class} body={err_body[:300]}", file=sys.stderr)
if e.code != 404:
_all_404 = False
if e.code in (400, 404):
try:
debug_path = os.path.join(_LOG_DIR, "antigravity-v2-400.json")
debug_path = os.path.join(_LOG_DIR, f"antigravity-v2-{e.code}.json")
with open(debug_path, "w") as dbg:
json.dump({"endpoint": ep, "model": model, "wrapped": wrapped, "error": err_body}, dbg, indent=2)
json.dump({"endpoint": ep, "url": target, "model": model, "wrapped": wrapped, "error": err_body}, dbg, indent=2)
except Exception:
pass
return self.send_json(e.code, {"error": {"type": "upstream_error", "message": _sanitize_err_body(err_body)}})
if e.code == 400:
return self.send_json(e.code, {"error": {"type": "upstream_error", "message": _sanitize_err_body(err_body)}})
if err_class in ("auth_permanent", "service_disabled", "forbidden", "account_banned", "validation_required"):
return self.send_json(e.code, {"error": {"type": "upstream_error", "message": _sanitize_err_body(err_body)}})
if err_class in ("quota_exhausted", "rate_limited"):
@@ -5714,15 +5729,51 @@ class Handler(http.server.BaseHTTPRequestHandler):
cooldown = reset_s if reset_s and reset_s > 10 else 60
pool.mark_rate_limited(acct, cooldown)
return self.send_json(e.code, {"error": {"type": "upstream_error", "message": _sanitize_err_body(err_body)}})
if ep == ordered[-1]:
if ep == ordered[-1] and not _all_404:
return self.send_json(e.code, {"error": {"type": "upstream_error", "message": _sanitize_err_body(err_body)}})
continue
except Exception as e:
_all_404 = False
print(f"[{self._session_id}] [antigravity-v2] {ep.replace('https://','')} conn failed: {e}", file=sys.stderr)
if ep == ordered[-1]:
return self.send_json(502, {"error": {"type": "proxy_error", "message": str(e)}})
continue
if _all_404 and upstream is None and len(_versions) > 1:
_fallback_ver = _versions[1]
print(f"[{self._session_id}] [antigravity-v2] all 404, retrying with fallback version {_fallback_ver}", file=sys.stderr)
_ag_ua_fb = f"antigravity/{_fallback_ver} {_os_name}/{_os_arch}"
headers["User-Agent"] = _ag_ua_fb
wrapped["userAgent"] = _ag_ua_fb
body_b = json.dumps(wrapped).encode()
for ep in ordered:
action = "streamGenerateContent" if stream else "generateContent"
url_suffix = f"v1internal:{action}?alt=sse" if stream else f"v1internal:{action}"
target = f"{ep}/{url_suffix}"
req = urllib.request.Request(target, data=body_b, headers=headers)
try:
upstream = urllib.request.urlopen(req, timeout=_upstream_timeout(body, stream))
chosen_ep = ep
with _antigravity_endpoint_lock:
_antigravity_preferred_endpoint = ep
break
except urllib.error.HTTPError as e:
err_body = e.read().decode()
err_class = _classify_antigravity_error(e.code, err_body)
print(f"[{self._session_id}] [antigravity-v2-fallback] {ep.replace('https://','')} {e.code} class={err_class}", file=sys.stderr)
if e.code == 400:
return self.send_json(e.code, {"error": {"type": "upstream_error", "message": _sanitize_err_body(err_body)}})
if err_class in ("auth_permanent", "service_disabled", "forbidden", "account_banned", "validation_required"):
return self.send_json(e.code, {"error": {"type": "upstream_error", "message": _sanitize_err_body(err_body)}})
if ep == ordered[-1]:
return self.send_json(e.code, {"error": {"type": "upstream_error", "message": _sanitize_err_body(err_body)}})
continue
except Exception as e:
print(f"[{self._session_id}] [antigravity-v2-fallback] {ep.replace('https://','')} conn failed: {e}", file=sys.stderr)
if ep == ordered[-1]:
return self.send_json(502, {"error": {"type": "proxy_error", "message": str(e)}})
continue
if upstream is None:
return self.send_json(502, {"error": {"type": "proxy_error", "message": "All endpoints failed"}})