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(marketplace): live badge probes the live registry — connected-with-zero-tools is no longer shown as live
Ruben Lütkee0dbb6cd13b6
diff --git a/jarvis/marketplace/plugin_registry.py b/jarvis/marketplace/plugin_registry.pyindex 33550f4b04..72dec98bf1 100644--- a/jarvis/marketplace/plugin_registry.py+++ b/jarvis/marketplace/plugin_registry.py@@ -70,6 +70,10 @@ class PluginToolRegistry:self._risk_tier = default_risk_tierself._clients: dict[str, Any] = {}self._tools: dict[str, MCPToolAdapter] = {}+ # Last swallowed connect/list_tools error per plugin (honest liveness+ # badge — see live_tool_count/last_connect_error below). Cleared on a+ # subsequent successful connect.+ self._last_errors: dict[str, str] = {}self._bootstrapped = False# Serialises bootstrap()/refresh_plugin()/stop(): all three mutate# self._clients/_tools across await points and are fired as independent@@ -85,6 +89,15 @@ class PluginToolRegistry:def is_bootstrapped(self) -> bool:return self._bootstrapped+ def live_tool_count(self, plugin_id: str) -> int:+ """Number of live tool adapters currently registered for this plugin."""+ prefix = f"{plugin_id}/"+ return sum(1 for name in self._tools if name.startswith(prefix))++ def last_connect_error(self, plugin_id: str) -> str | None:+ """The swallowed connect/list_tools error of the last attempt, if any."""+ return self._last_errors.get(plugin_id)+async def bootstrap(self) -> None:# Idempotent: a second bootstrap() would leak the first run's MCP# clients (their AsyncExitStacks) by overwriting self._clients. Callers@@ -150,8 +163,10 @@ class PluginToolRegistry:tool_defs = await client.list_tools()except Exception as exc: # noqa: BLE001 — graceful per-plugin degradelog.warning("plugin-registry: %s connect failed: %s", plugin.id, exc)+ self._last_errors[plugin.id] = str(exc)returnself._clients[plugin.id] = client+ self._last_errors.pop(plugin.id, None)for tool_def in tool_defs:adapter = MCPToolAdapter(client, tool_def, risk_tier=self._risk_tier)self._tools[adapter.name] = adapterdiff --git a/jarvis/ui/web/marketplace_routes.py b/jarvis/ui/web/marketplace_routes.pyindex 5d01d28314..dbbd86fc55 100644--- a/jarvis/ui/web/marketplace_routes.py+++ b/jarvis/ui/web/marketplace_routes.py@@ -75,6 +75,20 @@ def _refresh_plugin_in_live_registry(plugin_id: str) -> None:log.warning("live plugin refresh failed for %s", plugin_id, exc_info=True)+def _live_plugin_registry() -> Any:+ """The active ``PluginToolRegistry``, or ``None`` if unreachable.++ Same lookup as ``_refresh_plugin_in_live_registry`` — returns ``None`` on+ any failure (early boot, headless) so callers can fail open.+ """+ try:+ from jarvis.marketplace.plugin_shared import get_active_plugin_registry++ return get_active_plugin_registry()+ except Exception: # noqa: BLE001+ return None++# ----------------------------------------------------------------------# Helpers# ----------------------------------------------------------------------@@ -158,16 +172,31 @@ _validate_token = _make_validator()# -----------------------------------------------------------------------def _mcp_live(mcp: dict[str, Any]) -> tuple[bool, str | None]:+def _mcp_live(+ mcp: dict[str, Any], *, plugin_id: str = "", status: str = ""+) -> tuple[bool, str | None]:"""``(is_live, runtime_missing)`` for an MCP plugin's transport.M2 (honest status): a stdio plugin (GitHub=docker, Supabase=npx) is only LIVE ifits launcher binary is on PATH — else connecting saves the token but the tools- never appear, so a green "Connected · Live" badge is a lie. http transports are- always live; ``runtime_missing`` is the absent launcher name for an honest UI hint.+ never appear, so a green "Connected · Live" badge is a lie. ``runtime_missing``+ is the absent launcher name for an honest UI hint.++ Bug 14: an http plugin's connect-time ``list_tools()`` can 401 and be+ swallowed, leaving status "connected" with ZERO live tools — a green+ "Connected · Live" badge over a dead session. When a live registry is+ reachable AND the plugin is "connected" AND it reports zero tools, the+ session is dead (expired token, 401 at list_tools) and the badge goes+ honest. No registry reachable (early boot / headless) -> fail open, exactly+ today's behaviour."""transport = str(mcp.get("transport", "")).lower()if transport == "http":+ if status == "connected":+ reg = _live_plugin_registry() # the same accessor refresh uses+ if reg is not None and reg.live_tool_count(plugin_id) == 0:+ hint = reg.last_connect_error(plugin_id) or "no tools loaded — reconnect"+ return False, hintreturn True, Noneif transport == "stdio":import shutil@@ -199,7 +228,7 @@ async def list_plugins(response: Response) -> dict[str, Any]:item["expires_at"] = expires_atitem["last_refreshed"] = last_refreshedmcp = spec.mcp_server or {}- mcp_live, runtime_missing = _mcp_live(mcp)+ mcp_live, runtime_missing = _mcp_live(mcp, plugin_id=spec.id, status=status)if runtime_missing:item["runtime_missing"] = runtime_missingnative_live = Falsediff --git a/tests/unit/marketplace/test_mcp_liveness_runtime_gate.py b/tests/unit/marketplace/test_mcp_liveness_runtime_gate.pyindex cb66ac2c5f..78ca3223a6 100644--- a/tests/unit/marketplace/test_mcp_liveness_runtime_gate.py+++ b/tests/unit/marketplace/test_mcp_liveness_runtime_gate.py@@ -25,3 +25,24 @@ def test_stdio_with_missing_launcher_is_not_live_and_flags_runtime():def test_no_transport_is_not_live():assert _mcp_live({}) == (False, None)+++def test_http_connected_with_zero_live_tools_is_not_live(monkeypatch):+ from jarvis.ui.web import marketplace_routes as mr++ class _Reg:+ def live_tool_count(self, pid): return 0+ def last_connect_error(self, pid): return "HTTP 401 unauthorized"++ monkeypatch.setattr(mr, "_live_plugin_registry", lambda: _Reg())+ live, hint = mr._mcp_live({"transport": "http"}, plugin_id="notion", status="connected")+ assert live is False+ assert "401" in hint+++def test_http_without_registry_stays_live(monkeypatch):+ from jarvis.ui.web import marketplace_routes as mr++ monkeypatch.setattr(mr, "_live_plugin_registry", lambda: None)+ live, hint = mr._mcp_live({"transport": "http"}, plugin_id="notion", status="connected")+ assert live is True and hint is Nonediff --git a/tests/unit/marketplace/test_plugin_registry.py b/tests/unit/marketplace/test_plugin_registry.pyindex 9a53b7d685..6b61e76f06 100644--- a/tests/unit/marketplace/test_plugin_registry.py+++ b/tests/unit/marketplace/test_plugin_registry.py@@ -26,6 +26,16 @@ class _FakeClient:async def list_tools(self): return list(self._tools)+class _FailingClient:+ """Stands in for a client whose connect-time list_tools() 401s (Bug 14)."""+ def __init__(self, spec, env_overrides=None):+ self.spec = spec+ async def start(self) -> None:+ raise RuntimeError("HTTP 401 unauthorized")+ async def stop(self) -> None: ...+ async def list_tools(self): return []++class _RecordingBus:def __init__(self): self.events = []async def publish(self, ev): self.events.append(ev)@@ -37,6 +47,17 @@ def _store_with_calendar() -> TokenStore:return store+def registry_with_failing_client():+ """A registry + plugin whose client's start() raises HTTP 401 (Bug 14)."""+ catalog = PluginCatalog(version=1, schema_version="1", plugins=[_calendar_plugin()])+ reg = PluginToolRegistry(+ catalog=catalog, token_store=_store_with_calendar(),+ client_factory=_FailingClient, bus=_RecordingBus(),+ )+ return reg, catalog.plugins[0]++@pytest.mark.asyncioasync def test_bootstrap_exposes_connected_plugin_tools():catalog = PluginCatalog(version=1, schema_version="1", plugins=[_calendar_plugin()])@@ -129,3 +150,11 @@ async def test_concurrent_bootstrap_and_refresh_no_corruption():names = [t.name for t in reg.active_tools()]assert names.count("google-calendar/list_events") == 1 # not doubledassert list(reg._clients) == ["google-calendar"] # exactly one, not leaked+++async def test_connect_failure_is_recorded_and_tool_count_zero(registry_with_failing_client):+ reg, plugin = registry_with_failing_client # fake client whose start()/list_tools() raises 401+ await reg._connect_plugin(plugin)+ assert reg.live_tool_count(plugin.id) == 0+ assert "401" in (reg.last_connect_error(plugin.id) or "")