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: tolerate spurious Windows mkdir errors when ensuring data/loras exists

[._.]/ Adam Eivy474fe7451e51
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index d30436a814..6184c15b94 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -45,4 +45,5 @@
- **City daytime sky no longer washes out to white; night reads as a galaxy backdrop** — The bright-day sky and pavement were tuned so light, so the dome and ground turned into a near-white fog sheet over the city; daytime now keeps real blue in the horizon bands and a muted blue-gray street so the city stays legible in full sun. At night the galaxy map is the backdrop, the shader sky-dome gets out of the way, and the moon is a smaller, softer disc instead of an over-bright bloom. The experimental "Dreamworld" sky-theme picker (and its drifting clouds) has been removed — the City now has one canonical look that follows your theme's day/night mode; any previously-saved Dreamworld setting falls back to it automatically.
- **City night sky is a real environment map (the galaxy now also lights the scene)** — The night galaxy was a pair of hand-placed meshes that frequently didn't show and contributed no light. It's now wired through three.js's environment system the way an HDRI is: the equirectangular panorama is assigned to `scene.background` (a true 360° spheremap, visible in every camera direction) and, via `PMREMGenerator`, to `scene.environment` — so the galaxy also tints reflections and lighting on the metallic building/ground materials. The low-resolution (1774×887) AI-generated panorama that read as pixelated was replaced with a crisp 8192×4096 Milky Way (Solar System Scope, CC BY 4.0), brightness/saturation graded for the stylized night. Day is unchanged.
- **City no longer flashes a blank white scene when the GPU drops the WebGL context** — Heavy post-processing plus an always-on frame-readback buffer made Chromium lose the City's WebGL context easily, leaving a white canvas with no recovery. The readback buffer is now only enabled while taking a postcard, the render resolution is capped to keep the context stable, and a lost context is detected and either recovered on restore or surfaced over the page background instead of a white void. Known THREE.js deprecation and expected context-loss console messages are also filtered out so the browser console stays usable. With the post-processing pass gone, the City settings panel drops the now-inert Bloom, Film Grain, Chromatic Aberration, Color Grading, and Exposure controls so nothing toggles an effect that no longer renders.
+- **LoRA downloads no longer fail with a spurious `mkdir` error on Windows** — Installing a Civitai LoRA could fail with `UNKNOWN: unknown error, mkdir '…\data\loras'` even though the directory already existed. On Windows, `fs.mkdir(..., { recursive: true })` can intermittently throw `UNKNOWN`/`EPERM`/`EEXIST` — antivirus locks, OneDrive sync, and network/mapped drives all surface spurious failures that the POSIX "recursive is a no-op when the dir exists" contract doesn't anticipate. The shared `ensureDir` helper (and the LoRA installer, now routed through it) swallows the error whenever the path is in fact a directory afterward, so installs succeed on existing directories.
- **Browser download keep-alive no longer spams JSON-parse errors** — The browser service's CDP keep-alive treated any `200 OK` on its DevTools port as a live Chrome endpoint and called `res.json()` on it unconditionally. When another process answers on that port with HTML (e.g. the Vite dev server auto-incrementing onto it), the parse threw `Unexpected token '<', "<!DOCTYPE "...`, which the reconnect loop logged every 2 seconds. The CDP check now validates the response is actually Chrome's JSON (`webSocketDebuggerUrl` present) and treats anything else as "not reachable." Separately, the Vite dev server now uses `strictPort` so it fails loudly instead of silently walking up onto a reserved PortOS port (5555 API, 5556 browser CDP).
diff --git a/server/lib/fileUtils.js b/server/lib/fileUtils.js
index c24641465a..b39aa92e9f 100644
--- a/server/lib/fileUtils.js
+++ b/server/lib/fileUtils.js
@@ -99,8 +99,21 @@ export const PATHS = {
* await ensureDir('/custom/path/to/dir');
*/
export async function ensureDir(dir) {
- // mkdir with recursive: true is idempotent - it succeeds if dir exists
- await mkdir(dir, { recursive: true });
+ // mkdir with recursive: true is idempotent - it succeeds if dir exists.
+ // BUT on Windows it can intermittently throw UNKNOWN/EPERM/EEXIST even when
+ // the directory already exists or is created concurrently — antivirus locks,
+ // OneDrive sync, and network/mapped drives all surface spurious failures that
+ // the POSIX-modeled `recursive: true` no-op contract doesn't anticipate.
+ // Swallow the error when the path is in fact a directory afterward.
+ await mkdir(dir, { recursive: true }).catch((err) => {
+ if (err?.code === 'EEXIST') return; // already exists — the intended state
+ const s = statSync(dir, { throwIfNoEntry: false });
+ if (s && s.isDirectory()) {
+ console.log(`⚠️ ensureDir swallowed spurious ${err?.code || 'error'} — dir exists: ${dir}`);
+ return;
+ }
+ throw err;
+ });
}
/**
diff --git a/server/services/loras.js b/server/services/loras.js
index 674e794935..9997f7d04a 100644
--- a/server/services/loras.js
+++ b/server/services/loras.js
@@ -18,14 +18,14 @@
*/
import { existsSync } from 'fs';
-import { link, mkdir, readFile, rename, rm, stat, unlink, writeFile } from 'fs/promises';
+import { link, readFile, rename, rm, stat, unlink, writeFile } from 'fs/promises';
import { createWriteStream } from 'fs';
import { randomBytes } from 'crypto';
import { Readable } from 'stream';
import { pipeline } from 'stream/promises';
import { basename, join } from 'path';
import { ServerError } from '../lib/errorHandler.js';
-import { assertSafeFilename, listDirectoryByExtension, PATHS } from '../lib/fileUtils.js';
+import { assertSafeFilename, ensureDir, listDirectoryByExtension, PATHS } from '../lib/fileUtils.js';
import { isPlainObject } from '../lib/objects.js';
import {
applyDownloadToken,
@@ -331,7 +331,7 @@ export const installFromCivitai = async (input, { fetchImpl = fetch } = {}) => {
);
}
- await mkdir(PATHS.loras, { recursive: true });
+ await ensureDir(PATHS.loras);
console.log(`📥 Installing Civitai LoRA: ${model.name} v${version.id} → ${filename} (${file.sizeKB ? Math.round(file.sizeKB / 1024) + ' MB' : 'size unknown'})`);
// Authenticate downloads via `?token=` only — the Authorization header