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(brain): gate Gemini catalog + frontier picks on declared generateContent capability
Ruben Lütkea150e05b2b29
diff --git a/jarvis/brain/frontier_resolver.py b/jarvis/brain/frontier_resolver.pyindex 0f01b4a2c7..ca8638d062 100644--- a/jarvis/brain/frontier_resolver.py+++ b/jarvis/brain/frontier_resolver.py@@ -229,10 +229,20 @@ class FrontierResolver:f"?key={api_key}",)resp.raise_for_status()- # Gemini-Format: models[].name = "models/gemini-3-flash"+ # Gemini-Format: models[].name = "models/gemini-3-flash".+ # Capability gate: only ids the API declares as generateContent-+ # capable may win the auto-pick. Google has listed ids that 404+ # on every chat call (the 2026-04 "gemini-3-flash" incident:+ # listed as a clean stable name, so the GA-over-preview ranking+ # picked it — and every fresh install ran a dead model).+ from jarvis.brain.model_catalog import (+ gemini_entry_serves_generate_content,+ )+return [m["name"].removeprefix("models/")for m in resp.json().get("models", [])+ if gemini_entry_serves_generate_content(m)]raise ValueError(f"Unsupported provider: {provider}")diff --git a/jarvis/brain/model_catalog.py b/jarvis/brain/model_catalog.pyindex 36b3dc139d..2348ba5cad 100644--- a/jarvis/brain/model_catalog.py+++ b/jarvis/brain/model_catalog.py@@ -464,6 +464,13 @@ def parse_models_response(provider: str, payload: dict) -> list[ModelInfo]:raw = (m.get("name") or "").removeprefix("models/").strip()if not raw:continue+ # Capability gate: ListModels also returns ids that CANNOT serve+ # generateContent (embeddings, Imagen/Veo/Lyria, Live/bidi audio —+ # and historically "gemini-3-flash", listed yet 404 on every call).+ # Offering those in the brain picker guarantees a broken pick, so+ # drop them on the DECLARED capability, never the name (AP-21).+ if not gemini_entry_serves_generate_content(m):+ continuelabel = (m.get("displayName") or "").strip() or rawout.append(ModelInfo(id=raw, label=label, output_modalities=_output_modalities(m)))return out@@ -484,6 +491,25 @@ def parse_models_response(provider: str, payload: dict) -> list[ModelInfo]:return out+def gemini_entry_serves_generate_content(entry: dict) -> bool:+ """True when a Gemini ListModels entry can serve ``generateContent``.++ Google's ListModels declares each model's callable methods+ (``supportedGenerationMethods``, ``supportedActions`` on newer API+ revisions). A model listed WITHOUT ``generateContent`` 404s on every chat+ call — the exact failure the picker/resolver must never offer ("models/…+ is not found … or is not supported for generateContent"). Fail-open: an+ entry that declares nothing is kept, so a payload/mock without the field+ never empties the catalog.+ """+ methods = entry.get("supportedGenerationMethods")+ if not isinstance(methods, list):+ methods = entry.get("supportedActions")+ if not isinstance(methods, list):+ return True+ return "generateContent" in {str(x) for x in methods}++def _input_modalities(entry: dict) -> tuple[str, ...] | None:"""``architecture.input_modalities`` (e.g. ``("text","image")``) or None."""arch = entry.get("architecture")diff --git a/tests/unit/brain/test_frontier_resolver.py b/tests/unit/brain/test_frontier_resolver.pyindex 5a3ea22883..d9b316d249 100644--- a/tests/unit/brain/test_frontier_resolver.py+++ b/tests/unit/brain/test_frontier_resolver.py@@ -247,6 +247,86 @@ class TestResolveLatest:assert resolver._cache["gemini"]["fast"].model_id == "gemini-3-flash"+# ----------------------------------------------------------------------+# _fetch_models — Gemini capability gate (supportedGenerationMethods)+# ----------------------------------------------------------------------++class TestFetchModelsGeminiCapabilityGate:+ """Guard for the 2026-04 incident: Google LISTED "gemini-3-flash" as a+ clean stable id while every generateContent call 404'd — the GA-over-+ preview ranking then picked the dead model on every fresh install. The+ fetch must drop ids the API declares as not generateContent-capable."""++ @staticmethod+ def _resolver(tmp_path: Path, payload: dict) -> FrontierResolver:+ class _Resp:+ status_code = 200++ def json(self) -> dict:+ return payload++ def raise_for_status(self) -> None:+ return None++ class _Client:+ async def __aenter__(self) -> "_Client":+ return self++ async def __aexit__(self, *exc: object) -> bool:+ return False++ async def get(self, url: str, **kwargs: object) -> _Resp:+ return _Resp()++ return FrontierResolver(+ cache_path=tmp_path / "c.json", http_client_factory=_Client,+ )++ @pytest.mark.asyncio+ async def test_listed_id_without_generate_content_is_dropped(+ self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch,+ ) -> None:+ monkeypatch.setattr(+ "jarvis.brain.frontier_resolver.cfg.get_provider_secret",+ lambda provider: "test-key",+ )+ payload = {+ "models": [+ {+ "name": "models/gemini-3-flash",+ "supportedGenerationMethods": ["countTokens"],+ },+ {+ "name": "models/gemini-3-flash-preview",+ "supportedGenerationMethods": ["generateContent", "countTokens"],+ },+ {+ "name": "models/gemini-embedding-001",+ "supportedGenerationMethods": ["embedContent"],+ },+ ]+ }+ resolver = self._resolver(tmp_path, payload)+ models = await resolver._fetch_models("gemini")+ assert models == ["gemini-3-flash-preview"]+ # End-to-end: the dead "stable" id can no longer beat the servable+ # preview id in the GA-over-preview ranking.+ assert _pick_gemini(models, "fast") == "gemini-3-flash-preview"++ @pytest.mark.asyncio+ async def test_entries_without_method_declaration_are_kept(+ self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch,+ ) -> None:+ # Fail-open: no declared methods must never empty the roster.+ monkeypatch.setattr(+ "jarvis.brain.frontier_resolver.cfg.get_provider_secret",+ lambda provider: "test-key",+ )+ payload = {"models": [{"name": "models/gemini-3.5-flash"}]}+ resolver = self._resolver(tmp_path, payload)+ assert await resolver._fetch_models("gemini") == ["gemini-3.5-flash"]++# Synthetic exception type for the HTTP failure test.class httpx_RequestError(Exception):passdiff --git a/tests/unit/brain/test_model_catalog.py b/tests/unit/brain/test_model_catalog.pyindex 9f4fd0529b..cefafbc961 100644--- a/tests/unit/brain/test_model_catalog.py+++ b/tests/unit/brain/test_model_catalog.py@@ -149,6 +149,54 @@ class TestParseModelsResponse:# No displayName → label falls back to the id.assert ModelInfo(id="gemini-3.1-pro-preview", label="gemini-3.1-pro-preview") in models+ def test_gemini_drops_entries_not_capable_of_generate_content(self) -> None:+ # Guard for the 2026-04 incident: ListModels carried "gemini-3-flash"+ # while generateContent 404'd on it — the picker must never offer an+ # id whose entry declares it cannot serve generateContent.+ payload = {+ "models": [+ {+ "name": "models/gemini-3-flash-preview",+ "supportedGenerationMethods": ["generateContent", "countTokens"],+ },+ {+ "name": "models/gemini-3-flash",+ "supportedGenerationMethods": ["countTokens"],+ },+ {+ "name": "models/gemini-embedding-001",+ "supportedGenerationMethods": ["embedContent", "countTokens"],+ },+ {+ "name": "models/veo-3.1-generate-preview",+ "supportedGenerationMethods": ["predictLongRunning"],+ },+ {+ "name": "models/gemini-3.1-flash-live-preview",+ "supportedGenerationMethods": ["bidiGenerateContent"],+ },+ ]+ }+ ids = [m.id for m in parse_models_response("gemini", payload)]+ assert ids == ["gemini-3-flash-preview"]++ def test_gemini_supported_actions_variant_is_honored(self) -> None:+ # Newer API revisions rename the field to supportedActions.+ payload = {+ "models": [+ {"name": "models/gemini-4-flash", "supportedActions": ["generateContent"]},+ {"name": "models/gemini-4-embed", "supportedActions": ["embedContent"]},+ ]+ }+ ids = [m.id for m in parse_models_response("gemini", payload)]+ assert ids == ["gemini-4-flash"]++ def test_gemini_entries_without_method_declaration_are_kept(self) -> None:+ # Fail-open: a payload/mock without the field must not empty the list.+ payload = {"models": [{"name": "models/gemini-3.5-flash"}]}+ ids = [m.id for m in parse_models_response("gemini", payload)]+ assert ids == ["gemini-3.5-flash"]+def test_openrouter_uses_human_name_as_label(self) -> None:payload = {"data": [