Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(gpu): deliver GPU pack notices to dictation panel for start-minimized users (#2554) (#2565)

Aditya kumar singh1cd25b0edd10
diff --git a/main.js b/main.js
index a9cb5e263..f087be23a 100644
--- a/main.js
+++ b/main.js
@@ -564,8 +564,8 @@ function initializeCoreManagers() {
llamaVulkanManager,
]);
if (clearedPacks.length > 0) {
- // No window exists yet — persist the notice; a control panel window
- // shows it as a toast and clears it. See #1606.
+ // No window exists yet — persist the notice; the window that shows it
+ // as a toast takes it (#1606, #2554).
require("./src/helpers/gpuPackMigrationNotice").record(clearedPacks);
}
// The 1.8.3 migration deleted lib-carrying packs without recording that
@@ -1234,6 +1234,7 @@ async function startApp() {
const launchedHidden = wasLaunchedAtLoginHidden();
const startMinimized = environmentManager.getStartMinimized() || launchedHidden;
if (debugLogger) debugLogger.info("Start minimized", { enabled: startMinimized, launchedHidden });
+ windowManager.startedMinimized = startMinimized;
await windowManager.createMainWindow();
await checkStartupHold();
if (!startMinimized) {
diff --git a/preload.js b/preload.js
index 42ce31a0f..40ca4ced8 100644
--- a/preload.js
+++ b/preload.js
@@ -479,9 +479,12 @@ contextBridge.exposeInMainWorld("electronAPI", {
(callback) => () => callback()
),
- // One-time "GPU pack needs re-downloading" notice from the legacy-layout migration
- getGpuPackMigrationNotice: () => ipcRenderer.invoke("get-gpu-pack-migration-notice"),
- dismissGpuPackMigrationNotice: () => ipcRenderer.invoke("dismiss-gpu-pack-migration-notice"),
+ // One-time "GPU pack needs re-downloading" notice
+ takeGpuPackMigrationNotice: () => ipcRenderer.invoke("take-gpu-pack-migration-notice"),
+ onGpuPackMigrationNoticeReady: registerListener(
+ "gpu-pack-migration-notice-ready",
+ (callback) => () => callback()
+ ),
// Local Parakeet (NVIDIA) functions
transcribeLocalParakeet: (audioBlob, options) =>
diff --git a/src/components/GpuPackMigrationToastListener.tsx b/src/components/GpuPackMigrationToastListener.tsx
index ae386cc38..112918661 100644
--- a/src/components/GpuPackMigrationToastListener.tsx
+++ b/src/components/GpuPackMigrationToastListener.tsx
@@ -1,37 +1,57 @@
import { useEffect } from "react";
import { useTranslation } from "react-i18next";
import { useToast } from "./ui/useToast";
-import { isDictationPanelWindow } from "../utils/windowContext";
+import { isControlPanelWindow } from "../utils/windowContext";
/**
- * One-time notice that the legacy-layout migration cleared a GPU pack, which
+ * One-time notice that a GPU pack was cleared or needs re-downloading, which
* otherwise degrades to a silent CPU fallback. The notice is persisted by the
- * main process (it happens before any window exists) and cleared once shown.
- * See #1606.
+ * main process (it happens before any window exists) and taken by the window
+ * that shows it: the control panel, or the dictation panel of an app started
+ * to the tray, which main tells once the normal app is up (#1606, #2554).
*/
export default function GpuPackMigrationToastListener() {
const { t } = useTranslation();
const { toast } = useToast();
useEffect(() => {
- // Only the control panel shows it — the dictation panel is transient and
- // would burn the one-time notice where it's least likely to be read.
- if (isDictationPanelWindow()) return;
- let cancelled = false;
- window.electronAPI?.getGpuPackMigrationNotice?.().then((notice) => {
- if (cancelled || !notice) return;
+ // Taking the notice clears it, so it is shown even if this effect was
+ // cleaned up meanwhile (StrictMode remounts) rather than lost.
+ const takeAndShow = async () => {
+ const notice = await window.electronAPI?.takeGpuPackMigrationNotice?.();
+ if (!notice) return;
+
+ const inControlPanel = isControlPanelWindow();
+ if (!inControlPanel) void window.electronAPI?.showDictationPanel?.();
+ // The llama pack's card is under AI Models; every other pack is whisper's.
+ const settingsSection = notice.packs.every((pack) => pack.endsWith("llama"))
+ ? "llms"
+ : "speechToText";
toast({
title: t("app.toasts.gpuPackMigration.title"),
description: t("app.toasts.gpuPackMigration.description", {
packs: notice.packs.join(", "),
}),
- duration: 15000,
+ actions: [
+ {
+ label: t("providerErrors.openSettings"),
+ icon: "settings",
+ onClick: () => {
+ void window.electronAPI?.openSettingsSection?.(settingsSection);
+ },
+ },
+ ],
+ // An app started to the tray may take the notice at login, before
+ // anyone is looking, so the pill keeps it until it is dismissed.
+ duration: inControlPanel ? 15000 : 0,
});
- window.electronAPI?.dismissGpuPackMigrationNotice?.();
- });
- return () => {
- cancelled = true;
};
+
+ if (isControlPanelWindow()) {
+ void takeAndShow();
+ return undefined;
+ }
+ return window.electronAPI?.onGpuPackMigrationNoticeReady?.(() => void takeAndShow());
}, [toast, t]);
return null;
diff --git a/src/helpers/debugLogger.js b/src/helpers/debugLogger.js
index 449e0dbce..3f87b85d5 100644
--- a/src/helpers/debugLogger.js
+++ b/src/helpers/debugLogger.js
@@ -116,7 +116,7 @@ class DebugLogger {
resolveConsoleLogging() {
// Packaged Windows apps can inherit the launching shell's standard handles.
- return process.platform !== "win32" || !app.isPackaged || hasConsoleLogOptIn();
+ return process.platform !== "win32" || !app?.isPackaged || hasConsoleLogOptIn();
}
refreshLogLevel() {
diff --git a/src/helpers/gpuBinaryManager.js b/src/helpers/gpuBinaryManager.js
index 3d0f8e3ca..edf7b8c47 100644
--- a/src/helpers/gpuBinaryManager.js
+++ b/src/helpers/gpuBinaryManager.js
@@ -4,6 +4,7 @@ const { createHash } = require("crypto");
const path = require("path");
const { app } = require("electron");
const debugLogger = require("./debugLogger");
+const { warnGpuFallback } = require("./gpuFallbackLog");
const {
downloadFile,
fetchJson,
@@ -85,7 +86,16 @@ class GpuBinaryManager {
const binaryPath = path.join(this.binDir, assetConfig.outputName);
try {
if (!fs.existsSync(binaryPath)) return null;
- if (getMissingRequiredLibraries(this.binDir, assetConfig).length === 0) return binaryPath;
+ const missing = getMissingRequiredLibraries(this.binDir, assetConfig);
+ if (missing.length === 0) return binaryPath;
+ if (this._lastLoggedMissingLibraries !== missing.join(",")) {
+ this._lastLoggedMissingLibraries = missing.join(",");
+ warnGpuFallback("GPU pack binary present but missing required runtime libraries", {
+ pack: this.config.name,
+ binaryPath,
+ missingLibraries: missing,
+ });
+ }
} catch {}
return null;
}
diff --git a/src/helpers/gpuFallbackLog.js b/src/helpers/gpuFallbackLog.js
new file mode 100644
index 000000000..3fd9bad65
--- /dev/null
+++ b/src/helpers/gpuFallbackLog.js
@@ -0,0 +1,32 @@
+const fs = require("fs");
+const path = require("path");
+const { app } = require("electron");
+const debugLogger = require("./debugLogger");
+
+// debugLogger writes a file only at --log-level=debug, so a GPU pack that
+// can't be used would leave no trace of why transcription fell back (#2554).
+// These warnings also go to a log of their own at any level. The first one of
+// each launch replaces the previous launch's lines, so the file never grows.
+const LOG_FILENAME = "gpu-fallback.log";
+
+let startedThisLaunch = false;
+
+function getLogPath() {
+ return path.join(app.getPath("userData"), "logs", LOG_FILENAME);
+}
+
+function warnGpuFallback(message, meta) {
+ debugLogger.warn(message, meta);
+ try {
+ const logPath = getLogPath();
+ const line = `[${new Date().toISOString()}] [${app.getVersion()}] ${message} ${JSON.stringify(meta)}\n`;
+ fs.mkdirSync(path.dirname(logPath), { recursive: true });
+ if (startedThisLaunch) fs.appendFileSync(logPath, line);
+ else fs.writeFileSync(logPath, line);
+ startedThisLaunch = true;
+ } catch {
+ // Best-effort: the warning still went to debugLogger.
+ }
+}
+
+module.exports = { warnGpuFallback };
diff --git a/src/helpers/gpuPackMigrationNotice.js b/src/helpers/gpuPackMigrationNotice.js
index 3f616972c..f112b99a8 100644
--- a/src/helpers/gpuPackMigrationNotice.js
+++ b/src/helpers/gpuPackMigrationNotice.js
@@ -4,9 +4,9 @@ const { app } = require("electron");
// The legacy-layout migration (migrateLegacyBinDir) runs before any window
// exists and can clear a GPU pack the user relied on. This sentinel carries
-// the "re-download your GPU pack" notice across launches until a control
-// panel window has actually shown it — a broadcast at window creation would
-// be lost if the user quit first. See #1606.
+// the "re-download your GPU pack" notice across launches until a window has
+// actually taken it — a broadcast at window creation would be lost if the user
+// quit first. See #1606.
const SENTINEL_FILENAME = ".gpu-pack-migration-notice";
// Launch-time orphan detection (detectOrphanedGpuPacks) finds the same
@@ -71,4 +71,11 @@ function clear() {
} catch {}
}
-module.exports = { record, recordOnce, read, clear };
+// Read and clear in one step, so two windows can never both show it.
+function take() {
+ const notice = read();
+ if (notice) clear();
+ return notice;
+}
+
+module.exports = { record, recordOnce, read, clear, take };
diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.js
index e496b92c2..8191d689b 100644
--- a/src/helpers/ipcHandlers.js
+++ b/src/helpers/ipcHandlers.js
@@ -1429,6 +1429,15 @@ class IPCHandlers {
}
}
+ // The control panel shows the GPU pack notice. An app started to the tray
+ // creates none, so there the dictation panel shows it instead (#2554).
+ _gpuPackNoticeWindow() {
+ const { controlPanelWindow, mainWindow, startedMinimized } = this.windowManager;
+ if (controlPanelWindow && !controlPanelWindow.isDestroyed()) return controlPanelWindow;
+ if (startedMinimized && mainWindow && !mainWindow.isDestroyed()) return mainWindow;
+ return null;
+ }
+
_whisperGpuFailureStatus(backend) {
const gpuFailed = this._whisperGpuFailedBackends().includes(backend);
const reason = gpuFailed ? process.env[WHISPER_GPU_FAILURE_REASON_KEYS[backend]] : null;
@@ -1537,7 +1546,14 @@ class IPCHandlers {
ipcMain.handle("onboarding-set-active", (_event, active) => {
if (typeof active !== "boolean") return false;
- return this.windowManager.setOnboardingActive(active);
+ const result = this.windowManager.setOnboardingActive(active);
+ // The dictation panel can show the GPU pack notice only once the normal
+ // app is up: until then it stays hidden.
+ const noticeWindow = this._gpuPackNoticeWindow();
+ if (!active && noticeWindow && noticeWindow === this.windowManager.mainWindow) {
+ noticeWindow.webContents.send("gpu-pack-migration-notice-ready");
+ }
+ return result;
});
ipcMain.handle("onboarding-demo-begin", (_event, session) => {
@@ -3789,15 +3805,11 @@ class IPCHandlers {
return { success: true, deletedCount };
});
- // One-time "GPU pack needs re-downloading" notice recorded by the
- // legacy-layout migration before any window existed. See #1606.
- ipcMain.handle("get-gpu-pack-migration-notice", () => {
- return require("./gpuPackMigrationNotice").read();
- });
-
- ipcMain.handle("dismiss-gpu-pack-migration-notice", () => {
- require("./gpuPackMigrationNotice").clear();
- return { success: true };
+ // One-time "GPU pack needs re-downloading" notice recorded before any
+ // window existed (#1606). Only the window that shows it can take it.
+ ipcMain.handle("take-gpu-pack-migration-notice", (event) => {
+ if (event.sender !== this._gpuPackNoticeWindow()?.webContents) return null;
+ return require("./gpuPackMigrationNotice").take();
});
// Clears the remembered GPU failure and reloads the server with the GPU
diff --git a/src/helpers/whisper.js b/src/helpers/whisper.js
index 0a3301c5b..021a5b711 100644
--- a/src/helpers/whisper.js
+++ b/src/helpers/whisper.js
@@ -2,6 +2,7 @@ const fs = require("fs");
const fsPromises = require("fs").promises;
const path = require("path");
const debugLogger = require("./debugLogger");
+const { warnGpuFallback } = require("./gpuFallbackLog");
const {
downloadFile,
createDownloadSignal,
@@ -101,6 +102,50 @@ class WhisperManager {
return { useCuda, useVulkan };
}
+ // Why a backend the user wants can't be used, or null when it isn't wanted.
+ // Like resolveGpuStartOptions, an unset flag still wants a pack on disk.
+ _gpuFallbackReason(envVar, manager, backend) {
+ const flag = (process.env[envVar] || "").toLowerCase();
+ if (flag === "false") return null;
+ const needsUpdate = !!manager?.needsUpdate?.();
+ const downloaded = !!manager?.isDownloaded?.();
+ if (flag !== "true" && !needsUpdate && !downloaded) return null;
+ if (needsUpdate) return "pack needs update";
+ if (!downloaded) return "pack not installed or missing required libraries";
+ // A wanted, downloaded pack is skipped only after it failed on this machine.
+ return resolveFailedGpuBackends(process.env.WHISPER_GPU_FAILED).includes(backend)
+ ? "previous failure recorded"
+ : null;
+ }
+
+ _warnIfGpuFallback() {
+ const { useCuda, useVulkan } = this.resolveGpuStartOptions();
+ if (useCuda) return;
+ const runningOn = useVulkan ? "Vulkan" : "CPU";
+ const cudaReason = this._gpuFallbackReason(
+ "WHISPER_CUDA_ENABLED",
+ this._cudaBinaryManager,
+ "cuda"
+ );
+ const vulkanReason = this._gpuFallbackReason(
+ "WHISPER_VULKAN_ENABLED",
+ this._vulkanBinaryManager,
+ "vulkan"
+ );
+ const [label, pack, reason] = cudaReason
+ ? ["CUDA", "CUDA whisper", cudaReason]
+ : ["Vulkan", "Vulkan whisper", vulkanReason];
+ if (!reason) return;
+
+ const key = `${pack}:${reason}:${runningOn}`;
+ if (this._lastGpuFallbackWarning === key) return;
+ this._lastGpuFallbackWarning = key;
+ warnGpuFallback(`Whisper ${label} enabled but cannot be used, falling back to ${runningOn}`, {
+ pack,
+ reason,
+ });
+ }
+
// The pack the settings card describes, so the card never disagrees with the
// server (#1736): the pack every server start picks now (a GPU server always
// runs on it; while a pack change restarts the server, it names the target),
@@ -190,6 +235,7 @@ class WhisperManager {
const modelPath = this.getModelPath(whisperModel);
if (fs.existsSync(modelPath)) {
+ this._warnIfGpuFallback();
debugLogger.info("Pre-warming whisper-server", {
model: whisperModel,
modelPath,
@@ -444,6 +490,7 @@ class WhisperManager {
debugLogger.warn("VAD requested but ggml-silero model not found; running without VAD");
}
+ this._warnIfGpuFallback();
await this.serverManager.start(modelPath, {
...this.resolveGpuStartOptions(),
vadEnabled,
diff --git a/src/helpers/windowManager.js b/src/helpers/windowManager.js
index a7460e145..b95f46aba 100644
--- a/src/helpers/windowManager.js
+++ b/src/helpers/windowManager.js
@@ -80,6 +80,8 @@ class WindowManager {
this.onOnboardingDemoTeardown = null;
// Set by main.js so the tray's listen item rebuilds with dictation state.
this.onDictationStateChanged = null;
+ // Set by main.js: an app started to the tray creates no control panel.
+ this.startedMinimized = false;
this.notificationWindow = null;
this._meetingNotificationOwner = null;
this.meetingRecentDestinations = [];
diff --git a/src/types/electron.ts b/src/types/electron.ts
index a90af10f0..7a7455cfc 100644
--- a/src/types/electron.ts
+++ b/src/types/electron.ts
@@ -2061,9 +2061,9 @@ declare global {
onGpuFallbackNotification: (callback: () => void) => () => void;
onWhisperGpuStatusChanged: (callback: () => void) => () => void;
- // One-time "GPU pack needs re-downloading" notice from the legacy-layout migration
- getGpuPackMigrationNotice: () => Promise<{ packs: string[] } | null>;
- dismissGpuPackMigrationNotice: () => Promise<{ success: boolean }>;
+ // One-time "GPU pack needs re-downloading" notice, taken by the window that shows it
+ takeGpuPackMigrationNotice: () => Promise<{ packs: string[] } | null>;
+ onGpuPackMigrationNoticeReady: (callback: () => void) => () => void;
// Parakeet operations (NVIDIA via sherpa-onnx)
transcribeLocalParakeet: (
diff --git a/test/components/gpuPackMigrationToastListener.test.js b/test/components/gpuPackMigrationToastListener.test.js
new file mode 100644
index 000000000..e600c5ba2
--- /dev/null
+++ b/test/components/gpuPackMigrationToastListener.test.js
@@ -0,0 +1,127 @@
+const test = require("node:test");
+const assert = require("node:assert/strict");
+const React = require("react");
+const { createRoot } = require("react-dom/client");
+const {
+ createRendererServer,
+ installBrowserGlobals,
+ installHookDom,
+} = require("../lib/rendererTestHarness");
+
+// Main hands the notice out once (take) to the window that should show it.
+async function mountListener(t, { controlPanel, notice = { packs: ["CUDA whisper"] } }) {
+ let root;
+ t.after(async () => {
+ if (root) await React.act(async () => root.unmount());
+ delete globalThis.__gpuToasts;
+ });
+ globalThis.__gpuToasts = [];
+ const calls = { takes: 0, shownDictationPanel: 0, openedSection: null, notifyReady: null };
+ let remaining = notice;
+ installBrowserGlobals(t, {
+ window: {
+ electronAPI: {
+ takeGpuPackMigrationNotice: async () => {
+ calls.takes += 1;
+ const taken = remaining;
+ remaining = null;
+ return taken;
+ },
+ onGpuPackMigrationNoticeReady: (callback) => {
+ calls.notifyReady = callback;
+ return () => {
+ calls.notifyReady = null;
+ };
+ },
+ showDictationPanel: async () => {
+ calls.shownDictationPanel += 1;
+ },
+ openSettingsSection: async (section) => {
+ calls.openedSection = section;
+ return { success: true };
+ },
+ },
+ },
+ });
+ const container = installHookDom(t);
+ const vite = await createRendererServer(t, {
+ cachePrefix: "openwhispr-gpu-toast-listener-test-",
+ noExternal: ["react-i18next"],
+ mockModules: {
+ "react-i18next": `
+ export const useTranslation = () => ({
+ t: (key, values) => (values ? key + " " + JSON.stringify(values) : key),
+ });
+ `,
+ "/ui/useToast": `
+ export const useToast = () => ({ toast: (props) => globalThis.__gpuToasts.push(props) });
+ `,
+ "/utils/windowContext": `export const isControlPanelWindow = () => ${controlPanel};`,
+ },
+ });
+ const { default: Listener } = await vite.ssrLoadModule(
+ "/components/GpuPackMigrationToastListener.tsx"
+ );
+ root = createRoot(container);
+ await React.act(async () => root.render(React.createElement(Listener)));
+ return calls;
+}
+
+test("the control panel takes the notice on mount and offers Settings", async (t) => {
+ const calls = await mountListener(t, { controlPanel: true });
+
+ assert.equal(globalThis.__gpuToasts.length, 1);
+ const [toast] = globalThis.__gpuToasts;
+ assert.match(toast.description, /CUDA whisper/);
+ assert.equal(calls.shownDictationPanel, 0, "the control panel never surfaces the pill");
+ assert.equal(calls.notifyReady, null, "the control panel doesn't wait to be told");
+
+ assert.equal(toast.duration, 15000);
+ toast.actions[0].onClick();
+ assert.equal(calls.openedSection, "speechToText");
+});
+
+test("a notice naming only the llama pack opens AI Models settings", async (t) => {
+ const calls = await mountListener(t, { controlPanel: true, notice: { packs: ["Vulkan llama"] } });
+
+ globalThis.__gpuToasts[0].actions[0].onClick();
+ assert.equal(calls.openedSection, "llms");
+});
+
+test("a notice naming whisper and llama packs opens Speech-to-Text settings", async (t) => {
+ const calls = await mountListener(t, {
+ controlPanel: true,
+ notice: { packs: ["CUDA whisper", "Vulkan llama"] },
+ });
+
+ globalThis.__gpuToasts[0].actions[0].onClick();
+ assert.equal(calls.openedSection, "speechToText");
+});
+
+test("the dictation panel takes the notice only when main says so, then surfaces", async (t) => {
+ const calls = await mountListener(t, { controlPanel: false });
+
+ assert.equal(calls.takes, 0, "nothing is taken before main says the normal app is up");
+ assert.equal(globalThis.__gpuToasts.length, 0);
+
+ await React.act(async () => calls.notifyReady());
+
+ assert.equal(calls.takes, 1);
+ assert.equal(calls.shownDictationPanel, 1, "a hidden pill is shown so the toast is seen");
+ assert.equal(globalThis.__gpuToasts.length, 1);
+ assert.equal(
+ globalThis.__gpuToasts[0].duration,
+ 0,
+ "kept until dismissed: a login may be unattended"
+ );
+});
+
+test("a notice another window already took shows nothing", async (t) => {
+ const calls = await mountListener(t, { controlPanel: false, notice: null });
+
+ await React.act(async () => calls.notifyReady());
+
+ assert.equal(calls.takes, 1);
+ assert.equal(calls.shownDictationPanel, 0);
+ assert.equal(globalThis.__gpuToasts.length, 0);
+});
diff --git a/test/helpers/gpuBinaryManager.test.js b/test/helpers/gpuBinaryManager.test.js
index 085ca24d5..9c4479487 100644
--- a/test/helpers/gpuBinaryManager.test.js
+++ b/test/helpers/gpuBinaryManager.test.js
@@ -79,6 +79,7 @@ require.cache[require.resolve("../../src/helpers/downloadUtils.js")] = {
};
const GpuBinaryManager = require("../../src/helpers/gpuBinaryManager.js");
+const debugLogger = require("../../src/helpers/debugLogger.js");
const WhisperCudaManager = require("../../src/helpers/whisperCudaManager.js");
const LlamaVulkanManager = require("../../src/helpers/llamaVulkanManager.js");
const WhisperVulkanManager = require("../../src/helpers/whisperVulkanManager.js");
@@ -169,7 +170,9 @@ test("CUDA: resolves its exact asset from the pinned tag and installs binary + c
const binDir = path.join(userDataDir, "bin", "whisper-cuda");
const binaryPath = path.join(binDir, "whisper-server-linux-x64-cuda");
assert.ok(fs.existsSync(binaryPath));
- assert.ok(fs.statSync(binaryPath).mode & 0o100, "binary is executable");
+ if (process.env.OS !== "Windows_NT") {
+ assert.ok(fs.statSync(binaryPath).mode & 0o100, "binary is executable");
+ }
assert.ok(fs.existsSync(path.join(binDir, "libggml-cuda.so")), "companion lib copied");
assert.ok(!fs.existsSync(path.join(binDir, "README.md")), "unrelated files not copied");
assert.equal(manager.getCudaBinaryPath(), binaryPath);
@@ -699,3 +702,27 @@ test("getStatus reflects supported/downloaded/downloading", async () => {
seedPack("whisper-vulkan", ["whisper-server-linux-x64-vulkan"]);
assert.equal(manager.getStatus().downloaded, true);
});
+
+test("getBinaryPath: logs warning with missing required libraries when binary exists but is incomplete", () => {
+ const cuda = useWindowsAsset(new WhisperCudaManager());
+ seedPack(cuda.config.dirName, ["whisper-server-win32-x64-cuda.exe"]);
+
+ const originalWarn = debugLogger.warn;
+ const warned = [];
+ debugLogger.warn = (...args) => warned.push(args);
+
+ try {
+ const result = cuda.getBinaryPath();
+ assert.equal(result, null);
+ assert.equal(warned.length, 1);
+ assert.equal(warned[0][0], "GPU pack binary present but missing required runtime libraries");
+ assert.equal(warned[0][1].pack, "CUDA whisper");
+ assert.deepEqual(warned[0][1].missingLibraries, WINDOWS_MSVC_RUNTIME_LIBRARIES);
+
+ // Repeated call does not spam duplicate warning
+ cuda.getBinaryPath();
+ assert.equal(warned.length, 1);
+ } finally {
+ debugLogger.warn = originalWarn;
+ }
+});
diff --git a/test/helpers/gpuFallbackLog.test.js b/test/helpers/gpuFallbackLog.test.js
new file mode 100644
index 000000000..e09cb46bd
--- /dev/null
+++ b/test/helpers/gpuFallbackLog.test.js
@@ -0,0 +1,82 @@
+const test = require("node:test");
+const assert = require("node:assert/strict");
+const fs = require("node:fs");
+const os = require("node:os");
+const path = require("node:path");
+const Module = require("node:module");
+
+// debugLogger writes no file at the default level, so GPU fallback warnings
+// keep a small log of their own that a support request can point at (#2554).
+
+const modulePath = require.resolve("../../src/helpers/gpuFallbackLog");
+const originalLoad = Module._load;
+const warned = [];
+let userDataDir;
+
+Module._load = function loadWithStubs(request, parent, isMain) {
+ if (parent?.filename === modulePath && request === "electron") {
+ return { app: { getPath: () => userDataDir, getVersion: () => "9.9.9" } };
+ }
+ if (parent?.filename === modulePath && request === "./debugLogger") {
+ return { warn: (message, meta) => warned.push({ message, meta }) };
+ }
+ return originalLoad.call(this, request, parent, isMain);
+};
+
+// A fresh module stands for a new launch.
+function launch() {
+ delete require.cache[modulePath];
+ return require(modulePath);
+}
+
+function logLines() {
+ return fs
+ .readFileSync(path.join(userDataDir, "logs", "gpu-fallback.log"), "utf8")
+ .trim()
+ .split("\n");
+}
+
+test.beforeEach(() => {
+ userDataDir = fs.mkdtempSync(path.join(os.tmpdir(), "gpu-fallback-log-"));
+ warned.length = 0;
+});
+
+test.afterEach(() => {
+ fs.rmSync(userDataDir, { recursive: true, force: true });
+});
+
+test.after(() => {
+ Module._load = originalLoad;
+});
+
+test("a warning goes to debugLogger and to the GPU log at any level", () => {
+ const { warnGpuFallback } = launch();
+ warnGpuFallback("Whisper CUDA enabled but cannot be used", { reason: "pack needs update" });
+
+ assert.deepEqual(warned, [
+ { message: "Whisper CUDA enabled but cannot be used", meta: { reason: "pack needs update" } },
+ ]);
+ const [line] = logLines();
+ assert.match(line, /^\[\d{4}-\d{2}-\d{2}T[^\]]+\] \[9\.9\.9\] Whisper CUDA enabled/);
+ assert.match(line, /\{"reason":"pack needs update"\}$/);
+});
+
+test("a launch appends its warnings and the next launch replaces them", () => {
+ const first = launch();
+ first.warnGpuFallback("first", { n: 1 });
+ first.warnGpuFallback("second", { n: 2 });
+ assert.equal(logLines().length, 2);
+
+ launch().warnGpuFallback("next launch", { n: 3 });
+ const lines = logLines();
+ assert.equal(lines.length, 1);
+ assert.match(lines[0], /next launch/);
+});
+
+test("a log that can't be written still leaves the debugLogger warning", () => {
+ fs.writeFileSync(path.join(userDataDir, "logs"), "a file where the folder should be");
+ const { warnGpuFallback } = launch();
+
+ assert.doesNotThrow(() => warnGpuFallback("unwritable", {}));
+ assert.equal(warned.length, 1);
+});
diff --git a/test/helpers/gpuPackMigrationNotice.test.js b/test/helpers/gpuPackMigrationNotice.test.js
index 3c1b0940e..555b603ce 100644
--- a/test/helpers/gpuPackMigrationNotice.test.js
+++ b/test/helpers/gpuPackMigrationNotice.test.js
@@ -31,6 +31,14 @@ test("record/read/clear round-trip", () => {
assert.equal(notice.read(), null);
});
+test("take hands the notice out once", () => {
+ notice.record(["CUDA whisper"]);
+
+ assert.deepEqual(notice.take(), { packs: ["CUDA whisper"] });
+ assert.equal(notice.take(), null);
+ assert.equal(notice.read(), null);
+});
+
test("recording again merges and dedupes instead of overwriting", () => {
notice.record(["CUDA whisper"]);
notice.record(["CUDA whisper", "Vulkan llama"]);
diff --git a/test/helpers/gpuPackMigrationNoticeIpc.test.js b/test/helpers/gpuPackMigrationNoticeIpc.test.js
new file mode 100644
index 000000000..173b4eb9f
--- /dev/null
+++ b/test/helpers/gpuPackMigrationNoticeIpc.test.js
@@ -0,0 +1,196 @@
+const test = require("node:test");
+const assert = require("node:assert/strict");
+const Module = require("node:module");
+
+const handlersModulePath = require.resolve("../../src/helpers/ipcHandlers");
+const originalLoad = Module._load;
+const handlers = new Map();
+let pendingNotice = null;
+
+const electronStub = {
+ app: {
+ getPath: () => "/tmp",
+ getName: () => "test",
+ getVersion: () => "0.0.0",
+ isPackaged: false,
+ on: () => {},
+ requestSingleInstanceLock: () => true,
+ },
+ ipcMain: {
+ handle: (channel, fn) => handlers.set(channel, fn),
+ on: () => {},
+ removeHandler: () => {},
+ },
+ net: { fetch: async () => ({ ok: true, status: 200, json: async () => ({}) }) },
+ BrowserWindow: class BrowserWindow {
+ static getAllWindows() {
+ return [];
+ }
+ static fromWebContents() {
+ return null;
+ }
+ },
+ shell: {},
+ dialog: {},
+ screen: { getPrimaryDisplay: () => ({ workAreaSize: { width: 0, height: 0 } }) },
+ systemPreferences: { getMediaAccessStatus: () => "granted" },
+ session: { fromPartition: () => ({}) },
+ clipboard: {},
+ nativeImage: {},
+ globalShortcut: {},
+ utilityProcess: {},
+ MessageChannelMain: class {},
+};
+
+const noticeStub = {
+ take: () => {
+ const taken = pendingNotice;
+ pendingNotice = null;
+ return taken;
+ },
+};
+
+Module._load = function loadWithStubs(request, parent, isMain) {
+ if (request === "electron") return electronStub;
+ if (parent?.filename === handlersModulePath && request === "./debugLogger") {
+ return new Proxy({}, { get: () => () => {} });
+ }
+ if (parent?.filename === handlersModulePath && request === "./gpuPackMigrationNotice") {
+ return noticeStub;
+ }
+ return originalLoad.call(this, request, parent, isMain);
+};
+
+function anything() {
+ return new Proxy(function () {}, {
+ get: (_target, property) => {
+ if (property === Symbol.toPrimitive || property === "toString") return () => "";
+ if (property === "then") return undefined;
+ return anything();
+ },
+ apply: () => anything(),
+ });
+}
+
+function fakeWindow({ destroyed = false } = {}) {
+ const sent = [];
+ return {
+ sent,
+ isDestroyed: () => destroyed,
+ webContents: { send: (channel) => sent.push(channel) },
+ };
+}
+
+let target;
+test.before(() => {
+ delete require.cache[handlersModulePath];
+ const IPCHandlers = require(handlersModulePath);
+ const Ctor = IPCHandlers.default || IPCHandlers;
+ target = { _gpuPackNoticeWindow: Ctor.prototype._gpuPackNoticeWindow };
+ Ctor.prototype.setupHandlers.call(
+ new Proxy(target, {
+ get: (value, property) => (property in value ? value[property] : anything()),
+ })
+ );
+});
+
+test.after(() => {
+ Module._load = originalLoad;
+});
+
+function setUp({ startedMinimized, controlPanel, destroyed = [] }) {
+ pendingNotice = { packs: ["CUDA whisper"] };
+ const mainWindow = fakeWindow({ destroyed: destroyed.includes("main") });
+ const controlPanelWindow = controlPanel
+ ? fakeWindow({ destroyed: destroyed.includes("controlPanel") })
+ : null;
+ target.windowManager = {
+ startedMinimized,
+ mainWindow,
+ controlPanelWindow,
+ setOnboardingActive: () => true,
+ };
+ const take = (window) =>
+ handlers.get("take-gpu-pack-migration-notice")({ sender: window.webContents });
+ const setOnboardingActive = (active) => handlers.get("onboarding-set-active")({}, active);
+ return { mainWindow, controlPanelWindow, take, setOnboardingActive };
+}
+
+test("on a normal start only the control panel can take the notice", () => {
+ const { mainWindow, controlPanelWindow, take, setOnboardingActive } = setUp({
+ startedMinimized: false,
+ controlPanel: true,
+ });
+
+ setOnboardingActive(false);
+ assert.deepEqual(mainWindow.sent, [], "the pill is never told to take it");
+ assert.equal(take(mainWindow), null);
+ assert.deepEqual(take(controlPanelWindow), { packs: ["CUDA whisper"] });
+ assert.equal(take(controlPanelWindow), null, "taken once");
+});
+
+test("before a normal start's control panel exists the pill can't take the notice", () => {
+ const { mainWindow, take, setOnboardingActive } = setUp({
+ startedMinimized: false,
+ controlPanel: false,
+ });
+
+ setOnboardingActive(false);
+ assert.deepEqual(mainWindow.sent, []);
+ assert.equal(take(mainWindow), null);
+ assert.deepEqual(pendingNotice, { packs: ["CUDA whisper"] }, "kept for the control panel");
+});
+
+test("started to the tray, the pill is told once the normal app is up", () => {
+ const { mainWindow, take, setOnboardingActive } = setUp({
+ startedMinimized: true,
+ controlPanel: false,
+ });
+
+ setOnboardingActive(true);
+ assert.deepEqual(mainWindow.sent, [], "not while onboarding hides the pill");
+ setOnboardingActive(false);
+ assert.deepEqual(mainWindow.sent, ["gpu-pack-migration-notice-ready"]);
+
+ assert.equal(take(fakeWindow()), null, "an overlay window can't take it");
+ assert.deepEqual(take(mainWindow), { packs: ["CUDA whisper"] });
+});
+
+test("started to the tray, a control panel opened since takes the notice instead", () => {
+ const { mainWindow, controlPanelWindow, take, setOnboardingActive } = setUp({
+ startedMinimized: true,
+ controlPanel: true,
+ });
+
+ setOnboardingActive(false);
+ assert.deepEqual(mainWindow.sent, []);
+ assert.equal(take(mainWindow), null);
+ assert.deepEqual(take(controlPanelWindow), { packs: ["CUDA whisper"] });
+});
+
+test("a destroyed control panel hands the notice back to a tray start's pill", () => {
+ const { mainWindow, controlPanelWindow, take, setOnboardingActive } = setUp({
+ startedMinimized: true,
+ controlPanel: true,
+ destroyed: ["controlPanel"],
+ });
+
+ setOnboardingActive(false);
+ assert.deepEqual(mainWindow.sent, ["gpu-pack-migration-notice-ready"]);
+ assert.equal(take(controlPanelWindow), null);
+ assert.deepEqual(take(mainWindow), { packs: ["CUDA whisper"] });
+});
+
+test("destroyed windows are never told about or handed the notice", () => {
+ const { mainWindow, controlPanelWindow, take, setOnboardingActive } = setUp({
+ startedMinimized: true,
+ controlPanel: true,
+ destroyed: ["controlPanel", "main"],
+ });
+
+ setOnboardingActive(false);
+ assert.deepEqual(mainWindow.sent, []);
+ assert.equal(take(controlPanelWindow), null);
+ assert.equal(take(mainWindow), null);
+ assert.deepEqual(pendingNotice, { packs: ["CUDA whisper"] }, "kept for a later window");
+});
diff --git a/test/helpers/whisperGpuResolve.test.js b/test/helpers/whisperGpuResolve.test.js
index daef6ca70..4b2081569 100644
--- a/test/helpers/whisperGpuResolve.test.js
+++ b/test/helpers/whisperGpuResolve.test.js
@@ -3,6 +3,7 @@ const assert = require("node:assert/strict");
const WhisperManager = require("../../src/helpers/whisper.js");
const { resolveFailedGpuBackends } = require("../../src/helpers/whisper.js");
+const debugLogger = require("../../src/helpers/debugLogger.js");
// Every whisper-server start resolves its GPU backend from the current env +
// installed packs + remembered failures. This is what makes "Enable GPU" work
@@ -26,11 +27,16 @@ test.afterEach(() => {
}
});
-function managerWith({ cudaDownloaded = false, vulkanDownloaded = false } = {}) {
+function managerWith({
+ cudaDownloaded = false,
+ vulkanDownloaded = false,
+ cudaNeedsUpdate = false,
+ vulkanNeedsUpdate = false,
+} = {}) {
const manager = new WhisperManager();
manager.setGpuBinaryManagers({
- cuda: { isDownloaded: () => cudaDownloaded },
- vulkan: { isDownloaded: () => vulkanDownloaded },
+ cuda: { isDownloaded: () => cudaDownloaded, needsUpdate: () => cudaNeedsUpdate },
+ vulkan: { isDownloaded: () => vulkanDownloaded, needsUpdate: () => vulkanNeedsUpdate },
});
return manager;
}
@@ -164,3 +170,156 @@ test("without injected binary managers (macOS) no pack is in use", () => {
process.env.WHISPER_GPU_FAILED = "cuda,vulkan";
assert.equal(new WhisperManager().resolveGpuPackInUse(), null);
});
+
+test("_warnIfGpuFallback logs warning when CUDA is enabled in env but pack is missing", () => {
+ const manager = managerWith({ cudaDownloaded: false });
+ process.env.WHISPER_CUDA_ENABLED = "true";
+
+ const originalWarn = debugLogger.warn;
+ const warned = [];
+ debugLogger.warn = (...args) => warned.push(args);
+
+ try {
+ manager._warnIfGpuFallback();
+ assert.equal(warned.length, 1);
+ assert.equal(warned[0][0], "Whisper CUDA enabled but cannot be used, falling back to CPU");
+ assert.equal(warned[0][1].reason, "pack not installed or missing required libraries");
+
+ // Deduplication check
+ manager._warnIfGpuFallback();
+ assert.equal(warned.length, 1);
+ } finally {
+ debugLogger.warn = originalWarn;
+ }
+});
+
+test("_warnIfGpuFallback logs warning when CUDA is enabled in env and pack needs update", () => {
+ const manager = new WhisperManager();
+ manager.setGpuBinaryManagers({
+ cuda: { isDownloaded: () => false, needsUpdate: () => true },
+ vulkan: { isDownloaded: () => false, needsUpdate: () => false },
+ });
+ process.env.WHISPER_CUDA_ENABLED = "true";
+
+ const originalWarn = debugLogger.warn;
+ const warned = [];
+ debugLogger.warn = (...args) => warned.push(args);
+
+ try {
+ manager._warnIfGpuFallback();
+ assert.equal(warned.length, 1);
+ assert.equal(warned[0][0], "Whisper CUDA enabled but cannot be used, falling back to CPU");
+ assert.equal(warned[0][1].reason, "pack needs update");
+ } finally {
+ debugLogger.warn = originalWarn;
+ }
+});
+
+test("_warnIfGpuFallback does not log when CUDA is downloaded and used", () => {
+ const manager = managerWith({ cudaDownloaded: true });
+ process.env.WHISPER_CUDA_ENABLED = "true";
+
+ const originalWarn = debugLogger.warn;
+ const warned = [];
+ debugLogger.warn = (...args) => warned.push(args);
+
+ try {
+ manager._warnIfGpuFallback();
+ assert.equal(warned.length, 0);
+ } finally {
+ debugLogger.warn = originalWarn;
+ }
+});
+
+function fallbackWarnings(t, manager) {
+ const warn = t.mock.method(debugLogger, "warn", () => {});
+ manager._warnIfGpuFallback();
+ return warn.mock.calls.map(({ arguments: [message, meta] }) => ({ message, ...meta }));
+}
+
+test("_warnIfGpuFallback warns about an outdated pack whose flag line was lost (#1340)", (t) => {
+ const warnings = fallbackWarnings(t, managerWith({ cudaNeedsUpdate: true }));
+ assert.deepEqual(warnings, [
+ {
+ message: "Whisper CUDA enabled but cannot be used, falling back to CPU",
+ pack: "CUDA whisper",
+ reason: "pack needs update",
+ },
+ ]);
+});
+
+test("_warnIfGpuFallback stays quiet for a pack that was never installed or is turned off", (t) => {
+ assert.deepEqual(fallbackWarnings(t, managerWith()), [], "unset flag, no pack");
+
+ process.env.WHISPER_CUDA_ENABLED = "false";
+ process.env.WHISPER_VULKAN_ENABLED = "false";
+ const turnedOff = managerWith({ cudaNeedsUpdate: true, vulkanNeedsUpdate: true });
+ assert.deepEqual(fallbackWarnings(t, turnedOff), [], "explicit opt-out");
+});
+
+test("_warnIfGpuFallback names Vulkan when an unusable CUDA pack leaves it running", (t) => {
+ process.env.WHISPER_CUDA_ENABLED = "true";
+ const manager = managerWith({ cudaNeedsUpdate: true, vulkanDownloaded: true });
+ assert.deepEqual(manager.resolveGpuStartOptions(), { useCuda: false, useVulkan: true });
+
+ const [warning] = fallbackWarnings(t, manager);
+ assert.equal(warning.message, "Whisper CUDA enabled but cannot be used, falling back to Vulkan");
+});
+
+test("_warnIfGpuFallback warns about an unusable Vulkan pack when CUDA isn't wanted", (t) => {
+ process.env.WHISPER_VULKAN_ENABLED = "true";
+ const warnings = fallbackWarnings(t, managerWith({ vulkanNeedsUpdate: true }));
+ assert.deepEqual(warnings, [
+ {
+ message: "Whisper Vulkan enabled but cannot be used, falling back to CPU",
+ pack: "Vulkan whisper",
+ reason: "pack needs update",
+ },
+ ]);
+});
+
+test("_warnIfGpuFallback names a recorded failure for a downloaded pack", (t) => {
+ process.env.WHISPER_GPU_FAILED = "cuda";
+ const [warning] = fallbackWarnings(t, managerWith({ cudaDownloaded: true }));
+ assert.equal(warning.reason, "previous failure recorded");
+});
+
+test("pre-warm and every server start check for a GPU fallback before starting", async (t) => {
+ const os = require("node:os");
+ const fs = require("node:fs");
+ const path = require("node:path");
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "whisper-gpu-warn-"));
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
+ const modelPath = path.join(dir, "ggml-base.bin");
+ fs.writeFileSync(modelPath, "");
+
+ const manager = managerWith();
+ const order = [];
+ t.mock.method(manager, "_warnIfGpuFallback", () => order.push("warn"));
+ manager.getModelsDir = () => dir;
+ manager.getModelPath = () => modelPath;
+ manager.serverManager = {
+ isAvailable: () => true,
+ getServerBinaryPath: () => null,
+ start: async () => {
+ order.push("start");
+ throw new Error("stop here");
+ },
+ };
+
+ await manager.initializeAtStartup({
+ localTranscriptionProvider: "whisper",
+ whisperModel: "base",
+ });
+ assert.deepEqual(order, ["warn", "start"], "pre-warm");
+
+ order.length = 0;
+ await assert.rejects(manager._runServerTranscription(Buffer.alloc(0), "base", "en"), /stop here/);
+ assert.deepEqual(order, ["warn", "start"], "server start");
+});
+
+test("_warnIfGpuFallback ignores an outdated Vulkan pack while CUDA runs", (t) => {
+ const manager = managerWith({ cudaDownloaded: true, vulkanNeedsUpdate: true });
+ assert.deepEqual(manager.resolveGpuStartOptions(), { useCuda: true, useVulkan: false });
+ assert.deepEqual(fallbackWarnings(t, manager), []);
+});