Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: match atomicWrite swap siblings case-insensitively so NTFS casing differences don't defeat the ENOENT retry (#4095)

[._.]/ Adam Eivy12c6845a0d9c
diff --git a/server/lib/fileUtils.js b/server/lib/fileUtils.js
index b40445cbcd..954b1318c3 100644
--- a/server/lib/fileUtils.js
+++ b/server/lib/fileUtils.js
@@ -524,14 +524,22 @@ const PARSE_FAILED = Symbol('json-parse-failed');
* Only consulted on win32, and only after a read already failed with ENOENT, so
* the directory listing never lands on a POSIX read or on a successful read.
*
+ * Matching is case-INSENSITIVE: NTFS/FAT are case-insensitive, so the reader's
+ * `filePath` casing need not match the casing the writer used to create the
+ * file (and therefore the casing `readdir` reports). A case-sensitive compare
+ * would miss the sibling and let the phantom-empty through.
+ *
* @param {string} filePath
* @returns {Promise<boolean>}
*/
async function hasSwapSibling(filePath) {
const entries = await readdir(dirname(filePath)).catch(() => null);
if (!entries) return false;
- const prefix = `${basename(filePath)}.`;
- return entries.some((name) => name.startsWith(prefix) && (name.endsWith('.tmp') || name.endsWith('.bak')));
+ const prefix = `${basename(filePath).toLowerCase()}.`;
+ return entries.some((entry) => {
+ const name = entry.toLowerCase();
+ return name.startsWith(prefix) && (name.endsWith('.tmp') || name.endsWith('.bak'));
+ });
}
/**
diff --git a/server/lib/fileUtils.test.js b/server/lib/fileUtils.test.js
index d9d7dda108..f652d224e6 100644
--- a/server/lib/fileUtils.test.js
+++ b/server/lib/fileUtils.test.js
@@ -1388,6 +1388,18 @@ describe('Windows swap-window retries (#4095)', () => {
expect(fsPromises.readdir).toHaveBeenCalled();
});
+ it('matches a swap sibling whose casing differs — NTFS/FAT are case-insensitive', async () => {
+ const target = join(tmpRoot, 'casing.json');
+ writeFileSync(target, JSON.stringify({ real: true }));
+ // The writer may have created the file (and therefore its swap debris)
+ // under different casing than the reader's path — legal on Windows.
+ writeFileSync(join(tmpRoot, 'Casing.json.1234.5678.TMP'), 'partial');
+ fakePlatform('win32');
+ fsPromises.readFile.mockRejectedValueOnce(lockError('ENOENT'));
+
+ expect(await readJSONFileStrict(target, { fallback: true })).toEqual({ ok: true, value: { real: true } });
+ });
+
it('does not retry a plain missing file on win32 — no sibling, no second read', async () => {
const missing = join(tmpRoot, 'never-written.json');
fakePlatform('win32');