Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(providers): health check probes the model the runtime actually runs
Ruben Lütkea8f5791ffa8a
diff --git a/jarvis/brain/provider_test.py b/jarvis/brain/provider_test.pyindex da2f38ed4f..76fbd66b2a 100644--- a/jarvis/brain/provider_test.py+++ b/jarvis/brain/provider_test.py@@ -190,14 +190,32 @@ def _is_credential_present(spec: Any) -> bool:def _resolve_brain_model(cfg: Any, provider: str) -> str:- """Best-effort lookup of the configured model for a brain provider."""+ """The model the runtime would actually run for a brain provider.++ Mirrors the manager's resolution order (explicit config override, then the+ router-tier frontier default). Falling through to "" here would hand the+ probe to the plugin's hardcoded ``DEFAULT_MODEL`` — which can drift from the+ curated tier default and made a fresh install's health check 404 on a model+ id the real dispatch path never uses (AP-23 class).+ """+ model = ""try:providers = getattr(getattr(cfg, "brain", None), "providers", None)if isinstance(providers, dict):pc = providers.get(provider)else:pc = getattr(providers, provider, None)- return getattr(pc, "model", "") or ""+ model = getattr(pc, "model", "") or ""+ except Exception: # noqa: BLE001+ model = ""+ if model:+ return model+ try:+ # Lazy: manager imports this module (BILLING_LIMIT_MARKERS), so a+ # module-level import here would be a cycle.+ from jarvis.brain.manager import get_tier_default_model++ return get_tier_default_model("router", provider) or ""except Exception: # noqa: BLE001return ""@@ -304,6 +322,7 @@ async def run_provider_test(codex_status: Callable[[], Any] | None = None,antigravity_status: Callable[[], Any] | None = None,timeout_s: float = 60.0,+ model: str | None = None,) -> ProviderTestResult:"""Run a REAL minimal call against ``spec``'s provider and classify it.@@ -311,6 +330,10 @@ async def run_provider_test(``codex_status``) default to the production wiring and are injectable so thedispatch logic is unit-testable without hitting a live provider.+ ``model`` (brain tier only) probes that exact model instead of the+ provider's configured/default one — used by tiers with their own model pin+ (e.g. the Tool Model), so the health verdict matches what that tier runs.+``timeout_s`` bounds the wait for the FIRST byte/delta, not a dead endpoint(the SDK ``connect`` timeout, ~5s, catches those). It must clear the slowestLEGITIMATE provider's time-to-first-byte, else a slow-but-healthy provider is@@ -400,8 +423,8 @@ async def run_provider_test()if spec.tier == "brain":- model = _resolve_brain_model(cfg, provider)- hr = await brain_probe(provider, model)+ probe_model = model or _resolve_brain_model(cfg, provider)+ hr = await brain_probe(provider, probe_model)if getattr(hr, "ok", False):return ProviderTestResult(provider, OK, "", getattr(hr, "duration_ms", 0.0))err = getattr(hr, "error", None)diff --git a/jarvis/plugins/brain/gemini.py b/jarvis/plugins/brain/gemini.pyindex 695b7530b9..94831066c4 100644--- a/jarvis/plugins/brain/gemini.py+++ b/jarvis/plugins/brain/gemini.py@@ -27,7 +27,12 @@ from ._openai_base import CLIENT_TIMEOUT, stream_completelog = logging.getLogger(__name__)-DEFAULT_MODEL = "gemini-3-flash"+# Emergency anchor when no model is configured anywhere. MUST be an id the+# public Generative Language API actually serves: the stable alias+# "gemini-3-flash" is NOT listed (404 NOT_FOUND on generateContent) — only the+# -preview id exists. Keep in sync with TIER_DEFAULTS_BY_PROVIDER["router"]+# ["gemini"] (jarvis/brain/manager.py); a parity test guards this.+DEFAULT_MODEL = "gemini-3-flash-preview"OPENAI_COMPAT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta/openai/"_TRANSPORT_NATIVE = "native"diff --git a/jarvis/ui/web/provider_routes.py b/jarvis/ui/web/provider_routes.pyindex fc0797c959..f0983c4b0e 100644--- a/jarvis/ui/web/provider_routes.py+++ b/jarvis/ui/web/provider_routes.py@@ -722,12 +722,18 @@ class SectionHealthResponse(BaseModel):cached: bool = False-async def _tier_section_health(cfg: Any, spec: ProviderSpec | None) -> SectionHealth:+async def _tier_section_health(+ cfg: Any, spec: ProviderSpec | None, *, model: str | None = None+) -> SectionHealth:"""Health of one provider tier, derived from its ACTIVE provider only.A tier is only as healthy as the single provider currently powering it —deliberately NOT "does any provider here lack a key" (that would paint everytab red, since unused providers are normally left empty).++ ``model`` probes that exact model for a brain-tier spec — used by sections+ whose tier carries its own model pin (Tool Model), so the dot reflects what+ that tier actually runs, not the general brain model."""if spec is None:return SectionHealth(@@ -760,7 +766,7 @@ async def _tier_section_health(cfg: Any, spec: ProviderSpec | None) -> SectionHesubject_id=spec.id,)try:- result = await _provider_test.run_provider_test(spec, cfg)+ result = await _provider_test.run_provider_test(spec, cfg, model=model)except Exception as exc: # noqa: BLE001log.warning("section-health test for %s failed: %s", spec.id, exc)return SectionHealth(@@ -1165,8 +1171,13 @@ async def _compute_section_health(checks = {"brain": _tier_section_health(cfg, get_spec(subjects["brain"] or "")),+ # The Tool Model tier has its own model pin (tool_model → cu_model);+ # probe THAT model, not the general brain model. An unset pin falls+ # through to run_provider_test's own resolution (model → tier default)."computer-use": _tier_section_health(- cfg, get_spec(subjects["computer-use"] or "")+ cfg,+ get_spec(subjects["computer-use"] or ""),+ model=_provider_cu_model(cfg, subjects["computer-use"] or "") or None,),"tts": _tier_section_health(cfg, get_spec(subjects["tts"] or "")),"stt": _tier_section_health(cfg, get_spec(subjects["stt"] or "")),diff --git a/tests/integration/test_provider_routes.py b/tests/integration/test_provider_routes.pyindex 021e8c78c4..5532c9441e 100644--- a/tests/integration/test_provider_routes.py+++ b/tests/integration/test_provider_routes.py@@ -148,7 +148,7 @@ def no_real_provider_test(monkeypatch: pytest.MonkeyPatch) -> None:hermetic and fast."""from jarvis.brain import provider_test as _pt- async def _fake_run(spec: Any, cfg: Any) -> _FakeTestResult: # noqa: ANN401+ async def _fake_run(spec: Any, cfg: Any, **kwargs: Any) -> _FakeTestResult: # noqa: ANN401return _FakeTestResult("ok", "")monkeypatch.setattr(_pt, "run_provider_test", _fake_run)@@ -239,7 +239,7 @@ async def test_section_health_switch_cancels_old_provider_without_misattributionnvidia_started = asyncio.Event()nvidia_cancelled = asyncio.Event()- async def _probe(spec: Any, cfg: Any) -> _FakeTestResult: # noqa: ANN401+ async def _probe(spec: Any, cfg: Any, **kwargs: Any) -> _FakeTestResult: # noqa: ANN401if spec.id == "nvidia":nvidia_started.set()try:@@ -292,7 +292,7 @@ async def test_section_health_model_switch_cancels_old_probe_for_same_provider(old_started = asyncio.Event()old_cancelled = asyncio.Event()- async def _probe(spec: Any, cfg: Any) -> _FakeTestResult: # noqa: ANN401+ async def _probe(spec: Any, cfg: Any, **kwargs: Any) -> _FakeTestResult: # noqa: ANN401selected_model = cfg.brain.providers["openrouter"].modelif spec.id == "openrouter" and selected_model == "slow-model":old_started.set()@@ -326,6 +326,42 @@ async def test_section_health_model_switch_cancels_old_probe_for_same_provider(assert old_response.sections["brain"].status == "ok"+def test_section_health_computer_use_probes_the_tool_model_pin(+ server_with_brain: WebServer,+ secret_store: _InMemorySecretStore,+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """The Tool Model tab must test the model that tier actually runs.++ Live macOS fresh-install bug 2026-07-17: the computer-use section probed+ the provider's general brain model ("" on a fresh install), which collapsed+ into the plugin's hardcoded default — a retired id that 404'd, painting the+ Tool Model tab red although the runtime resolution was healthy (AP-23).+ """+ from jarvis.brain import provider_test as provider_test_module+ from jarvis.core.config import BrainProviderConfig, BrainTierConfig++ secret_store.data["gemini_api_key"] = "AIza-test"+ server_with_brain.cfg.brain.tool_model = BrainTierConfig(provider="gemini")+ server_with_brain.cfg.brain.providers["gemini"] = BrainProviderConfig(+ model="general-brain-model", tool_model="pinned-tool-model"+ )++ seen: dict[str, Any] = {}++ async def _probe(spec: Any, cfg: Any, **kwargs: Any) -> _FakeTestResult: # noqa: ANN401+ seen[spec.id] = kwargs.get("model")+ return _FakeTestResult("ok", "")++ monkeypatch.setattr(provider_test_module, "run_provider_test", _probe)++ with TestClient(server_with_brain.app) as client:+ body = client.get("/api/providers/section-health?refresh=true").json()++ assert body["sections"]["computer-use"]["subject_id"] == "gemini"+ assert seen["gemini"] == "pinned-tool-model"++def test_list_providers_exposes_credential_help_and_billing(server_with_brain: WebServer, secret_store: _InMemorySecretStore) -> None:diff --git a/tests/unit/brain/test_provider_test_service.py b/tests/unit/brain/test_provider_test_service.pyindex a2fc4795f4..d52eb33caf 100644--- a/tests/unit/brain/test_provider_test_service.py+++ b/tests/unit/brain/test_provider_test_service.py@@ -58,6 +58,55 @@ def test_brain_probe_ok_is_ok() -> None:assert res.latency_ms == pytest.approx(1234.0)+def test_brain_probe_uses_tier_default_when_no_model_configured() -> None:+ """Fresh install: no model configured anywhere → the probe must receive the+ curated router-tier default, never "" (which would collapse into the+ plugin's hardcoded DEFAULT_MODEL — the macOS Tool-Model 404, AP-23)."""+ seen: list[str] = []++ async def probe(_p, m):+ seen.append(m)+ return HealthResult(provider="gemini", model=m, ok=True)++ fresh_cfg = SimpleNamespace(brain=SimpleNamespace(providers={}))+ res = _run(run_provider_test(get_spec("gemini"), fresh_cfg, present=True, brain_probe=probe))+ assert res.status == "ok"+ from jarvis.brain.manager import get_tier_default_model++ assert seen == [get_tier_default_model("router", "gemini")]+++def test_brain_probe_configured_model_wins_over_tier_default() -> None:+ seen: list[str] = []++ async def probe(_p, m):+ seen.append(m)+ return HealthResult(provider="gemini", model=m, ok=True)++ res = _run(run_provider_test(get_spec("gemini"), _cfg(), present=True, brain_probe=probe))+ assert res.status == "ok"+ assert seen == ["gemini-3.5-flash"]+++def test_brain_probe_explicit_model_override_wins() -> None:+ """A tier with its own pin (Tool Model) probes THAT model, not the+ provider's general brain model."""+ seen: list[str] = []++ async def probe(_p, m):+ seen.append(m)+ return HealthResult(provider="gemini", model=m, ok=True)++ res = _run(+ run_provider_test(+ get_spec("gemini"), _cfg(), present=True, brain_probe=probe,+ model="gemini-3.1-pro-preview",+ )+ )+ assert res.status == "ok"+ assert seen == ["gemini-3.1-pro-preview"]++def test_brain_probe_bad_key_is_bad_key() -> None:async def probe(_p, _m):return HealthResult(diff --git a/tests/unit/brain/test_section_health.py b/tests/unit/brain/test_section_health.pyindex 803268311d..03ab54f3d4 100644--- a/tests/unit/brain/test_section_health.py+++ b/tests/unit/brain/test_section_health.py@@ -85,7 +85,7 @@ async def test_every_catalog_provider_health_is_bound_to_its_exact_id(monkeypatch.setattr(provider_routes, "_is_credential_present", lambda *args: True)- async def _probe(selected, cfg):+ async def _probe(selected, cfg, **kwargs):return SimpleNamespace(status="ok", detail="")monkeypatch.setattr(provider_test, "run_provider_test", _probe)diff --git a/tests/unit/test_tier_defaults.py b/tests/unit/test_tier_defaults.pyindex a38717ad2e..ff1b3c96b1 100644--- a/tests/unit/test_tier_defaults.py+++ b/tests/unit/test_tier_defaults.py@@ -109,3 +109,25 @@ class TestPublicGetter:def test_get_default_returns_none_for_unknown_tier(self):assert get_tier_default_model("unknown_tier", "gemini") is None+++class TestPluginDefaultParity:+ """The plugin's emergency ``DEFAULT_MODEL`` must never drift from the+ curated router-tier default.++ Live macOS fresh-install bug 2026-07-17: with no model configured anywhere,+ the health probe collapsed into ``GeminiBrain``'s hardcoded default, which+ was still the retired stable alias ``gemini-3-flash`` — Google's API only+ serves the ``-preview`` id, so every fresh install's Tool Model tab went+ red with a 404 while the maintainer's pinned config masked it (AP-23).+ """++ def test_gemini_plugin_default_matches_router_tier_default(self):+ from jarvis.plugins.brain.gemini import DEFAULT_MODEL++ assert DEFAULT_MODEL == get_tier_default_model("router", "gemini")++ def test_openai_plugin_default_matches_router_tier_default(self):+ from jarvis.plugins.brain.openai import DEFAULT_MODEL++ assert DEFAULT_MODEL == get_tier_default_model("router", "openai")diff --git a/tests/unit/web/test_realtime_provider_category.py b/tests/unit/web/test_realtime_provider_category.pyindex 3a064dba0d..66b76a1d86 100644--- a/tests/unit/web/test_realtime_provider_category.py+++ b/tests/unit/web/test_realtime_provider_category.py@@ -224,7 +224,7 @@ def test_realtime_switch_unknown_provider_is_404(monkeypatch):def test_section_health_includes_realtime_key(monkeypatch):from jarvis.brain import provider_test as _pt- async def _fake_run(spec, cfg):+ async def _fake_run(spec, cfg, **kwargs):from types import SimpleNamespacereturn SimpleNamespace(status="ok", detail="")@@ -242,7 +242,7 @@ def test_section_health_includes_realtime_key(monkeypatch):def test_section_health_realtime_needs_setup_without_key(monkeypatch):from jarvis.brain import provider_test as _pt- async def _fake_run(spec, cfg):+ async def _fake_run(spec, cfg, **kwargs):from types import SimpleNamespacereturn SimpleNamespace(status="ok", detail="")