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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix: show why a GPT-Live call could not start (#1078)
Ruben Lütke0abfa02f08db
diff --git a/dodaios/browser_voice/route.py b/dodaios/browser_voice/route.pyindex da5f5e478c..636e7f8a1a 100644--- a/dodaios/browser_voice/route.py+++ b/dodaios/browser_voice/route.py@@ -42,11 +42,36 @@ _UNSAFE_FALLBACK_DETAIL = ("closed without replaying audio through the classic pipeline to avoid ""duplicate actions.")+_USAGE_FALLBACK_DISABLED_NOTE = (+ "Automatic usage-billed API fallback is disabled; "+ "Dodaios did not switch to another provider."+)_USAGE_FALLBACK_DISABLED_DETAIL = ("The selected voice connection could not start. Check its connection and "- "model settings. Automatic usage-billed API fallback is disabled; "- "Dodaios did not switch to another provider."+ "model settings. " + _USAGE_FALLBACK_DISABLED_NOTE)+++def _fallback_disabled_detail(error: BaseException | str | None) -> str:+ """The person-facing text when the selected live provider cannot start.++ A classified subscription failure (plan not offered, reconnect needed,+ allowance exhausted, ...) keeps its static message so the person learns+ what to fix. Anything else gets the generic text: raw provider detail+ never reaches the surface.+ """+ try:+ from dodaios.plugins.realtime.openai_subscription_live import (+ static_failure_message,+ )++ reason = static_failure_message(error)+ except Exception: # noqa: BLE001 - the generic text is always safe+ log.debug("browser_voice: failure classification unavailable", exc_info=True)+ reason = None+ if not reason:+ return _USAGE_FALLBACK_DISABLED_DETAIL+ return f"{reason} {_USAGE_FALLBACK_DISABLED_NOTE}"# The close reason a browser shows the person when the classic chain cannot be# built. WebSocket close reasons are capped at 123 bytes._SPEECH_STACK_UNAVAILABLE_REASON = (@@ -512,7 +537,9 @@ async def browser_voice_ws(ws: WebSocket) -> None:dropped_audio_frames = 0audio_sender_failed = asyncio.Event()- async def _switch_to_classic(reason: str) -> bool:+ async def _switch_to_classic(+ reason: str, error: BaseException | None = None+ ) -> bool:nonlocal sessionif not bool(getattr(session, "is_realtime", False)):return False@@ -527,7 +554,9 @@ async def browser_voice_ws(ws: WebSocket) -> None:await _send_json({"type": "provider_error",- "error": _USAGE_FALLBACK_DISABLED_DETAIL,+ "error": _fallback_disabled_detail(+ error if error is not None else reason+ ),})except Exception: # noqa: BLE001 - surface may already be gone@@ -596,7 +625,7 @@ async def browser_voice_ws(ws: WebSocket) -> None:timeout=_TRANSPORT_SEND_TIMEOUT_S,)except Exception as exc: # noqa: BLE001 - cross to classic once- if not await _switch_to_classic(str(exc)):+ if not await _switch_to_classic(str(exc), exc):raiseawait asyncio.wait_for(session.handle_audio_frame(data),@@ -680,7 +709,7 @@ async def browser_voice_ws(ws: WebSocket) -> None:if not can_fallback:log.warning("browser_voice: control handling failed: %s", exc)break- if not await _switch_to_classic(str(exc)):+ if not await _switch_to_classic(str(exc), exc):breakfinally:output.close()diff --git a/dodaios/plugins/realtime/openai_subscription_live.py b/dodaios/plugins/realtime/openai_subscription_live.pyindex 2643d15c0e..504bf56d1f 100644--- a/dodaios/plugins/realtime/openai_subscription_live.py+++ b/dodaios/plugins/realtime/openai_subscription_live.py@@ -49,6 +49,47 @@ _CALL_ID = re.compile()+def _static_message(code: str, plan: str = "") -> str:+ """The fixed, provider-free text for one classified failure ``code``."""+ plan = plan.strip().lower()+ named = f" ({plan.replace('_', ' ').title()} plan)" if _PLAN.fullmatch(plan) else ""+ messages = {+ "authentication_required": "Reconnect your ChatGPT subscription before starting voice.",+ "access_denied": "The ChatGPT account does not allow this GPT-Live session.",+ "voice_not_offered": (+ f"The selected ChatGPT account{named} is not offered subscription voice. "+ "Check its plan or select another account in Agent accounts."+ ),+ "quota_exhausted": "The ChatGPT subscription voice allowance is exhausted.",+ "rate_limited": "ChatGPT subscription voice is temporarily rate limited.",+ "invalid_configuration": "The selected subscription voice configuration was rejected.",+ "invalid_response": "ChatGPT subscription voice returned an invalid response.",+ "connection_lost": "The ChatGPT subscription voice connection was lost.",+ "control_unavailable": "The ChatGPT subscription voice control connection failed.",+ "provider_error": "ChatGPT subscription voice is temporarily unavailable.",+ }+ return messages.get(code, messages["provider_error"])+++_STATIC_CODES = (+ "authentication_required",+ "access_denied",+ "voice_not_offered",+ "quota_exhausted",+ "rate_limited",+ "invalid_configuration",+ "invalid_response",+ "connection_lost",+ "control_unavailable",+ "provider_error",+)+_NAMED_PLAN_MESSAGE = re.compile(+ r"The selected ChatGPT account \(([A-Za-z0-9][A-Za-z0-9_ -]{0,31}) plan\) is not "+ r"offered subscription voice\. Check its plan or select another account in "+ r"Agent accounts\.\Z"+)++class SubscriptionLiveError(RuntimeError):"""Static, safe error classification for UI recovery and no-key fallback."""@@ -57,24 +98,38 @@ class SubscriptionLiveError(RuntimeError):) -> None:self.code = codeself.allocation_unconfirmed = allocation_unconfirmed- plan = plan.strip().lower()- named = f" ({plan.replace('_', ' ').title()} plan)" if _PLAN.fullmatch(plan) else ""- messages = {- "authentication_required": "Reconnect your ChatGPT subscription before starting voice.",- "access_denied": "The ChatGPT account does not allow this GPT-Live session.",- "voice_not_offered": (- f"The selected ChatGPT account{named} is not offered subscription voice. "- "Check its plan or select another account in Agent accounts."- ),- "quota_exhausted": "The ChatGPT subscription voice allowance is exhausted.",- "rate_limited": "ChatGPT subscription voice is temporarily rate limited.",- "invalid_configuration": "The selected subscription voice configuration was rejected.",- "invalid_response": "ChatGPT subscription voice returned an invalid response.",- "connection_lost": "The ChatGPT subscription voice connection was lost.",- "control_unavailable": "The ChatGPT subscription voice control connection failed.",- "provider_error": "ChatGPT subscription voice is temporarily unavailable.",- }- super().__init__(messages.get(code, messages["provider_error"]))+ super().__init__(_static_message(code, plan))+++def static_failure_message(error: BaseException | str | None) -> str | None:+ """Return the safe, classified text behind a subscription voice failure.++ Accepts the raised exception (its cause/context chain is searched for a+ :class:`SubscriptionLiveError`) or a failure string a session recorded.+ A string only counts when it is exactly one of the static messages, so raw+ provider text can never come back out of this function.+ """+ if isinstance(error, BaseException):+ seen: set[int] = set()+ current: BaseException | None = error+ while current is not None and id(current) not in seen:+ seen.add(id(current))+ if isinstance(current, SubscriptionLiveError):+ text = str(current)+ return text if static_failure_message(text) else None+ current = current.__cause__ or current.__context__+ return static_failure_message(str(error))+ if not isinstance(error, str):+ return None+ text = error.strip()+ if any(text == _static_message(code) for code in _STATIC_CODES):+ return text+ match = _NAMED_PLAN_MESSAGE.match(text)+ if match is not None and text == _static_message(+ "voice_not_offered", match.group(1).lower().replace(" ", "_")+ ):+ return text+ return Nonedef _error_code(status: int | None, error: dict | None = None) -> str:diff --git a/tests/unit/browser_voice/test_live_failure_reason.py b/tests/unit/browser_voice/test_live_failure_reason.pynew file mode 100644index 0000000000..cbe6a27d9d--- /dev/null+++ b/tests/unit/browser_voice/test_live_failure_reason.py@@ -0,0 +1,127 @@+"""Issue #828: a GPT-Live start failure tells the person what to fix.++The browser route used to send only the generic "could not start" text when+the subscription session failed and usage-billed fallback was disabled. A+classified :class:`SubscriptionLiveError` (plan not offered, reconnect needed,+allowance exhausted) now reaches the surface with its static message, while+raw provider text still never does.+"""++from __future__ import annotations++from types import SimpleNamespace++import pytest++import dodaios.browser_voice.route as route_mod+from dodaios.browser_voice.route import (+ _USAGE_FALLBACK_DISABLED_DETAIL,+ _USAGE_FALLBACK_DISABLED_NOTE,+ _fallback_disabled_detail,+ browser_voice_ws,+)+from dodaios.plugins.realtime.openai_subscription_live import (+ SubscriptionLiveError,+ static_failure_message,+)+from dodaios.ui.web.missions_auth import register_token, revoke_token+from tests.unit.browser_voice.test_route import (+ _VALID_TOKEN,+ _FakeWS,+ _RecSession,+ _state,+)++[email protected](autouse=True)+def _registered_browser_token():+ register_token(_VALID_TOKEN)+ try:+ yield+ finally:+ revoke_token(_VALID_TOKEN)+++def _provider_errors(ws: _FakeWS) -> list[str]:+ return [m.get("error") for m in ws.sent_json if m.get("type") == "provider_error"]+++async def _run_failing_start(monkeypatch, error: BaseException) -> _FakeWS:+ classic = _RecSession()++ class _SubscriptionOnlyRealtime(_RecSession):+ is_realtime = True+ allow_classic_fallback = False++ async def handle_control(self, _msg: dict) -> None:+ raise error++ state = _state(classic)+ state.config.voice = SimpleNamespace(mode="realtime")+ monkeypatch.setattr(+ route_mod, "_build_browser_session", lambda **_kwargs: _SubscriptionOnlyRealtime()+ )+ ws = _FakeWS(+ [{"type": "websocket.receive", "text": '{"type":"audio_start","sample_rate":48000}'}],+ state=state,+ )+ await browser_voice_ws(ws)+ assert classic.controls == []+ assert ws.closed == (1011, "automatic API fallback disabled")+ return ws+++ ("code", "plan", "expected_start"),+ [+ ("voice_not_offered", "free", "The selected ChatGPT account (Free plan) is not offered"),+ ("authentication_required", "", "Reconnect your ChatGPT subscription"),+ ("quota_exhausted", "", "The ChatGPT subscription voice allowance is exhausted."),+ ],+)+async def test_classified_subscription_failure_reaches_the_surface(+ monkeypatch, code, plan, expected_start+) -> None:+ ws = await _run_failing_start(monkeypatch, SubscriptionLiveError(code, plan=plan))++ errors = _provider_errors(ws)+ assert len(errors) == 1+ assert errors[0].startswith(expected_start)+ assert errors[0].endswith(_USAGE_FALLBACK_DISABLED_NOTE)+ assert errors[0] != _USAGE_FALLBACK_DISABLED_DETAIL+++async def test_wrapped_subscription_failure_is_still_classified(monkeypatch) -> None:+ try:+ try:+ raise SubscriptionLiveError("quota_exhausted")+ except SubscriptionLiveError as inner:+ raise RuntimeError("transport wrapper") from inner+ except RuntimeError as wrapped:+ ws = await _run_failing_start(monkeypatch, wrapped)++ assert _provider_errors(ws) == [+ "The ChatGPT subscription voice allowance is exhausted. "+ + _USAGE_FALLBACK_DISABLED_NOTE+ ]+++async def test_raw_provider_text_is_never_forwarded(monkeypatch) -> None:+ raw = 'HTTP 500 {"error": {"message": "secret internal detail sk-abc"}}'+ ws = await _run_failing_start(monkeypatch, RuntimeError(raw))++ assert _provider_errors(ws) == [_USAGE_FALLBACK_DISABLED_DETAIL]+ assert all("secret" not in str(m) for m in ws.sent_json)+++def test_recorded_failure_strings_only_pass_when_static() -> None:+ message = str(SubscriptionLiveError("voice_not_offered", plan="go"))+ assert static_failure_message(message) == message+ assert _fallback_disabled_detail(message) == f"{message} {_USAGE_FALLBACK_DISABLED_NOTE}"+ assert static_failure_message("provider stream ended mid-turn") is None+ assert static_failure_message(message + " extra provider detail") is None+ assert _fallback_disabled_detail("stream ended") == _USAGE_FALLBACK_DISABLED_DETAIL+ assert _fallback_disabled_detail(None) == _USAGE_FALLBACK_DISABLED_DETAIL