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:
Dan
2026-11-18 19:49:14 -08:00
co-authored by Claude Fable 5.2
parent 3d5691dfa3
commit e1c02d5266
43 changed files with 2104 additions and 227 deletions
+41 -16
View File
@@ -1,4 +1,7 @@
import { existsSync, readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { AUDIO_FORMAT, DEFAULT_LIMITS } from '@hermeven/contracts';
import { validateManifest, type ModelManifest } from './stt/modelStore.mjs';
export interface BridgeConfig {
host: string;
@@ -25,11 +28,11 @@ export interface BridgeConfig {
provider: 'none' | 'builtin' | 'openai-compatible';
baseUrl: string;
apiKey: string;
/** Hub model id for `builtin`; provider model name for `openai-compatible`. */
/** Bundled manifest name for `builtin`; provider model name for `openai-compatible`. */
model: string;
/** `builtin` only: weight precision and where model files are cached. */
dtype: string;
cacheDir: string;
/** `builtin` only: the pinned artifacts to load, and the directory they are read from. */
manifest: ModelManifest | null;
modelDir: string;
};
limits: {
captureMaxSeconds: number;
@@ -46,7 +49,6 @@ export interface BridgeConfig {
tokenTtlSeconds: number;
pairingTtlSeconds: number;
pairingCodeTtlSeconds: number;
pairingCodeMaxFailures: number;
};
/** How long input/answer text stays in the bridge's result cache. Hermes is the authority. */
resultRetentionSeconds: number;
@@ -98,6 +100,34 @@ function httpUrl(key: string, raw: string): string {
return raw.replace(/\/+$/, '');
}
/** Manifests shipped with the bridge: `services/bridge/models/<name>.json`. */
export function bundledManifestPath(name: string): string {
return fileURLToPath(new URL(`../models/${name}.json`, import.meta.url));
}
function loadModelManifest(name: string, customPath: string | undefined): ModelManifest {
let path: string;
if (customPath) {
path = customPath;
} else {
if (!/^[a-z0-9][a-z0-9.-]*$/.test(name)) {
throw new ConfigError('STT_MODEL must be the name of a bundled pinned model (whisper-base, whisper-tiny)');
}
path = bundledManifestPath(name);
if (!existsSync(path)) {
throw new ConfigError(
`STT_MODEL "${name}" has no bundled pinned manifest. Use whisper-base or whisper-tiny, or point ` +
'STT_MODEL_MANIFEST at a manifest that pins a commit id and a SHA-256 for every file.',
);
}
}
try {
return validateManifest(JSON.parse(readFileSync(path, 'utf8')));
} catch (err) {
throw new ConfigError(`Speech model manifest could not be used: ${err instanceof Error ? err.message : 'unreadable'}`);
}
}
export function loadConfig(env: NodeJS.ProcessEnv = process.env): BridgeConfig {
const host = env.HERMEVEN_HOST || '127.0.0.1';
const allowNonLoopback = bool(env, 'HERMEVEN_ALLOW_NON_LOOPBACK');
@@ -132,14 +162,10 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): BridgeConfig {
if (sttProvider !== 'none' && sttProvider !== 'builtin' && sttProvider !== 'openai-compatible') {
throw new ConfigError('STT_PROVIDER must be "builtin", "openai-compatible" or "none"');
}
const sttModel = env.STT_MODEL || (sttProvider === 'builtin' ? 'onnx-community/whisper-base' : '');
if (sttProvider === 'builtin' && !/^[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+$/.test(sttModel)) {
throw new ConfigError('STT_MODEL must be a Hugging Face model id such as onnx-community/whisper-base');
}
const sttDtype = env.STT_DTYPE || 'q8';
if (!['q8', 'q4', 'fp32', 'fp16', 'int8', 'uint8'].includes(sttDtype)) {
throw new ConfigError('STT_DTYPE must be one of q8, q4, fp32, fp16, int8, uint8');
}
const sttModel = env.STT_MODEL || (sttProvider === 'builtin' ? 'whisper-base' : '');
// The built-in model is always pinned: a commit id plus a SHA-256 for every file. There is
// no unpinned mode. A model that is not bundled needs its own manifest file.
const sttManifest = sttProvider === 'builtin' ? loadModelManifest(sttModel, env.STT_MODEL_MANIFEST) : null;
let sttBaseUrl = '';
if (sttProvider === 'openai-compatible') {
if (!env.STT_BASE_URL) throw new ConfigError('STT_BASE_URL is required for STT_PROVIDER=openai-compatible');
@@ -169,8 +195,8 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): BridgeConfig {
baseUrl: sttBaseUrl,
apiKey: env.STT_API_KEY || '',
model: sttModel,
dtype: sttDtype,
cacheDir: env.STT_CACHE_DIR || './data/models',
manifest: sttManifest,
modelDir: env.STT_MODEL_DIR || './data/models',
},
limits: {
captureMaxSeconds,
@@ -188,7 +214,6 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): BridgeConfig {
tokenTtlSeconds: int(env, 'HERMEVEN_TOKEN_TTL_SECONDS', 7 * 86_400, 60),
pairingTtlSeconds: int(env, 'HERMEVEN_PAIRING_TTL_SECONDS', 90 * 86_400, 60),
pairingCodeTtlSeconds: int(env, 'HERMEVEN_PAIRING_CODE_TTL_SECONDS', 300, 30, 3600),
pairingCodeMaxFailures: int(env, 'HERMEVEN_PAIRING_CODE_MAX_FAILURES', 5, 1, 20),
},
resultRetentionSeconds: int(env, 'HERMEVEN_RESULT_RETENTION_SECONDS', 900, 10, 86_400),
logLevel: env.HERMEVEN_LOG_LEVEL || 'info',