Skip to content

The open-source AI voice studio. Clone, dictate, create.

feat: gate Voicebox Cloud behind VOICEBOX_CLOUD_ENABLED (default off)

jamiepine9707a200c1ee
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9818c816..a4cacaf4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,15 @@
## [Unreleased]
+### Changed
+
+- **Voicebox Cloud is hidden until it ships.** The "Log in with browser" section in
+ Settings → General only renders when the backend reports `cloud_enabled`, and the
+ `/cloud/*` routes answer 404 unless the backend runs with
+ `VOICEBOX_CLOUD_ENABLED=1`, so a default build never calls out to voicebox.sh.
+ The flag is read at runtime, so it can be turned on for a shipped build without a
+ rebuild.
+
### Developer Experience
- **`just setup` now pins the Python venv to 3.12.** Setup preferred `python3.12` when
diff --git a/app/src/components/ServerTab/GeneralPage.tsx b/app/src/components/ServerTab/GeneralPage.tsx
index 0d8d7af7..312a534c 100644
--- a/app/src/components/ServerTab/GeneralPage.tsx
+++ b/app/src/components/ServerTab/GeneralPage.tsx
@@ -208,7 +208,7 @@ export function GeneralPage() {
/>
</SettingSection>
- <CloudSection />
+ {health?.cloud_enabled && <CloudSection />}
<ApiReferenceCard serverUrl={serverUrl} />
diff --git a/app/src/lib/api/types.ts b/app/src/lib/api/types.ts
index d360ed1c..457cf711 100644
--- a/app/src/lib/api/types.ts
+++ b/app/src/lib/api/types.ts
@@ -271,6 +271,7 @@ export interface HealthResponse {
backend_type?: string;
backend_variant?: string; // "cpu", "cuda", or "rocm"
supports_rocm?: boolean; // AMD GPU on Windows — the ROCm backend is applicable
+ cloud_enabled?: boolean; // VOICEBOX_CLOUD_ENABLED on the backend — show the Cloud section
}
export interface CudaDownloadProgress {
diff --git a/backend/config.py b/backend/config.py
index cb6bc168..5b9ac046 100644
--- a/backend/config.py
+++ b/backend/config.py
@@ -157,3 +157,13 @@ def get_cloud_web_url() -> str:
def get_cloud_api_url() -> str:
"""Base URL of the Voicebox Cloud API (bearer-authenticated sync/account)."""
return os.environ.get("VOICEBOX_CLOUD_API_URL", "https://api.voicebox.sh").rstrip("/")
+
+
+# Cloud is off by default until the service is deployed. VOICEBOX_CLOUD_ENABLED=1
+# (or true/yes/on) turns on the /cloud routes and the Settings → General section;
+# the desktop sidecar inherits the launcher's environment, so the same variable
+# works for a shipped build without a rebuild. Read per request, not at import,
+# so a test or a long-lived process sees the current value.
+def is_cloud_enabled() -> bool:
+ """Whether Voicebox Cloud login/sync is enabled for this backend."""
+ return os.environ.get("VOICEBOX_CLOUD_ENABLED", "").strip().lower() in ("1", "true", "yes", "on")
diff --git a/backend/models.py b/backend/models.py
index 0f6d2dac..94a9fd54 100644
--- a/backend/models.py
+++ b/backend/models.py
@@ -445,6 +445,7 @@ class HealthResponse(BaseModel):
backend_variant: Optional[str] = None # Binary variant (cpu, cuda, or rocm)
supports_rocm: bool = False # AMD GPU on Windows — the ROCm backend is applicable
gpu_compatibility_warning: Optional[str] = None # Warning if GPU arch unsupported
+ cloud_enabled: bool = False # VOICEBOX_CLOUD_ENABLED — the app shows the Cloud section only when true
class DirectoryCheck(BaseModel):
diff --git a/backend/routes/cloud.py b/backend/routes/cloud.py
index 3abf2ef5..4f6fa3f3 100644
--- a/backend/routes/cloud.py
+++ b/backend/routes/cloud.py
@@ -6,19 +6,31 @@ The browser-based pairing flow:
the backend exchanges it for an API key.
3. GET /cloud/status — the UI polls this to learn when it connected.
4. POST /cloud/disconnect — forget the local credential.
+
+Every route is mounted but answers 404 unless VOICEBOX_CLOUD_ENABLED is set
+(see ``config.is_cloud_enabled``), so a build with cloud off never reaches out
+to voicebox.sh.
"""
import socket
-from fastapi import APIRouter, Depends, Request
+from fastapi import APIRouter, Depends, HTTPException, Request
from fastapi.responses import HTMLResponse
from sqlalchemy.orm import Session
-from .. import models
+from .. import config, models
from ..database import get_db
from ..services import cloud as cloud_service
-router = APIRouter(prefix="/cloud", tags=["cloud"])
+CLOUD_DISABLED_DETAIL = "Voicebox Cloud is disabled. Set VOICEBOX_CLOUD_ENABLED=1 to enable it."
+
+
+def require_cloud_enabled() -> None:
+ if not config.is_cloud_enabled():
+ raise HTTPException(status_code=404, detail=CLOUD_DISABLED_DETAIL)
+
+
+router = APIRouter(prefix="/cloud", tags=["cloud"], dependencies=[Depends(require_cloud_enabled)])
def _callback_url(request: Request) -> str:
diff --git a/backend/routes/health.py b/backend/routes/health.py
index 1568455d..df22bbf5 100644
--- a/backend/routes/health.py
+++ b/backend/routes/health.py
@@ -188,6 +188,7 @@ async def health():
backend_variant=os.environ.get("VOICEBOX_BACKEND_VARIANT", default_variant),
supports_rocm=is_amd_gpu_windows(),
gpu_compatibility_warning=gpu_compat_warning,
+ cloud_enabled=config.is_cloud_enabled(),
)
diff --git a/backend/tests/test_cloud_gate.py b/backend/tests/test_cloud_gate.py
new file mode 100644
index 00000000..124de0ab
--- /dev/null
+++ b/backend/tests/test_cloud_gate.py
@@ -0,0 +1,132 @@
+"""
+Regression tests for the VOICEBOX_CLOUD_ENABLED gate.
+
+Voicebox Cloud ships off by default: the /cloud routes stay mounted but answer
+404 and never call out to voicebox.sh, and /health reports ``cloud_enabled`` so
+the app can hide the Settings → General section. Setting the variable turns
+both back on without a rebuild.
+
+Runs without torch: the cloud router is mounted on a bare FastAPI app with the
+DB dependency overridden, and the cloud service is stubbed so no network or
+browser is touched.
+
+Usage:
+ python -m pytest backend/tests/test_cloud_gate.py -v
+"""
+
+import pytest
+from fastapi import FastAPI
+from starlette.testclient import TestClient
+
+from backend import config
+from backend.database import get_db
+from backend.routes import cloud as cloud_routes
+
+CLOUD_ENV_VAR = "VOICEBOX_CLOUD_ENABLED"
+
+
+def client(monkeypatch):
+ app = FastAPI()
+ app.include_router(cloud_routes.router)
+ app.dependency_overrides[get_db] = lambda: object()
+
+ calls: list[str] = []
+
+ def _start_login(callback_url, device_name):
+ calls.append("start_login")
+ return "https://example.invalid/connect"
+
+ async def _handle_callback(db, code, state):
+ calls.append("handle_callback")
+ return True, "Connected"
+
+ def _get_status(db):
+ calls.append("get_status")
+ return {
+ "connected": False,
+ "device_name": None,
+ "account_user_id": None,
+ "key_prefix": None,
+ "connected_at": None,
+ "dashboard_url": "https://example.invalid/account",
+ }
+
+ monkeypatch.setattr(cloud_routes.cloud_service, "start_login", _start_login)
+ monkeypatch.setattr(cloud_routes.cloud_service, "handle_callback", _handle_callback)
+ monkeypatch.setattr(cloud_routes.cloud_service, "get_status", _get_status)
+ monkeypatch.setattr(cloud_routes.cloud_service, "disconnect", lambda db: calls.append("disconnect"))
+
+ test_client = TestClient(app)
+ test_client.service_calls = calls
+ return test_client
+
+
[email protected]("value", [None, "", "0", "false", "no", "off", "maybe"])
+def test_cloud_disabled_by_default_and_for_falsy_values(monkeypatch, value):
+ if value is None:
+ monkeypatch.delenv(CLOUD_ENV_VAR, raising=False)
+ else:
+ monkeypatch.setenv(CLOUD_ENV_VAR, value)
+ assert config.is_cloud_enabled() is False
+
+
[email protected]("value", ["1", "true", "TRUE", "yes", "on", " On "])
+def test_cloud_enabled_for_truthy_values(monkeypatch, value):
+ monkeypatch.setenv(CLOUD_ENV_VAR, value)
+ assert config.is_cloud_enabled() is True
+
+
+ ("method", "path"),
+ [
+ ("post", "/cloud/login/start"),
+ ("get", "/cloud/callback?code=abc&state=xyz"),
+ ("get", "/cloud/status"),
+ ("post", "/cloud/disconnect"),
+ ],
+)
+def test_cloud_routes_return_404_when_disabled(client, monkeypatch, method, path):
+ monkeypatch.delenv(CLOUD_ENV_VAR, raising=False)
+
+ response = getattr(client, method)(path)
+
+ assert response.status_code == 404
+ assert response.json()["detail"] == cloud_routes.CLOUD_DISABLED_DETAIL
+ assert client.service_calls == [], "a disabled backend must never touch the cloud service"
+
+
+def test_cloud_routes_work_when_enabled(client, monkeypatch):
+ monkeypatch.setenv(CLOUD_ENV_VAR, "1")
+
+ assert client.get("/cloud/status").status_code == 200
+ assert client.post("/cloud/login/start").json()["authorize_url"] == "https://example.invalid/connect"
+ assert client.get("/cloud/callback?code=abc&state=xyz").status_code == 200
+ assert client.post("/cloud/disconnect").status_code == 200
+ assert client.service_calls == [
+ "get_status",
+ "start_login",
+ "handle_callback",
+ "disconnect",
+ "get_status",
+ ]
+
+
+def test_flag_is_read_per_request_not_at_import(client, monkeypatch):
+ monkeypatch.delenv(CLOUD_ENV_VAR, raising=False)
+ assert client.get("/cloud/status").status_code == 404
+
+ monkeypatch.setenv(CLOUD_ENV_VAR, "1")
+ assert client.get("/cloud/status").status_code == 200
+
+
+def test_health_response_reports_cloud_flag():
+ from backend import models
+
+ assert models.HealthResponse(status="healthy", model_loaded=False, gpu_available=False).cloud_enabled is False
+ assert (
+ models.HealthResponse(
+ status="healthy", model_loaded=False, gpu_available=False, cloud_enabled=True
+ ).cloud_enabled
+ is True
+ )