Skip to content

Personal AI, On Personal Devices

Python

fix(engine): surface provider error on Atlas Cloud empty choices and isolate API key in tests (#1051)

Arush Wadhawandd64c04969f1
diff --git a/src/openjarvis/engine/cloud.py b/src/openjarvis/engine/cloud.py
index 17bff9d9..c89f72cf 100644
--- a/src/openjarvis/engine/cloud.py
+++ b/src/openjarvis/engine/cloud.py
@@ -1119,7 +1119,9 @@ class CloudEngine(InferenceEngine):
self._atlascloud_client, create_kwargs
)
elapsed = time.monotonic() - t0
- choice = resp.choices[0]
+ choice = _first_choice_or_raise(
+ resp, provider="Atlas Cloud", model=actual_model
+ )
usage = resp.usage
prompt_tokens = usage.prompt_tokens if usage else 0
completion_tokens = usage.completion_tokens if usage else 0
diff --git a/tests/engine/conftest.py b/tests/engine/conftest.py
index 07540366..41444138 100644
--- a/tests/engine/conftest.py
+++ b/tests/engine/conftest.py
@@ -6,6 +6,7 @@ import pytest
CLOUD_KEY_ENV_VARS = (
"ANTHROPIC_API_KEY",
+ "ATLASCLOUD_API_KEY",
"DEEPSEEK_API_KEY",
"GEMINI_API_KEY",
"GOOGLE_API_KEY",
diff --git a/tests/engine/test_cloud.py b/tests/engine/test_cloud.py
index 2d3a624f..6099dce3 100644
--- a/tests/engine/test_cloud.py
+++ b/tests/engine/test_cloud.py
@@ -135,6 +135,7 @@ class TestCloudEngineEmptyChoices:
[
("gpt-4o", "_openai_client", "OpenAI"),
("openrouter/test-model", "_openrouter_client", "OpenRouter"),
+ ("atlascloud/openai/gpt-4.1-mini", "_atlascloud_client", "Atlas Cloud"),
("MiniMax-M3", "_minimax_client", "MiniMax"),
("deepseek-v4-flash", "_deepseek_client", "DeepSeek"),
],
@@ -146,16 +147,7 @@ class TestCloudEngineEmptyChoices:
client_attr: str,
provider: str,
) -> None:
- for env_var in (
- "OPENAI_API_KEY",
- "ANTHROPIC_API_KEY",
- "GOOGLE_API_KEY",
- "OPENROUTER_API_KEY",
- "MINIMAX_API_KEY",
- "DEEPSEEK_API_KEY",
- "OPENAI_CODEX_API_KEY",
- "OPENAI_CODEX_BASE_URL",
- ):
+ for env_var in (*CLOUD_KEY_ENV_VARS, "OPENAI_CODEX_BASE_URL"):
monkeypatch.delenv(env_var, raising=False)
fake_resp = SimpleNamespace(
diff --git a/tests/engine/test_cloud_atlascloud.py b/tests/engine/test_cloud_atlascloud.py
index a9fbd40d..665fd187 100644
--- a/tests/engine/test_cloud_atlascloud.py
+++ b/tests/engine/test_cloud_atlascloud.py
@@ -32,17 +32,9 @@ from openjarvis.engine.cloud import (
)
from openjarvis.intelligence.model_catalog import BUILTIN_MODELS
from openjarvis.server import cloud_router
+from tests.engine.conftest import CLOUD_KEY_ENV_VARS
-_ALL_CLOUD_KEYS = (
- "OPENAI_API_KEY",
- "ANTHROPIC_API_KEY",
- "GEMINI_API_KEY",
- "GOOGLE_API_KEY",
- "OPENROUTER_API_KEY",
- "MINIMAX_API_KEY",
- "DEEPSEEK_API_KEY",
- "ATLASCLOUD_API_KEY",
-)
+_ALL_CLOUD_KEYS = CLOUD_KEY_ENV_VARS
_DEFAULT_MODEL = "atlascloud/openai/gpt-4.1-mini"
@@ -209,6 +201,29 @@ class TestAtlasCloudGenerate:
assert result["usage"]["completion_tokens"] == 5
assert result["finish_reason"] == "stop"
+ def test_generate_empty_choices_surfaces_provider_error(
+ self, monkeypatch: pytest.MonkeyPatch
+ ) -> None:
+ engine = _make_cloud_engine(monkeypatch)
+ client = mock.MagicMock()
+ fake_resp = SimpleNamespace(
+ choices=None,
+ error={"message": "Upstream error: Service temporarily overloaded"},
+ usage=None,
+ model="openai/gpt-4.1-mini",
+ )
+ client.chat.completions.create.return_value = fake_resp
+ engine._atlascloud_client = client
+
+ with pytest.raises(EngineConnectionError) as exc_info:
+ engine.generate(
+ [Message(role=Role.USER, content="Hi")],
+ model=_DEFAULT_MODEL,
+ )
+
+ assert "Atlas Cloud" in str(exc_info.value)
+ assert "Service temporarily overloaded" in str(exc_info.value)
+
def test_generate_retries_without_unsupported_temperature(
self, monkeypatch: pytest.MonkeyPatch
) -> None: