Address Cody review round 2: all ten findings (CODY-001 to CODY-010)
CODY-001 Bridge URL must be HTTPS (HTTP only to loopback), in the client and
in manifest generation.
CODY-002 Even host calls stay serialised until the SDK call really settles;
a microphone start that completes after its timeout is followed by
a stop.
CODY-003 Request id is stored before the first submit and cleared only on a
definitive answer; lost replies are treated as ambiguous and
reconciled under the same id; HUD no longer claims "not sent".
CODY-004 Revoking a device cancels its in-flight turns, aborts
transcription and asks Hermes to stop, from HTTP and CLI paths.
CODY-005 Speech model pinned to a commit with per-file SHA-256; fetched and
verified ahead of time; verified on every load; never downloaded
at run time; no unpinned configuration.
CODY-006 State directory 0700, database/WAL/SHM 0600 regardless of umask.
CODY-007 credential_expired handled like unauthorized on every path.
CODY-008 Approval wait start and paused agent deadline persisted and
restored across restarts (schema v2).
CODY-009 Exactly one conversation create per epoch, sent in sequence, with
stale results dropped before persistence.
CODY-010 Wrong pairing guesses no longer consume the outstanding code;
failures are indistinguishable.
Checks: typecheck clean; npm test 182 passed; client build ok;
test:real-stt 11 passed (including with no network); test:real-hermes 9
passed; test:simulator 6 passed; git diff --check clean.
Not reviewed. No physical-device, droplet or production evidence.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Worker } from 'node:worker_threads';
|
||||
import { AUDIO_FORMAT } from '@hermeven/contracts';
|
||||
import { SttError, type SttAdapter, type TranscribeRequest } from './adapter.ts';
|
||||
import type { ModelManifest } from './modelStore.mjs';
|
||||
|
||||
/**
|
||||
* Built-in speech-to-text: OpenAI's Whisper model run on the bridge host's CPU
|
||||
@@ -10,15 +11,15 @@ import { SttError, type SttAdapter, type TranscribeRequest } from './adapter.ts'
|
||||
* The model lives in a worker thread (whisperWorker.mjs), so loading it and
|
||||
* transcribing never block the bridge's HTTP server or its Hermes polling.
|
||||
*
|
||||
* The model files are downloaded from the Hugging Face hub the first time the
|
||||
* bridge starts and are then read from `cacheDir`.
|
||||
* The bridge never downloads anything at run time. Model files are fetched ahead of
|
||||
* time (`bridge:cli fetch-model`) at a pinned commit, and every file is checked against
|
||||
* its pinned SHA-256 each time the model is loaded.
|
||||
*/
|
||||
export interface BuiltinWhisperOptions {
|
||||
/** Hub id, for example `onnx-community/whisper-base` (multilingual) or `...-base.en`. */
|
||||
model: string;
|
||||
/** Weight precision. `q8` is the small, CPU-friendly default. */
|
||||
dtype: string;
|
||||
cacheDir: string;
|
||||
/** What exactly to load: hub id, immutable revision, precision, and each file's hash. */
|
||||
manifest: ModelManifest;
|
||||
/** Model store directory. Read-only at run time. */
|
||||
modelDir: string;
|
||||
/** Test seam: replaces the worker thread with an in-process recogniser. */
|
||||
load?: () => Promise<Recognizer>;
|
||||
}
|
||||
@@ -58,6 +59,8 @@ export class BuiltinWhisperStt implements SttAdapter {
|
||||
private recognizer: Promise<Recognizer> | null = null;
|
||||
private worker: Worker | null = null;
|
||||
private closed = false;
|
||||
/** Why the last load failed: `missing`, `mismatch` (files differ from the pin) or `load`. */
|
||||
lastLoadFailure: 'missing' | 'mismatch' | 'load' | null = null;
|
||||
/** One transcription at a time: the model is CPU-bound and this is a single-user bridge. */
|
||||
private queue: Promise<unknown> = Promise.resolve();
|
||||
|
||||
@@ -102,9 +105,10 @@ export class BuiltinWhisperStt implements SttAdapter {
|
||||
};
|
||||
worker.on('error', () => fail('worker error'));
|
||||
worker.on('exit', () => fail('worker exited'));
|
||||
worker.on('message', (message: { type: string; id?: number; text?: string }) => {
|
||||
worker.on('message', (message: { type: string; id?: number; text?: string; reason?: 'missing' | 'mismatch' | 'load' }) => {
|
||||
if (message.type === 'loaded') {
|
||||
loaded = true;
|
||||
this.lastLoadFailure = null;
|
||||
resolve(
|
||||
(audio, options) =>
|
||||
new Promise((res, rej) => {
|
||||
@@ -115,6 +119,7 @@ export class BuiltinWhisperStt implements SttAdapter {
|
||||
}),
|
||||
);
|
||||
} else if (message.type === 'load_failed') {
|
||||
this.lastLoadFailure = message.reason ?? 'load';
|
||||
void worker.terminate();
|
||||
} else if (message.id !== undefined) {
|
||||
const pending = waiting.get(message.id);
|
||||
@@ -123,7 +128,7 @@ export class BuiltinWhisperStt implements SttAdapter {
|
||||
else pending?.reject(new Error('recognition failed'));
|
||||
}
|
||||
});
|
||||
worker.postMessage({ type: 'load', model: this.opts.model, dtype: this.opts.dtype, cacheDir: this.opts.cacheDir });
|
||||
worker.postMessage({ type: 'load', dir: this.opts.modelDir, manifest: this.opts.manifest });
|
||||
});
|
||||
}
|
||||
|
||||
@@ -150,7 +155,7 @@ export class BuiltinWhisperStt implements SttAdapter {
|
||||
}
|
||||
// English-only models take no language argument; multilingual ones are told the
|
||||
// language from the device locale rather than left to guess it from a short clip.
|
||||
const options: Record<string, unknown> = this.opts.model.endsWith('.en')
|
||||
const options: Record<string, unknown> = this.opts.manifest.model.endsWith('.en')
|
||||
? {}
|
||||
: { language: request.locale.split('-')[0]!.toLowerCase(), task: 'transcribe' };
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user