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
fix(meetings): always persist delayed diarization to its owning note
Chadpiha88701d195308
diff --git a/src/components/notes/NoteEditor.tsx b/src/components/notes/NoteEditor.tsxindex 9f53bfbba..1112fa9e6 100644--- a/src/components/notes/NoteEditor.tsx+++ b/src/components/notes/NoteEditor.tsx@@ -72,7 +72,6 @@ import { parseTranscriptSegments } from "../../utils/parseTranscriptSegments";import {applyTranscriptSpeakerPatch,lockTranscriptSpeaker,- mergeTranscriptSegments,serializeTranscriptSegments,} from "../../utils/transcriptSpeakerState";import NoteParticipants from "./NoteParticipants";@@ -365,7 +364,6 @@ export default function NoteEditor({Array<{ id: number; display_name: string; email: string | null }>>([]);const editorRef = useRef<Editor | null>(null);- const displaySegmentsRef = useRef<TranscriptSegment[]>([]);const embeddedChat = useEmbeddedChat({noteId: note.id,@@ -400,10 +398,6 @@ export default function NoteEditor({return parseTranscriptSegments(note.transcript || "");}, [diarizedSegments, note.transcript]);- useEffect(() => {- displaySegmentsRef.current = displaySegments;- }, [displaySegments]);-const hasChatSegments = displaySegments.length > 0;const knownSpeakers = useMemo(@@ -527,49 +521,28 @@ export default function NoteEditor({prevRecordingForDiarizationRef.current = isRecording;}, [diarizationSessionId, isRecording, scheduleUiUpdate]);+ // Persistence happens in meetingRecordingStore's module-level listener+ // (#1495); this only mirrors a published result into the rendered note's UI.+ const completedDiarization = useMeetingRecordingStore((s) => s.completedDiarization);useEffect(() => {- const expectedSession = diarizationSessionId;- const cleanup = window.electronAPI?.onMeetingDiarizationComplete?.(async (data) => {- if (!expectedSession || data?.sessionId !== expectedSession) return;-- setIsDiarizing(false);-- if (!data?.segments?.length) return;-- // Store segments outlive their recording — only use them for the note they belong to.- const { recordingNoteId, segments: liveSegments } = useMeetingRecordingStore.getState();- const persisted = await window.electronAPI?.getNote?.(note.id);- const existing = persisted?.transcript- ? parseTranscriptSegments(persisted.transcript)- : recordingNoteId === note.id && liveSegments.length > 0- ? liveSegments- : displaySegmentsRef.current;-- const enriched = mergeTranscriptSegments(- existing,- data.segments.map((s: any, i: number) => ({- ...s,- id: s.id || `diarized-${i}`,- }))- );- setDiarizedSegments(enriched);-- window.electronAPI.updateNote(note.id, { transcript: serializeTranscriptSegments(enriched) });-- if (data.speakerEmbeddings) {- window.electronAPI?.saveNoteSpeakerEmbeddings?.(note.id, data.speakerEmbeddings);- }-- const autoMappings: Record<string, string> = {};- for (const s of enriched) {- if (s.speakerName && s.speaker) autoMappings[s.speaker] = s.speakerName;- }- if (Object.keys(autoMappings).length > 0) {- setSpeakerMappings((prev) => ({ ...autoMappings, ...prev }));- }- });- return () => cleanup?.();- }, [note.id, diarizationSessionId]);+ 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.+ useMeetingRecordingStore.setState({ completedDiarization: null });+ setIsDiarizing(false);++ const enriched = completedDiarization.segments;+ if (enriched.length === 0) return;+ setDiarizedSegments(enriched);++ const autoMappings: Record<string, string> = {};+ for (const s of enriched) {+ if (s.speakerName && s.speaker) autoMappings[s.speaker] = s.speakerName;+ }+ if (Object.keys(autoMappings).length > 0) {+ setSpeakerMappings((prev) => ({ ...autoMappings, ...prev }));+ }+ }, [completedDiarization, note.id]);const persistDisplaySegments = useCallback(async (nextSegments: TranscriptSegment[], updateOverlay = true) => {diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.jsindex 45f77c4ba..c5836194c 100644--- a/src/helpers/ipcHandlers.js+++ b/src/helpers/ipcHandlers.js@@ -9874,7 +9874,7 @@ class IPCHandlers {) {const send = (payload) => {if (win && !win.isDestroyed()) {- win.webContents.send("meeting-diarization-complete", { sessionId, ...payload });+ win.webContents.send("meeting-diarization-complete", { sessionId, noteId, ...payload });}};diff --git a/src/stores/meetingRecordingStore.ts b/src/stores/meetingRecordingStore.tsindex 59a0c1247..867a3fa90 100644--- a/src/stores/meetingRecordingStore.ts+++ b/src/stores/meetingRecordingStore.ts@@ -31,10 +31,14 @@ import { isTranscriptionContextAllowed } from "./policyRules";import { usePolicyStore } from "./policyStore";import {lockTranscriptSpeaker,+ mergeTranscriptSegments,normalizeTranscriptSegment,+ serializeTranscriptSegments,type TranscriptSpeakerLockSource,type TranscriptSpeakerStatus,} from "../utils/transcriptSpeakerState";+import { parseTranscriptSegments } from "../utils/parseTranscriptSegments";+import { resolveDiarizationTarget, selectBaseSegments } from "../utils/diarizationCompletion";export interface TranscriptSegment {id: string;@@ -80,6 +84,8 @@ interface MeetingRecordingState {systemPartialSpeakerId: string | null;systemPartialSpeakerName: string | null;diarizationSessionId: string | null;+ /** Latest diarization result published for UI mirroring; consumed (nulled) by the editor that applies it. */+ completedDiarization: { noteId: number; segments: TranscriptSegment[] } | null;sessionDiarizationEnabled: boolean;sessionExpectedCount: number;userTouchedStepper: boolean;@@ -434,6 +440,7 @@ export const useMeetingRecordingStore = create<MeetingRecordingState>()(() => ({systemPartialSpeakerId: null,systemPartialSpeakerName: null,diarizationSessionId: null,+ completedDiarization: null,sessionDiarizationEnabled:(getSettings() as { speakerDiarizationEnabled?: boolean }).speakerDiarizationEnabled ?? true,sessionExpectedCount: DEFAULT_EXPECTED_SPEAKER_COUNT,@@ -802,6 +809,7 @@ export async function startRecording(args: StartRecordingArgs): Promise<boolean>systemPartialSpeakerId: null,systemPartialSpeakerName: null,diarizationSessionId: null,+ completedDiarization: null,error: null,micCaptureStatus: "inactive",});@@ -1372,6 +1380,71 @@ export function cancelPreparedTranscription(): void {window.electronAPI?.meetingTranscriptionCancel?.();}+// Persists delayed diarization results to the note that owns the recording+// session (#1495). Registered once at module load so results survive the+// notes view unmounting; NoteEditor only mirrors `completedDiarization`.+if (typeof window !== "undefined") {+ window.electronAPI?.onMeetingDiarizationComplete?.(async (data) => {+ const {+ diarizationSessionId,+ recordingNoteId,+ segments: liveSegments,+ } = useMeetingRecordingStore.getState();+ const { targetNoteId, isCurrentSession } = resolveDiarizationTarget({+ payloadNoteId: data?.noteId,+ payloadSessionId: data?.sessionId,+ currentSessionId: diarizationSessionId,+ recordingNoteId,+ });+ if (targetNoteId == null) return;++ const publish = (segments: TranscriptSegment[]) => {+ if (isCurrentSession) {+ useMeetingRecordingStore.setState({+ completedDiarization: { noteId: targetNoteId, segments },+ });+ }+ };++ 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;+ }++ const persisted = await window.electronAPI?.getNote?.(targetNoteId);+ // 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+ ? parseTranscriptSegments(persisted.transcript)+ : null,+ liveSegments,+ recordingNoteId,+ targetNoteId,+ });+ const enriched = mergeTranscriptSegments(+ existing,+ data.segments.map((segment, index) => ({+ ...segment,+ id: segment.id || `diarized-${index}`,+ }))+ );++ window.electronAPI?.updateNote?.(targetNoteId, {+ transcript: serializeTranscriptSegments(enriched),+ });+ if (data.speakerEmbeddings) {+ window.electronAPI?.saveNoteSpeakerEmbeddings?.(targetNoteId, data.speakerEmbeddings);+ }++ publish(enriched);+ });+}+// Throttled resize listener — keeps layout reflows during drag from thrashing// React. Registered once at module load; the store outlives any view.if (typeof window !== "undefined") {diff --git a/src/types/electron.ts b/src/types/electron.tsindex 5dd0eea35..87953b9fb 100644--- a/src/types/electron.ts+++ b/src/types/electron.ts@@ -2248,6 +2248,7 @@ declare global {onMeetingDiarizationComplete?: (callback: (data: {sessionId?: string;+ noteId?: number | null;segments: Array<{id: string;text: string;diff --git a/src/utils/diarizationCompletion.ts b/src/utils/diarizationCompletion.tsnew file mode 100644index 000000000..75ab39a34--- /dev/null+++ b/src/utils/diarizationCompletion.ts@@ -0,0 +1,55 @@+// 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.++export interface DiarizationCompletionPlan {+ targetNoteId: number | null;+ isCurrentSession: boolean;+}++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 };+}++export function selectBaseSegments<Segment>(params: {+ persistedSegments: Segment[] | null;+ liveSegments: Segment[];+ recordingNoteId: number | null;+ targetNoteId: number;+}): Segment[] {+ const { persistedSegments, liveSegments, recordingNoteId, targetNoteId } = params;++ 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;+ }+ return [];+}diff --git a/test/utils/diarizationCompletion.test.js b/test/utils/diarizationCompletion.test.jsnew file mode 100644index 000000000..d31bb8f13--- /dev/null+++ b/test/utils/diarizationCompletion.test.js@@ -0,0 +1,146 @@+const test = require("node:test");+const assert = require("node:assert/strict");++const {+ resolveDiarizationTarget,+ selectBaseSegments,+} = require("../../src/utils/diarizationCompletion.ts");++// Issue #1495: a delayed diarization result must be saved to the note that+// owns the recording session, never to whichever note happens to be rendered.+// Persistence runs at store level; `isCurrentSession` gates only whether the+// result is published to the UI.++test("payload noteId targets the owning note", () => {+ const result = resolveDiarizationTarget({+ payloadNoteId: 1,+ payloadSessionId: "diar-100",+ currentSessionId: "diar-100",+ recordingNoteId: 1,+ });+ assert.deepEqual(result, { targetNoteId: 1, isCurrentSession: true });+});++test("payload noteId still targets the owning note after a new session started", () => {+ // Data-loss mode of #1495: Meeting B already started, so the store's+ // session no longer matches A's — A's result must still land on A, but+ // must not be published to a UI that is waiting on the newer session.+ const result = resolveDiarizationTarget({+ payloadNoteId: 1,+ payloadSessionId: "diar-100",+ currentSessionId: "diar-200",+ recordingNoteId: 2,+ });+ assert.deepEqual(result, { targetNoteId: 1, isCurrentSession: false });+});++test("payload noteId with no pending session is current", () => {+ // Nothing newer is pending, so publishing is safe and clearing a waiting+ // spinner prevents it from getting stuck.+ const result = resolveDiarizationTarget({+ 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", () => {+ 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 });+});++const seg = (id) => ({ id, text: id, source: "mic" });++test("persisted segments of the target note win over live segments", () => {+ const persisted = [seg("p1")];+ const result = selectBaseSegments({+ persistedSegments: persisted,+ liveSegments: [seg("l1")],+ recordingNoteId: 1,+ targetNoteId: 1,+ });+ assert.equal(result, persisted);+});++test("an empty persisted transcript still wins over the fallbacks", () => {+ // A transcript that parses to zero segments is authoritative for the note;+ // falling back to live segments would reintroduce stale data.+ const persisted = [];+ const result = selectBaseSegments({+ persistedSegments: persisted,+ liveSegments: [seg("l1")],+ recordingNoteId: 1,+ targetNoteId: 1,+ });+ assert.equal(result, persisted);+});++test("live segments are used only when the recording belongs to the target note", () => {+ const live = [seg("l1")];+ const result = selectBaseSegments({+ persistedSegments: null,+ liveSegments: live,+ recordingNoteId: 1,+ targetNoteId: 1,+ });+ assert.equal(result, live);+});++test("another note's live segments are never merged into the target note", () => {+ // The cross-contamination guard: the store's live segments belong to the+ // recording note — they must not become part of any other note's transcript.+ const result = selectBaseSegments({+ persistedSegments: null,+ liveSegments: [seg("l1")],+ recordingNoteId: 2,+ targetNoteId: 1,+ });+ assert.deepEqual(result, []);+});++test("no persisted transcript and empty live segments merge into nothing", () => {+ const result = selectBaseSegments({+ persistedSegments: null,+ liveSegments: [],+ recordingNoteId: 1,+ targetNoteId: 1,+ });+ assert.deepEqual(result, []);+});