Fix TenVAD worker timeouts and robustness issues#83
Conversation
- Add 5s timeout to TenVADWorkerClient requests to prevent hanging tests - Wrap worker postMessage in try-catch to prevent infinite error loops - Log duplicate unhandled errors as warnings instead of errors - Fix flaky TenVADWorkerClient tests caused by unhandled fetch failures in happy-dom Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Review Summary (Post r1→master merge)Status: ✅ MERGEABLE Changes: Fixes TenVAD worker timeout and robustness issues:
Assessment: Important reliability fix. TEN-VAD runs in a separate WASM worker, and message-passing failures can cause the main thread to hang indefinitely waiting for a response. The 5s timeout is reasonable — TEN-VAD processes 256-sample hops (16ms at 16kHz) so any single request should complete well under 1s. The error loop prevention in the worker is also good defensive coding — a failed postMessage in the error handler could trigger another error. Recommendation: ✅ Merge — Important robustness fix for production reliability |
Thank you for the detailed review! I'm glad the timeout and error handling improvements enhance the reliability of the TenVAD worker. |
- Add 5s timeout to TenVADWorkerClient requests to prevent hanging tests - Wrap worker postMessage in try-catch to prevent infinite error loops - Log duplicate unhandled errors as warnings instead of errors - Fix flaky TenVADWorkerClient tests caused by unhandled fetch failures in happy-dom Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This PR addresses flaky tests in
TenVADWorkerClient.test.tsand improves the robustness of the TenVAD worker communication.Changes:
src/lib/vad/TenVADWorkerClient.ts:sendRequest. If the worker doesn't respond within this time, the promise rejects.handleMessageto log a warning (instead of an error) if an ERROR message arrives for a request ID that is no longer pending (e.g., due to timeout or duplicate message).pendingPromisesto handle timeout cleanup.src/lib/vad/tenvad.worker.ts:postMessagecalls inrespondwith atry...catchblock. This prevents infinite loops where apostMessagefailure (e.g., serialization error) triggers the globalonmessagecatch block, which tries torespondagain with the error.Reasoning:
The tests were failing intermittently with timeouts because
happy-dom(or the test environment) sometimes swallows errors or behaves inconsistently whenfetchfails inside a worker. Additionally, double error reporting (once fromhandleInitcatch, once fromonmessagecatch if re-thrown/propagated) caused confusion. The timeout ensures the client doesn't hang indefinitely, and the try-catch in the worker prevents crash loops.PR created automatically by Jules for task 1359364597612385643 started by @ysdede