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:
Dan
2026-11-18 18:39:28 -08:00
co-authored by Claude Fable 5.2
parent 6d74f9e121
commit 0c9dcd864f
14 changed files with 212 additions and 31 deletions
+13
View File
@@ -1,5 +1,6 @@
import { describe, expect, it } from 'vitest';
import { SCHEMA_VERSION, type TurnResult } from '@hermeven/contracts';
import { pollDelay } from '../src/core/controller.ts';
import { initialState, reduce, type AppEvent, type AppState, type Effect } from '../src/core/reducer.ts';
const ID1 = '11111111-1111-4111-8111-111111111111';
@@ -39,6 +40,18 @@ function result(requestId: string, over: Partial<TurnResult> = {}): TurnResult {
};
}
describe('poll schedule', () => {
it('checks often while an answer is likely, and eases off for long runs', () => {
expect(pollDelay(0)).toBe(200);
expect(pollDelay(7_999)).toBe(200);
expect(pollDelay(8_000)).toBe(400);
expect(pollDelay(30_000)).toBe(1000);
expect(pollDelay(600_000)).toBe(1000);
// Stays far inside the bridge's 600 requests per minute per device.
expect(60_000 / pollDelay(0)).toBeLessThan(600);
});
});
describe('happy path', () => {
it('READY -> LISTENING -> TRANSCRIBING -> THINKING -> ANSWER', () => {
let s = ready();