Skip to content

Comments

Fix TenVAD worker timeouts and robustness issues#83

Open
ysdede wants to merge 2 commits intostagingfrom
fix-tenvad-client-timeout-1359364597612385643
Open

Fix TenVAD worker timeouts and robustness issues#83
ysdede wants to merge 2 commits intostagingfrom
fix-tenvad-client-timeout-1359364597612385643

Conversation

@ysdede
Copy link
Owner

@ysdede ysdede commented Feb 8, 2026

This PR addresses flaky tests in TenVADWorkerClient.test.ts and improves the robustness of the TenVAD worker communication.

Changes:

  1. src/lib/vad/TenVADWorkerClient.ts:

    • Added a 5000ms timeout to sendRequest. If the worker doesn't respond within this time, the promise rejects.
    • Updated handleMessage to 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).
    • Refactored pendingPromises to handle timeout cleanup.
  2. src/lib/vad/tenvad.worker.ts:

    • Wrapped postMessage calls in respond with a try...catch block. This prevents infinite loops where a postMessage failure (e.g., serialization error) triggers the global onmessage catch block, which tries to respond again with the error.

Reasoning:
The tests were failing intermittently with timeouts because happy-dom (or the test environment) sometimes swallows errors or behaves inconsistently when fetch fails inside a worker. Additionally, double error reporting (once from handleInit catch, once from onmessage catch 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

- 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>
@ysdede ysdede changed the base branch from audit/perf-degradation-resource-mgmt to staging February 10, 2026 20:59
@ysdede
Copy link
Owner Author

ysdede commented Feb 10, 2026

Review Summary (Post r1→master merge)

Status: ✅ MERGEABLE

Changes: Fixes TenVAD worker timeout and robustness issues:

  1. TenVADWorkerClient.ts:

    • Adds 5-second timeout to sendRequest() to prevent indefinite hangs
    • Wraps resolve/reject with timeout cleanup
    • Downgrades orphan error from console.error to console.warn
  2. tenvad.worker.ts:

    • Wraps
      espond() (postMessage) in try-catch to prevent infinite error loops if postMessage fails

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

@google-labs-jules
Copy link
Contributor

Review Summary (Post r1→master merge)

Status: ✅ MERGEABLE

Changes: Fixes TenVAD worker timeout and robustness issues:

  1. TenVADWorkerClient.ts:

    • Adds 5-second timeout to sendRequest() to prevent indefinite hangs
    • Wraps resolve/reject with timeout cleanup
    • Downgrades orphan error from console.error to console.warn
  2. tenvad.worker.ts:

    • Wraps
      espond() (postMessage) in try-catch to prevent infinite error loops if postMessage fails

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>
Repository owner deleted a comment from google-labs-jules bot Feb 17, 2026
Repository owner deleted a comment from coderabbitai bot Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant