Skip to content

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.

fix(core): probe the Claude subscription seat off the event loop

rubenluetke10-beepa611f48b4c65
diff --git a/jarvis/agent_chat/service.py b/jarvis/agent_chat/service.py
index bab97d7a94..7f36cdea1b 100644
--- a/jarvis/agent_chat/service.py
+++ b/jarvis/agent_chat/service.py
@@ -543,13 +543,12 @@ class AgentChatService:
if session.surface == "jarvis":
from jarvis.core.model_selection import worker_selection
from jarvis.core.runtime_refs import get_brain_manager
- from jarvis.core.task_agent import subscription_seat
+ from jarvis.core.task_agent import subscription_seat_off_loop
manager = get_brain_manager()
selection = worker_selection(getattr(manager, "_config", None))
if selection is not None:
- # The Claude slot probes the CLI login (cached); keep it off the loop.
- seat = await asyncio.to_thread(subscription_seat, selection.provider)
+ seat = await subscription_seat_off_loop(selection.provider)
provider, selected_runner = seat or (selection.provider, "brain")
if (session.provider, session.model) != (provider, selection.model or ""):
session = replace(
diff --git a/jarvis/agent_chat/tasks.py b/jarvis/agent_chat/tasks.py
index 8683bd7a18..e65039749a 100644
--- a/jarvis/agent_chat/tasks.py
+++ b/jarvis/agent_chat/tasks.py
@@ -5,7 +5,12 @@ from __future__ import annotations
import asyncio
from uuid import uuid4
-from jarvis.core.task_agent import TaskToolScope, register_scope, release_scope, subscription_seat
+from jarvis.core.task_agent import (
+ TaskToolScope,
+ register_scope,
+ release_scope,
+ subscription_seat_off_loop,
+)
async def run_subscription_task(*, selection, prompt, tool_names, trace_id=None) -> str:
@@ -15,7 +20,7 @@ async def run_subscription_task(*, selection, prompt, tool_names, trace_id=None)
from jarvis.core.paths import chat_workspace_dir
from jarvis.core.protocols import ChatTurn, current_chat_turn
- seat = subscription_seat(selection.provider)
+ seat = await subscription_seat_off_loop(selection.provider)
if seat is None:
raise RuntimeError("No subscription runner is registered for the selected agent.")
provider, runner = seat
diff --git a/jarvis/brain/manager.py b/jarvis/brain/manager.py
index 5e63ed29b8..e8b288c240 100644
--- a/jarvis/brain/manager.py
+++ b/jarvis/brain/manager.py
@@ -13522,10 +13522,13 @@ class BrainManager:
allowed_tools = (*allowed_tools, _ARTIFACT_TOOL_NAME)
tools = self._select_task_tools(allowed_tools)
from jarvis.core.model_selection import operation_model, worker_selection
- from jarvis.core.task_agent import run_selected, subscription_seat
+ from jarvis.core.task_agent import run_selected, subscription_seat_off_loop
selected = operation_model.get() or worker_selection(self._config)
- if selected is not None and subscription_seat(selected.provider) is not None:
+ if (
+ selected is not None
+ and await subscription_seat_off_loop(selected.provider) is not None
+ ):
return await run_selected(
selection=selected, prompt=prompt, tool_names=tuple(tools), trace_id=trace_id
)
diff --git a/jarvis/core/task_agent.py b/jarvis/core/task_agent.py
index 77a79d3a3e..43024e934b 100644
--- a/jarvis/core/task_agent.py
+++ b/jarvis/core/task_agent.py
@@ -2,6 +2,7 @@
from __future__ import annotations
+import asyncio
from collections.abc import Awaitable, Callable
from dataclasses import dataclass
from typing import Any
@@ -65,6 +66,19 @@ def subscription_seat(provider: str) -> tuple[str, str] | None:
return seat
+async def subscription_seat_off_loop(provider: str) -> tuple[str, str] | None:
+ """``subscription_seat`` for code running on the event loop.
+
+ The Claude slot's login probe can run two blocking ``claude`` subprocesses
+ (4 s + 6 s) when its cache is cold; on the loop that froze voice,
+ WebSockets and the IDE for up to ~10 s (#251). Other seats are a dict
+ lookup and stay inline.
+ """
+ if provider != "claude-api":
+ return subscription_seat(provider)
+ return await asyncio.to_thread(subscription_seat, provider)
+
+
_CLAUDE_LOGIN_TTL_S = 60.0
_claude_login: tuple[float, bool] | None = None
diff --git a/jarvis/society/routine_runner.py b/jarvis/society/routine_runner.py
index b9badaac19..05080c25c9 100644
--- a/jarvis/society/routine_runner.py
+++ b/jarvis/society/routine_runner.py
@@ -49,7 +49,7 @@ def _billed_via_api(provider: str) -> bool:
return resolve_runner(provider, surface=SURFACE) in ("brain", "api", "unknown")
-def _subscription_seat(cfg: Any) -> tuple[str, str, str] | None:
+async def _subscription_seat(cfg: Any) -> tuple[str, str, str] | None:
"""The Jarvis chat's current subscription seat, if it has one.
Mirrors what a typed turn on the front page resolves to
@@ -59,7 +59,7 @@ def _subscription_seat(cfg: Any) -> tuple[str, str, str] | None:
"""
try:
from jarvis.core.model_selection import worker_selection
- from jarvis.core.task_agent import subscription_seat
+ from jarvis.core.task_agent import subscription_seat_off_loop
except Exception: # noqa: BLE001 — no selection layer: no subscription seat
return None
try:
@@ -68,7 +68,7 @@ def _subscription_seat(cfg: Any) -> tuple[str, str, str] | None:
return None
if selection is None or not selection.provider:
return None
- mapped = subscription_seat(selection.provider)
+ mapped = await subscription_seat_off_loop(selection.provider)
if mapped is not None:
return mapped[0], selection.model or "", selection.reasoning_effort or ""
if not _billed_via_api(selection.provider):
@@ -102,7 +102,7 @@ async def _seat_for_run(runtime: Any, agent: Any, task_id: str) -> tuple[str, st
if getattr(agent, "provider", ""):
_provider, _model, _effort = pair_for(cfg, agent)
return _provider, _model, _effort, account_id
- subscription = _subscription_seat(cfg)
+ subscription = await _subscription_seat(cfg)
if subscription is not None:
provider, model, effort = subscription
return provider, model, effort, account_id
diff --git a/tests/unit/core/test_task_agent_claude_seat.py b/tests/unit/core/test_task_agent_claude_seat.py
index 8052309d11..992b3d5998 100644
--- a/tests/unit/core/test_task_agent_claude_seat.py
+++ b/tests/unit/core/test_task_agent_claude_seat.py
@@ -70,3 +70,32 @@ def test_unreadable_login_means_no_subscription(monkeypatch) -> None:
monkeypatch.setattr(claude_auth, "ClaudeAuthService", _Broken)
assert task_agent._claude_subscription_ready() is False
+
+
+async def test_claude_seat_probe_runs_off_the_event_loop(monkeypatch) -> None:
+ """#251: the cold login probe runs up to two blocking ``claude``
+ subprocesses; on the loop it froze voice, WebSockets and the IDE."""
+ import threading
+
+ loop_thread = threading.get_ident()
+ probe_threads: list[int] = []
+
+ def _probe() -> bool:
+ probe_threads.append(threading.get_ident())
+ return True
+
+ monkeypatch.setattr(task_agent, "_claude_subscription_ready", _probe)
+
+ seat = await task_agent.subscription_seat_off_loop("claude-api")
+
+ assert seat == ("claude-api", "claude-cli")
+ assert probe_threads and probe_threads[0] != loop_thread
+
+
+async def test_other_seats_resolve_inline_without_a_thread(monkeypatch) -> None:
+ async def _no_thread(*_a, **_k):
+ raise AssertionError("a dict lookup needs no worker thread")
+
+ monkeypatch.setattr(task_agent.asyncio, "to_thread", _no_thread)
+
+ assert await task_agent.subscription_seat_off_loop("codex") == ("openai-codex", "codex-cli")