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(local-models): a refused Agents-tier pair is explained in one plain sentence, never a dumped error body

rubenluetke10-beep542fd3620485
diff --git a/jarvis/local_models/assistant_session.py b/jarvis/local_models/assistant_session.py
index 2da9a898ee..4d5aea5c65 100644
--- a/jarvis/local_models/assistant_session.py
+++ b/jarvis/local_models/assistant_session.py
@@ -174,12 +174,7 @@ async def probe_live(
try:
result = await run(spec, cfg, model=model or None, timeout_s=timeout_s)
ok = result.status == provider_test.OK
- reason = (
- ""
- if ok
- else f"{provider} ({model or 'default model'}): {result.status.replace('_', ' ')}"
- + (f" — {result.detail}" if result.detail else "")
- )
+ reason = "" if ok else _plain_reason(provider, model, result)
except Exception as exc: # noqa: BLE001 — a probe crash is "not usable", logged
log.warning("agents tier: live probe of %s/%s crashed: %s", provider, model, exc)
ok, reason = False, f"{provider} ({model}): probe failed — {exc}"
@@ -188,6 +183,34 @@ async def probe_live(
return out
+_PLAIN_BY_STATUS: Final[dict[str, str]] = {
+ "no_credits": "the account has no credit or quota left for this model",
+ "rate_limited": "the provider is rate-limiting this key right now",
+ "bad_key": "the key was refused",
+ "model_unavailable": "the provider no longer offers this model",
+ "unreachable": "the provider could not be reached",
+ "not_configured": "no key is stored for it",
+}
+
+
+def _plain_reason(provider: str, model: str, result: Any) -> str:
+ """One readable sentence, never a dumped error body.
+
+ The status vocabulary is the API-keys page's; the provider's own text is
+ kept only when it is short and free of JSON braces (a 404 body is not
+ something a person should have to read in a status line).
+ """
+ status = str(getattr(result, "status", "") or "error")
+ head = f"{provider} ({model or 'default model'}): "
+ plain = _PLAIN_BY_STATUS.get(status)
+ detail = str(getattr(result, "detail", "") or "").strip()
+ if plain:
+ return head + plain + "."
+ if detail and "{" not in detail and len(detail) <= 140:
+ return head + detail
+ return head + status.replace("_", " ") + "."
+
+
def agents_tier(
cfg: Any,
*,
diff --git a/tests/unit/local_models/test_assistant_session.py b/tests/unit/local_models/test_assistant_session.py
index ba19c2f0c2..c28136c3f8 100644
--- a/tests/unit/local_models/test_assistant_session.py
+++ b/tests/unit/local_models/test_assistant_session.py
@@ -124,7 +124,7 @@ async def test_probe_live_classifies_with_the_provider_test_and_caches() -> None
cfg = _cfg("gemini", "g-pro", fallback_provider="openai", fallback_model="o-1")
pairs = policy.chain_candidates(cfg, usable=lambda _p: True, tool_capable=lambda _p: True)
out = await policy.probe_live(cfg, pairs, tester=_tester)
- assert out[("gemini", "g-pro")][0] is False and "no credits" in out[("gemini", "g-pro")][1]
+ assert out[("gemini", "g-pro")] == (False, "gemini (g-pro): the account has no credit or quota left for this model.")
assert out[("openai", "o-1")] == (True, "")
again = await policy.probe_live(cfg, pairs, tester=_tester)
assert again == out and len(calls) == 2 # cached, no second real call