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): make whisper GPU state truthful — live activation, honest status, remembered failures

Gabriel Stein9578a89ab7ce
diff --git a/main.js b/main.js
index 1c8102f1b..f6157d44e 100644
--- a/main.js
+++ b/main.js
@@ -425,6 +425,8 @@ function initializeCoreManagers() {
if (process.platform !== "darwin") {
whisperCudaManager = new WhisperCudaManager();
whisperVulkanManager = new WhisperVulkanManager();
+ // Lets every server start resolve its GPU backend from installed packs
+ whisperManager.setGpuBinaryManagers({ cuda: whisperCudaManager, vulkan: whisperVulkanManager });
}
parakeetManager = new ParakeetManager();
diarizationManager = new DiarizationManager();
@@ -1128,16 +1130,10 @@ async function startApp() {
}, WHISPER_WAKE_REWARM_DELAY_MS);
});
- // Non-blocking server pre-warming. CUDA wins when both GPU backends are enabled.
- const useCuda = process.env.WHISPER_CUDA_ENABLED === "true" && whisperCudaManager?.isDownloaded();
+ // Non-blocking server pre-warming; GPU backend resolved by the manager
const whisperSettings = {
localTranscriptionProvider: process.env.LOCAL_TRANSCRIPTION_PROVIDER || "",
whisperModel: process.env.LOCAL_WHISPER_MODEL,
- useCuda,
- useVulkan:
- !useCuda &&
- process.env.WHISPER_VULKAN_ENABLED === "true" &&
- whisperVulkanManager?.isDownloaded(),
};
whisperManager.initializeAtStartup(whisperSettings).catch((err) => {
debugLogger.debug("Whisper startup init error (non-fatal)", { error: err.message });
diff --git a/preload.js b/preload.js
index 217506caa..07352f331 100644
--- a/preload.js
+++ b/preload.js
@@ -312,6 +312,7 @@ contextBridge.exposeInMainWorld("electronAPI", {
whisperServerStart: (modelName) => ipcRenderer.invoke("whisper-server-start", modelName),
whisperServerStop: () => ipcRenderer.invoke("whisper-server-stop"),
whisperServerStatus: () => ipcRenderer.invoke("whisper-server-status"),
+ whisperGpuRetry: () => ipcRenderer.invoke("whisper-gpu-retry"),
// CUDA GPU acceleration
listGpus: () => ipcRenderer.invoke("list-gpus"),
diff --git a/src/components/TranscriptionModelPicker.tsx b/src/components/TranscriptionModelPicker.tsx
index 405972fae..2f3249fca 100644
--- a/src/components/TranscriptionModelPicker.tsx
+++ b/src/components/TranscriptionModelPicker.tsx
@@ -392,6 +392,12 @@ export default function TranscriptionModelPicker({
percentage: 0,
});
const [gpuDismissed, setGpuDismissed] = useState(false);
+ // The pack fell back to CPU on this machine (persisted by main until retried)
+ const [gpuFailed, setGpuFailed] = useState(false);
+ // A server reload with the new backend is in flight (Vulkan cold starts are slow)
+ const [gpuActivating, setGpuActivating] = useState(false);
+ // Live truth from the running server; "active" is never inferred from a download
+ const [gpuActive, setGpuActive] = useState(false);
useEffect(() => {
if (selectedLocalProvider !== internalLocalProvider) {
@@ -595,12 +601,14 @@ export default function TranscriptionModelPicker({
if (cuda?.gpuInfo.hasNvidiaGpu) {
setGpuBackend("cuda");
setGpuDownloaded(cuda.downloaded);
+ setGpuFailed(!!cuda.gpuFailed);
return;
}
const vulkan = await window.electronAPI?.getVulkanWhisperStatus?.();
if (vulkan?.vulkan.available) {
setGpuBackend("vulkan");
setGpuDownloaded(vulkan.downloaded);
+ setGpuFailed(!!vulkan.gpuFailed);
}
} catch {}
};
@@ -616,6 +624,48 @@ export default function TranscriptionModelPicker({
return subscribe?.((data) => setGpuProgress(data));
}, [gpuDownloading, gpuBackend]);
+ // Live server state: "GPU acceleration active" reflects what the server is
+ // actually running on, not just that a pack is on disk (a crashed GPU server
+ // silently falls back to CPU). Faster poll while an activation is in flight.
+ useEffect(() => {
+ if (!effectiveLocal || internalLocalProvider !== "whisper" || !gpuDownloaded) return;
+ const poll = () => {
+ window.electronAPI
+ ?.whisperServerStatus?.()
+ .then((status) => {
+ setGpuActive(!!status?.gpuAccelerated);
+ if (status?.gpuAccelerated) setGpuActivating(false);
+ })
+ .catch(() => {});
+ };
+ poll();
+ const id = setInterval(poll, gpuActivating ? 1000 : 5000);
+ return () => clearInterval(id);
+ }, [effectiveLocal, internalLocalProvider, gpuDownloaded, gpuActivating]);
+
+ // Safety valve: a Vulkan cold start can take up to ~2 minutes (see #698);
+ // past that the live status or a fallback notification settles the state.
+ useEffect(() => {
+ if (!gpuActivating) return;
+ const timeout = setTimeout(() => setGpuActivating(false), 150_000);
+ return () => clearTimeout(timeout);
+ }, [gpuActivating]);
+
+ // Main falls back to CPU (and remembers it) when a GPU server crashes
+ useEffect(() => {
+ const onFallback = () => {
+ setGpuFailed(true);
+ setGpuActivating(false);
+ setGpuActive(false);
+ };
+ const disposeCuda = window.electronAPI?.onCudaFallbackNotification?.(onFallback);
+ const disposeVulkan = window.electronAPI?.onGpuFallbackNotification?.(onFallback);
+ return () => {
+ disposeCuda?.();
+ disposeVulkan?.();
+ };
+ }, []);
+
const handleGpuDownload = async () => {
setGpuDownloading(true);
try {
@@ -623,18 +673,35 @@ export default function TranscriptionModelPicker({
gpuBackend === "cuda"
? await window.electronAPI?.downloadCudaWhisperBinary?.()
: await window.electronAPI?.downloadVulkanWhisperBinary?.();
- if (result?.success) setGpuDownloaded(true);
+ if (result?.success) {
+ setGpuDownloaded(true);
+ setGpuFailed(false);
+ // Main reloads the server with the new backend only when one is loaded;
+ // otherwise the pack simply engages on the next dictation.
+ setGpuActivating(!!result.willRestart);
+ }
} finally {
setGpuDownloading(false);
}
};
+ const handleGpuRetry = async () => {
+ setGpuFailed(false);
+ const result = await window.electronAPI?.whisperGpuRetry?.();
+ setGpuActivating(!!result?.willRestart);
+ };
+
const handleGpuDelete = async () => {
const result =
gpuBackend === "cuda"
? await window.electronAPI?.deleteCudaWhisperBinary?.()
: await window.electronAPI?.deleteVulkanWhisperBinary?.();
- if (result?.success) setGpuDownloaded(false);
+ if (result?.success) {
+ setGpuDownloaded(false);
+ setGpuFailed(false);
+ setGpuActivating(false);
+ setGpuActive(false);
+ }
};
const handleGpuCancel = async () => {
@@ -1145,8 +1212,41 @@ export default function TranscriptionModelPicker({
{gpuDownloaded ? (
<div className="flex items-center justify-between">
<div className="flex items-center gap-1.5">
- <Check size={13} className="text-success" />
- <span className="text-xs font-medium text-foreground">{t("gpu.active")}</span>
+ {gpuFailed ? (
+ <>
+ <span className="inline-block w-1.5 h-1.5 rounded-full shrink-0 bg-warning" />
+ <span className="text-xs font-medium text-foreground">
+ {t("gpu.activationFailed")}
+ </span>
+ <button
+ onClick={handleGpuRetry}
+ className="text-xs text-muted-foreground hover:text-foreground transition-colors ml-1"
+ >
+ {t("gpu.retry")}
+ </button>
+ </>
+ ) : gpuActivating ? (
+ <>
+ <span className="inline-block w-1.5 h-1.5 rounded-full shrink-0 bg-primary animate-pulse" />
+ <span className="text-xs font-medium text-foreground">
+ {t("gpu.activating")}
+ </span>
+ </>
+ ) : gpuActive ? (
+ <>
+ <Check size={13} className="text-success" />
+ <span className="text-xs font-medium text-foreground">
+ {t("gpu.active")}
+ </span>
+ </>
+ ) : (
+ <>
+ <span className="inline-block w-1.5 h-1.5 rounded-full shrink-0 bg-primary" />
+ <span className="text-xs font-medium text-foreground">
+ {t("gpu.ready")}
+ </span>
+ </>
+ )}
</div>
<Button
onClick={handleGpuDelete}
diff --git a/src/helpers/environment.js b/src/helpers/environment.js
index 579205002..91eafb87a 100644
--- a/src/helpers/environment.js
+++ b/src/helpers/environment.js
@@ -47,6 +47,7 @@ const PERSISTED_KEYS = [
"UI_LANGUAGE",
"WHISPER_CUDA_ENABLED",
"WHISPER_VULKAN_ENABLED",
+ "WHISPER_GPU_FAILED",
"WHISPER_THREADS",
"TRANSCRIPTION_GPU_UUID",
"INTELLIGENCE_GPU_UUID",
diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.js
index 6c6b04f9f..4eedf219a 100644
--- a/src/helpers/ipcHandlers.js
+++ b/src/helpers/ipcHandlers.js
@@ -5,6 +5,7 @@ const os = require("os");
const crypto = require("crypto");
const debugLogger = require("./debugLogger");
const { broadcastToWindows } = require("./windowBroadcast");
+const { resolveFailedGpuBackends } = require("./whisper");
const { BYOK_API_KEYS } = require("../config/secretKeys");
const tokenStore = require("./tokenStore");
const { createCloudApiRequestHandler } = require("./cloudApiRequest");
@@ -593,10 +594,14 @@ class IPCHandlers {
});
if (this.whisperManager?.serverManager) {
+ // Remember the failed backend so it isn't re-attempted (and its model
+ // reload re-paid) on every launch; cleared by retry, re-download, delete.
this.whisperManager.serverManager.on("cuda-fallback", () => {
+ this._recordWhisperGpuFailure("cuda");
broadcastToWindows("cuda-fallback-notification", {});
});
this.whisperManager.serverManager.on("gpu-fallback", () => {
+ this._recordWhisperGpuFailure("vulkan");
broadcastToWindows("gpu-fallback-notification", {});
});
}
@@ -1017,6 +1022,44 @@ class IPCHandlers {
}
}
+ _whisperGpuFailedBackends() {
+ return resolveFailedGpuBackends(process.env.WHISPER_GPU_FAILED);
+ }
+
+ _recordWhisperGpuFailure(backend) {
+ const failed = this._whisperGpuFailedBackends();
+ if (!failed.includes(backend)) failed.push(backend);
+ this._syncStartupEnv({ WHISPER_GPU_FAILED: failed.join(",") });
+ }
+
+ _clearWhisperGpuFailure(backend) {
+ const failed = this._whisperGpuFailedBackends().filter((b) => b !== backend);
+ if (failed.length > 0) {
+ this._syncStartupEnv({ WHISPER_GPU_FAILED: failed.join(",") });
+ } else {
+ this._syncStartupEnv({}, ["WHISPER_GPU_FAILED"]);
+ }
+ }
+
+ // Captured before a handler stops the server to touch pack files (stopServer
+ // clears currentServerModel); tells _applyWhisperGpuPreference what to reload.
+ _whisperReloadModel() {
+ return this.whisperManager.serverManager.isRemote
+ ? null
+ : this.whisperManager.currentServerModel;
+ }
+
+ // Apply a GPU pack change to the loaded server without blocking the caller's
+ // IPC reply (a Vulkan cold start can take minutes); the renderer follows
+ // progress by polling whisper-server-status. Returns whether a reload was
+ // kicked off so the UI shows "activating" only when one is coming.
+ _applyWhisperGpuPreference(modelName) {
+ this.whisperManager.restartServerWithGpuPreference(modelName).catch((err) => {
+ debugLogger.error("whisper-server GPU preference restart failed", { error: err.message });
+ });
+ return !!modelName;
+ }
+
_syncStartupEnv(setVars, clearVars = []) {
let changed = false;
for (const [key, value] of Object.entries(setVars)) {
@@ -2585,13 +2628,10 @@ class IPCHandlers {
});
ipcMain.handle("whisper-server-start", async (event, modelName) => {
- const useCuda =
- process.env.WHISPER_CUDA_ENABLED === "true" && this.whisperCudaManager?.isDownloaded();
- const useVulkan =
- !useCuda &&
- process.env.WHISPER_VULKAN_ENABLED === "true" &&
- this.whisperVulkanManager?.isDownloaded();
- return this.whisperManager.startServer(modelName, { useCuda, useVulkan });
+ return this.whisperManager.startServer(
+ modelName,
+ this.whisperManager.resolveGpuStartOptions()
+ );
});
ipcMain.handle("whisper-server-stop", async () => {
@@ -2635,13 +2675,7 @@ class IPCHandlers {
{ from: oldUuid, to: uuid },
"gpu"
);
- const modelName = this.whisperManager.currentServerModel;
- await this.whisperManager.stopServer();
- if (modelName) {
- await this.whisperManager.startServer(modelName, {
- useCuda: !!process.env.WHISPER_CUDA_ENABLED,
- });
- }
+ await this.whisperManager.restartServerWithGpuPreference();
}
if (purpose === "intelligence") {
const modelManager = require("./modelManagerBridge").default;
@@ -2689,6 +2723,7 @@ class IPCHandlers {
downloading: this.whisperCudaManager.isDownloading(),
path: this.whisperCudaManager.getCudaBinaryPath(),
gpuInfo,
+ gpuFailed: this._whisperGpuFailedBackends().includes("cuda"),
};
});
@@ -2697,6 +2732,10 @@ class IPCHandlers {
return { success: false, error: "CUDA not supported on this platform" };
}
try {
+ const reloadModel = this._whisperReloadModel();
+ // Stop the server first: swapping a pack a running binary is loaded
+ // from EBUSYs on Windows (same rule as the Vulkan handler below)
+ await this.whisperManager.stopServer().catch(() => {});
await this.whisperCudaManager.download((downloaded, total) => {
if (!event.sender.isDestroyed()) {
event.sender.send("cuda-download-progress", {
@@ -2707,9 +2746,8 @@ class IPCHandlers {
}
});
this._syncStartupEnv({ WHISPER_CUDA_ENABLED: "true" });
- // Restart whisper-server so it picks up the CUDA binary
- await this.whisperManager.stopServer().catch(() => {});
- return { success: true };
+ this._clearWhisperGpuFailure("cuda");
+ return { success: true, willRestart: this._applyWhisperGpuPreference(reloadModel) };
} catch (error) {
debugLogger.error("CUDA binary download failed", {
error: error.message,
@@ -2726,11 +2764,14 @@ class IPCHandlers {
ipcMain.handle("delete-cuda-whisper-binary", async () => {
if (!this.whisperCudaManager) return { success: false };
+ const reloadModel = this._whisperReloadModel();
// Stop the server first so the running binary can be deleted on Windows
await this.whisperManager.stopServer().catch(() => {});
const result = await this.whisperCudaManager.delete();
if (result.success) {
this._syncStartupEnv({}, ["WHISPER_CUDA_ENABLED"]);
+ this._clearWhisperGpuFailure("cuda");
+ this._applyWhisperGpuPreference(reloadModel);
}
return result;
});
@@ -2744,6 +2785,7 @@ class IPCHandlers {
downloading: this.whisperVulkanManager?.isDownloading() ?? false,
vulkan,
hasNvidiaGpu: gpuInfo.hasNvidiaGpu,
+ gpuFailed: this._whisperGpuFailedBackends().includes("vulkan"),
};
});
@@ -2752,6 +2794,7 @@ class IPCHandlers {
return { success: false, error: "Vulkan not supported on this platform" };
}
try {
+ const reloadModel = this._whisperReloadModel();
// Stop the server first: overwriting a running binary EBUSYs on Windows
await this.whisperManager.stopServer().catch(() => {});
await this.whisperVulkanManager.download((downloaded, total) => {
@@ -2764,7 +2807,8 @@ class IPCHandlers {
}
});
this._syncStartupEnv({ WHISPER_VULKAN_ENABLED: "true" });
- return { success: true };
+ this._clearWhisperGpuFailure("vulkan");
+ return { success: true, willRestart: this._applyWhisperGpuPreference(reloadModel) };
} catch (error) {
debugLogger.error("Vulkan whisper binary download failed", {
error: error.message,
@@ -2781,13 +2825,26 @@ class IPCHandlers {
ipcMain.handle("delete-vulkan-whisper-binary", async () => {
if (!this.whisperVulkanManager) return { success: false };
+ const reloadModel = this._whisperReloadModel();
// Stop the server first so the running binary can be deleted on Windows
await this.whisperManager.stopServer().catch(() => {});
const { deletedCount } = await this.whisperVulkanManager.delete();
this._syncStartupEnv({}, ["WHISPER_VULKAN_ENABLED"]);
+ this._clearWhisperGpuFailure("vulkan");
+ this._applyWhisperGpuPreference(reloadModel);
return { success: true, deletedCount };
});
+ // Clears the remembered GPU failure and reloads the server with the GPU
+ // backend re-enabled (Retry on the "GPU could not be activated" state)
+ ipcMain.handle("whisper-gpu-retry", async () => {
+ this._syncStartupEnv({}, ["WHISPER_GPU_FAILED"]);
+ return {
+ success: true,
+ willRestart: this._applyWhisperGpuPreference(this._whisperReloadModel()),
+ };
+ });
+
ipcMain.handle("check-ffmpeg-availability", async (event) => {
return this.whisperManager.checkFFmpegAvailability();
});
diff --git a/src/helpers/whisper.js b/src/helpers/whisper.js
index fe1eca14d..61add8fd6 100644
--- a/src/helpers/whisper.js
+++ b/src/helpers/whisper.js
@@ -31,6 +31,15 @@ function getValidModelNames() {
return Object.keys(modelRegistryData.whisperModels);
}
+// WHISPER_GPU_FAILED holds a comma-separated list of backends that fell back
+// to CPU on this machine (e.g. "cuda" or "cuda,vulkan")
+function resolveFailedGpuBackends(value) {
+ return String(value || "")
+ .split(",")
+ .map((entry) => entry.trim())
+ .filter(Boolean);
+}
+
function shouldRewarmOnWake({
isRemote,
useCuda,
@@ -57,6 +66,47 @@ class WhisperManager {
this.cachedVadModelPath = undefined;
this._transcribing = false;
this._rewarmInFlight = false;
+ this._cudaBinaryManager = null;
+ this._vulkanBinaryManager = null;
+ }
+
+ setGpuBinaryManagers({ cuda, vulkan }) {
+ this._cudaBinaryManager = cuda || null;
+ this._vulkanBinaryManager = vulkan || null;
+ }
+
+ // The GPU backend for every server start is resolved fresh from the current
+ // env + installed packs, so enabling or removing a pack applies immediately
+ // instead of after an app restart. WHISPER_GPU_FAILED lists backends that
+ // crashed on this machine (persisted by ipcHandlers when the server falls
+ // back to CPU); they stay off until the user retries or re-downloads, so a
+ // doomed backend isn't re-attempted — and its model reload re-paid — on
+ // every launch.
+ resolveGpuStartOptions() {
+ const failed = resolveFailedGpuBackends(process.env.WHISPER_GPU_FAILED);
+ const useCuda =
+ process.env.WHISPER_CUDA_ENABLED === "true" &&
+ !failed.includes("cuda") &&
+ !!this._cudaBinaryManager?.isDownloaded();
+ const useVulkan =
+ !useCuda &&
+ process.env.WHISPER_VULKAN_ENABLED === "true" &&
+ !failed.includes("vulkan") &&
+ !!this._vulkanBinaryManager?.isDownloaded();
+ return { useCuda, useVulkan };
+ }
+
+ // Re-resolve GPU options and reload the server in place. Used after a GPU
+ // pack download, delete, or failure-retry so the change takes effect without
+ // an app restart. Callers that had to stop the server before touching pack
+ // files pass the model they captured first; no-op when none was loaded.
+ async restartServerWithGpuPreference(modelName = this.currentServerModel) {
+ if (!modelName || this.serverManager.isRemote) return { success: true, restarted: false };
+
+ const options = { ...this.serverManager.lastStartOptions, ...this.resolveGpuStartOptions() };
+ await this.stopServer();
+ const result = await this.startServer(modelName, options);
+ return { ...result, restarted: true };
}
getModelsDir() {
@@ -103,7 +153,8 @@ class WhisperManager {
await cleanupStaleDownloads(this.getModelsDir());
// Pre-warm whisper-server if local mode enabled (eliminates 2-5s cold-start delay)
- const { localTranscriptionProvider, whisperModel, useCuda, useVulkan } = settings;
+ const { localTranscriptionProvider, whisperModel } = settings;
+ const { useCuda, useVulkan } = this.resolveGpuStartOptions();
if (
localTranscriptionProvider === "whisper" &&
@@ -116,16 +167,13 @@ class WhisperManager {
debugLogger.info("Pre-warming whisper-server", {
model: whisperModel,
modelPath,
- cuda: !!useCuda,
- vulkan: !!useVulkan,
+ cuda: useCuda,
+ vulkan: useVulkan,
});
try {
const serverStartTime = Date.now();
- await this.serverManager.start(modelPath, {
- useCuda: !!useCuda,
- useVulkan: !!useVulkan,
- });
+ await this.serverManager.start(modelPath, { useCuda, useVulkan });
this.currentServerModel = whisperModel;
debugLogger.info("whisper-server pre-warmed successfully", {
@@ -272,11 +320,12 @@ class WhisperManager {
return false;
}
- // Replay the last start options (VAD, threads, GPU backend) so the reloaded
- // server matches the signature the next dictation will use; a bare start would
- // otherwise be rejected by start()'s no-op guard and reload the model on the
- // first dictation. See #766.
- const options = { ...sm.lastStartOptions };
+ // Replay the last start options (VAD, threads) so the reloaded server
+ // matches the signature the next dictation will use; a bare start would
+ // otherwise be rejected by start()'s no-op guard and reload the model on
+ // the first dictation. See #766. GPU flags are re-resolved so a backend
+ // that failed since is not re-attempted.
+ const options = { ...sm.lastStartOptions, ...this.resolveGpuStartOptions() };
this._rewarmInFlight = true;
try {
debugLogger.info("Re-warming whisper-server after wake from sleep", { model: modelName });
@@ -363,8 +412,7 @@ class WhisperManager {
}
await this.serverManager.start(modelPath, {
- useCuda: this.serverManager.useCuda,
- useVulkan: this.serverManager.useVulkan,
+ ...this.resolveGpuStartOptions(),
vadEnabled,
vadModelPath,
vadConfig: options.vadConfig || null,
@@ -867,3 +915,4 @@ class WhisperManager {
module.exports = WhisperManager;
module.exports.shouldRewarmOnWake = shouldRewarmOnWake;
+module.exports.resolveFailedGpuBackends = resolveFailedGpuBackends;
diff --git a/src/helpers/whisperServer.js b/src/helpers/whisperServer.js
index de32f69ae..d6134e57c 100644
--- a/src/helpers/whisperServer.js
+++ b/src/helpers/whisperServer.js
@@ -540,7 +540,6 @@ class WhisperServerManager extends EventEmitter {
let stderrBuffer = "";
let exitCode = null;
- let earlyExit = false;
this.process.stdout.on("data", (data) => {
debugLogger.debug("whisper-server stdout", { data: data.toString().trim() });
@@ -558,7 +557,6 @@ class WhisperServerManager extends EventEmitter {
this.process.on("close", (code) => {
exitCode = code;
- if (Date.now() - startTime < 10000) earlyExit = true;
debugLogger.debug("whisper-server process exited", { code });
this.ready = false;
this.process = null;
@@ -574,26 +572,23 @@ class WhisperServerManager extends EventEmitter {
} catch (err) {
// An intentional stop() during startup is not a GPU/thread failure
if (err.isStopped) throw err;
- if (usingVulkan) {
- // Fall back on ANY startup rejection — Vulkan can die late (VRAM OOM
- // mid-model-load) or hang, not just exit early like the CUDA rule below
- debugLogger.warn("Vulkan whisper-server failed, falling back to CPU", {
- error: err.message,
- exitCode,
- stderr: stderrBuffer.slice(0, 200),
- });
- this.emit("gpu-fallback");
+ if (usingCuda || usingVulkan) {
+ // Fall back on ANY startup rejection — a GPU server can exit early
+ // (missing kernels), die late (VRAM OOM mid-model-load), or hang, and
+ // in every case the CPU binary is the working answer. stop() reaps a
+ // hung process before the CPU restart.
+ debugLogger.warn(
+ `${usingCuda ? "CUDA" : "Vulkan"} whisper-server failed, falling back to CPU`,
+ {
+ error: err.message,
+ exitCode,
+ stderr: stderrBuffer.slice(0, 200),
+ }
+ );
+ this.emit(usingCuda ? "cuda-fallback" : "gpu-fallback");
await this.stop();
return this._doStart(modelPath, { ...options, useCuda: false, useVulkan: false });
}
- if (usingCuda && earlyExit) {
- debugLogger.warn("CUDA whisper-server failed, falling back to CPU", {
- exitCode,
- stderr: stderrBuffer.slice(0, 200),
- });
- this.emit("cuda-fallback");
- return this._doStart(modelPath, { ...options, useCuda: false });
- }
if (shouldFallbackToDefaultThreads(threadResolution)) {
const defaultThreadResolution = createThreadResolution(
null,
@@ -1002,14 +997,20 @@ class WhisperServerManager extends EventEmitter {
}
getStatus() {
+ const running = this.ready && (this.process !== null || this.isRemote);
+ const gpuBackend = this.useCuda ? "cuda" : this.useVulkan ? "vulkan" : null;
return {
available: this.isAvailable(),
- running: this.ready && (this.process !== null || this.isRemote),
+ running,
port: this.port,
hostname: this.hostname,
isRemote: this.isRemote,
modelPath: this.modelPath,
modelName: this.modelPath ? path.basename(this.modelPath, ".bin").replace("ggml-", "") : null,
+ // What the server is actually running on right now — the UI must never
+ // infer this from "the GPU pack is downloaded" (see the CPU fallbacks)
+ gpuBackend,
+ gpuAccelerated: running && !this.isRemote && gpuBackend !== null,
};
}
}
diff --git a/src/types/electron.ts b/src/types/electron.ts
index f8581785f..c20736aca 100644
--- a/src/types/electron.ts
+++ b/src/types/electron.ts
@@ -491,6 +491,8 @@ export interface CudaWhisperStatus {
downloading: boolean;
path: string | null;
gpuInfo: GpuInfo;
+ /** CUDA fell back to CPU on this machine and stays off until retried. */
+ gpuFailed?: boolean;
}
export interface VulkanWhisperStatus {
@@ -498,6 +500,21 @@ export interface VulkanWhisperStatus {
downloading: boolean;
vulkan: VulkanGpuResult;
hasNvidiaGpu: boolean;
+ /** Vulkan fell back to CPU on this machine and stays off until retried. */
+ gpuFailed?: boolean;
+}
+
+export interface WhisperServerStatus {
+ available: boolean;
+ running: boolean;
+ port: number | null;
+ hostname: string;
+ isRemote: boolean;
+ modelPath: string | null;
+ modelName: string | null;
+ gpuBackend: "cuda" | "vulkan" | null;
+ /** True only when the running server is actually using a local GPU backend. */
+ gpuAccelerated: boolean;
}
export interface WhisperCheckResult {
@@ -1275,6 +1292,10 @@ declare global {
error?: string;
}>;
+ // Whisper server lifecycle
+ whisperServerStatus: () => Promise<WhisperServerStatus>;
+ whisperGpuRetry: () => Promise<{ success: boolean; willRestart: boolean }>;
+
// CUDA GPU acceleration
listGpus?: () => Promise<GpuDevice[]>;
setGpuDeviceIndex?: (
@@ -1284,7 +1305,11 @@ declare global {
getGpuDeviceIndex?: (purpose: "transcription" | "intelligence") => Promise<string>;
detectGpu: () => Promise<GpuInfo>;
getCudaWhisperStatus: () => Promise<CudaWhisperStatus>;
- downloadCudaWhisperBinary: () => Promise<{ success: boolean; error?: string }>;
+ downloadCudaWhisperBinary: () => Promise<{
+ success: boolean;
+ willRestart?: boolean;
+ error?: string;
+ }>;
cancelCudaWhisperDownload: () => Promise<{ success: boolean }>;
deleteCudaWhisperBinary: () => Promise<{ success: boolean }>;
onCudaDownloadProgress: (
@@ -1298,7 +1323,11 @@ declare global {
// Vulkan GPU acceleration (whisper on AMD/Intel GPUs)
getVulkanWhisperStatus: () => Promise<VulkanWhisperStatus>;
- downloadVulkanWhisperBinary: () => Promise<{ success: boolean; error?: string }>;
+ downloadVulkanWhisperBinary: () => Promise<{
+ success: boolean;
+ willRestart?: boolean;
+ error?: string;
+ }>;
cancelVulkanWhisperDownload: () => Promise<{ success: boolean }>;
deleteVulkanWhisperBinary: () => Promise<{ success: boolean; deletedCount?: number }>;
onVulkanWhisperDownloadProgress: (
diff --git a/test/helpers/whisperGpuResolve.test.js b/test/helpers/whisperGpuResolve.test.js
new file mode 100644
index 000000000..1c9297977
--- /dev/null
+++ b/test/helpers/whisperGpuResolve.test.js
@@ -0,0 +1,95 @@
+const test = require("node:test");
+const assert = require("node:assert/strict");
+
+const WhisperManager = require("../../src/helpers/whisper.js");
+const { resolveFailedGpuBackends } = require("../../src/helpers/whisper.js");
+
+// Every whisper-server start resolves its GPU backend from the current env +
+// installed packs + remembered failures. This is what makes "Enable GPU" work
+// without an app restart, and what stops a crashed backend from being
+// re-attempted (and its model reload re-paid) on every launch.
+
+const ENV_KEYS = ["WHISPER_CUDA_ENABLED", "WHISPER_VULKAN_ENABLED", "WHISPER_GPU_FAILED"];
+const saved = {};
+
+test.beforeEach(() => {
+ for (const key of ENV_KEYS) {
+ saved[key] = process.env[key];
+ delete process.env[key];
+ }
+});
+
+test.afterEach(() => {
+ for (const key of ENV_KEYS) {
+ if (saved[key] === undefined) delete process.env[key];
+ else process.env[key] = saved[key];
+ }
+});
+
+function managerWith({ cudaDownloaded = false, vulkanDownloaded = false } = {}) {
+ const manager = new WhisperManager();
+ manager.setGpuBinaryManagers({
+ cuda: { isDownloaded: () => cudaDownloaded },
+ vulkan: { isDownloaded: () => vulkanDownloaded },
+ });
+ return manager;
+}
+
+test("no packs enabled resolves to CPU", () => {
+ assert.deepEqual(managerWith().resolveGpuStartOptions(), { useCuda: false, useVulkan: false });
+});
+
+test("an enabled + downloaded pack engages without an app restart", () => {
+ process.env.WHISPER_CUDA_ENABLED = "true";
+ const manager = managerWith({ cudaDownloaded: true });
+ assert.deepEqual(manager.resolveGpuStartOptions(), { useCuda: true, useVulkan: false });
+});
+
+test("enabled but not downloaded resolves to CPU (env flag alone is not an install)", () => {
+ process.env.WHISPER_CUDA_ENABLED = "true";
+ process.env.WHISPER_VULKAN_ENABLED = "true";
+ assert.deepEqual(managerWith().resolveGpuStartOptions(), { useCuda: false, useVulkan: false });
+});
+
+test("CUDA wins when both backends are enabled and downloaded", () => {
+ process.env.WHISPER_CUDA_ENABLED = "true";
+ process.env.WHISPER_VULKAN_ENABLED = "true";
+ const manager = managerWith({ cudaDownloaded: true, vulkanDownloaded: true });
+ assert.deepEqual(manager.resolveGpuStartOptions(), { useCuda: true, useVulkan: false });
+});
+
+test("a remembered CUDA failure degrades to Vulkan, then both failures to CPU", () => {
+ process.env.WHISPER_CUDA_ENABLED = "true";
+ process.env.WHISPER_VULKAN_ENABLED = "true";
+ const manager = managerWith({ cudaDownloaded: true, vulkanDownloaded: true });
+
+ process.env.WHISPER_GPU_FAILED = "cuda";
+ assert.deepEqual(manager.resolveGpuStartOptions(), { useCuda: false, useVulkan: true });
+
+ process.env.WHISPER_GPU_FAILED = "cuda,vulkan";
+ assert.deepEqual(manager.resolveGpuStartOptions(), { useCuda: false, useVulkan: false });
+});
+
+test("clearing the failure re-enables the backend (Retry)", () => {
+ process.env.WHISPER_CUDA_ENABLED = "true";
+ process.env.WHISPER_GPU_FAILED = "cuda";
+ const manager = managerWith({ cudaDownloaded: true });
+ assert.equal(manager.resolveGpuStartOptions().useCuda, false);
+
+ delete process.env.WHISPER_GPU_FAILED;
+ assert.equal(manager.resolveGpuStartOptions().useCuda, true);
+});
+
+test("without injected binary managers (macOS) everything resolves to CPU", () => {
+ process.env.WHISPER_CUDA_ENABLED = "true";
+ process.env.WHISPER_VULKAN_ENABLED = "true";
+ const manager = new WhisperManager();
+ assert.deepEqual(manager.resolveGpuStartOptions(), { useCuda: false, useVulkan: false });
+});
+
+test("resolveFailedGpuBackends tolerates empty and messy values", () => {
+ assert.deepEqual(resolveFailedGpuBackends(undefined), []);
+ assert.deepEqual(resolveFailedGpuBackends(""), []);
+ assert.deepEqual(resolveFailedGpuBackends("cuda"), ["cuda"]);
+ assert.deepEqual(resolveFailedGpuBackends(" cuda , vulkan ,"), ["cuda", "vulkan"]);
+});