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(providers): say "free tier day limit", not 500 characters of JSON

Personal Jarvis Maintainerea824ad70106
diff --git a/jarvis/brain/provider_test.py b/jarvis/brain/provider_test.py
index 155ea8fb78..97516ecc7f 100644
--- a/jarvis/brain/provider_test.py
+++ b/jarvis/brain/provider_test.py
@@ -210,6 +210,70 @@ def classify_provider_error(message: str | None) -> str:
return ERROR
+# ── Turning a provider's own 4xx body into a sentence ────────────────────────
+# A provider writes its error body for a log, not for the person holding the
+# key. Google answers a spent free-tier DAY with ~500 characters of nested JSON
+# whose single actionable fact — *this model, N requests, per day* — sits in the
+# middle of it. Printed verbatim on a card the whole thing reads as a broken key
+# or a broken integration, and that is exactly what it cost live (2026-08-11):
+# the Tool Model tab went red over a daily cap while the SAME key kept serving
+# the realtime session from a different quota, so the obvious conclusion drawn
+# was "the key is wrong" — and no amount of re-testing could disprove it,
+# because every retry reproduced the same wall of JSON.
+#
+# Pure and regex-only for the same reason as the classifier above: it must read
+# a Gemini ``ClientError`` without importing any provider SDK. A shape it does
+# not recognise returns "" — the caller then keeps the raw text, so an unknown
+# error is never replaced by a confident guess about what it means.
+
+# Google's prose summary line: "limit: 20, model: gemini-3.6-flash".
+_GOOGLE_QUOTA_PROSE_RE = re.compile(r"limit:\s*(\d+)\s*,\s*model:\s*([A-Za-z0-9._-]+)")
+# The machine twins, for a body whose prose line was truncated in transport.
+_GOOGLE_QUOTA_VALUE_RE = re.compile(r'"quotaValue"\s*:\s*"?(\d+)"?')
+_GOOGLE_QUOTA_MODEL_RE = re.compile(r'"model"\s*:\s*"([A-Za-z0-9._-]+)"')
+
+# The free-tier DAILY caps — the one quota shape that comes back on a clock
+# rather than on a payment, which is why it earns its own wording. Either
+# marker alone is conclusive; Google sends both.
+_GOOGLE_FREE_TIER_DAY_MARKERS = (
+ "generaterequestsperdayperprojectpermodel-freetier",
+ "generate_content_free_tier_requests",
+)
+
+
+def explain_provider_error(message: str | None) -> str:
+ """A short actionable sentence for *message*, or ``""`` to keep it raw.
+
+ Only recognised shapes are rewritten. The caller is expected to fall back to
+ the original text (``explain_provider_error(x) or x``) so that an unfamiliar
+ error still reaches the user in full rather than being flattened into a
+ friendly sentence that does not fit it.
+ """
+ if not message:
+ return ""
+ if not any(m in message.lower() for m in _GOOGLE_FREE_TIER_DAY_MARKERS):
+ return ""
+
+ prose = _GOOGLE_QUOTA_PROSE_RE.search(message)
+ if prose is not None:
+ limit, model = prose.group(1), prose.group(2)
+ else:
+ limit_match = _GOOGLE_QUOTA_VALUE_RE.search(message)
+ model_match = _GOOGLE_QUOTA_MODEL_RE.search(message)
+ limit = limit_match.group(1) if limit_match else ""
+ model = model_match.group(1) if model_match else ""
+
+ allowance = f"{limit} requests per day" if limit else "a limited number of requests per day"
+ subject = model or "this model"
+ return (
+ f"Free tier day limit reached — Google allows {allowance} for {subject}, "
+ "and today's are spent. The key itself is valid: this cap is counted per "
+ "model per day, and a realtime session draws on a different quota "
+ "entirely. It resets at midnight Pacific time. To lift it now, add "
+ "billing to this key's Google project or point this tier at another model."
+ )
+
+
# ── The live per-tier connectivity test ──────────────────────────────────────
diff --git a/jarvis/ui/web/provider_routes.py b/jarvis/ui/web/provider_routes.py
index 0b9e110f08..43cbdb202c 100644
--- a/jarvis/ui/web/provider_routes.py
+++ b/jarvis/ui/web/provider_routes.py
@@ -1203,6 +1203,19 @@ async def _run_tier_test(spec: ProviderSpec, cfg: Any, *, model: str | None = No
)
+def _human_detail(result: Any) -> str:
+ """The card text for a provider-test *result*.
+
+ One seam for every surface that shows a failure to the user (the per-card
+ Test button, the section-health banner, the model-picker probe), so a shape
+ that has been put into words is worded the same everywhere. An unrecognised
+ error keeps its raw text — losing it would trade a confusing message for an
+ unactionable one.
+ """
+ raw = getattr(result, "detail", "") or ""
+ return _provider_test.explain_provider_error(raw) or raw
+
+
@router.post("/providers/{provider_id}/test")
async def test_provider_connection(provider_id: str, request: Request) -> ProviderTestResponse:
"""Run a REAL minimal call against ``provider_id`` and report the honest
@@ -1242,7 +1255,7 @@ async def test_provider_connection(provider_id: str, request: Request) -> Provid
return ProviderTestResponse(
provider=result.provider,
status=result.status,
- detail=result.detail,
+ detail=_human_detail(result),
latency_ms=round(result.latency_ms, 1),
integration_ok=result.status in _provider_test.INTEGRATION_OK_STATUSES,
)
@@ -1412,7 +1425,7 @@ async def _tier_section_health(
return SectionHealth(
status=status,
reason=result.status,
- detail=f"{spec.label}: {result.detail or result.status}",
+ detail=f"{spec.label}: {_human_detail(result) or result.status}",
subject_id=spec.id,
)
@@ -2210,7 +2223,7 @@ async def _apply_brain_model(
result = await _probe_brain_model(provider_id, probe_model)
probe_payload = BrainModelProbe(
status=result.status,
- detail=result.detail,
+ detail=_human_detail(result),
latency_ms=round(result.latency_ms, 1),
integration_ok=result.status in _provider_test.INTEGRATION_OK_STATUSES,
)
diff --git a/tests/unit/brain/test_free_tier_day_limit_wording.py b/tests/unit/brain/test_free_tier_day_limit_wording.py
new file mode 100644
index 0000000000..1de433efc0
--- /dev/null
+++ b/tests/unit/brain/test_free_tier_day_limit_wording.py
@@ -0,0 +1,91 @@
+"""A spent free-tier DAY must be explained in words, not dumped as raw JSON.
+
+Live forensic (2026-08-11): the Tool Model tab went red with "Not working —
+Google Gemini: ClientError: 429 Too Many Requests. {…500 characters of nested
+JSON…}". The one fact that mattered — Google allows 20 generate_content
+requests per DAY for gemini-3.6-flash on a free key, and they were spent — sat
+in the middle of that body. The same key was at that moment serving a live
+realtime session perfectly well, because the Live API draws on a different
+quota, so the card read as "your key is broken" while the key was fine. Every
+retry reproduced the identical wall of JSON, which made the wrong conclusion
+look confirmed.
+
+The status classification is deliberately unchanged: a daily cap does not come
+back before midnight Pacific, so the runtime must keep treating it as terminal
+for the session and cross to another provider family (AP-22). Only the wording
+the user reads is at stake here.
+"""
+from __future__ import annotations
+
+from jarvis.brain.provider_test import (
+ NO_CREDITS,
+ classify_provider_error,
+ explain_provider_error,
+)
+
+# The live body, verbatim in shape: prose summary line + the QuotaFailure twin.
+GEMINI_FREE_TIER_DAY = (
+ "ClientError: 429 Too Many Requests. {'message': '{\\n \"error\": {\\n "
+ '"code": 429,\\n "message": "You exceeded your current quota, please check '
+ "your plan and billing details. For more information on this error, head "
+ "to: https://ai.google.dev/gemini-api/docs/rate-limits. \\\\n* Quota "
+ "exceeded for metric: generativelanguage.googleapis.com/"
+ "generate_content_free_tier_requests, limit: 20, model: gemini-3.6-flash"
+ '\\nPlease retry in 12.029047747s.",\\n "status": "RESOURCE_EXHAUSTED",\\n '
+ '"details": [\\n {\\n "@type": "type.googleapis.com/google.rpc.QuotaFailure"'
+ ',\\n "violations": [\\n {\\n "quotaMetric": "generativelanguage.googleapis'
+ '.com/generate_content_free_tier_requests",\\n "quotaId": "GenerateRequests'
+ 'PerDayPerProjectPerModel-FreeTier",\\n "quotaDimensions": {\\n "location": '
+ '"global",\\n "model": "gemini-3.6-flash"\\n },\\n "quotaValue": "20"\\n }\\n '
+ "]\\n }\\n ]\\n }\\n}', 'status': 'Too Many Requests'}"
+)
+
+
+def test_free_tier_day_limit_names_the_number_and_the_model():
+ said = explain_provider_error(GEMINI_FREE_TIER_DAY)
+ assert "20 requests per day" in said
+ assert "gemini-3.6-flash" in said
+
+
+def test_free_tier_day_limit_clears_the_key_and_names_the_reset():
+ said = explain_provider_error(GEMINI_FREE_TIER_DAY)
+ # The single misreading this exists to prevent.
+ assert "key itself is valid" in said
+ assert "midnight Pacific" in said
+ # …and the raw JSON does not survive into the card text.
+ assert "quotaId" not in said
+ assert "RESOURCE_EXHAUSTED" not in said
+
+
+def test_free_tier_day_limit_survives_a_truncated_prose_line():
+ """A transport that drops the prose summary still leaves the machine twin."""
+ machine_only = (
+ '{"quotaId": "GenerateRequestsPerDayPerProjectPerModel-FreeTier", '
+ '"quotaDimensions": {"model": "gemini-3.6-flash"}, "quotaValue": "20"}'
+ )
+ said = explain_provider_error(machine_only)
+ assert "20 requests per day" in said
+ assert "gemini-3.6-flash" in said
+
+
+def test_unrecognised_errors_keep_their_raw_text():
+ """An unknown shape must not be flattened into a confident wrong sentence."""
+ assert explain_provider_error("Error code: 401 - invalid x-api-key") == ""
+ assert explain_provider_error("Connection error.") == ""
+ assert explain_provider_error("") == ""
+ assert explain_provider_error(None) == ""
+
+
+def test_a_rate_limit_that_is_not_the_free_tier_day_cap_is_left_alone():
+ """Per-MINUTE throttling clears by itself — different advice, so no rewrite."""
+ per_minute = (
+ "429 Too Many Requests. Quota exceeded for metric: "
+ "generativelanguage.googleapis.com/generate_requests_per_model_per_minute, "
+ "limit: 10, model: gemini-3.6-flash"
+ )
+ assert explain_provider_error(per_minute) == ""
+
+
+def test_classification_is_unchanged_by_the_wording():
+ """The runtime must still treat a spent day as terminal, not transient."""
+ assert classify_provider_error(GEMINI_FREE_TIER_DAY) == NO_CREDITS