fix(assemblyai_asr): route unknown messages to on_event not on_error#2188
Conversation
Unrecognized AssemblyAI v3 streaming messages (e.g. SpeechStarted) were passed as a dict to on_error, which feeds ModuleError(message=str) and raises a Pydantic validation error. Treat them as informational vendor events via on_event instead, and fix the on_event log f-string.
AssemblyAI v3 reports errors via WebSocket close codes (no in-band error message type), but _message_handler passed the raw exception object and an int code to on_error, which feeds ModuleError(message=str)/ ModuleErrorVendorInfo(code=str) and raises a Pydantic validation error. Stringify both, matching sibling extensions, and let CancelledError propagate instead of referencing an undefined name.
|
The lint needs to be fixed first |
|
tests/test_handle_message.py::test_connection_closed_passes_string_args_to_on_error failed. |
Review — fix(assemblyai_asr): route unknown messages to on_event not on_errorThanks for the clear writeup. The diagnosis is solid and the production-code changes are all correct. The core routing fix is the right call, and the supporting fixes that came along with it are genuinely good catches. Production code — looks correct
Potential issue — the new
|
Problem
The AssemblyAI ASR extension crashed on normal streaming traffic with:
Root cause
AssemblyAI's v3 streaming API sends informational messages such as
SpeechStarted. Inrecognition.py:_handle_messageonlyBegin/Turn/Terminationare handled; everything else fell into theelsebranch which calledself.callback.on_error(message_data)— passing the raw dict. Inextension.py:on_errorthat dict was fed intoModuleError(message=...), whosemessagefield is typedstr, so Pydantic raised thestring_typevalidation error (caught and logged atrecognition.py:130).Two defects:
SpeechStartedis not an error; routing it to the error path would also emit a spurious ASR error downstream.on_errorcontractually requires astr.Fix
recognition.py— unrecognized messages are now routed toon_event(accepts a dict, logs only) instead ofon_error.extension.py— fixed a missingfprefix on theon_eventlog line (now on the active path) so the payload interpolates.tests/test_handle_message.pyassertingSpeechStartedand other unknown message types route toon_event, noton_error.Verification
The local environment lacks
pytestand the runtime deps (websockets,ten_runtime,ten_ai_base), so the project harness could not run here. The fix was verified by loading the realrecognition.pywith those deps stubbed and exercising_handle_message:on_errorcalled with adict(reproduces the crash trigger).on_errornot called;on_eventcalled with theSpeechStarteddict.The added unit tests run in CI where the deps are available.