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): keep a resumed note's earlier rows out of its diarization merge (#2737)
Henry Subad29ce9f79d
diff --git a/src/stores/meetingRecordingStore.ts b/src/stores/meetingRecordingStore.tsindex df2e48da9..5e95e4f1c 100644--- a/src/stores/meetingRecordingStore.ts+++ b/src/stores/meetingRecordingStore.ts@@ -421,6 +421,11 @@ const meetingRecordingStartCoordinator = createMeetingRecordingStartCoordinator(const meetingRecordingStopBarrier = createMeetingRecordingStopBarrier();let isPrepared = false;let segmentsRefValue: TranscriptSegment[] = [];+// A resumed note seeds the recording with its earlier transcript, but that+// session's diarization covers only its own audio, so its result must not be+// matched against the seeded rows. Keyed by diarization session at stop.+let sessionSeedLength = 0;+const seedLengthByDiarizationSession = new Map<string, number>();let preparePromise: Promise<void> | null = null;let ipcCleanups: Array<() => void> = [];let speakerIdentifications: SpeakerIdentification[] = [];@@ -814,6 +819,7 @@ export async function startRecording(args: StartRecordingArgs): Promise<boolean>}segmentsRefValue = seed;+ sessionSeedLength = seed.length;speakerIdentifications = [];nextPlaceholderSpeakerIndex = maxSpeakerIndex + 1;recentSystemSpeaker = null;@@ -1677,12 +1683,14 @@ export async function stopRecording(expectedSessionId?: string): Promise<StopRecawait cleanup();let stoppedDiarizationSessionId: string | null = null;+ const seedLength = sessionSeedLength;try {const result = await window.electronAPI?.meetingTranscriptionStop?.(sessionId ?? undefined);if (result?.diarizationSessionId) {stoppedDiarizationSessionId = result.diarizationSessionId;+ seedLengthByDiarizationSession.set(stoppedDiarizationSessionId, seedLength);useMeetingRecordingStore.setState({diarizationSessionId: stoppedDiarizationSessionId,});@@ -1776,7 +1784,10 @@ if (typeof window !== "undefined") {currentSessionId: diarizationSessionId,activeRecordingNoteId: isRecording ? recordingNoteId : null,});- if (targetNoteId == null) return;+ if (targetNoteId == null) {+ if (data?.sessionId) seedLengthByDiarizationSession.delete(data.sessionId);+ return;+ }// Publishing an empty result clears a waiting editor's spinner without// painting an overlay; anything non-empty is already persisted.@@ -1789,6 +1800,7 @@ if (typeof window !== "undefined") {};if (!data?.segments?.length) {+ if (data?.sessionId) seedLengthByDiarizationSession.delete(data.sessionId);publish([]);return;}@@ -1803,6 +1815,12 @@ if (typeof window !== "undefined") {"meeting");}+ // Read after the getNote await: a skipped diarization is sent before the+ // stop call that records this session's seed length returns.+ const seedLength = data.sessionId+ ? (seedLengthByDiarizationSession.get(data.sessionId) ?? 0)+ : 0;+ if (data.sessionId) seedLengthByDiarizationSession.delete(data.sessionId);// 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.@@ -1819,13 +1837,17 @@ if (typeof window !== "undefined") {recordingNoteId,targetNoteId,});- const enriched = mergeTranscriptSegments(- existing,- data.segments.map((segment, index) => ({- ...segment,- id: segment.id || `diarized-${index}`,- }))- );+ const seededCount = Math.min(seedLength, existing.length);+ const enriched = [+ ...existing.slice(0, seededCount),+ ...mergeTranscriptSegments(+ existing.slice(seededCount),+ data.segments.map((segment, index) => ({+ ...segment,+ id: segment.id || `diarized-${index}`,+ }))+ ),+ ];try {// Awaited so the next queued completion's getNote is guaranteed todiff --git a/test/stores/meetingRecordingStoreDiarizationPublish.test.js b/test/stores/meetingRecordingStoreDiarizationPublish.test.jsindex 733561784..f7373b75a 100644--- a/test/stores/meetingRecordingStoreDiarizationPublish.test.js+++ b/test/stores/meetingRecordingStoreDiarizationPublish.test.js@@ -14,9 +14,17 @@ const {const NOTE_ID = 11;const START_ARGS = { noteId: NOTE_ID, noteTitle: "Standup", folderId: null, autoEndEligible: true };-function createElectronAPI() {+function createElectronAPI({ stopDiarizationSessionId = null } = {}) {const noopListener = () => () => {};- const state = { diarizationCallback: null, updatedTranscripts: [] };+ const state = {+ diarizationCallback: null,+ segmentCallback: null,+ updatedTranscripts: [],+ stopDiarizationSessionId,+ // Runs inside meetingTranscriptionStop, before its reply, like main's+ // synchronous skip-diarization send.+ onStop: null,+ };const notes = new Map([[NOTE_ID, { id: NOTE_ID, transcript: "", deleted_at: null }]]);const api = {checkSystemAudioAccess: async () => ({@@ -31,7 +39,10 @@ function createElectronAPI() {systemAudioStrategy: "native",}),meetingTranscriptionSetSystemAudioAvailable: async () => ({ success: true }),- meetingTranscriptionStop: async () => ({ success: true, diarizationSessionId: null }),+ meetingTranscriptionStop: async () => {+ state.onStop?.(state.stopDiarizationSessionId);+ return { success: true, diarizationSessionId: state.stopDiarizationSessionId };+ },meetingTranscriptionSend: () => {},getNote: async (id) => notes.get(id) ?? null,updateNote: async (id, patch) => {@@ -47,7 +58,12 @@ function createElectronAPI() {state.diarizationCallback = null;};},- onMeetingTranscriptionSegment: noopListener,+ onMeetingTranscriptionSegment: (callback) => {+ state.segmentCallback = callback;+ return () => {+ state.segmentCallback = null;+ };+ },onMeetingSpeakerIdentified: noopListener,onMeetingSpeakersMerged: noopListener,onMeetingSessionSpeakerConfigUpdated: noopListener,@@ -55,10 +71,10 @@ function createElectronAPI() {onMeetingTranscriptionFatalError: noopListener,onMeetingSystemAudioSilent: noopListener,};- return { api, state };+ return { api, state, notes };}-async function loadStore(t, api) {+async function loadModules(t, api) {installMicCaptureGlobals(t);installBrowserGlobals(t, {window: { electronAPI: api, setTimeout: (fn, ms) => setTimeout(fn, ms) },@@ -66,7 +82,13 @@ async function loadStore(t, api) {const vite = await createRendererServer(t, {cachePrefix: "openwhispr-meeting-diarization-publish-test-",});- return vite.ssrLoadModule("/stores/meetingRecordingStore.ts");+ const store = await vite.ssrLoadModule("/stores/meetingRecordingStore.ts");+ const { parseTranscriptSegments } = await vite.ssrLoadModule("/utils/parseTranscriptSegments.ts");+ return { store, parseTranscriptSegments };+}++async function loadStore(t, api) {+ return (await loadModules(t, api)).store;}const ENRICHED = [{ id: "d0", text: "hello there", speaker: "speaker_0", speakerName: "Ada" }];@@ -140,3 +162,157 @@ test("a live recording on another note does not suppress the publish", async (t)assert.equal(store.useMeetingRecordingStore.getState().completedDiarization?.noteId, NOTE_ID);await store.stopRecording();});++// A resumed note seeds the recording with its earlier transcript, but the+// diarization result covers only the resumed session's audio. A repeated line+// must enrich the resumed session's row, never the earlier session's twin.+test("a resumed note's diarization labels the resumed session's row, not an earlier one with the same text", async (t) => {+ const { api, state } = createElectronAPI({ stopDiarizationSessionId: "diar-resumed" });+ const store = await loadStore(t, api);++ const earlierSession = [+ {+ id: "stored-0",+ text: "Can everyone hear me?",+ source: "system",+ timestamp: 1.0,+ speaker: "speaker_0",+ speakerName: "Bob",+ speakerIsPlaceholder: false,+ speakerStatus: "confirmed",+ },+ {+ id: "stored-1",+ text: "Yeah.",+ source: "system",+ timestamp: 4.2,+ speaker: "speaker_1",+ speakerName: "Carol",+ speakerIsPlaceholder: false,+ speakerStatus: "confirmed",+ },+ ];+ assert.equal(await store.startRecording({ ...START_ARGS, seedSegments: earlierSession }), true);+ state.segmentCallback({+ type: "final",+ source: "system",+ text: "Yeah.",+ timestamp: 1760000003000,+ });+ await store.stopRecording();++ state.diarizationCallback({+ noteId: NOTE_ID,+ sessionId: "diar-resumed",+ segments: [+ {+ text: "Yeah.",+ source: "system",+ timestamp: 3.0,+ speaker: "speaker_0",+ speakerName: "Dave",+ speakerIsPlaceholder: false,+ speakerStatus: "confirmed",+ },+ ],+ });+ await settle();++ const rows = JSON.parse(state.updatedTranscripts.at(-1).transcript);+ assert.deepEqual(+ rows.map((row) => [row.text, row.timestamp, row.speakerName]),+ [+ ["Can everyone hear me?", 1.0, "Bob"],+ ["Yeah.", 4.2, "Carol"],+ ["Yeah.", 3.0, "Dave"],+ ]+ );+});++const diarized = (text, timestamp, speakerName) => ({+ text,+ source: "system",+ timestamp,+ speaker: "speaker_0",+ speakerName,+ speakerIsPlaceholder: false,+ speakerStatus: "confirmed",+});++const rowsOf = (note) =>+ JSON.parse(note.transcript).map((row) => [row.text, row.timestamp, row.speakerName]);++// Each stop keeps its own seed length: with one shared value, the resumed+// session's seed would also shield the earlier session's own diarization.+test("an earlier session's diarization that lands after the note was resumed still labels its rows", async (t) => {+ const { api, state, notes } = createElectronAPI();+ const { store, parseTranscriptSegments } = await loadModules(t, api);+ const note = notes.get(NOTE_ID);++ state.stopDiarizationSessionId = "diar-1";+ assert.equal(await store.startRecording(START_ARGS), true);+ state.segmentCallback({+ type: "final",+ source: "system",+ text: "Yeah.",+ timestamp: 1760000001000,+ });+ await store.stopRecording();++ state.stopDiarizationSessionId = "diar-2";+ const seedSegments = parseTranscriptSegments(note.transcript);+ assert.equal(await store.startRecording({ ...START_ARGS, seedSegments }), true);+ state.segmentCallback({+ type: "final",+ source: "system",+ text: "Yeah.",+ timestamp: 1760000100000,+ });+ await store.stopRecording();++ state.diarizationCallback({+ noteId: NOTE_ID,+ sessionId: "diar-1",+ segments: [diarized("Yeah.", 1.0, "Carol")],+ });+ await settle();+ state.diarizationCallback({+ noteId: NOTE_ID,+ sessionId: "diar-2",+ segments: [diarized("Yeah.", 2.0, "Dave")],+ });+ await settle();++ assert.deepEqual(rowsOf(note), [+ ["Yeah.", 1.0, "Carol"],+ ["Yeah.", 2.0, "Dave"],+ ]);+});++// Main sends a skipped diarization before the stop call returns, so the+// listener must read the seed length only after its getNote round trip.+test("a skipped diarization sent before stop returns still leaves the seeded rows alone", async (t) => {+ const { api, state, notes } = createElectronAPI({ stopDiarizationSessionId: "diar-skipped" });+ const { store, parseTranscriptSegments } = await loadModules(t, api);+ const note = notes.get(NOTE_ID);+ note.transcript = JSON.stringify([diarized("Yeah.", 1.0, "Carol")]);++ state.onStop = (sessionId) =>+ state.diarizationCallback({+ noteId: NOTE_ID,+ sessionId,+ segments: [{ id: "segment-0", text: "Yeah.", source: "system", timestamp: 1760000100001 }],+ });+ const seedSegments = parseTranscriptSegments(note.transcript);+ assert.equal(await store.startRecording({ ...START_ARGS, seedSegments }), true);+ state.segmentCallback({+ type: "final",+ source: "system",+ text: "Yeah.",+ timestamp: 1760000100000,+ });+ await store.stopRecording();+ await settle();++ assert.deepEqual(rowsOf(note)[0], ["Yeah.", 1.0, "Carol"]);+});