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(stt): cross to a keyed cloud STT family before dropping to local whisper

Ruben Lütkeab5fad975320
diff --git a/jarvis/plugins/stt/__init__.py b/jarvis/plugins/stt/__init__.py
index 1af4128440..1bd740dd58 100644
--- a/jarvis/plugins/stt/__init__.py
+++ b/jarvis/plugins/stt/__init__.py
@@ -38,6 +38,18 @@ _STT_SECRET_CANDIDATES: dict[str, tuple[tuple[str, str], ...]] = {
"deepgram-nova3": (("deepgram_api_key", "DEEPGRAM_API_KEY"),),
}
+# Cross-family probe order when the configured cloud STT has no usable key: the
+# family the maintainer ships first, then the common BYO-key alternatives. Only a
+# family that BOTH has a key AND is registered as a `jarvis.stt` entry-point is
+# ever chosen (unregistered names — e.g. openai/deepgram today — are skipped, so
+# we never promise an STT we cannot build). This mirrors the TTS factory's
+# `_TTS_CROSS_FAMILY_ORDER`; it is what lets a fresh downloader whose only key is
+# an OpenRouter key (a gateway shared with the brain) get working voice input
+# instead of dead-ending on local faster-whisper the base install never shipped.
+_STT_CROSS_FAMILY_ORDER: tuple[str, ...] = (
+ "groq-api", "openrouter-stt", "openai-api", "deepgram",
+)
+
def _stt_has_credential(provider_name: str, kwargs: dict[str, Any]) -> bool:
"""Whether the configured cloud STT has a usable key (else: fall to local).
@@ -57,6 +69,58 @@ def _stt_has_credential(provider_name: str, kwargs: dict[str, Any]) -> bool:
return _cfg.get_secret_any(candidates) is not None
+def _stt_family_has_key(provider_name: str) -> bool:
+ """Whether the STT *family* ``provider_name`` has a usable credential on this host.
+
+ Like :func:`_stt_has_credential` but without kwargs — used by the cross-family
+ resolver to probe candidate families. Honours the team proxy for the proxy-
+ capable ``groq-api`` (a proxied provider carries a per-user token even with no
+ local key), and treats unknown / third-party providers (no entry in
+ ``_STT_SECRET_CANDIDATES``) as keyed so their path is never gated.
+ """
+ from jarvis.core import config as _cfg
+
+ if provider_name == "groq-api":
+ try:
+ ep = _cfg.resolve_provider_endpoint("groq-api")
+ if getattr(ep, "via_proxy", False) and getattr(ep, "credential", None):
+ return True
+ except Exception as exc: # noqa: BLE001 — a proxy probe must never break STT build
+ logger.debug("STT groq proxy probe failed ({}); using key candidates.", exc)
+ candidates = _STT_SECRET_CANDIDATES.get(provider_name)
+ if candidates is None:
+ return True
+ return _cfg.get_secret_any(candidates) is not None
+
+
+def _resolve_keyed_stt_provider(primary_name: str) -> str:
+ """Pick a cloud STT the host can actually run (open-source AP-22).
+
+ Keeps the configured provider when it has a usable key — so the maintainer
+ path (whose configured key resolves) is untouched. Otherwise crosses to the
+ first cloud STT family the user DOES have a key for AND that is registered as
+ an entry-point. When NO cloud family has a usable key, returns the configured
+ name unchanged; the caller then drops to the key-free local faster-whisper as
+ the universal floor. Mirrors the TTS factory's ``_resolve_keyed_tts_provider``.
+ """
+ if _stt_family_has_key(primary_name):
+ return primary_name
+ for cand in _STT_CROSS_FAMILY_ORDER:
+ if cand == primary_name:
+ continue
+ if _stt_family_has_key(cand) and _load_provider_class(cand) is not None:
+ logger.warning(
+ "STT provider {!r} has no usable API key; crossing to {!r} — the "
+ "cloud STT family the user actually has a key for — so voice input "
+ "still works for a single-key user (open-source AP-22). Set "
+ "[stt].provider to silence this.",
+ primary_name,
+ cand,
+ )
+ return cand
+ return primary_name
+
+
def _load_provider_class(name: str) -> type | None:
"""Resolve an STT provider class by its entry-point ``name`` (e.g. ``groq-api``)."""
eps = importlib_metadata.entry_points()
@@ -84,6 +148,13 @@ def build_stt_from_config(stt_cfg: Any) -> Any:
no entry-point or raises on construction.
"""
provider_name = (getattr(stt_cfg, "provider", "") or "").strip()
+ # Open-source AP-22: when the configured cloud STT has no usable key, cross to
+ # a cloud STT family the user DOES have a key for BEFORE dropping to local
+ # faster-whisper (which is not installed on a base/headless host). The
+ # maintainer (whose configured key resolves) is unaffected; local whisper stays
+ # the last-resort floor when no cloud family has a usable key.
+ if provider_name and provider_name != "faster-whisper":
+ provider_name = _resolve_keyed_stt_provider(provider_name)
language = getattr(stt_cfg, "language", "auto")
language = language if language and language != "auto" else None
bias_prompt = (getattr(stt_cfg, "bias_prompt", "") or "").strip()
diff --git a/tests/unit/plugins/stt/test_stt_keyaware_fallback.py b/tests/unit/plugins/stt/test_stt_keyaware_fallback.py
index e27cb7aea4..d8eb77e0bc 100644
--- a/tests/unit/plugins/stt/test_stt_keyaware_fallback.py
+++ b/tests/unit/plugins/stt/test_stt_keyaware_fallback.py
@@ -66,3 +66,94 @@ def test_cloud_stt_with_key_is_still_used(monkeypatch):
"When the cloud STT's key IS present, the factory must use the cloud "
"provider, not needlessly fall back to local."
)
+
+
+def _only(family_key: str):
+ """A get_secret_any double where ONLY ``family_key`` resolves to a key."""
+
+ def _fake(candidates) -> str | None:
+ keys = {c[0] for c in candidates}
+ return "real-key" if family_key in keys else None
+
+ return _fake
+
+
+def test_resolver_crosses_to_openrouter_when_only_it_has_a_key(monkeypatch):
+ """Configured groq with no groq key, but an OpenRouter key present -> cross.
+
+ This is THE common fresh-download case: the single key is an OpenRouter key
+ (a gateway shared with the brain), and openrouter-stt reuses it. The resolver
+ must pick it instead of dead-ending on local whisper (open-source AP-22).
+ """
+ monkeypatch.setattr(stt_pkg, "_load_provider_class", lambda name: _FakeCloudSTT)
+ monkeypatch.setattr(
+ cfg,
+ "resolve_provider_endpoint",
+ lambda pid, **kw: ResolvedEndpoint(base_url=None, credential=None, via_proxy=False),
+ )
+ monkeypatch.setattr(cfg, "get_secret_any", _only("openrouter_api_key"))
+
+ assert stt_pkg._resolve_keyed_stt_provider("groq-api") == "openrouter-stt"
+
+
+def test_resolver_keeps_provider_when_no_cloud_family_has_a_key(monkeypatch):
+ """No cloud STT family keyed -> keep configured name (caller drops to local)."""
+ monkeypatch.setattr(stt_pkg, "_load_provider_class", lambda name: _FakeCloudSTT)
+ monkeypatch.setattr(
+ cfg,
+ "resolve_provider_endpoint",
+ lambda pid, **kw: ResolvedEndpoint(base_url=None, credential=None, via_proxy=False),
+ )
+ monkeypatch.setattr(cfg, "get_secret_any", lambda candidates: None)
+
+ assert stt_pkg._resolve_keyed_stt_provider("groq-api") == "groq-api"
+
+
+def test_resolver_skips_a_keyed_but_unregistered_family(monkeypatch):
+ """A family with a key but NO entry-point must be skipped, not promised.
+
+ openai has a candidate key slot but ships no jarvis.stt entry-point today, so
+ an openai-only user still falls through to local whisper rather than getting a
+ provider that cannot be built.
+ """
+ # Only openrouter-stt resolves to a class; every other name is "unregistered".
+ monkeypatch.setattr(
+ stt_pkg,
+ "_load_provider_class",
+ lambda name: _FakeCloudSTT if name == "openrouter-stt" else None,
+ )
+ monkeypatch.setattr(
+ cfg,
+ "resolve_provider_endpoint",
+ lambda pid, **kw: ResolvedEndpoint(base_url=None, credential=None, via_proxy=False),
+ )
+ # Only an openai key is present — but openai is unregistered here.
+ monkeypatch.setattr(cfg, "get_secret_any", _only("openai_api_key"))
+
+ assert stt_pkg._resolve_keyed_stt_provider("groq-api") == "groq-api"
+
+
+def test_cross_family_build_uses_cloud_not_local(monkeypatch):
+ """End to end: groq default + only an OpenRouter key -> cloud STT, not local."""
+ loaded: dict[str, str] = {}
+
+ def _fake_load(name: str):
+ loaded["name"] = name
+ return _FakeCloudSTT
+
+ monkeypatch.setattr(stt_pkg, "_load_provider_class", _fake_load)
+ monkeypatch.setattr(
+ cfg,
+ "resolve_provider_endpoint",
+ lambda pid, **kw: ResolvedEndpoint(base_url=None, credential=None, via_proxy=False),
+ )
+ monkeypatch.setattr(fwhisper, "FasterWhisperProvider", _FakeLocalSTT)
+ monkeypatch.setattr(cfg, "get_secret_any", _only("openrouter_api_key"))
+
+ provider = stt_pkg.build_stt_from_config(STTConfig(provider="groq-api"))
+
+ assert isinstance(provider, _FakeCloudSTT), (
+ "A single-key OpenRouter user must get cloud STT via the cross-family "
+ "resolver, not dead-end on local faster-whisper the base install lacks."
+ )
+ assert loaded["name"] == "openrouter-stt"