π OpenHands: AI-Driven Development
feat: explicit OH_DEPLOYMENT_MODE flag; gate cloud-account CTA to enterprise cloud (#14794)
Alona2d34bb7ce650
diff --git a/enterprise/server/constants.py b/enterprise/server/constants.pyindex f3e17f88d3..fdcc44ca76 100644--- a/enterprise/server/constants.py+++ b/enterprise/server/constants.py@@ -19,8 +19,7 @@ IS_FEATURE_ENV = (IS_LOCAL_ENV = bool(HOST == 'localhost')-# _is_all_hands_managed_domain() can be removed/replaced when a self-hosted specific-# env var is created (e.g is_self_hosted` or `deployment_mode`)+# Explicit OH_DEPLOYMENT_MODE wins; _is_all_hands_managed_domain() is the host fallback.def _is_all_hands_managed_domain(host: str) -> bool:"""Check if the host is an All-Hands managed domain."""return (@@ -32,12 +31,14 @@ def _is_all_hands_managed_domain(host: str) -> bool:def _get_deployment_mode() -> str:- """Determine deployment mode based on WEB_HOST.+ """Determine deployment mode.- Returns:- 'cloud' for All-Hands managed infrastructure (app.all-hands.dev, etc.)- 'self_hosted' for enterprise self-hosted deployments (customer domains)+ Honors an explicit OH_DEPLOYMENT_MODE ('cloud' | 'self_hosted'); otherwise+ infers from WEB_HOST (managed domain -> 'cloud', else 'self_hosted')."""+ explicit = os.getenv('OH_DEPLOYMENT_MODE', '').strip().lower()+ if explicit in ('cloud', 'self_hosted'):+ return explicitif _is_all_hands_managed_domain(HOST):return 'cloud'return 'self_hosted'diff --git a/enterprise/tests/unit/server/test_constants.py b/enterprise/tests/unit/server/test_constants.pyindex f1deccbab9..4578314285 100644--- a/enterprise/tests/unit/server/test_constants.py+++ b/enterprise/tests/unit/server/test_constants.py@@ -8,6 +8,11 @@ import pytestclass TestDeploymentMode:"""Tests for _get_deployment_mode() and _is_all_hands_managed_domain() functions."""+ @pytest.fixture(autouse=True)+ def _no_explicit_mode(self, monkeypatch):+ """Host-heuristic tests must ignore any ambient OH_DEPLOYMENT_MODE."""+ monkeypatch.delenv('OH_DEPLOYMENT_MODE', raising=False)+@pytest.mark.parametrize('web_host,expected_mode',[@@ -41,6 +46,34 @@ class TestDeploymentMode:assert constants_module.DEPLOYMENT_MODE == expected_mode+ @pytest.mark.parametrize(+ 'flag,web_host,expected_mode',+ [+ # Explicit flag wins over the host heuristic+ ('self_hosted', 'app.all-hands.dev', 'self_hosted'),+ ('cloud', 'openhands.acme.com', 'cloud'),+ # Case/whitespace tolerant+ (' Self_Hosted ', 'app.all-hands.dev', 'self_hosted'),+ # Invalid/empty values fall back to the host heuristic+ ('bogus', 'app.all-hands.dev', 'cloud'),+ ('', 'openhands.acme.com', 'self_hosted'),+ ],+ )+ def test_explicit_deployment_mode_overrides_host(+ self, flag: str, web_host: str, expected_mode: str+ ):+ """OH_DEPLOYMENT_MODE takes precedence; invalid values fall back to WEB_HOST."""+ with patch.dict(+ 'os.environ', {'OH_DEPLOYMENT_MODE': flag, 'WEB_HOST': web_host}+ ):+ import importlib++ import server.constants as constants_module++ importlib.reload(constants_module)++ assert constants_module.DEPLOYMENT_MODE == expected_mode+@pytest.mark.parametrize('host,expected',[diff --git a/frontend/src/components/shared/modals/settings/model-selector.tsx b/frontend/src/components/shared/modals/settings/model-selector.tsxindex 7675f9622a..4f00ef60d7 100644--- a/frontend/src/components/shared/modals/settings/model-selector.tsx+++ b/frontend/src/components/shared/modals/settings/model-selector.tsx@@ -13,6 +13,7 @@ import { HelpLink } from "#/ui/help-link";import { PRODUCT_URL } from "#/utils/constants";import { useSearchProviders } from "#/hooks/query/use-search-providers";import { useProviderModels } from "#/hooks/query/use-provider-models";+import { useAppMode } from "#/hooks/use-app-mode";interface ModelSelectorProps {isDisabled?: boolean;@@ -46,6 +47,8 @@ export function ModelSelector({isLoading: isLoadingModels,error: modelsError,} = useProviderModels(selectedProvider);+ // The OpenHands-account CTA points at the cloud product; only show it there.+ const { isEnterpriseCloud } = useAppMode();const verifiedProviders = React.useMemo(() => providers.filter((p) => p.verified),@@ -159,7 +162,7 @@ export function ModelSelector({</Autocomplete></fieldset>- {selectedProvider === "openhands" && (+ {selectedProvider === "openhands" && isEnterpriseCloud && (<HelpLinktestId="openhands-account-help"text={t(I18nKey.SETTINGS$NEED_OPENHANDS_ACCOUNT)}diff --git a/openhands/app_server/web_client/web_client_deployment_mode.py b/openhands/app_server/web_client/web_client_deployment_mode.pyindex b903783094..2b82f76831 100644--- a/openhands/app_server/web_client/web_client_deployment_mode.py+++ b/openhands/app_server/web_client/web_client_deployment_mode.py@@ -4,15 +4,18 @@ from typing import LiteralDeploymentMode = Literal['cloud', 'self_hosted']-# This can be removed / replaced when a DeploymentMode (or similar) env var is created.+# Honors an explicit OH_DEPLOYMENT_MODE; the OH_WEB_HOST/WEB_HOST heuristic is the fallback.def get_deployment_mode() -> DeploymentMode | None:- """Get deployment mode based on OH_WEB_HOST environment variable.+ """Get deployment mode.- Returns:- 'cloud' for All-Hands managed infrastructure (app.all-hands.dev, etc.)- 'self_hosted' for enterprise self-hosted deployments (customer domains)- None if WEB_HOST is not set+ Honors an explicit OH_DEPLOYMENT_MODE ('cloud' | 'self_hosted'); otherwise+ infers from OH_WEB_HOST/WEB_HOST (managed domain -> 'cloud'), or None if unset."""+ explicit = os.getenv('OH_DEPLOYMENT_MODE', '').strip().lower()+ if explicit == 'cloud':+ return 'cloud'+ if explicit == 'self_hosted':+ return 'self_hosted'web_host = os.getenv('OH_WEB_HOST', os.getenv('WEB_HOST', '')).strip()if not web_host:return Nonediff --git a/tests/unit/app_server/test_web_client_deployment_mode.py b/tests/unit/app_server/test_web_client_deployment_mode.pyindex 7eb26eff39..f44bd59dbc 100644--- a/tests/unit/app_server/test_web_client_deployment_mode.py+++ b/tests/unit/app_server/test_web_client_deployment_mode.py@@ -12,6 +12,12 @@ from openhands.app_server.web_client.web_client_deployment_mode import (class TestGetDeploymentMode:"""Tests for get_deployment_mode() function."""+ @pytest.fixture(autouse=True)+ def _hermetic_env(self, monkeypatch):+ """Each test fully controls deployment-mode env; ignore ambient values."""+ for var in ('OH_DEPLOYMENT_MODE', 'OH_WEB_HOST', 'WEB_HOST'):+ monkeypatch.delenv(var, raising=False)+@pytest.mark.parametrize('web_host,expected',[@@ -79,3 +85,26 @@ class TestGetDeploymentMode:del os.environ['OH_WEB_HOST']result = get_deployment_mode()assert result == 'self_hosted'++ @pytest.mark.parametrize(+ 'flag,web_host,expected',+ [+ # Explicit flag wins over the host heuristic+ ('self_hosted', 'app.all-hands.dev', 'self_hosted'),+ ('cloud', 'customer.example.com', 'cloud'),+ # Case/whitespace tolerant+ (' Cloud ', 'customer.example.com', 'cloud'),+ # Invalid value falls back to the host chain+ ('bogus', 'app.all-hands.dev', 'cloud'),+ ],+ )+ def test_explicit_deployment_mode_overrides_host(+ self, flag: str, web_host: str, expected: str+ ):+ """OH_DEPLOYMENT_MODE takes precedence; invalid values fall back to WEB_HOST."""+ with patch.dict(+ 'os.environ',+ {'OH_DEPLOYMENT_MODE': flag, 'WEB_HOST': web_host},+ clear=False,+ ):+ assert get_deployment_mode() == expected