Skip to content

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

fix(transcription): reload local GPU model on wake from sleep (#1032)

Alcahest Malus Dienheim24bbd4162160
diff --git a/main.js b/main.js
index a52fa62b2..dea8437c4 100644
--- a/main.js
+++ b/main.js
@@ -320,6 +320,8 @@ let ipcHandlers = null;
let cliBridge = null;
let globeKeyAlertShown = false;
let authBridgeServer = null;
+const WHISPER_WAKE_REWARM_DELAY_MS = 3000;
+let wakeRewarmTimer = null;
function parseAuthBridgePort() {
const raw = (process.env.OPENWHISPR_AUTH_BRIDGE_PORT || "").trim();
@@ -939,6 +941,14 @@ async function startApp() {
if (googleCalendarManager) {
googleCalendarManager.onWakeFromSleep();
}
+ // Sleep evicts the local GPU model from VRAM; reload it once the driver settles. See #766.
+ if (wakeRewarmTimer) clearTimeout(wakeRewarmTimer);
+ wakeRewarmTimer = setTimeout(() => {
+ wakeRewarmTimer = null;
+ whisperManager?.onWakeFromSleep().catch((err) => {
+ debugLogger.debug("whisper wake re-warm error (non-fatal)", { error: err.message });
+ });
+ }, WHISPER_WAKE_REWARM_DELAY_MS);
});
// Non-blocking server pre-warming
@@ -1587,6 +1597,10 @@ if (gotSingleInstanceLock) {
}
function performSyncTeardown() {
+ if (wakeRewarmTimer) {
+ clearTimeout(wakeRewarmTimer);
+ wakeRewarmTimer = null;
+ }
if (authBridgeServer) {
authBridgeServer.close();
authBridgeServer = null;
diff --git a/src/helpers/whisper.js b/src/helpers/whisper.js
index 5f5cc24b8..dd7d8de54 100644
--- a/src/helpers/whisper.js
+++ b/src/helpers/whisper.js
@@ -30,6 +30,13 @@ function getValidModelNames() {
return Object.keys(modelRegistryData.whisperModels);
}
+function shouldRewarmOnWake({ isRemote, useCuda, modelName, transcribing, rewarmInFlight }) {
+ // Only re-warm a running local CUDA whisper-server: sleep evicts its model from
+ // VRAM. Skip remote/CPU servers, and skip while a transcription (already warming
+ // the server) or another re-warm is in flight. See #766.
+ return !isRemote && !!useCuda && !!modelName && !transcribing && !rewarmInFlight;
+}
+
class WhisperManager {
constructor() {
this.cachedFFmpegPath = null;
@@ -40,6 +47,8 @@ class WhisperManager {
this.serverManager = new WhisperServerManager();
this.currentServerModel = null;
this.cachedVadModelPath = undefined;
+ this._transcribing = false;
+ this._rewarmInFlight = false;
}
getModelsDir() {
@@ -235,6 +244,40 @@ class WhisperManager {
this.currentServerModel = null;
}
+ async onWakeFromSleep() {
+ const sm = this.serverManager;
+ const modelName = this.currentServerModel;
+ if (
+ !shouldRewarmOnWake({
+ isRemote: sm.isRemote,
+ useCuda: sm.useCuda,
+ modelName,
+ transcribing: this._transcribing,
+ rewarmInFlight: this._rewarmInFlight,
+ })
+ ) {
+ return false;
+ }
+
+ // 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.
+ const options = { ...sm.lastStartOptions, useCuda: true };
+ this._rewarmInFlight = true;
+ try {
+ debugLogger.info("Re-warming whisper-server after wake from sleep", { model: modelName });
+ await this.stopServer();
+ const result = await this.startServer(modelName, options);
+ if (!result?.success) {
+ debugLogger.warn("whisper-server wake re-warm failed", { reason: result?.reason });
+ return false;
+ }
+ return true;
+ } finally {
+ this._rewarmInFlight = false;
+ }
+ }
+
getServerStatus() {
return this.serverManager.getStatus();
}
@@ -286,6 +329,16 @@ class WhisperManager {
}
async transcribeViaServer(audioBlob, model, language, initialPrompt = null, options = {}) {
+ // Mark the server busy so a wake re-warm doesn't kill an in-flight dictation. See #766.
+ this._transcribing = true;
+ try {
+ return await this._runServerTranscription(audioBlob, model, language, initialPrompt, options);
+ } finally {
+ this._transcribing = false;
+ }
+ }
+
+ async _runServerTranscription(audioBlob, model, language, initialPrompt = null, options = {}) {
debugLogger.info("Transcription mode: SERVER", { model, language: language || "auto" });
const modelPath = this.getModelPath(model);
@@ -770,3 +823,4 @@ class WhisperManager {
}
module.exports = WhisperManager;
+module.exports.shouldRewarmOnWake = shouldRewarmOnWake;
diff --git a/src/helpers/whisperServer.js b/src/helpers/whisperServer.js
index 0e20fdd67..3db11f064 100644
--- a/src/helpers/whisperServer.js
+++ b/src/helpers/whisperServer.js
@@ -176,6 +176,7 @@ class WhisperServerManager extends EventEmitter {
this.useCuda = false;
this.vadSignature = "vad:off";
this.threadSignature = "threads:default";
+ this.lastStartOptions = {};
}
getFFmpegPath() {
@@ -372,6 +373,10 @@ class WhisperServerManager extends EventEmitter {
async start(modelPath, options = {}) {
if (this.startupPromise) return this.startupPromise;
+ // Remember the options so a wake re-warm can reload with the same VAD/thread
+ // signature and survive start()'s no-op guard on the next dictation. See #766.
+ this.lastStartOptions = { ...options };
+
const threadResolution = resolveWhisperThreads(options);
const nextThreadSignature = getThreadSignature(threadResolution);
const nextVadSignature = getVadSignature(options);
diff --git a/test/helpers/whisperWakeRewarm.test.js b/test/helpers/whisperWakeRewarm.test.js
new file mode 100644
index 000000000..8a5cb7587
--- /dev/null
+++ b/test/helpers/whisperWakeRewarm.test.js
@@ -0,0 +1,36 @@
+const test = require("node:test");
+const assert = require("node:assert/strict");
+
+const { shouldRewarmOnWake } = require("../../src/helpers/whisper");
+
+const base = {
+ isRemote: false,
+ useCuda: true,
+ modelName: "large",
+ transcribing: false,
+ rewarmInFlight: false,
+};
+
+test("re-warms a running local CUDA whisper-server after wake", () => {
+ assert.equal(shouldRewarmOnWake(base), true);
+});
+
+test("skips CPU whisper-server (model survives sleep in RAM)", () => {
+ assert.equal(shouldRewarmOnWake({ ...base, useCuda: false }), false);
+});
+
+test("skips a remote whisper-server", () => {
+ assert.equal(shouldRewarmOnWake({ ...base, isRemote: true }), false);
+});
+
+test("skips when no server model is active", () => {
+ assert.equal(shouldRewarmOnWake({ ...base, modelName: null }), false);
+});
+
+test("skips while a transcription is already warming the server", () => {
+ assert.equal(shouldRewarmOnWake({ ...base, transcribing: true }), false);
+});
+
+test("skips while another wake re-warm is already in flight", () => {
+ assert.equal(shouldRewarmOnWake({ ...base, rewarmInFlight: true }), false);
+});