Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
refactor(meetings): tighten diarization completion routing
Gabriel Steinffe8d689f82a
diff --git a/src/components/notes/NoteEditor.tsx b/src/components/notes/NoteEditor.tsxindex 1112fa9e6..dfe72512c 100644--- a/src/components/notes/NoteEditor.tsx+++ b/src/components/notes/NoteEditor.tsx@@ -526,8 +526,8 @@ export default function NoteEditor({const completedDiarization = useMeetingRecordingStore((s) => s.completedDiarization);useEffect(() => {if (!completedDiarization || completedDiarization.noteId !== note.id) return;- // Consume so a later remount doesn't reapply a stale overlay on top of- // newer edits; the transcript itself is already persisted.+ // Consume so a remount can't repaint this overlay over newer edits; the+ // transcript itself is already persisted.useMeetingRecordingStore.setState({ completedDiarization: null });setIsDiarizing(false);diff --git a/src/stores/meetingRecordingStore.ts b/src/stores/meetingRecordingStore.tsindex 3fbfd6cf5..64f6fefa1 100644--- a/src/stores/meetingRecordingStore.ts+++ b/src/stores/meetingRecordingStore.ts@@ -14,7 +14,7 @@ import {resolveInitialSpeakerCountOverride,resolveParticipantSpeakerCountSync,} from "../utils/participants";-import type { SystemAudioAccessResult, SystemAudioStrategy } from "../types/electron";+import type { NoteItem, SystemAudioAccessResult, SystemAudioStrategy } from "../types/electron";import type { CalendarAttendee } from "../types/calendar";import {DEFAULT_SYSTEM_AUDIO_ACCESS,@@ -1400,10 +1400,11 @@ if (typeof window !== "undefined") {payloadNoteId: data?.noteId,payloadSessionId: data?.sessionId,currentSessionId: diarizationSessionId,- recordingNoteId,});if (targetNoteId == null) return;+ // Publishing an empty result clears a waiting editor's spinner without+ // painting an overlay; anything non-empty is already persisted.const publish = (segments: TranscriptSegment[]) => {if (isCurrentSession) {useMeetingRecordingStore.setState({@@ -1413,24 +1414,27 @@ if (typeof window !== "undefined") {};if (!data?.segments?.length) {- // Diarization failed or was skipped — publish so a waiting editor can- // clear its spinner, but there is nothing to persist.publish([]);return;}- let persisted;+ let persisted: NoteItem | null | undefined;try {persisted = await window.electronAPI?.getNote?.(targetNoteId);- } catch {- // Without the persisted note there is no safe base to merge into —- // publish the empty result so a waiting editor still clears its spinner.+ } catch (error) {+ logger.error(+ "Diarization completion could not read its note",+ { noteId: targetNoteId, error: (error as Error).message },+ "meeting"+ );+ }+ // No note means no safe base to merge into, and writing to a deleted one+ // would resurrect its tombstone in the sidebar, cloud mirror, and vector+ // index.+ if (!persisted || persisted.deleted_at) {publish([]);return;}- // Writing to a deleted note would resurrect its tombstone in the- // sidebar, cloud mirror, and vector index.- if (!persisted || persisted.deleted_at) return;const existing = selectBaseSegments({persistedSegments: persisted.transcript@@ -1456,8 +1460,6 @@ if (typeof window !== "undefined") {transcript: serializeTranscriptSegments(enriched),});} catch (error) {- // Clear a waiting spinner without an overlay the database never- // accepted; the outer catch logs the failure.publish([]);throw error;}diff --git a/src/utils/diarizationCompletion.ts b/src/utils/diarizationCompletion.tsindex 75ab39a34..972b36aa8 100644--- a/src/utils/diarizationCompletion.ts+++ b/src/utils/diarizationCompletion.ts@@ -1,9 +1,9 @@-// Routing rules for meeting-diarization-complete events (issue #1495):-// results must be persisted to the note that owns the recording session,-// never to whichever note happens to be rendered when the event arrives.-// Persistence runs at store level (meetingRecordingStore), so results-// survive the notes view unmounting; `isCurrentSession` gates only whether-// the result is published to the UI.+// Routing rules for meeting-diarization-complete events (issue #1495): a result+// must be persisted to the note that owns the recording session, never to+// whichever note happens to be rendered when the event arrives.+//+// Persistence runs at store level (meetingRecordingStore) so results survive the+// notes view unmounting; `isCurrentSession` gates only the publish to the UI.export interface DiarizationCompletionPlan {targetNoteId: number | null;@@ -14,25 +14,15 @@ export function resolveDiarizationTarget(params: {payloadNoteId?: number | null;payloadSessionId?: string | null;currentSessionId: string | null;- recordingNoteId: number | null;}): DiarizationCompletionPlan {- const { payloadNoteId, payloadSessionId, currentSessionId, recordingNoteId } = params;-- // A null current session means nothing newer is pending, so publishing is- // safe and clearing a waiting spinner prevents it from getting stuck.- const isCurrentSession = currentSessionId == null || payloadSessionId === currentSessionId;-- if (payloadNoteId != null) {- return { targetNoteId: payloadNoteId, isCurrentSession };- }-- // Legacy payloads without a noteId can only be attributed via the session- // check; recordingNoteId still names the owner (it is not cleared on stop).- if (currentSessionId != null && payloadSessionId === currentSessionId) {- return { targetNoteId: recordingNoteId, isCurrentSession };- }-- return { targetNoteId: null, isCurrentSession };+ const { payloadNoteId, payloadSessionId, currentSessionId } = params;++ return {+ targetNoteId: payloadNoteId ?? null,+ // A null current session means nothing newer is pending, so publishing is+ // safe and clearing a waiting spinner prevents it from getting stuck.+ isCurrentSession: currentSessionId == null || payloadSessionId === currentSessionId,+ };}export function selectBaseSegments<Segment>(params: {@@ -43,13 +33,9 @@ export function selectBaseSegments<Segment>(params: {}): Segment[] {const { persistedSegments, liveSegments, recordingNoteId, targetNoteId } = params;- if (persistedSegments) {- return persistedSegments;- }+ if (persistedSegments) return persistedSegments;// Live segments belong to the recording note; merging them into any other// note would cross-contaminate transcripts.- if (recordingNoteId === targetNoteId && liveSegments.length > 0) {- return liveSegments;- }+ if (recordingNoteId === targetNoteId && liveSegments.length > 0) return liveSegments;return [];}diff --git a/test/utils/diarizationCompletion.test.js b/test/utils/diarizationCompletion.test.jsindex d31bb8f13..5d0949cd4 100644--- a/test/utils/diarizationCompletion.test.js+++ b/test/utils/diarizationCompletion.test.js@@ -16,7 +16,6 @@ test("payload noteId targets the owning note", () => {payloadNoteId: 1,payloadSessionId: "diar-100",currentSessionId: "diar-100",- recordingNoteId: 1,});assert.deepEqual(result, { targetNoteId: 1, isCurrentSession: true });});@@ -29,7 +28,6 @@ test("payload noteId still targets the owning note after a new session started",payloadNoteId: 1,payloadSessionId: "diar-100",currentSessionId: "diar-200",- recordingNoteId: 2,});assert.deepEqual(result, { targetNoteId: 1, isCurrentSession: false });});@@ -41,47 +39,18 @@ test("payload noteId with no pending session is current", () => {payloadNoteId: 1,payloadSessionId: "diar-100",currentSessionId: null,- recordingNoteId: null,});assert.deepEqual(result, { targetNoteId: 1, isCurrentSession: true });});-test("without payload noteId, a matching session attributes to the recording note", () => {- const result = resolveDiarizationTarget({- payloadNoteId: null,- payloadSessionId: "diar-100",- currentSessionId: "diar-100",- recordingNoteId: 2,- });- assert.deepEqual(result, { targetNoteId: 2, isCurrentSession: true });-});--test("without payload noteId and no recording note, the result is dropped", () => {+test("a payload without a noteId is dropped", () => {+ // Main snapshots the same noteId the renderer passed to+ // meetingTranscriptionStart, so a missing one means the recording was never+ // tied to a note and there is nothing to persist to.const result = resolveDiarizationTarget({payloadNoteId: null,payloadSessionId: "diar-100",currentSessionId: "diar-100",- recordingNoteId: null,- });- assert.deepEqual(result, { targetNoteId: null, isCurrentSession: true });-});--test("without payload noteId, a session mismatch produces no target", () => {- const result = resolveDiarizationTarget({- payloadNoteId: null,- payloadSessionId: "diar-100",- currentSessionId: "diar-200",- recordingNoteId: 2,- });- assert.deepEqual(result, { targetNoteId: null, isCurrentSession: false });-});--test("without payload noteId and no current session, the result is dropped", () => {- const result = resolveDiarizationTarget({- payloadNoteId: null,- payloadSessionId: "diar-100",- currentSessionId: null,- recordingNoteId: 2,});assert.deepEqual(result, { targetNoteId: null, isCurrentSession: true });});