Run Whisper in a worker thread; shorten polling
The speech model now lives in a worker thread (whisperWorker.mjs), so loading and transcribing no longer block the bridge's HTTP server or its Hermes polling. Measured longest event-loop pause during transcription: 387 ms before, 3 ms after. A dead worker is replaced on the next request; closing the bridge terminates it. Polling: bridge to Hermes every 150 ms (was 500). The app polls the bridge every 200 ms for the first 8 s of a turn, 400 ms until 30 s, then 1 s (was a fixed 700 ms). Tests: 131 unit/integration, 7 real-speech, 9 real-Hermes, 6 simulator, all passing. Effect on a phone or a droplet is not measured. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
+22
-5
@@ -29,7 +29,7 @@ Exit 0, no diagnostics, for contracts, bridge, client and tests.
|
||||
```
|
||||
$ npm test
|
||||
Test Files 8 passed (8)
|
||||
Tests 130 passed (130)
|
||||
Tests 131 passed (131)
|
||||
```
|
||||
|
||||
Run after a clean `npm ci`. Six consecutive full runs were green after the fix described under
|
||||
@@ -40,7 +40,7 @@ Run after a clean `npm ci`. Six consecutive full runs were green after the fix d
|
||||
| `packages/contracts/test/contracts.test.ts` | 4 | Schema acceptance and rejection, error-code retryability |
|
||||
| `services/bridge/test/units.test.ts` | 13 | Config guards, credential expiry and renewal, pairing codes, adapter helpers |
|
||||
| `services/bridge/test/builtinWhisper.test.ts` | 8 | Built-in STT adapter with a stand-in recogniser: silence gate, language, ordering, cancel, load failure |
|
||||
| `apps/even-client/test/reducer.test.ts` | 24 | State transitions, cancellation, stale and late results, connection loss |
|
||||
| `apps/even-client/test/reducer.test.ts` | 25 | State transitions, cancellation, stale and late results, connection loss |
|
||||
| `apps/even-client/test/layout.test.ts` | 16 | Pagination, Unicode, long answers, plain-text conversion, HUD frames fit |
|
||||
| `apps/even-client/test/events.test.ts` | 8 | Gesture mapping through the SDK's parser, the tap-has-no-eventType quirk |
|
||||
| `tests/integration/bridge.test.ts` | 40 | Auth, device binding, limits, rate limiting, STT and Hermes outcomes, duplicates, cancel, restart, redaction |
|
||||
@@ -150,10 +150,10 @@ later turns well under 1 s. These are not performance figures for anything real.
|
||||
|
||||
```
|
||||
$ npm run test:real-stt
|
||||
Tests 4 passed (4)
|
||||
Tests 7 passed (7)
|
||||
```
|
||||
|
||||
`onnx-community/whisper-base`, 8-bit weights, run in the bridge process on the CPU. The input is
|
||||
`onnx-community/whisper-base`, 8-bit weights, run on the CPU in a worker thread of the bridge. The input is
|
||||
`tests/real-stt/fixtures/jfk.wav`, 11.0 s of clean archive speech, uploaded through
|
||||
`POST /v1/turns` as raw PCM exactly as the client uploads a capture.
|
||||
|
||||
@@ -163,6 +163,9 @@ $ npm run test:real-stt
|
||||
| Three seconds of digital silence: `stt_empty`, the agent is not called | pass |
|
||||
| Three seconds of very quiet noise: `stt_empty` | pass |
|
||||
| A second recording with the model already loaded | pass |
|
||||
| Two devices submit recordings at the same moment: both transcribed, in turn | pass |
|
||||
| A model id that does not exist: speech is `unavailable`, the bridge keeps answering | pass |
|
||||
| Closing the adapter stops the worker; a closed adapter refuses work | pass |
|
||||
|
||||
Transcript produced: "And so my fellow Americans, ask not what your country can do for you, ask
|
||||
what you can do for your country." That matches the recording.
|
||||
@@ -174,7 +177,7 @@ Measurements from this run, one sample each, on an Intel i7-13850HX desktop:
|
||||
| Model load (files already cached) | 1.2 to 3.8 s |
|
||||
| 11.0 s of speech | 1.6 s |
|
||||
| Memory (resident) after loading / after transcribing | about 0.5 GB / 0.8 GB |
|
||||
| Longest event-loop pause during transcription | 0.39 s |
|
||||
| Longest event-loop pause during transcription | 0.39 s with the model in the bridge's main thread; **3 ms** after moving it to a worker thread |
|
||||
| Same clip with the process pinned to one core | 1.7 s (no slower) |
|
||||
|
||||
Things this run also showed that are worth knowing:
|
||||
@@ -190,6 +193,20 @@ Things this run also showed that are worth knowing:
|
||||
The bridge process was also started with default settings: it logged `stt.loading`, then
|
||||
`stt.ready`, and answered `/healthz` throughout.
|
||||
|
||||
### Polling intervals
|
||||
|
||||
Shortened at Dan's request. These are settings, and their effect on a real answer has not been
|
||||
measured on a phone.
|
||||
|
||||
| Loop | Before | Now |
|
||||
|---|---|---|
|
||||
| Bridge asks Hermes for run status | every 500 ms | every 150 ms (`HERMES_POLL_INTERVAL_MS`) |
|
||||
| App asks the bridge for the turn | every 700 ms | every 200 ms for the first 8 s, 400 ms until 30 s, then 1 s |
|
||||
|
||||
Worst-case delay added by polling to an answer that arrives within 8 s: about 0.35 s, down from
|
||||
about 1.2 s. The app's schedule eases off for long agent runs to limit radio use; battery impact
|
||||
is unmeasured.
|
||||
|
||||
### Build and packaging
|
||||
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user