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(brain): a Vertex host without a login stops costing every tool-model turn 7-10 s, and no delegated turn stays mute past 3 s

rubenluetke10-beep3bb5fb1cb5a1
diff --git a/jarvis/brain/manager.py b/jarvis/brain/manager.py
index c102b4cd29..203b7dacdc 100644
--- a/jarvis/brain/manager.py
+++ b/jarvis/brain/manager.py
@@ -12790,6 +12790,14 @@ def _is_missing_key_exc(msg: str) -> bool:
"not configured",
"api-key nicht gesetzt", "apikey missing",
"not logged in", "please run /login", "credentials.json",
+ # Vertex AI's Google Cloud project path signs with Application Default
+ # Credentials; a host without a gcloud login or service account raises
+ # google-auth's DefaultCredentialsError ("Your default credentials were
+ # not found"). Live 2026-08-22 18:40/18:42: classified as call_fail,
+ # the keyless Tool Model led the chain on EVERY delegated voice turn and
+ # paid 7-10 s for the same miss before a working provider was tried.
+ "default credentials were not found", "defaultcredentialserror",
+ "application default credentials were not found",
))
diff --git a/jarvis/core/google_genai.py b/jarvis/core/google_genai.py
index c96719db7a..af98bf5e07 100644
--- a/jarvis/core/google_genai.py
+++ b/jarvis/core/google_genai.py
@@ -264,6 +264,16 @@ _CLOUD_PLATFORM_SCOPE = "https://www.googleapis.com/auth/cloud-platform"
_ADC_LOCK = threading.Lock()
_ADC_CACHE: dict[str, Any] = {}
+#: A resolution that RAISED is remembered too — (monotonic deadline, reason) —
+#: so the next call answers "no credential" in microseconds instead of paying
+#: google-auth's 5-8 s probe again. Live 2026-08-22 18:40 and 18:42: a Tool
+#: Model pinned to Vertex on a host with no gcloud login paid 7.4-9.5 s per
+#: delegated voice turn for the identical DefaultCredentialsError, on EVERY
+#: turn, before the chain even reached a provider that could answer. A login
+#: that appears later is still picked up: the miss expires, and
+#: :func:`reset_vertex_credentials_cache` (login changes) clears it at once.
+_ADC_MISSING: dict[str, tuple[float, str]] = {}
+_ADC_RETRY_AFTER_S = 600.0
def _adc_cache_key() -> str:
@@ -298,28 +308,36 @@ def vertex_credentials() -> Any | None:
BLOCKING on the first call (see the measurement above) — call it from a
worker thread, never on the event loop. Later calls answer from the cache.
- ``None`` means google-auth could not resolve a credential; nothing is
- cached for that case, so a login that appears later is picked up, and the
- caller leaves the SDK's own lazy resolution in place, which surfaces
- Google's honest error on the first real call.
+ ``None`` means google-auth could not resolve a credential. A resolution
+ that RAISED is remembered for ``_ADC_RETRY_AFTER_S`` (see ``_ADC_MISSING``)
+ so the miss is not re-paid on every turn; :func:`vertex_credentials_missing_reason`
+ exposes it and the project-path client builder fails fast on it. A login
+ that appears later is picked up once the miss expires or the cache is reset.
"""
key = _adc_cache_key()
cached = _ADC_CACHE.get(key)
if cached is not None:
return cached
+ if vertex_credentials_missing_reason(key):
+ return None
with _ADC_LOCK:
cached = _ADC_CACHE.get(key) # a concurrent loader may have won
if cached is not None:
return cached
+ if vertex_credentials_missing_reason(key):
+ return None
started = time.perf_counter()
try:
credentials = _load_application_default_credentials()
except Exception as exc: # noqa: BLE001 — auth trouble surfaces on the first call
+ reason = f"{type(exc).__name__}: {exc}"
+ _ADC_MISSING[key] = (time.monotonic() + _ADC_RETRY_AFTER_S, reason)
log.info(
- "Vertex AI: Application Default Credentials not resolvable (%s: %s) — "
- "the SDK resolves auth on the first call instead.",
- type(exc).__name__,
- exc,
+ "Vertex AI: Application Default Credentials not resolvable (%s) — "
+ "remembered for %.0f s so no call pays this probe again; the "
+ "Vertex project path is unavailable until a login appears.",
+ reason,
+ _ADC_RETRY_AFTER_S,
)
return None
if credentials is None:
@@ -383,10 +401,27 @@ def warm_vertex_credentials() -> bool:
return bool(getattr(credentials, "valid", False))
+def vertex_credentials_missing_reason(key: str | None = None) -> str:
+ """Why the last ADC resolution failed, or ``""`` when none is remembered.
+
+ Lock-free and instant (a dict read): the event loop and the client
+ builders ask this before anything that could block. An expired miss reads
+ as "not remembered" so the next resolution probes google-auth again.
+ """
+ entry = _ADC_MISSING.get(_adc_cache_key() if key is None else key)
+ if entry is None:
+ return ""
+ deadline, reason = entry
+ if time.monotonic() >= deadline:
+ return ""
+ return reason
+
+
def reset_vertex_credentials_cache() -> None:
- """Forget the shared credentials (tests; login changes)."""
+ """Forget the shared credentials AND any remembered miss (tests; login changes)."""
with _ADC_LOCK:
_ADC_CACHE.clear()
+ _ADC_MISSING.clear()
# ── one TLS trust store per process ──────────────────────────────────────────
@@ -794,6 +829,21 @@ def build_vertex_client(
settings = settings.for_realtime()
kwargs = _client_kwargs(api_key, "vertex", _with_shared_tls(http_options), settings)
if "project" in kwargs:
+ missing = vertex_credentials_missing_reason()
+ if missing:
+ # Fail NOW, in microseconds, with the reason google-auth gave the
+ # last time. Building the client anyway would let the SDK resolve
+ # auth itself on the first call — the same 5-8 s probe, the same
+ # DefaultCredentialsError — on every turn (live 2026-08-22 18:40).
+ # The wording is what the brain chain dead-lists on (missing_key):
+ # a provider without a credential must not lead the chain again.
+ raise RuntimeError(
+ "Vertex AI is not configured on this host: Application Default "
+ f"Credentials were not found ({missing}). Run `gcloud auth "
+ "application-default login` or point GOOGLE_APPLICATION_CREDENTIALS "
+ "at a service-account file; the project path is retried after "
+ f"{_ADC_RETRY_AFTER_S:.0f} s."
+ )
credentials = _adc_for_sync_build()
if credentials is not None:
kwargs["credentials"] = credentials
diff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.py
index e10fab6595..351adf10f7 100644
--- a/jarvis/realtime/session.py
+++ b/jarvis/realtime/session.py
@@ -630,7 +630,13 @@ class _LoopLagProbe:
# classify and the upper cap for every bridge (tests pin it low). A
# capability-limited provider hands every action to the slower orchestrator,
# so its cap is tighter still. Ready results pre-empt the bridge lifecycle.
-_DELEGATE_BRIDGE_DELAY_S = 6.0
+# Same number as the short-work grace (3 s) since 2026-08-22: an unclassified
+# delegated turn sat 6.0 s mute before its first sign of life (live 18:40:12,
+# "unclassified line requested 6.00 s after dispatch") while the maintainer's
+# benchmark — a phone assistant — answers outright in 1-3 s. Whatever the turn
+# is, the user hears SOMETHING within three seconds; a result ready before
+# that still pre-empts the line.
+_DELEGATE_BRIDGE_DELAY_S = SHORT_GRACE_S
_CAPABILITY_LIMITED_DELEGATE_BRIDGE_DELAY_S = 1.0
# One source of truth for the short-work grace: the shared core's constant
# (3 s since 2026-08-18, ADR-0033). Kept as a module attribute so tests can
diff --git a/tests/unit/brain/test_vertex_adc_missing_classification.py b/tests/unit/brain/test_vertex_adc_missing_classification.py
new file mode 100644
index 0000000000..4200f70524
--- /dev/null
+++ b/tests/unit/brain/test_vertex_adc_missing_classification.py
@@ -0,0 +1,58 @@
+"""A Vertex project path without Application Default Credentials is a DEAD
+provider for the session (missing_key), not a transient call failure.
+
+Live 2026-08-22 18:40:06 → 18:40:15 and 18:42:14 → 18:42:21 (gemini-live,
+delegated voice turns): ``[brain.tool_model] provider = "vertex"`` on a host
+with no gcloud login. Every delegated turn led the chain with Vertex, paid
+google-auth's 7-10 s probe for the identical ``DefaultCredentialsError: Your
+default credentials were not found``, and only then crossed to a provider that
+could answer — the single biggest slice of a 34 s "tool model" turn. The
+classifier knew keys, not ADC, so the miss was ``call_fail`` and never
+dead-listed. Pinned here: both the raw google-auth wording and the fast-fail
+message :func:`jarvis.core.google_genai.build_vertex_client` raises on a
+remembered miss classify as ``missing_key``.
+"""
+
+from __future__ import annotations
+
+from jarvis.brain.manager import _DEAD_LIST_KINDS, _classify_provider_error
+
+GOOGLE_AUTH_WORDING = (
+ "Your default credentials were not found. To set up Application Default "
+ "Credentials, see https://cloud.google.com/docs/authentication/external/set-up-adc "
+ "for more information."
+)
+
+FAST_FAIL_WORDING = (
+ "Vertex AI is not configured on this host: Application Default Credentials "
+ "were not found (DefaultCredentialsError: Your default credentials were not "
+ "found). Run `gcloud auth application-default login` or point "
+ "GOOGLE_APPLICATION_CREDENTIALS at a service-account file; the project path "
+ "is retried after 600 s."
+)
+
+
+def test_google_auth_default_credentials_not_found_dead_lists_vertex() -> None:
+ kind = _classify_provider_error(GOOGLE_AUTH_WORDING, default="call_fail")
+ assert kind == "missing_key"
+ assert kind in _DEAD_LIST_KINDS
+
+
+def test_the_exception_class_name_alone_is_enough() -> None:
+ kind = _classify_provider_error(
+ "DefaultCredentialsError: could not automatically determine credentials",
+ default="call_fail",
+ )
+ assert kind == "missing_key"
+
+
+def test_the_fast_fail_message_dead_lists_too() -> None:
+ kind = _classify_provider_error(FAST_FAIL_WORDING, default="call_fail")
+ assert kind in _DEAD_LIST_KINDS
+
+
+def test_an_ordinary_call_failure_is_untouched() -> None:
+ assert (
+ _classify_provider_error("Error code: 500 - internal error", default="call_fail")
+ == "call_fail"
+ )
diff --git a/tests/unit/core/test_google_vertex_project_path.py b/tests/unit/core/test_google_vertex_project_path.py
index 7543351b35..19fc9f5c7a 100644
--- a/tests/unit/core/test_google_vertex_project_path.py
+++ b/tests/unit/core/test_google_vertex_project_path.py
@@ -411,8 +411,15 @@ def test_credentials_are_loaded_once_and_shared(adc: dict) -> None:
assert adc["loads"] == 1, "google.auth.default() must run once per process"
-def test_a_failed_resolution_is_not_cached(monkeypatch: pytest.MonkeyPatch) -> None:
- """A login that appears later must be picked up, not shadowed by a miss."""
+def test_a_failed_resolution_is_remembered_for_a_bounded_time(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """The miss is paid ONCE, not on every turn — and a login that appears
+ later is still picked up: the miss expires, and a cache reset clears it.
+
+ Live 2026-08-22 18:40/18:42: the Tool Model pinned to Vertex on a host
+ without a gcloud login re-ran google-auth's 5-8 s probe on every delegated
+ voice turn for the identical DefaultCredentialsError."""
attempts = {"n": 0}
def _boom():
@@ -423,7 +430,54 @@ def test_a_failed_resolution_is_not_cached(monkeypatch: pytest.MonkeyPatch) -> N
assert gg.vertex_credentials() is None
assert gg.cached_vertex_credentials() is None
assert gg.vertex_credentials() is None
+ assert attempts["n"] == 1, "the second call must answer from the remembered miss"
+ assert "no ADC on this host" in gg.vertex_credentials_missing_reason()
+
+ # The miss expires → google-auth is asked again (a login may be there now).
+ now = {"t": 0.0}
+ monkeypatch.setattr(gg.time, "monotonic", lambda: now["t"])
+ gg.reset_vertex_credentials_cache()
+ assert gg.vertex_credentials() is None
assert attempts["n"] == 2
+ now["t"] = gg._ADC_RETRY_AFTER_S + 1.0
+ assert gg.vertex_credentials_missing_reason() == ""
+ assert gg.vertex_credentials() is None
+ assert attempts["n"] == 3
+
+ # A reset (login changes) forgets the miss at once.
+ gg.reset_vertex_credentials_cache()
+ assert gg.vertex_credentials_missing_reason() == ""
+
+
+def test_the_project_client_fails_fast_on_a_remembered_miss(
+ monkeypatch: pytest.MonkeyPatch, stub_genai: _StubGenaiModule
+) -> None:
+ """With the miss remembered, building the project-path client raises at
+ once — the SDK must not get to re-run the same probe on its first call —
+ and the message carries the wording the brain chain dead-lists on."""
+
+ def _boom():
+ raise RuntimeError("DefaultCredentialsError: Your default credentials were not found")
+
+ monkeypatch.setattr(gg, "_load_application_default_credentials", _boom)
+ monkeypatch.setattr(gg, "vertex_project_settings", lambda: _project("prod-proj", "global"))
+ assert gg.vertex_credentials() is None # the one paid probe
+
+ with pytest.raises(RuntimeError, match="Application Default Credentials were not found"):
+ gg.build_vertex_client("")
+ assert stub_genai.calls == [], "no client may be built without a credential"
+
+ from jarvis.brain.manager import _DEAD_LIST_KINDS, _classify_provider_error
+
+ try:
+ gg.build_vertex_client("")
+ except RuntimeError as exc:
+ assert _classify_provider_error(str(exc), default="call_fail") in _DEAD_LIST_KINDS
+
+ # An express key never consults the miss: it authenticates by the key.
+ monkeypatch.setattr(gg, "vertex_project_settings", lambda: _project(None))
+ gg.build_vertex_client("AQ.express")
+ assert len(stub_genai.calls) == 1
def test_the_project_client_is_handed_the_shared_credentials(