Skip to content

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

fix: serialize .env writes to prevent ENOENT rename race (#940)

Gabriel Stein69a493c1b72f
diff --git a/src/helpers/environment.js b/src/helpers/environment.js
index 825d95a62..847a640a1 100644
--- a/src/helpers/environment.js
+++ b/src/helpers/environment.js
@@ -58,6 +58,10 @@ const PERSISTED_KEYS = [
"VERTEX_LOCATION",
];
+// Module-level so writes are serialized across all instances — hotkeyManager
+// creates its own EnvironmentManager alongside the main.js singleton.
+let envWriteQueue = Promise.resolve();
+
class EnvironmentManager {
constructor() {
this.loadEnvironmentVariables();
@@ -213,7 +217,14 @@ class EnvironmentManager {
);
}
- async _writeEnvFileAtomic(envPath) {
+ _writeEnvFileAtomic(envPath) {
+ // Concurrent write+rename pairs share the same .env.tmp path, and the
+ // loser's rename throws ENOENT (#903).
+ envWriteQueue = envWriteQueue.catch(() => {}).then(() => this._writeEnvFile(envPath));
+ return envWriteQueue;
+ }
+
+ async _writeEnvFile(envPath) {
// Only strip plaintext secrets once migration has fully completed —
// otherwise a partial-migration recovery can lose unencrypted secrets.
const stripSecrets =