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
test(brain): cover the voice-key reservation and keep single-key installs working
rubenluetke10-beepbf3a3234e57e
diff --git a/jarvis/brain/factory.py b/jarvis/brain/factory.pyindex 7798c5da62..f41cbce0c3 100644--- a/jarvis/brain/factory.py+++ b/jarvis/brain/factory.py@@ -1179,39 +1179,9 @@ def _phase2_full_brain(config=config,)- # Provider-override logic: if the user has switched to a different provider- # via voice/UI ("switch to gemini" -> brain.primary="gemini" persisted in- # jarvis.toml) while [brain.router].provider still points to "claude-api",- # we prefer brain.primary. That is the global master selection that should- # apply to all tiers.- startup_override: str | None = None- tier_cfg_startup = getattr(config.brain, "router", None)- tier_provider = tier_cfg_startup.provider if tier_cfg_startup else None- # The realtime voice call owns its key (user mandate 2026-09-29: the GPT-Live- # key pays for the voice call and its thinking model only). While voice runs- # realtime the Brain tab is hidden, so a ``brain.primary`` left on that- # key's family is not a choice anyone can see — it must not pull text turns- # onto the voice budget when the router tier names another provider. A- # single-key install (no other router provider) keeps working on the key.- from jarvis.brain.voice_key import bills_voice_key-- primary_on_voice_key = bills_voice_key(config, config.brain.primary)- if (- primary_on_voice_key- and tier_provider- and not bills_voice_key(config, tier_provider)- ):- log.info(- "Router stays on [brain.router].provider=%s: brain.primary=%s bills "- "the realtime voice key.",- tier_provider, config.brain.primary,- )- elif config.brain.primary and config.brain.primary != tier_provider:- startup_override = config.brain.primary- log.info(- "Startup override: brain.primary=%s overrides [brain.router].provider=%s",- config.brain.primary, tier_provider,- )+ # brain.primary normally overrides [brain.router].provider — except when it+ # would put text turns on the realtime voice key (see the helper).+ startup_override = _router_provider_override(config)# Build the router-tier BrainManager via from_tier_configmanager = BrainManager.from_tier_config(@@ -2101,26 +2071,27 @@ def _pick_keyed_flash_fallback(ack_cfg: Any, jcfg: Any = None) -> str | None:from jarvis.brain.voice_key import bills_voice_keyfrom jarvis.core.config import get_provider_secret, get_secret- # Families on the realtime voice key are tried last (mandate 2026-09-29),- # so a single-key install still resolves while a multi-key one keeps the- # voice budget for the voice call.- names = sorted(REGISTRY, key=lambda name: bills_voice_key(jcfg, name))- for name in names:+ # A family on the realtime voice key is deferred (mandate 2026-09-29): the+ # next keyed family in REGISTRY order answers instead. It still comes back+ # before a keyless local provider, so a single-key install without a local+ # server keeps a working flash tier (AP-22).+ deferred: str | None = None+ for name in REGISTRY:provider_cfg = getattr(ack_cfg.providers, name, None)if provider_cfg is None:continuesecret_name = getattr(provider_cfg, "api_key_secret", None)+ if secret_name is None:+ return deferred or name# The family resolver is the second probe so a credential that lives# only in a scoped slot of the same family (e.g. the Realtime card's# key) still marks the provider usable — the adapters resolve their# key through the same two-step lookup.- if (- secret_name is None- or get_secret(secret_name)- or get_provider_secret(name)- ):- return name- return None+ if get_secret(secret_name) or get_provider_secret(name):+ if not bills_voice_key(jcfg, name):+ return name+ deferred = deferred or name+ return deferreddef _build_ack_fallback(ack_cfg: Any, preferences_provider: Any = None) -> Any:@@ -2365,3 +2336,44 @@ def build_readback_composer(jcfg: Any | None = None) -> Any:"build_readback_composer() failed: %s — fallback-only mode.", exc)return ReadbackComposer()+++def _router_provider_override(config: Any) -> str | None:+ """The provider that overrides ``[brain.router].provider`` at boot, or None.++ Provider-override logic: if the user has switched to a different provider+ via voice/UI ("switch to gemini" -> brain.primary="gemini" persisted in+ jarvis.toml) while [brain.router].provider still points elsewhere, we+ prefer brain.primary. That is the global master selection that should+ apply to all tiers.++ The realtime voice call owns its key (user mandate 2026-09-29: the GPT-Live+ key pays for the voice call and its thinking model only). While voice runs+ realtime the Brain tab is hidden, so a ``brain.primary`` left on that key's+ family is not a choice anyone can see; it must not pull text turns onto the+ voice budget when the router tier names another provider. A single-key+ install (no other router provider) keeps working on the key.+ """+ from jarvis.brain.voice_key import bills_voice_key++ primary = config.brain.primary+ tier_cfg = getattr(config.brain, "router", None)+ tier_provider = tier_cfg.provider if tier_cfg else None+ if (+ bills_voice_key(config, primary)+ and tier_provider+ and not bills_voice_key(config, tier_provider)+ ):+ log.info(+ "Router stays on [brain.router].provider=%s: brain.primary=%s bills "+ "the realtime voice key.",+ tier_provider, primary,+ )+ return None+ if primary and primary != tier_provider:+ log.info(+ "Startup override: brain.primary=%s overrides [brain.router].provider=%s",+ primary, tier_provider,+ )+ return primary+ return Nonediff --git a/jarvis/brain/resolver.py b/jarvis/brain/resolver.pyindex da535970e3..d3c43f84a8 100644--- a/jarvis/brain/resolver.py+++ b/jarvis/brain/resolver.py@@ -721,14 +721,23 @@ def _resolve_chain(config: JarvisConfig) -> list[tuple[str, str | None]]:deduped = [entry for entry in deduped if entry[0] != "claude-api"]# The realtime voice call owns its key (user mandate 2026-09-29). Families- # that bill it move to the end, so skill drafting, bios and other- # background resolves reach it only when nothing else can answer — a- # single-key install still works, a multi-key one stops draining the voice.+ # that bill it move behind every other cloud family, so skill drafting,+ # bios and other background resolves reach it only when nothing else can+ # answer. They still precede the trailing keyless local tail: a single-key+ # install without a local server must keep a working resolve (AP-22).from jarvis.brain.voice_key import bills_voice_keyon_voice_key = [entry for entry in deduped if bills_voice_key(config, entry[0])]if on_voice_key and len(on_voice_key) < len(deduped):- deduped = [entry for entry in deduped if entry not in on_voice_key] + on_voice_key+ rest = [entry for entry in deduped if entry not in on_voice_key]+ local_ids = {provider for provider, _ in _local_tail(config)}+ # Only the tail run counts: a local provider the user put first (a+ # deliberate local primary or override) keeps its lead.+ lead_kept = 1 if rest[0] == deduped[0] else 0+ split = len(rest)+ while split > lead_kept and rest[split - 1][0] in local_ids:+ split -= 1+ deduped = rest[:split] + on_voice_key + rest[split:]return dedupeddiff --git a/tests/unit/brain/test_ack_brain/test_flash_provider_fallback.py b/tests/unit/brain/test_ack_brain/test_flash_provider_fallback.pyindex 1543ee17d9..8a50cc8cd5 100644--- a/tests/unit/brain/test_ack_brain/test_flash_provider_fallback.py+++ b/tests/unit/brain/test_ack_brain/test_flash_provider_fallback.py@@ -108,3 +108,62 @@ def test_does_not_change_ack_behavior_when_primary_has_a_flash_adapter(assert ack_cfg.provider == "openai"assert type(provider).__name__ == "OpenAIMiniAck"assert called is False+++def _live_jcfg(*, brain_primary: str) -> SimpleNamespace:+ """GPT-Live is the voice: the OpenAI key belongs to the voice call."""+ return SimpleNamespace(+ voice=SimpleNamespace(mode="realtime"),+ brain=SimpleNamespace(+ primary=brain_primary,+ realtime=SimpleNamespace(provider="openai-live"),+ ),+ )+++def test_primary_on_the_voice_key_hands_flash_work_to_another_family(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """Mandate 2026-09-29: the GPT-Live key pays for the voice call only."""+ keys = {"openai_api_key": "sk-test", "gemini_api_key": "gk-test"}+ monkeypatch.setattr(+ "jarvis.core.config.get_secret", lambda key, env_fallback=None: keys.get(key)+ )++ ack_cfg = make_ack_config(provider="follow_brain")+ provider = _build_flash_provider(_live_jcfg(brain_primary="openai"), ack_cfg)++ assert ack_cfg.provider == "gemini"+ assert type(provider).__name__ == "GeminiFlashAck"+++def test_single_voice_key_install_still_gets_a_flash_tier(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """With the voice key as the only credential, flash work stays on it+ rather than on a local server that may not exist (AP-22)."""+ monkeypatch.setattr(+ "jarvis.core.config.get_secret",+ lambda key, env_fallback=None: "sk-test" if key == "openai_api_key" else None,+ )++ ack_cfg = make_ack_config(provider="follow_brain")+ _build_flash_provider(_live_jcfg(brain_primary="openai"), ack_cfg)++ assert ack_cfg.provider == "openai"+++def test_pipeline_voice_keeps_following_an_openai_primary(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """Without a realtime voice the key is an ordinary brain key."""+ monkeypatch.setattr(+ "jarvis.core.config.get_secret", lambda key, env_fallback=None: "sk-test"+ )+ jcfg = _live_jcfg(brain_primary="openai")+ jcfg.voice.mode = "pipeline"++ ack_cfg = make_ack_config(provider="follow_brain")+ _build_flash_provider(jcfg, ack_cfg)++ assert ack_cfg.provider == "openai"diff --git a/tests/unit/brain/test_resolver_voice_key.py b/tests/unit/brain/test_resolver_voice_key.pynew file mode 100644index 0000000000..6b3b548f02--- /dev/null+++ b/tests/unit/brain/test_resolver_voice_key.py@@ -0,0 +1,81 @@+"""Background resolves stay off the realtime voice key (mandate 2026-09-29).++The OpenAI key a user adds for GPT-Live pays for the voice call and its+thinking model. Skill drafting, bios and other background work must reach+that key only when no other cloud family can answer, and a single-key install+must still resolve onto it before an absent local server.+"""++from __future__ import annotations++import pytest++import jarvis.core.config as cfg_mod+from jarvis.brain import resolver+from jarvis.core.config import BrainConfig, BrainTierConfig, JarvisConfig++[email protected](autouse=True)+def _hermetic(monkeypatch):+ resolver._reset_for_tests()+ monkeypatch.setattr(cfg_mod, "get_provider_secret", lambda pid: None)+ import jarvis.brain.manager as manager++ monkeypatch.setattr(manager, "_keyless_provider_is_rescued_by_oauth", lambda pid: False)+ yield+ resolver._reset_for_tests()+++def _keys(monkeypatch, *providers: str) -> None:+ monkeypatch.setattr(+ cfg_mod,+ "get_provider_secret",+ lambda pid: "sk-test" if pid in providers else None,+ )+++def _gpt_live(primary: str, *, mode: str = "realtime") -> JarvisConfig:+ config = JarvisConfig(brain=BrainConfig(primary=primary))+ config.brain.realtime = BrainTierConfig(provider="openai-live", model="gpt-live-1")+ config.voice.mode = mode+ return config+++def _providers(config: JarvisConfig) -> list[str]:+ return [provider for provider, _ in resolver._resolve_chain(config)]+++def test_voice_key_primary_moves_behind_other_cloud_families(monkeypatch) -> None:+ _keys(monkeypatch, "openai", "gemini", "grok")++ providers = _providers(_gpt_live("openai"))++ assert providers[0] != "openai"+ assert providers.index("gemini") < providers.index("openai")+ assert providers.index("grok") < providers.index("openai")+++def test_voice_key_still_precedes_the_keyless_local_tail(monkeypatch) -> None:+ """A single-key install without a local server keeps a working resolve."""+ _keys(monkeypatch, "openai")++ providers = _providers(_gpt_live("openai"))++ assert providers.index("openai") < providers.index("ollama")+ assert providers[-2:] == ["ollama", "local-openai"]+++def test_a_deliberate_local_primary_keeps_the_lead(monkeypatch) -> None:+ _keys(monkeypatch, "openai")++ providers = _providers(_gpt_live("ollama"))++ assert providers[0] == "ollama"+++def test_pipeline_voice_leaves_an_openai_primary_first(monkeypatch) -> None:+ _keys(monkeypatch, "openai", "gemini")++ providers = _providers(_gpt_live("openai", mode="pipeline"))++ assert providers[0] == "openai"diff --git a/tests/unit/brain/test_router_voice_key_override.py b/tests/unit/brain/test_router_voice_key_override.pynew file mode 100644index 0000000000..490550fdd0--- /dev/null+++ b/tests/unit/brain/test_router_voice_key_override.py@@ -0,0 +1,47 @@+"""The router brain stays off the realtime voice key (mandate 2026-09-29).++Live forensic: GPT-Live owned the OpenAI key, ``brain.primary`` still said+"openai" (invisible while the Brain tab is hidden in realtime mode), and the+boot override put every text turn — including gpt-5.5-pro deep turns — on+the voice budget until the voice call failed with "no credits".+"""++from __future__ import annotations++from jarvis.brain.factory import _router_provider_override+from jarvis.core.config import BrainConfig, BrainTierConfig, JarvisConfig+++def _config(*, primary: str, router: str | None, mode: str = "realtime") -> JarvisConfig:+ config = JarvisConfig(brain=BrainConfig(primary=primary))+ config.brain.router = BrainTierConfig(provider=router) if router else None+ config.brain.realtime = BrainTierConfig(provider="openai-live", model="gpt-live-1")+ config.voice.mode = mode+ return config+++def test_voice_key_primary_does_not_override_the_router_provider() -> None:+ assert _router_provider_override(_config(primary="openai", router="grok")) is None+++def test_single_key_install_keeps_the_voice_key_router() -> None:+ """No other router provider: the key still carries text turns (AP-22)."""+ assert _router_provider_override(_config(primary="openai", router=None)) == "openai"+++def test_router_on_the_voice_key_too_keeps_the_primary_override() -> None:+ assert _router_provider_override(_config(primary="openai", router="codex")) == "openai"+++def test_a_primary_off_the_voice_key_still_overrides_the_router() -> None:+ assert _router_provider_override(_config(primary="gemini", router="grok")) == "gemini"+++def test_pipeline_voice_keeps_the_ordinary_override() -> None:+ config = _config(primary="openai", router="grok", mode="pipeline")++ assert _router_provider_override(config) == "openai"+++def test_same_provider_needs_no_override() -> None:+ assert _router_provider_override(_config(primary="grok", router="grok")) is Nonediff --git a/tests/unit/brain/test_section_health.py b/tests/unit/brain/test_section_health.pyindex 15a25aa2ee..6e63fae334 100644--- a/tests/unit/brain/test_section_health.py+++ b/tests/unit/brain/test_section_health.py@@ -328,3 +328,68 @@ class TestSubagentSectionHealth:)health = pr._jarvis_agent_section_health(self._cfg())assert "Claude (API-Key)" in health.detail+++def _gpt_live_config(mode: str = "realtime") -> SimpleNamespace:+ return SimpleNamespace(+ voice=SimpleNamespace(mode=mode),+ brain=SimpleNamespace(realtime=SimpleNamespace(provider="openai-live")),+ )+++async def _brain_probe_flag(monkeypatch, cfg, brain_subject: str) -> bool:+ """Run the rollup with every check stubbed; return the brain ``probe`` flag."""+ from jarvis.ui.web import provider_routes as pr++ seen: dict[str, bool] = {}++ async def _tier(cfg, spec, *, probe=True, **kwargs):+ if spec is not None and spec.id == brain_subject:+ seen["brain"] = probe+ return pr.SectionHealth(status=sh.OK, reason="ok")++ async def _other(*args, **kwargs):+ return pr.SectionHealth(status=sh.OK, reason="ok")++ def _sync_other(*args, **kwargs):+ return pr.SectionHealth(status=sh.OK, reason="ok")++ monkeypatch.setattr(pr, "_tier_section_health", _tier)+ monkeypatch.setattr(pr, "_realtime_section_health", _other)+ monkeypatch.setattr(pr, "_dictation_section_health", _other)+ monkeypatch.setattr(pr, "_jarvis_agent_section_health", _sync_other)+ monkeypatch.setattr(pr, "_advanced_section_health", _sync_other)+ monkeypatch.setattr(pr, "_local_models_section_health", _sync_other)+ monkeypatch.setattr(pr, "_codex_binary_path", lambda request: None)+ monkeypatch.setattr(pr, "_polish_enabled", lambda cfg: False)+ subjects = {key: None for key in pr._SECTION_HEALTH_KEYS}+ subjects["brain"] = brain_subject+ await pr._compute_section_health(SimpleNamespace(), cfg, subjects)+ return seen["brain"]+++async def test_brain_on_the_voice_key_is_not_probed_twice(monkeypatch) -> None:+ """The realtime section already spends one call on the GPT-Live key; the+ hidden Brain tab must not spend a second one on the same key (2026-09-29)."""+ assert await _brain_probe_flag(monkeypatch, _gpt_live_config(), "openai") is False+++async def test_brain_off_the_voice_key_is_still_probed(monkeypatch) -> None:+ assert await _brain_probe_flag(monkeypatch, _gpt_live_config(), "grok") is True+++async def test_pipeline_voice_probes_an_openai_brain(monkeypatch) -> None:+ cfg = _gpt_live_config(mode="pipeline")++ assert await _brain_probe_flag(monkeypatch, cfg, "openai") is True+++def test_passive_health_polls_reuse_the_cache_for_minutes() -> None:+ """Sidebar and dock poll this in every window and every build reloads every+ window; a sub-minute TTL turned that into a paid probe per minute."""+ from jarvis.ui.web import provider_routes as pr++ assert pr._SECTION_HEALTH_TTL_S >= 15 * 60