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(google): keep the first-use client build off the event loop

rubenluetke10-beep7ba501e22f67
diff --git a/jarvis/brain/ack_brain/providers/gemini.py b/jarvis/brain/ack_brain/providers/gemini.py
index f56c1d9f97..60bc29899b 100644
--- a/jarvis/brain/ack_brain/providers/gemini.py
+++ b/jarvis/brain/ack_brain/providers/gemini.py
@@ -56,7 +56,11 @@ class GeminiFlashAck:
persona_prompt: str,
) -> str | None:
try:
- client = self._ensure_client()
+ # First use builds the client: google-genai import + (for an AQ.
+ # key) the one-time routing probe — neither belongs on the loop.
+ import asyncio
+
+ client = await asyncio.to_thread(self._ensure_client)
from google.genai import types as genai_types
response = await client.aio.models.generate_content(
@@ -87,7 +91,10 @@ class GeminiFlashAck:
non-streaming ``run()`` so a broken stream never silences the ack.
"""
try:
- client = self._ensure_client()
+ # Same off-loop client build as ``run`` above.
+ import asyncio
+
+ client = await asyncio.to_thread(self._ensure_client)
from google.genai import types as genai_types
# The google-genai async API has shipped both an awaitable-returning
diff --git a/jarvis/core/google_genai.py b/jarvis/core/google_genai.py
index 9d50152573..6eadbd914b 100644
--- a/jarvis/core/google_genai.py
+++ b/jarvis/core/google_genai.py
@@ -118,7 +118,8 @@ def _configured_mode() -> str:
from jarvis.core.config import load_config
mode = str(load_config().google.vertex_mode or "auto").strip().lower()
- except Exception: # noqa: BLE001 — config trouble must never break clients
+ except Exception as exc: # noqa: BLE001 — config trouble must never break clients
+ log.debug("vertex_mode unreadable (%s: %s) — using 'auto'.", type(exc).__name__, exc)
return "auto"
return mode if mode in ("auto", "always", "never") else "auto"
diff --git a/jarvis/dictation/polish_client.py b/jarvis/dictation/polish_client.py
index 903e59f694..d8ccc9d29b 100644
--- a/jarvis/dictation/polish_client.py
+++ b/jarvis/dictation/polish_client.py
@@ -77,6 +77,7 @@ credential lookup.
from __future__ import annotations
+import asyncio
import logging
import time
from collections.abc import Sequence
@@ -901,7 +902,9 @@ class GeminiPolishClient:
timeout_s: float,
) -> str | None:
try:
- client = self._ensure_client(timeout_s)
+ # First use builds the client: google-genai import + (for an AQ.
+ # key) the one-time routing probe — neither belongs on the loop.
+ client = await asyncio.to_thread(self._ensure_client, timeout_s)
from google.genai import types as genai_types
response = await client.aio.models.generate_content(
diff --git a/jarvis/harness/native_computer_use.py b/jarvis/harness/native_computer_use.py
index dcd17d5809..d8019c2b39 100644
--- a/jarvis/harness/native_computer_use.py
+++ b/jarvis/harness/native_computer_use.py
@@ -186,7 +186,9 @@ class GeminiNativeCU:
Returns a list of loop action dicts, or ``None`` on ANY failure so the
caller falls back to the hand-rolled engine.
"""
- client = self._ensure_client()
+ # First use builds the client: google-genai import + (for an AQ. key)
+ # the one-time routing probe — neither belongs on the event loop.
+ client = await asyncio.to_thread(self._ensure_client)
if client is None:
return None
try:
diff --git a/jarvis/plugins/brain/gemini.py b/jarvis/plugins/brain/gemini.py
index a6b6aa1eed..e8dd67978d 100644
--- a/jarvis/plugins/brain/gemini.py
+++ b/jarvis/plugins/brain/gemini.py
@@ -12,6 +12,7 @@ where the Google SDK dependency graph has no installable wheel.
"""
from __future__ import annotations
+import asyncio
import base64
import json
import logging
@@ -728,7 +729,9 @@ class GeminiBrain:
self._cache_slots.clear()
async def complete(self, req: BrainRequest) -> AsyncIterator[BrainDelta]:
- client = self._ensure_client()
+ # First use builds the client: google-genai import + (for an AQ. key)
+ # the one-time routing probe — neither belongs on the event loop.
+ client = await asyncio.to_thread(self._ensure_client)
if self._transport == _TRANSPORT_OPENAI_COMPAT:
async for delta in stream_complete(
client,
diff --git a/jarvis/plugins/stt/gemini_api.py b/jarvis/plugins/stt/gemini_api.py
index 708fe4c8cb..8c949732cc 100644
--- a/jarvis/plugins/stt/gemini_api.py
+++ b/jarvis/plugins/stt/gemini_api.py
@@ -327,7 +327,9 @@ class GeminiSTT:
async def _post_transcription(
self, wav_bytes: bytes, *, language: str | None = None
) -> Transcript:
- client = self._ensure_client()
+ # First use builds the client: google-genai import + (for an AQ. key)
+ # the one-time routing probe — neither belongs on the event loop.
+ client = await asyncio.to_thread(self._ensure_client)
contents = self._build_contents(wav_bytes, language=language)
# ``config`` as a plain dict is accepted by google-genai; temperature 0.0
# keeps the transcription as deterministic as a generative model allows.
diff --git a/jarvis/plugins/tts/gemini_flash_tts.py b/jarvis/plugins/tts/gemini_flash_tts.py
index 65a3c42029..e4a545008d 100644
--- a/jarvis/plugins/tts/gemini_flash_tts.py
+++ b/jarvis/plugins/tts/gemini_flash_tts.py
@@ -349,7 +349,9 @@ class GeminiFlashTTS:
`language_code` can be overridden per call (e.g. "de-DE" / "en-US"),
so the multi-language pipeline can switch the voice pronunciation accordingly.
"""
- self._ensure_client()
+ # First use builds the client: google-genai import + (for an AQ. key)
+ # the one-time routing probe — neither belongs on the event loop.
+ await asyncio.to_thread(self._ensure_client)
voice = voice or self._default_voice
self.last_voice = voice
self.last_voice_provider = self.name