Skip to content

Official Codebase of 3DCodeVerse

Python

models: one retryable_status table — gemini retries a 409 like the SDK adapters, and is_model_outage reads the same table

gaoypeng1a01f17835de
diff --git a/harness/codeverse3d/models/anthropic.py b/harness/codeverse3d/models/anthropic.py
index 3fe486b1..c6e0c35e 100644
--- a/harness/codeverse3d/models/anthropic.py
+++ b/harness/codeverse3d/models/anthropic.py
@@ -174,7 +174,7 @@ def classify_exception(exc: BaseException) -> ModelError:
"""Map anthropic SDK exceptions onto ``ModelError`` (the shared ladder in parts.py)."""
import anthropic
- return classify_sdk_exception(exc, anthropic, "Anthropic", extra_retry=frozenset({529}))
+ return classify_sdk_exception(exc, anthropic, "Anthropic")
class AnthropicModel(SdkModel):
diff --git a/harness/codeverse3d/models/gemini.py b/harness/codeverse3d/models/gemini.py
index 37ca997a..028cdf8c 100644
--- a/harness/codeverse3d/models/gemini.py
+++ b/harness/codeverse3d/models/gemini.py
@@ -46,6 +46,7 @@ from codeverse3d.models.parts import (
image_bytes,
message_blocks,
retry_budget_s,
+ retryable_status,
)
from codeverse3d.models.pricing import estimate_cost, per_image_usd
from codeverse3d.models.retry import KeyPool, KeyPoolExhausted, OnAttempt, _Try, rotate_with_retries
@@ -263,9 +264,7 @@ def classify_exception(exc: BaseException) -> ModelError:
if isinstance(exc, genai_errors.APIError):
code = int(exc.code or 0)
msg = f"Gemini API error {code}: {exc.message}"
- if code == 429 or code == 408 or code >= 500:
- return ModelError(msg, retryable=True, status=code)
- return ModelError(msg, retryable=False, status=code)
+ return ModelError(msg, retryable=retryable_status(code), status=code)
if isinstance(exc, (httpx.TimeoutException, TimeoutError)):
return ModelError(f"Gemini request timed out: {exc}", retryable=True, status=408)
if isinstance(exc, (httpx.TransportError, ConnectionError)):
diff --git a/harness/codeverse3d/models/parts.py b/harness/codeverse3d/models/parts.py
index 457802e9..d2b7c1c1 100644
--- a/harness/codeverse3d/models/parts.py
+++ b/harness/codeverse3d/models/parts.py
@@ -111,14 +111,20 @@ class Stopwatch:
self.ms = int((time.perf_counter() - self._t0) * 1000)
-def classify_sdk_exception(exc: BaseException, sdk: Any, label: str,
- *, extra_retry: frozenset[int] = frozenset()) -> Any:
+def retryable_status(status: int | None) -> bool:
+ """THE HTTP statuses a retry may get through, for every provider (N76): request timeout
+ 408, conflict 409, rate limit 429 and every 5xx (anthropic's 529 overloaded among them) —
+ the list the openai and anthropic SDKs retry themselves."""
+ return status is not None and (status in (408, 409, 429) or status >= 500)
+
+
+def classify_sdk_exception(exc: BaseException, sdk: Any, label: str) -> Any:
"""The openai/anthropic SDK exception ladder → ``ModelError``.
anthropic-sdk-python is a fork of openai-python, so ``APIStatusError`` /
``APITimeoutError`` / ``APIConnectionError`` / ``APIError`` and ``.status_code`` /
``.message`` are the same names on both — this ladder was written out twice,
- differing only in the module, the label and anthropic's extra 529.
+ differing only in the module and the label.
The MESSAGE WORDING IS LOAD-BEARING: eval/bench/_infra.py string-matches "request timed
out" and "connection error" to tell a provider outage from a model failure, so the
@@ -128,8 +134,7 @@ def classify_sdk_exception(exc: BaseException, sdk: Any, label: str,
return exc
if isinstance(exc, sdk.APIStatusError):
status = int(getattr(exc, "status_code", 0) or 0)
- retry = status in ({408, 409, 429} | set(extra_retry)) or status >= 500
- return ModelError(f"{label} API error {status}: {exc.message}", retryable=retry, status=status)
+ return ModelError(f"{label} API error {status}: {exc.message}", retryable=retryable_status(status), status=status)
if isinstance(exc, sdk.APITimeoutError):
return ModelError(f"{label} request timed out: {exc}", retryable=True, status=408)
if isinstance(exc, sdk.APIConnectionError):
diff --git a/harness/codeverse3d/tracks/generation.py b/harness/codeverse3d/tracks/generation.py
index 87fdc365..4ca8882f 100644
--- a/harness/codeverse3d/tracks/generation.py
+++ b/harness/codeverse3d/tracks/generation.py
@@ -361,9 +361,10 @@ def is_model_outage(e: BaseException) -> bool:
capacity / rate limiting — never off its message. A 503 capacity storm reaches us only
after ``models.retry`` has already spent its whole storm budget waiting."""
from codeverse3d.models.base import ModelError
+ from codeverse3d.models.parts import retryable_status
- if isinstance(e, ModelError):
- return bool(e.retryable) or e.status in (429, 500, 502, 503, 504, 529)
+ if isinstance(e, ModelError): # a spent key pool is retryable=False, status 429: an outage all the same
+ return bool(e.retryable) or retryable_status(e.status)
return False
diff --git a/harness/tests/models/test_gemini.py b/harness/tests/models/test_gemini.py
index 5570a575..ff4edbee 100644
--- a/harness/tests/models/test_gemini.py
+++ b/harness/tests/models/test_gemini.py
@@ -209,6 +209,12 @@ def test_classify_exception_transport():
assert classify_exception(httpx.ReadTimeout("t")).retryable
assert classify_exception(httpx.ConnectError("c")).retryable
assert not classify_exception(ValueError("v")).retryable
+ # one status table with the SDK adapters (N76): a 409 is retried and is an outage, a 400 is neither
+ from codeverse3d.tracks.generation import is_model_outage
+
+ for code, retry in ((409, True), (408, True), (429, True), (529, True), (400, False), (404, False)):
+ err = classify_exception(_api_error(code, "x", "X"))
+ assert (err.retryable, is_model_outage(err)) == (retry, retry), code
def test_to_contents_merges_same_role_and_requires_content():