Skip to content

Commit df2aade

Browse files
🤖 fix: use atomic writes for experiments cache (#1209)
The test `refreshExperiment updates cache and writes it to disk` was flaky because `fs.writeFile` is not atomic — it truncates the file before writing, creating a race window where readers can see an empty or partial file. Switch to `write-file-atomic` which writes to a temp file then renames, making the operation atomic. --- _Generated with `mux` • Model: `anthropic:claude-opus-4-5` • Thinking: `high`_
1 parent b328d2d commit df2aade

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

‎src/node/services/experimentsService.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import { getMuxHome } from "@/common/constants/paths";
44
import type { ExperimentValue } from "@/common/orpc/types";
55
import { log } from "@/node/services/log";
66
import type { TelemetryService } from "@/node/services/telemetryService";
7+
78
import * as fs from "fs/promises";
9+
import writeFileAtomic from "write-file-atomic";
810
import * as path from "path";
911

1012
export type { ExperimentValue };
@@ -298,7 +300,7 @@ export class ExperimentsService {
298300
};
299301

300302
await fs.mkdir(this.muxHome, { recursive: true });
301-
await fs.writeFile(this.cacheFilePath, JSON.stringify(payload, null, 2), "utf-8");
303+
await writeFileAtomic(this.cacheFilePath, JSON.stringify(payload, null, 2), "utf-8");
302304
} catch {
303305
// Ignore cache persistence failures
304306
}

0 commit comments

Comments
 (0)