Skip to content

The agent that grows with you

fix: retry a 403 stamped code=upstream_unavailable instead of failing as auth

teknium11213109474bb
diff --git a/agent/error_classifier.py b/agent/error_classifier.py
index 5cc499267dd..4c988b5c455 100644
--- a/agent/error_classifier.py
+++ b/agent/error_classifier.py
@@ -900,7 +900,15 @@ def _off_route_host(c: _Ctx) -> str:
# ── Status code handlers ────────────────────────────────────────────────
+# Structured codes some gateways put on a 403 that mean "the upstream is down,
+# retry later" — not a credential refusal (#75388). Checked before the auth
+# default so the configured retry budget applies and no credential is benched.
+_403_TRANSIENT_CODES = frozenset({"upstream_unavailable"})
+
+
def _status_403(c: _Ctx) -> Verdict:
+ if c.code in _403_TRANSIENT_CODES:
+ return _V_OVERLOADED
# OpenRouter 403 "key limit exceeded" and similar plan/credit exhaustion are billing.
xai_spend = c.provider_slug == "xai-oauth" and c.code == _XAI_SPENDING_LIMIT_ERROR_CODE
billing = xai_spend or any(p in c.msg for p in ("key limit exceeded", "spending limit") + _BILLING_PATTERNS)
diff --git a/tests/agent/test_error_classifier.py b/tests/agent/test_error_classifier.py
index b575667ae2d..c5a5e21fe50 100644
--- a/tests/agent/test_error_classifier.py
+++ b/tests/agent/test_error_classifier.py
@@ -209,6 +209,16 @@ class TestClassifyApiError:
assert result.reason == FailoverReason.auth
assert result.should_fallback is True
+ def test_403_upstream_unavailable_code_is_transient_not_auth(self):
+ """A gateway 403 stamped ``code=upstream_unavailable`` is a transient upstream
+ outage: retried with backoff, credential untouched (#75388)."""
+ body = {"error": {"message": "Upstream service temporarily unavailable. Please retry later.",
+ "type": "upstream_unavailable", "code": "upstream_unavailable"}}
+ result = classify_api_error(MockAPIError("Forbidden", status_code=403, body=body), provider="custom")
+ assert result.reason == FailoverReason.overloaded
+ assert result.retryable is True
+ assert result.should_rotate_credential is False
+