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
+48 -24
View File
@@ -14,23 +14,14 @@ import type { DevicePort } from './port.ts';
const BODY = { id: 1, name: 'body' } as const;
const STATUS = { id: 2, name: 'status' } as const;
/** A flaky BLE hop can hang a bridge call for a long time; never let one block the UI forever. */
const CALL_TIMEOUT_MS = 8000;
/** A flaky BLE hop can hang a host call for a long time; never let one block the UI forever. */
export const CALL_TIMEOUT_MS = 8000;
function withTimeout<T>(promise: Promise<T>, fallback: T): Promise<T> {
return new Promise((resolve) => {
const timer = setTimeout(() => resolve(fallback), CALL_TIMEOUT_MS);
promise.then(
(value) => {
clearTimeout(timer);
resolve(value);
},
() => {
clearTimeout(timer);
resolve(fallback);
},
);
});
interface Bounded<T> {
/** The caller's answer: the real result, or the fallback if the host took too long. */
value: T;
/** True when `value` is the fallback because the host had not answered in time. */
timedOut: boolean;
}
/**
@@ -43,15 +34,37 @@ export class EvenDevice implements DevicePort {
private pending: HudFrame | null = null;
private flushing = false;
private ready = false;
/** All host calls go through one queue: concurrent bridge calls are documented as unsafe. */
/**
* All host calls go through one queue: concurrent bridge calls are documented as unsafe.
* The queue advances only when the host call has ACTUALLY settled. A caller that gives up
* waiting gets a fallback answer, but the next host call still waits its turn, so two calls
* are never in flight together and a late completion is always followed, in order, by
* whatever was queued behind it.
*/
private queue: Promise<unknown> = Promise.resolve();
constructor(private readonly bridge: EvenAppBridge) {}
constructor(
private readonly bridge: EvenAppBridge,
private readonly callTimeoutMs: number = CALL_TIMEOUT_MS,
) {}
private enqueue<T>(call: () => Promise<T>, fallback: T): Promise<T> {
const next = this.queue.then(() => withTimeout(call(), fallback));
this.queue = next.catch(() => undefined);
return next;
private enqueueBounded<T>(call: () => Promise<T>, fallback: T): Promise<Bounded<T>> {
// What the host really does, serialised behind every earlier call.
const settled: Promise<T> = this.queue.then(call).catch(() => fallback);
this.queue = settled;
// What the caller sees: the same result, or the fallback after the timeout. The timer
// starts when the call is requested, so time spent queued behind a stuck call counts.
return new Promise((resolve) => {
const timer = setTimeout(() => resolve({ value: fallback, timedOut: true }), this.callTimeoutMs);
void settled.then((value) => {
clearTimeout(timer);
resolve({ value, timedOut: false });
});
});
}
private async enqueue<T>(call: () => Promise<T>, fallback: T): Promise<T> {
return (await this.enqueueBounded(call, fallback)).value;
}
async init(frame: HudFrame): Promise<boolean> {
@@ -136,10 +149,21 @@ export class EvenDevice implements DevicePort {
}
}
startMic(): Promise<boolean> {
return this.enqueue(() => this.bridge.audioControl(true, AudioInputSource.Glasses), false);
async startMic(): Promise<boolean> {
const started = await this.enqueueBounded(() => this.bridge.audioControl(true, AudioInputSource.Glasses), false);
if (started.timedOut) {
// The caller is being told "the microphone did not open" and will not stop it. But the
// host may still open it later. Queue a stop now: it runs strictly after the pending
// start settles, so whatever the start ends up doing, the microphone finishes closed.
void this.enqueueBounded(() => this.bridge.audioControl(false), false);
}
return started.value;
}
/**
* Always sends the stop, even if a start is still pending or was never confirmed: closing a
* closed microphone is harmless, leaving one open is not. Queued behind any pending start.
*/
async stopMic(): Promise<void> {
await this.enqueue(() => this.bridge.audioControl(false), false);
}