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 text when reasoning returns blank output (#1645)
Chad Piha7f08a4917ba9
diff --git a/src/components/ControlPanel.tsx b/src/components/ControlPanel.tsxindex 93c448060..6dbbe8b6e 100644--- a/src/components/ControlPanel.tsx+++ b/src/components/ControlPanel.tsx@@ -68,7 +68,11 @@ import {initializeNotes,} from "../stores/noteStore";import { fetchProviders as fetchStreamingProviders } from "../stores/streamingProvidersStore";-import { executeTranslationChain, shouldRunTranslateStep } from "../helpers/translationChain";+import {+ executeTranslationChain,+ hasTextContent,+ shouldRunTranslateStep,+} from "../helpers/translationChain";import { applyChineseScript, resolveChineseScriptTarget } from "../utils/chineseScript";import HistoryView from "./HistoryView";import BackgroundActionToastListener from "./notes/BackgroundActionToastListener";@@ -740,7 +744,7 @@ export default function ControlPanel({ initialSettingsSection }: ControlPanelProconst reasonedText = await ReasoningService.processText(rawText, model, agentName, {disableThinking: getSettings().cleanupDisableThinking,});- if (reasonedText && reasonedText !== rawText) {+ if (hasTextContent(reasonedText) && reasonedText !== rawText) {const updated = await window.electronAPI.updateTranscriptionText(id,reasonedText,diff --git a/src/helpers/audioManager.js b/src/helpers/audioManager.jsindex a7e776039..edf45348b 100644--- a/src/helpers/audioManager.js+++ b/src/helpers/audioManager.js@@ -64,6 +64,7 @@ import {import { resolveStreamingFallbackTarget } from "./transcriptionFallback";import {executeTranslationChain,+ hasTextContent,resolveTranslatedText,shouldRunTranslateStep,} from "./translationChain";@@ -2616,7 +2617,8 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);processingTime: new Date().toISOString(),});- return result;+ // A blank reply must not wipe the dictation — keep the transcript (#1616).+ return hasTextContent(result) ? result : normalizedText;} catch (error) {if (error.selectionEditFatal) throw error;logger.logReasoning("REASONING_FAILED", {@@ -2871,7 +2873,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);...route.config,requiresAgent: true,});- if (reasoned) processedText = reasoned;+ if (hasTextContent(reasoned)) processedText = reasoned;} else if (route.kind === "cleanup" && cleanupCloudMode === "openwhispr") {const reasonResult = await withSessionRefresh(async () => {const res = await window.electronAPI.cloudReason(processedText, {@@ -2899,7 +2901,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);});// Cloud cleanup can return success with empty text; keep the raw transcription instead of wiping it.- if (reasonResult.success && reasonResult.text) {+ if (reasonResult.success && hasTextContent(reasonResult.text)) {processedText = reasonResult.text;}} else if (route.kind === "cleanup") {@@ -2911,7 +2913,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);agentName,route.config);- if (reasoned) processedText = reasoned;+ if (hasTextContent(reasoned)) processedText = reasoned;}} else if (route.kind === "translation") {const chainResult = await this.runTranslationChain({@@ -4253,7 +4255,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);...route.config,requiresAgent: true,});- if (reasoned) finalText = reasoned;+ if (hasTextContent(reasoned)) finalText = reasoned;logger.info("Streaming dictation-agent complete",{ reasoningDurationMs: Math.round(performance.now() - reasoningStart) },@@ -4285,7 +4287,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);return res;});- if (reasonResult.success && reasonResult.text) {+ if (reasonResult.success && hasTextContent(reasonResult.text)) {finalText = reasonResult.text;}usedCloudReasoning = true;@@ -4307,7 +4309,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);agentName,route.config);- if (reasoned) finalText = reasoned;+ if (hasTextContent(reasoned)) finalText = reasoned;logger.info("Streaming BYOK reasoning complete",{ reasoningDurationMs: Math.round(performance.now() - reasoningStart) },diff --git a/src/helpers/translationChain.js b/src/helpers/translationChain.jsindex 869d577b4..e26b2e6b4 100644--- a/src/helpers/translationChain.js+++ b/src/helpers/translationChain.js@@ -6,6 +6,13 @@ function normalizeComparableText(value) {return value.trim().replace(/\s+/g, " ");}+// Shared guard for reasoning/cleanup output (#1616): a whitespace-only reply counts+// as empty and must never replace existing text. Also used by the agent/cleanup+// call sites in audioManager and the history-retry path in ControlPanel.+export function hasTextContent(value) {+ return typeof value === "string" && value.trim().length > 0;+}+// Whether the translate step should run: skip only when an explicit source language// equals the target. "auto" (or empty, treated as auto) always translates.export function shouldRunTranslateStep(sourceLanguage, targetLanguage) {@@ -34,7 +41,7 @@ export async function executeTranslationChain({if (cleanupReachable) {try {const cleaned = await runCleanup(out);- if (normalizeComparableText(cleaned)) out = cleaned;+ if (hasTextContent(cleaned)) out = cleaned;// Cloud cleanup counts as cloud reasoning once its call succeeds, even if it// returned empty text.if (cleanupIsCloud) usedCloudReasoning = true;@@ -64,5 +71,5 @@ export async function executeTranslationChain({// Keep the chain result only when it produced text; an empty/missing result// preserves the input so a dictation is never overwritten with nothing.export function resolveTranslatedText(previousText, chainResult) {- return normalizeComparableText(chainResult?.text) ? chainResult.text : previousText;+ return hasTextContent(chainResult?.text) ? chainResult.text : previousText;}diff --git a/test/helpers/translationChain.test.js b/test/helpers/translationChain.test.jsindex 46b73b5e8..31b83c654 100644--- a/test/helpers/translationChain.test.js+++ b/test/helpers/translationChain.test.js@@ -411,3 +411,16 @@ test("translated: false when the translate step is skipped", async () => {assert.equal(result.translated, false);assert.equal(result.text, "raw");});++// Guard shared with the agent/cleanup call sites (audioManager, ControlPanel history+// retry): whitespace-only reasoning output must never replace existing text (#1616).+test("hasTextContent: true only for strings with non-whitespace content", async () => {+ const { hasTextContent } = await load();++ assert.equal(hasTextContent("cleaned text"), true);+ assert.equal(hasTextContent(" padded "), true);+ assert.equal(hasTextContent(""), false);+ assert.equal(hasTextContent(" \n\t "), false);+ assert.equal(hasTextContent(null), false);+ assert.equal(hasTextContent(undefined), false);+});