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:
@@ -38,6 +38,10 @@ export interface AppState {
|
||||
*/
|
||||
generation: number;
|
||||
conversationId: string | null;
|
||||
/** Bumped whenever the conversation is reset; a create result from an older epoch is dropped. */
|
||||
conversationEpoch: number;
|
||||
/** A new conversation has been requested and not yet confirmed. */
|
||||
creatingConversation: boolean;
|
||||
requestId: string | null;
|
||||
captureStartedAt: number | null;
|
||||
captureMaxSeconds: number;
|
||||
@@ -57,6 +61,8 @@ export const initialState: AppState = {
|
||||
phase: 'unpaired',
|
||||
generation: 0,
|
||||
conversationId: null,
|
||||
conversationEpoch: 0,
|
||||
creatingConversation: false,
|
||||
requestId: null,
|
||||
captureStartedAt: null,
|
||||
captureMaxSeconds: 30,
|
||||
@@ -83,8 +89,8 @@ export type AppEvent =
|
||||
| { type: 'capture_started'; generation: number; at: number }
|
||||
| { type: 'capture_failed'; generation: number; reason: 'mic_refused' | 'mic_stalled' | 'empty' }
|
||||
| { type: 'capture_limit'; generation: number }
|
||||
| { type: 'conversation_created'; generation: number; conversationId: string }
|
||||
| { type: 'conversation_failed'; generation: number; error: HudError }
|
||||
| { type: 'conversation_created'; epoch: number; conversationId: string }
|
||||
| { type: 'conversation_failed'; epoch: number; error: HudError }
|
||||
/** `pages` is the already-paginated plain-text answer when the result carries one. */
|
||||
| { type: 'turn_update'; generation: number; result: TurnResult; pages: string[] | null }
|
||||
| { type: 'turn_rejected'; generation: number; error: HudError }
|
||||
@@ -101,7 +107,7 @@ export type Effect =
|
||||
| { type: 'resubmit'; generation: number; requestId: string }
|
||||
| { type: 'poll'; generation: number; requestId: string }
|
||||
| { type: 'cancel_turn'; requestId: string }
|
||||
| { type: 'create_conversation'; generation: number }
|
||||
| { type: 'create_conversation'; epoch: number }
|
||||
| { type: 'exit_dialog' };
|
||||
|
||||
export interface Step {
|
||||
@@ -153,6 +159,7 @@ export function reduce(state: AppState, event: AppEvent): Step {
|
||||
generation: state.generation + 1,
|
||||
captureMaxSeconds: event.captureMaxSeconds,
|
||||
conversationId: event.conversationId,
|
||||
conversationEpoch: state.conversationEpoch + 1,
|
||||
};
|
||||
if (!event.paired) return same({ ...base, phase: 'unpaired' });
|
||||
if (event.resumeRequestId) {
|
||||
@@ -169,7 +176,12 @@ export function reduce(state: AppState, event: AppEvent): Step {
|
||||
case 'unpaired': {
|
||||
const effects: Effect[] = state.phase === 'listening' ? [{ type: 'discard_capture' }] : [];
|
||||
return {
|
||||
state: { ...initialState, generation: state.generation + 1, captureMaxSeconds: state.captureMaxSeconds },
|
||||
state: {
|
||||
...initialState,
|
||||
generation: state.generation + 1,
|
||||
conversationEpoch: state.conversationEpoch + 1,
|
||||
captureMaxSeconds: state.captureMaxSeconds,
|
||||
},
|
||||
effects,
|
||||
};
|
||||
}
|
||||
@@ -238,21 +250,36 @@ export function reduce(state: AppState, event: AppEvent): Step {
|
||||
case 'new_conversation': {
|
||||
// Only from a resting state: a reset must never be mistaken for cancelling the backend.
|
||||
if (!IDLE.has(state.phase)) return same(state);
|
||||
const generation = state.generation + 1;
|
||||
// One is already on its way: a second press must not start a second create.
|
||||
if (state.creatingConversation) return same(state);
|
||||
const conversationEpoch = state.conversationEpoch + 1;
|
||||
return {
|
||||
state: { ...clearTurn(state), phase: 'ready', generation, conversationId: null, notice: 'New conversation' },
|
||||
effects: [{ type: 'create_conversation', generation }],
|
||||
state: {
|
||||
...clearTurn(state),
|
||||
phase: 'ready',
|
||||
generation: state.generation + 1,
|
||||
conversationId: null,
|
||||
conversationEpoch,
|
||||
creatingConversation: true,
|
||||
notice: 'New conversation',
|
||||
},
|
||||
effects: [{ type: 'create_conversation', epoch: conversationEpoch }],
|
||||
};
|
||||
}
|
||||
|
||||
case 'conversation_created': {
|
||||
if (event.generation !== state.generation) return same(state);
|
||||
return same({ ...state, conversationId: event.conversationId });
|
||||
// Keyed to the conversation epoch, not the turn generation: the user may already have
|
||||
// started a question (which bumps the generation) while the conversation was being made.
|
||||
if (event.epoch !== state.conversationEpoch) return same(state);
|
||||
return same({ ...state, conversationId: event.conversationId, creatingConversation: false });
|
||||
}
|
||||
|
||||
case 'conversation_failed': {
|
||||
if (event.generation !== state.generation) return same(state);
|
||||
return same({ ...clearTurn(state), phase: 'error', error: event.error });
|
||||
if (event.epoch !== state.conversationEpoch) return same(state);
|
||||
// If a question is in flight, its own submit reports the failure; only a resting screen
|
||||
// is replaced by the error.
|
||||
if (!IDLE.has(state.phase)) return same({ ...state, creatingConversation: false });
|
||||
return same({ ...clearTurn(state), creatingConversation: false, phase: 'error', error: event.error });
|
||||
}
|
||||
|
||||
case 'capture_started': {
|
||||
|
||||
Reference in New Issue
Block a user