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(dictation): keep local cleanup off Cloud when cleanupCloudMode is stale (#2713)
Chad Piha0a2f59867576
diff --git a/src/helpers/audioManager.js b/src/helpers/audioManager.jsindex 94e58712d..79e82a6d9 100644--- a/src/helpers/audioManager.js+++ b/src/helpers/audioManager.js@@ -3533,6 +3533,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);const timings = {};const settings = getSettings();+ const isCloudCleanup = isCloudCleanupMode();const language = getBaseLanguageCode(this.getEffectiveSttLanguage(settings));const arrayBuffer = await audioBlob.arrayBuffer();@@ -3557,14 +3558,9 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);opts.analyticsOccurredAt = analyticsOccurredAt.toISOString();opts.localDate = localDateKey(analyticsOccurredAt);}- const cleanupCloudMode = settings.cleanupCloudMode || "openwhispr";// Only cloud cleanup writes a combined STT log; translation alone does not.// A voice assistant recording never runs cleanup, so this upload is its log.- if (- settings.useCleanupModel &&- cleanupCloudMode === "openwhispr" &&- !this.voiceAgentRequested- ) {+ if (settings.useCleanupModel && isCloudCleanup && !this.voiceAgentRequested) {opts.sendLogs = "false";}@@ -3610,8 +3606,6 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);if (this.translationRequested && route.kind !== "translation") {this.notifyTranslationFallback("unreachable");}- const cleanupCloudMode = settings.cleanupCloudMode || "openwhispr";-try {if (route.kind === "agent") {const reasoned = await this.processAgentCommand(@@ -3625,7 +3619,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);wasCancelled);if (hasTextContent(reasoned)) processedText = reasoned;- } else if (route.kind === "cleanup" && cleanupCloudMode === "openwhispr") {+ } else if (route.kind === "cleanup" && isCloudCleanup) {const customPrompt = this.getCustomPrompt();const reasonResult = await withSessionRefresh(async () => {const res = await window.electronAPI.cloudReason(processedText, {@@ -3679,31 +3673,30 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);settings,agentName,route,- cleanup:- cleanupCloudMode === "openwhispr"- ? {- mode: "cloudReason",- meta: {- streamingFallbackReason,- orukeetLanguageRouting: metadata.orukeetLanguageRouting,- orukeetCleanup: metadata.orukeetCleanup,- ...detectedLanguageFields,- sttProvider: result.sttProvider,- sttModel: result.sttModel,- sttProcessingMs: result.sttProcessingMs,- sttWordCount: result.sttWordCount,- sttLanguage: result.sttLanguage,- audioDurationMs: result.audioDurationMs,- audioSizeBytes,- audioFormat,- },- log: { level: "error", channel: "transcription" },- }- : {- mode: "model",- model: getEffectiveCleanupModel(),- log: { level: "error", channel: "transcription" },+ cleanup: isCloudCleanup+ ? {+ mode: "cloudReason",+ meta: {+ streamingFallbackReason,+ orukeetLanguageRouting: metadata.orukeetLanguageRouting,+ orukeetCleanup: metadata.orukeetCleanup,+ ...detectedLanguageFields,+ sttProvider: result.sttProvider,+ sttModel: result.sttModel,+ sttProcessingMs: result.sttProcessingMs,+ sttWordCount: result.sttWordCount,+ sttLanguage: result.sttLanguage,+ audioDurationMs: result.audioDurationMs,+ audioSizeBytes,+ audioFormat,},+ log: { level: "error", channel: "transcription" },+ }+ : {+ mode: "model",+ model: getEffectiveCleanupModel(),+ log: { level: "error", channel: "transcription" },+ },});processedText = resolveTranslatedText(processedText, chainResult);}@@ -4697,7 +4690,6 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);!settings.useCleanupModel ||!isCloudCleanupMode() ||!isLlmSelectionAllowed(usePolicyStore.getState(), { mode: "openwhispr" }) ||- (settings.cleanupCloudMode || "openwhispr") !== "openwhispr" ||voiceAgentRequested ||translationRequested)@@ -5823,7 +5815,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);if (this.translationRequested && route.kind !== "translation") {this.notifyTranslationFallback("unreachable");}- const cleanupCloudMode = stSettings.cleanupCloudMode || "openwhispr";+ const isCloudCleanup = isCloudCleanupMode();try {if (route.kind === "agent") {@@ -5843,7 +5835,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);{ reasoningDurationMs: Math.round(performance.now() - reasoningStart) },"streaming");- } else if (route.kind === "cleanup" && cleanupCloudMode === "openwhispr") {+ } else if (route.kind === "cleanup" && isCloudCleanup) {const customPrompt = this.getCustomPrompt();// ASR finished but the combined cleanup didn't: paste the raw text, as// any other failed cleanup does.@@ -5925,31 +5917,30 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);settings: stSettings,agentName,route,- cleanup:- cleanupCloudMode === "openwhispr"- ? {- mode: "cloudReason",- meta: {- sttProvider: providerName,- sttModel: streamingSttModel,- sttProcessingMs: streamingSttProcessingMs,- sttWordCount: streamingSttWordCount,- sttLanguage: streamingSttLanguage,- ...detectedLanguageFields,- ...uncombinedTelemetry,- audioDurationMs: durationSeconds- ? Math.round(durationSeconds * 1000)- : undefined,- audioSizeBytes: streamingAudioBytesSent || undefined,- audioFormat: "linear16",- },- log: { level: "error", channel: "streaming" },- }- : {- mode: "model",- model: getEffectiveCleanupModel(),- log: { level: "error", channel: "streaming" },+ cleanup: isCloudCleanup+ ? {+ mode: "cloudReason",+ meta: {+ sttProvider: providerName,+ sttModel: streamingSttModel,+ sttProcessingMs: streamingSttProcessingMs,+ sttWordCount: streamingSttWordCount,+ sttLanguage: streamingSttLanguage,+ ...detectedLanguageFields,+ ...uncombinedTelemetry,+ audioDurationMs: durationSeconds+ ? Math.round(durationSeconds * 1000)+ : undefined,+ audioSizeBytes: streamingAudioBytesSent || undefined,+ audioFormat: "linear16",},+ log: { level: "error", channel: "streaming" },+ }+ : {+ mode: "model",+ model: getEffectiveCleanupModel(),+ log: { level: "error", channel: "streaming" },+ },});finalText = resolveTranslatedText(finalText, chainResult);usedCloudReasoning = chainResult.usedCloudReasoning || usedCloudReasoning;diff --git a/src/stores/settingsStore.ts b/src/stores/settingsStore.tsindex 0abd72985..eac85f35e 100644--- a/src/stores/settingsStore.ts+++ b/src/stores/settingsStore.ts@@ -2725,6 +2725,8 @@ export const useSettingsStore = create<SettingsState>()((set, get) => ({// --- Selectors (derived state, not stored) ---+// Route cleanup to Cloud on this, never on cleanupCloudMode alone: picking a local+// model or the notes onboarding mode toggle sets cleanupMode and leaves that field stale.export const selectIsCloudCleanupMode = (state: SettingsState) =>state.isSignedIn && state.cleanupMode === "openwhispr" && state.cleanupCloudMode === "openwhispr";diff --git a/test/helpers/audioManagerStreamingFinalization.test.js b/test/helpers/audioManagerStreamingFinalization.test.jsindex cdd355d68..fff23ee3f 100644--- a/test/helpers/audioManagerStreamingFinalization.test.js+++ b/test/helpers/audioManagerStreamingFinalization.test.js@@ -2104,3 +2104,282 @@ test("combined options are captured and passed through recording start", async (assert.equal(manager._activeStreamingConfig.orukeetPipeline, "gemma12");await manager.cancelStreamingRecording();});++// Cleanup routes on the store's whole cloud predicate, so the mock mirrors+// selectIsCloudCleanupMode: onboarding's local choice leaves cleanupCloudMode at+// its "openwhispr" default, and that field alone must never send text to Cloud.+const CLEANUP_ROUTING_STORE = `+ export const getSettings = () => globalThis.__streamingFinalizationSettings;+ export const isCloudCleanupMode = () => {+ const s = getSettings();+ return !!s.isSignedIn && s.cleanupMode === "openwhispr" && s.cleanupCloudMode === "openwhispr";+ };+ export const selectResolvedLLMConfig = (s) => ({+ model: s.cleanupModel,+ provider: s.cleanupMode === "openwhispr" ? "openwhispr" : "qwen",+ mode: s.cleanupMode,+ });+ export const getEffectiveCleanupModel = () =>+ isCloudCleanupMode() ? "" : selectResolvedLLMConfig(getSettings()).model;+ export const isCloudDictationAgentMode = () => false;+ export const isCloudTranslationMode = () => false;+`;++const LOCAL_CLEANUP_MODEL = "qwen3.5-4b-q4_k_m";++// `expected` is where cleanup runs: "cloud" (cloudReason), "model" (the scope's+// own model) or "raw" (no reachable cleanup, so the transcript is kept as is).+const CLEANUP_ROUTING_CASES = [+ {+ label: "local, cloud field left at default",+ cleanupMode: "local",+ cleanupCloudMode: "openwhispr",+ expected: "model",+ },+ {+ label: "local, cloud field byok",+ cleanupMode: "local",+ cleanupCloudMode: "byok",+ expected: "model",+ },+ {+ label: "local, model not downloaded",+ cleanupMode: "local",+ cleanupCloudMode: "openwhispr",+ cleanupModel: "",+ expected: "raw",+ },+ {+ label: "self-hosted, cloud field left at default",+ cleanupMode: "self-hosted",+ cleanupCloudMode: "openwhispr",+ expected: "model",+ },+ {+ label: "providers (BYOK)",+ cleanupMode: "providers",+ cleanupCloudMode: "byok",+ expected: "model",+ },+ {+ label: "providers, cloud field left at default",+ cleanupMode: "providers",+ cleanupCloudMode: "openwhispr",+ expected: "model",+ },+ {+ label: "OpenWhispr Cloud",+ cleanupMode: "openwhispr",+ cleanupCloudMode: "openwhispr",+ expected: "cloud",+ },+ {+ label: "OpenWhispr Cloud, signed out",+ cleanupMode: "openwhispr",+ cleanupCloudMode: "openwhispr",+ cleanupModel: "",+ isSignedIn: false,+ expected: "raw",+ },+];++const SIGNED_IN_CLEANUP_ROUTING_CASES = CLEANUP_ROUTING_CASES.filter(+ ({ isSignedIn }) => isSignedIn !== false+);++function cleanupRoutingSettings({+ cleanupMode,+ cleanupCloudMode,+ cleanupModel = LOCAL_CLEANUP_MODEL,+ isSignedIn = true,+}) {+ return {+ useCleanupModel: true,+ cleanupMode,+ cleanupCloudMode,+ cleanupModel,+ isSignedIn,+ customPrompts: {},+ };+}++function cleanedText(text, { expected }) {+ if (expected === "cloud") return `${text}。`;+ return expected === "model" ? `${text} (local)` : text;+}++const CLEANUP_TRANSLATION_MODULES = {+ "/stores/settingsStore": CLEANUP_ROUTING_STORE,+ "/config/prompts": `+ export const resolvePrompt = () => "translation prompt";+ export const appendScreenContextSuffix = (prompt) => prompt;+ `,+ "/dictationAgentInference": `+ export const resolveDictationAgentInference = () => ({ reachable: false, config: {} });+ export const resolveDictationAgentVisionInference = () => ({ active: false, config: {} });+ `,+ "/dictationTranslationInference": `+ export const resolveDictationTranslationInference = () => ({+ reachable: true, model: "translation-model", config: { provider: "qwen" }+ });+ `,+};++// Cloud carries the STT telemetry for its combined log; any other cleanup+// descriptor names the scope's model and sends nothing to Cloud.+function assertChainCleanup(cleanup, routing) {+ if (routing.expected === "cloud") {+ assert.equal(cleanup.mode, "cloudReason");+ return;+ }+ assert.equal(cleanup.mode, "model");+ assert.equal(cleanup.model, cleanupRoutingSettings(routing).cleanupModel);+ assert.equal(cleanup.meta, undefined);+}++function useOnlineNavigator(t) {+ const originalNavigator = globalThis.navigator;+ Object.defineProperty(globalThis, "navigator", { value: { onLine: true }, configurable: true });+ t.after(() =>+ Object.defineProperty(globalThis, "navigator", {+ value: originalNavigator,+ configurable: true,+ })+ );+}++function countingReasoningModel(localCalls) {+ return async (text, model) => {+ localCalls.push([text, model]);+ return `${text} (local)`;+ };+}++test("streaming cleanup goes to Cloud only when the cleanup scope is OpenWhispr Cloud", async (t) => {+ const AudioManager = await loadManagerClass(t, {+ "/stores/settingsStore": CLEANUP_ROUTING_STORE,+ });+ for (const routing of CLEANUP_ROUTING_CASES) {+ await t.test(routing.label, async () => {+ const localCalls = [];+ const { reasonCalls, usage, published } = await stopManagedDictation(AudioManager, {+ final: { success: true, text: "hello there", model: "orukeet-v0.1.0" },+ language: "en",+ upload: async () => assert.fail("must not re-transcribe"),+ settings: cleanupRoutingSettings(routing),+ overrides: {+ processWithReasoningModel: countingReasoningModel(localCalls),+ finalizeChineseScript: async (text) => text,+ },+ });+ assert.equal(reasonCalls.length, routing.expected === "cloud" ? 1 : 0);+ assert.deepEqual(+ localCalls.map(([, model]) => model),+ routing.expected === "model" ? [LOCAL_CLEANUP_MODEL] : []+ );+ assert.equal(published[0].text, cleanedText("hello there", routing));+ // Only a Cloud cleanup writes the combined log, so only it suppresses the STT one.+ assert.equal(usage.length, 1);+ assert.equal(usage[0].sendLogs, routing.expected !== "cloud");+ });+ }+});++test("streaming translation cleans up in Cloud only when the cleanup scope is OpenWhispr Cloud", async (t) => {+ const AudioManager = await loadManagerClass(t, CLEANUP_TRANSLATION_MODULES);+ for (const routing of CLEANUP_ROUTING_CASES) {+ await t.test(routing.label, async () => {+ const chainCleanups = [];+ await stopManagedDictation(AudioManager, {+ final: { success: true, text: "hello there", model: "orukeet-v0.1.0" },+ language: "en",+ upload: async () => assert.fail("must not re-transcribe"),+ settings: {+ ...cleanupRoutingSettings(routing),+ translationSourceLanguage: "en",+ translationTargetLanguage: "es",+ },+ overrides: {+ translationRequested: true,+ runTranslationChain: async ({ cleanup }) => {+ chainCleanups.push(cleanup);+ return { text: "hola" };+ },+ finalizeChineseScript: async (text) => text,+ },+ });+ assert.equal(chainCleanups.length, 1);+ assertChainCleanup(chainCleanups[0], routing);+ });+ }+});++test("batch Cloud cleanup goes to Cloud only when the cleanup scope is OpenWhispr Cloud", async (t) => {+ const AudioManager = await loadManagerClass(t, {+ "/stores/settingsStore": CLEANUP_ROUTING_STORE,+ });+ useOnlineNavigator(t);+ // Signed out never re-transcribes through Cloud, so it never reaches this path.+ for (const routing of SIGNED_IN_CLEANUP_ROUTING_CASES) {+ await t.test(routing.label, async () => {+ const transcribeOpts = [];+ globalThis.window.electronAPI.cloudTranscribe = async (_audio, opts) => {+ transcribeOpts.push(opts);+ return { success: true, text: "明日の会議", sttProvider: "openai" };+ };+ const localCalls = [];+ const { reasonCalls, published } = await stopManagedDictation(AudioManager, {+ final: JA_FINAL,+ settings: cleanupRoutingSettings(routing),+ overrides: {+ isDictionaryEcho: () => false,+ getWhisperPrompt: () => null,+ finalizeChineseScript: async (text) => text,+ processWithReasoningModel: countingReasoningModel(localCalls),+ },+ });+ assert.equal(transcribeOpts.length, 1);+ assert.equal(reasonCalls.length, routing.expected === "cloud" ? 1 : 0);+ assert.equal(localCalls.length, routing.expected === "model" ? 1 : 0);+ assert.equal(published[0].text, cleanedText("明日の会議", routing));+ // Only a Cloud cleanup writes the combined log, so only it suppresses the STT one.+ assert.equal(transcribeOpts[0].sendLogs, routing.expected === "cloud" ? "false" : undefined);+ });+ }+});++test("batch Cloud translation cleans up in Cloud only when the cleanup scope is OpenWhispr Cloud", async (t) => {+ const AudioManager = await loadManagerClass(t, CLEANUP_TRANSLATION_MODULES);+ useOnlineNavigator(t);+ for (const routing of SIGNED_IN_CLEANUP_ROUTING_CASES) {+ await t.test(routing.label, async () => {+ const transcribeOpts = [];+ globalThis.window.electronAPI.cloudTranscribe = async (_audio, opts) => {+ transcribeOpts.push(opts);+ return { success: true, text: "明日の会議", sttProvider: "openai" };+ };+ const chainCleanups = [];+ await stopManagedDictation(AudioManager, {+ final: JA_FINAL,+ settings: {+ ...cleanupRoutingSettings(routing),+ translationSourceLanguage: "ja",+ translationTargetLanguage: "en",+ },+ overrides: {+ translationRequested: true,+ isDictionaryEcho: () => false,+ getWhisperPrompt: () => null,+ runTranslationChain: async ({ cleanup }) => {+ chainCleanups.push(cleanup);+ return { text: "tomorrow's meeting" };+ },+ finalizeChineseScript: async (text) => text,+ },+ });+ assert.equal(transcribeOpts.length, 1);+ assert.equal(chainCleanups.length, 1);+ assertChainCleanup(chainCleanups[0], routing);+ });+ }+});