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
perf(api): parallelize and share provider status discovery
rubenluetke10-beepf929b3bba012
diff --git a/jarvis/ui/web/agent_status.py b/jarvis/ui/web/agent_status.pynew file mode 100644index 0000000000..f085b3b3a0--- /dev/null+++ b/jarvis/ui/web/agent_status.py@@ -0,0 +1,46 @@+"""Concurrent, read-only subscription probes for the existing agent status API."""++from __future__ import annotations++import asyncio+import importlib+import logging+from typing import Any++log = logging.getLogger(__name__)+++def _status(module: str, service: str, args: tuple[Any, ...]) -> Any:+ # Imports and constructors may themselves read credentials or resolve a CLI.+ factory = getattr(importlib.import_module(module), service)+ return factory(*args).status()+++async def subscription_statuses(codex_binary: str | None) -> dict[str, Any]:+ """Probe independent logins together; one broken CLI hides only its own row."""+ probes = (+ ("claude", "jarvis.claude_auth", "ClaudeAuthService", ()),+ ("codex", "jarvis.codex_auth", "CodexAuthService", (codex_binary,)),+ ("google", "jarvis.google_cli.auth_service", "GoogleCliAuthService", ()),+ ("grok", "jarvis.grok_build_auth", "GrokBuildAuthService", ()),+ )++ async def probe(key: str, module: str, service: str, args: tuple[Any, ...]) -> tuple[str, Any]:+ try:+ return key, await asyncio.to_thread(_status, module, service, args)+ except Exception:+ log.debug("Agent status: %s login probe unavailable", key, exc_info=True)+ return key, None++ return dict(await asyncio.gather(*(probe(*item) for item in probes)))+++def observe_status_result(task: asyncio.Task[dict[str, Any]]) -> None:+ """Consume a failed shared read even if its last HTTP waiter disconnected."""+ if task.cancelled():+ return+ error = task.exception()+ if error is not None:+ log.warning(+ "Shared agent status read failed", exc_info=(type(error), error, error.__traceback__)+ )diff --git a/jarvis/ui/web/server.py b/jarvis/ui/web/server.pyindex 3df3b0a84e..e6ed63371c 100644--- a/jarvis/ui/web/server.py+++ b/jarvis/ui/web/server.py@@ -1073,9 +1073,8 @@ class WebServer:"""return {"ready": bool(getattr(self, "_voice_ready", False))}- @app.get("/api/jarvis-agent/status")- async def jarvis_agent_status() -> dict[str, Any]:- """Jarvis-Agent bridge status for the settings view (Welle 3).+ async def _jarvis_agent_status_snapshot() -> dict[str, Any]:+ """Jarvis-Agent bridge status for the settings view (Wave 3).Read-only snapshot:@@ -1100,6 +1099,11 @@ class WebServer:"""import shutil+ from .agent_status import subscription_statuses++ codex_bin = getattr(getattr(cfg, "codex", None), "binary_path", "") or None+ auth_statuses = await subscription_statuses(codex_bin)+oc_cfg = cfg.harness.jarvis_agentrouter_primary = (cfg.brain.primary or "").lower()@@ -1214,12 +1218,11 @@ class WebServer:# expired state for older Linux/Windows installs.if mapping.jarvis == "claude-api":try:- from jarvis.claude_auth import ClaudeAuthServicefrom jarvis.claude_credentials import (freshest_claude_oauth,)- auth_status = await asyncio.to_thread(ClaudeAuthService().status)+ auth_status = auth_statuses["claude"]oauth_connected = bool(auth_status.connected and auth_status.mode == "subscription")@@ -1301,14 +1304,7 @@ class WebServer:# subagent row. Backed by the ChatGPT subscription (OAuth) OR an# OpenAI API key — "key_set" is true when either is present.try:- from jarvis.codex_auth import CodexAuthService-- codex_bin = getattr(getattr(cfg, "codex", None), "binary_path", "") or None- # Off the event loop like the Claude probe above: it spawns the- # CLI binary, and on the loop that few-hundred-millisecond pause- # froze the realtime voice socket into an audible mid-sentence- # hole (forensic 2026-07-27).- codex_status = await asyncio.to_thread(CodexAuthService(codex_bin).status)+ codex_status = auth_statuses["codex"]codex_connected = codex_status.connectedcodex_installed = codex_status.installedexcept Exception: # noqa: BLE001@@ -1361,12 +1357,10 @@ class WebServer:antigravity_status = Nonetry:from jarvis.google_cli.auth_service import (- GoogleCliAuthService,antigravity_provider_ready,)- # Off the event loop for the same reason as the Codex probe.- antigravity_status = await asyncio.to_thread(GoogleCliAuthService().status)+ antigravity_status = auth_statuses["google"]antigravity_connected = (antigravity_status.connected and antigravity_status.mode == "oauth-personal")@@ -1424,11 +1418,10 @@ class WebServer:grok_build_status = Nonetry:from jarvis.grok_build_auth import (- GrokBuildAuthService,grok_build_provider_ready,)- grok_build_status = await asyncio.to_thread(GrokBuildAuthService().status)+ grok_build_status = auth_statuses["grok"]grok_build_connected = (grok_build_status.connected and grok_build_status.mode == "subscription")@@ -1483,6 +1476,21 @@ class WebServer:"mapping": mapping_rows,}+ pending_agent_status: asyncio.Task[dict[str, Any]] | None = None++ @app.get("/api/jarvis-agent/status")+ async def jarvis_agent_status() -> dict[str, Any]:+ """Read bridge configuration and provider credential readiness without secrets."""+ nonlocal pending_agent_status+ from .agent_status import observe_status_result++ # Several windows ask together. Share only unfinished work so a new+ # read after a login or config change still gets a fresh snapshot.+ if pending_agent_status is None or pending_agent_status.done():+ pending_agent_status = asyncio.create_task(_jarvis_agent_status_snapshot())+ pending_agent_status.add_done_callback(observe_status_result)+ return await asyncio.shield(pending_agent_status)+@app.get("/api/memory/facts")async def get_memory_facts() -> dict[str, Any]:"""Returns the core memory (persona, user facts, preferences).diff --git a/tests/unit/ui/web/test_agent_status_latency.py b/tests/unit/ui/web/test_agent_status_latency.pynew file mode 100644index 0000000000..90be17e84b--- /dev/null+++ b/tests/unit/ui/web/test_agent_status_latency.py@@ -0,0 +1,118 @@+"""Cold status reads must not serialize CLI startup or duplicate work per window."""++from __future__ import annotations++import asyncio+import threading+from types import SimpleNamespace++import pytest++from jarvis.ui.web import agent_status+++async def test_subscription_probes_start_together(monkeypatch):+ barrier = threading.Barrier(4, timeout=5)++ def probe(module, service, args):+ barrier.wait()+ return service++ monkeypatch.setattr(agent_status, "_status", probe)+ result = await agent_status.subscription_statuses(None)+ assert result == {+ "claude": "ClaudeAuthService",+ "codex": "CodexAuthService",+ "google": "GoogleCliAuthService",+ "grok": "GrokBuildAuthService",+ }+++async def test_one_broken_probe_preserves_other_provider_results(monkeypatch):+ def probe(module, service, args):+ if service == "ClaudeAuthService":+ raise OSError("CLI unavailable")+ return service++ monkeypatch.setattr(agent_status, "_status", probe)+ result = await agent_status.subscription_statuses(None)+ assert result["claude"] is None+ assert result["codex"] == "CodexAuthService"+ assert result["google"] == "GoogleCliAuthService"+ assert result["grok"] == "GrokBuildAuthService"+++def status_endpoint(monkeypatch, tmp_path):+ import jarvis.claude_credentials as credentials+ import jarvis.core.config as config+ from jarvis.core.bus import EventBus+ from jarvis.ui.web.server import WebServer++ monkeypatch.setattr(config, "get_secret", lambda *_args, **_kwargs: None)+ monkeypatch.setattr(config, "get_provider_secret", lambda *_args, **_kwargs: None)+ monkeypatch.setattr(config, "get_jarvis_agent_secret", lambda *_args, **_kwargs: None)+ monkeypatch.setattr(+ credentials, "freshest_claude_oauth", lambda: SimpleNamespace(status="missing")+ )+ cfg = config.JarvisConfig()+ cfg.memory.data_dir = str(tmp_path)+ app = WebServer(bus=EventBus(), cfg=cfg).app+ return next(+ route.endpoint+ for route in app.routes+ if getattr(route, "path", "") == "/api/jarvis-agent/status"+ )+++async def test_windows_share_pending_status_and_disconnect_does_not_cancel_it(+ monkeypatch, status_endpoint+):+ entered = asyncio.Event()+ release = asyncio.Event()+ calls = 0++ async def probes(_binary):+ nonlocal calls+ calls += 1+ entered.set()+ await release.wait()+ return {key: None for key in ("claude", "codex", "google", "grok")}++ monkeypatch.setattr(agent_status, "subscription_statuses", probes)+ first = asyncio.create_task(status_endpoint())+ await asyncio.wait_for(entered.wait(), 5)+ second = asyncio.create_task(status_endpoint())+ await asyncio.sleep(0)+ first.cancel()+ with pytest.raises(asyncio.CancelledError):+ await first+ assert calls == 1+ release.set()+ result = await asyncio.wait_for(second, 5)+ assert result["mapping"]+ # A later read is fresh: saving a key or switching a login cannot be hidden+ # by caching the entire status response across completed requests.+ await asyncio.wait_for(status_endpoint(), 5)+ assert calls == 2+++async def test_failed_shared_status_is_retried(monkeypatch, status_endpoint):+ calls = 0++ async def probes(_binary):+ nonlocal calls+ calls += 1+ if calls == 1:+ raise RuntimeError("temporary discovery failure")+ return {key: None for key in ("claude", "codex", "google", "grok")}++ monkeypatch.setattr(agent_status, "subscription_statuses", probes)+ with pytest.raises(RuntimeError, match="temporary discovery failure"):+ await status_endpoint()+ assert (await status_endpoint())["mapping"]+ assert calls == 2