Repository navigation
Conversation
There was a problem hiding this comment.
Devin Review found 2 potential issues.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| retryable = data.get("retryable") | ||
| if not isinstance(retryable, bool): | ||
| retryable = code not in _NON_RETRYABLE_STT_CODES |
There was a problem hiding this comment.
🔴 No retry after temporary rate limits
When AssemblyAI rejects a session start for exceeding its per-minute limit, _NON_RETRYABLE_STT_CODES treats it as a permanent failure. The provider uses 1008 for both that limit and credential failures. RecognizeStream stops immediately instead of using the configured retries.
Learn more
AssemblyAI’s streaming rate-limit documentation specifies a 1008 Error frame with the text Unauthorized Connection: Too many concurrent sessions when the account uses its session-start allowance for the minute. The code also covers permanent credential and billing failures. This frame has no retryable flag, so it goes through the same default as a bad key. RecognizeStream._main_task exits on the first failure rather than using its configured retries. Previously, the close code reached recv_task without an explicit retry flag, so APIStatusError treated it as retryable.
Example: A free account starts its sixth stream just before the minute resets. The provider rejects the start with 1008. The stream stops even though a configured retry after the reset could open it successfully.
Recommended fix: When no explicit boolean is present, distinguish the documented rate-limit text from other 1008 errors and keep authorization failures non-retryable. Allow retry after backoff into the next rate-limit window, subject to the configured retry policy. Test the documented frame alongside a bad-key frame.
Was this helpful? React with 👍 or 👎 to provide feedback.
| if self._last_error is not None: | ||
| raise self._last_error |
There was a problem hiding this comment.
🟡 Wrong error after reconnect
When a replacement socket closes unexpectedly without an Error frame, recv_task raises the previous socket’s error. RecognizeStream retries on the same stream, so callers get the old status and session instead of the new close details.
Learn more
A WebSocket Error frame becomes an exception in _process_stream_event. recv_task immediately propagates it, so that receive loop never reads the following close frame. When the error is retryable, RecognizeStream._main_task runs another attempt on the same object with the saved exception still set. An unexpected close without an Error frame on that new socket takes the saved exception instead of the current close code and reason.
Example: One socket sends a retryable 3005 server error. The replacement closes with 1001 and no Error frame. The caller sees the earlier 3005 error and its session ID rather than the replacement’s close details.
Recommended fix: Remove _last_error and the close-branch lookup. Keep immediate propagation of parsed Error frames and report the current socket’s close details when no Error frame arrives. Add a two-socket regression test with a retryable Error frame on the first socket and a bare unexpected close on the second.
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
Errormessages from AssemblyAI inlivekit.plugins.assemblyai.STT.Errormessage is received from the AssemblyAI WebSocket (e.g.,{"type": "Error", "error_code": 3005, "error": "Session duration exceeded"}),_process_stream_eventnow extracts theerror_code,error, anderror_type, logs the error with session context, and raises anAPIStatusErrorcarrying the specific status code, error message, andretryablestatus.retryableboolean sent by the server.recv_taskto re-raiseAPIErrordirectly so that errors raised during event processing propagate out ofrecv_taskrather than being caught by the genericexcept Exception:block._last_errorso that if the server transmits anErrorframe immediately prior to closing the socket, the specificAPIStatusErroris surfaced rather than a generic"AssemblyAI connection closed unexpectedly".Verification
tests/test_plugin_assemblyai_stt.py:test_process_stream_event_error_raises_api_status_error: VerifiesErrorframe raisesAPIStatusErrorwith correct code, message, request ID, and retryable flag.test_process_stream_event_error_auth_non_retryable: Verifies error code 1008 (auth) is markedretryable=False.test_process_stream_event_error_explicit_retryable: Verifies explicitretryablefield from frame overrides defaults.test_process_stream_event_error_without_error_code: Verifies graceful fallback whenerror_codeis omitted (status_code=-1).tests/test_plugin_assemblyai_stt.pyand 51 tests intests/test_plugin_assemblyai_tts.pypass cleanly.ruff checkandruff format --checkreport 0 issues.