Skip to content

fix(ruv-swarm): use fileURLToPath for module paths (fixes Windows C:\C:\ path bug)#192

Open
k2jac9 wants to merge 1 commit into
ruvnet:mainfrom
k2jac9:fix/windows-fileurltopath-paths
Open

fix(ruv-swarm): use fileURLToPath for module paths (fixes Windows C:\C:\ path bug)#192
k2jac9 wants to merge 1 commit into
ruvnet:mainfrom
k2jac9:fix/windows-fileurltopath-paths

Conversation

@k2jac9

@k2jac9 k2jac9 commented Jun 18, 2026

Copy link
Copy Markdown

Summary

Fixes broken module-path resolution on Windows in ruv-swarm caused by using new URL('.', import.meta.url).pathname to locate files relative to a module.

On Windows, new URL('.', import.meta.url).pathname returns a leading-slash, drive-prefixed string such as /C:/Users/.../ruv-swarm/src/. Feeding that into path.join(...) produces \C:\Users\..., and when an fs call later resolves that against the current drive you get the invalid doubled-drive path C:\C:\Users\....

Symptom

Every ruv-swarm invocation on Windows prints:

[ERROR] Failed to initialize pooled persistence {
  error: "ENOENT: no such file or directory, mkdir 'C:\\C:\\Users\\...\\ruv-swarm\\node_modules\\ruv-swarm\\data'"
}

The SQLite persistence layer never initializes (swarm state/memory is not saved), and the same broken construction is used for the WASM directory and the integrity-checksum path, so those are affected too.

Fix

Replace new URL(...).pathname with fileURLToPath(...) from node:url, which is the correct file: URL → filesystem path conversion. It produces a proper native path on Windows and is a no-op on POSIX (/home/... stays /home/...).

8 path constructions across 6 modules:

File Constructions fixed
src/persistence.js 1 (default DB path)
src/persistence-pooled.js 1 (default DB path)
src/index.js 1 (WASM dir)
src/security.js 2 (checksums + dependency verify)
src/wasm-loader2.js 1 (base dir)
src/sqlite-pool.js 2 (worker script path)

Test evidence

Before: ruv-swarm init mesh 3 fails persistence init with the C:\C:\... ENOENT above.

After (Windows 11, Node 25):

🧠 Initializing ruv-swarm with WASM capabilities...
[INFO] Pooled persistence layer initialized successfully
✅ WASM bindings loaded successfully (actual WASM)
💾 High-availability pooled persistence layer initialized
📊 Pool configuration: 6 readers, 3 workers
🧠 Neural network capabilities loaded
📈 Forecasting capabilities loaded
✅ ruv-swarm initialized successfully
📦 Loading 0 existing swarms from database...
✅ Loaded 0 swarms into memory

No behavior change on POSIX. No dependency or API changes — purely a path-resolution correctness fix.

On Windows, `new URL('.', import.meta.url).pathname` returns a leading-slash,
drive-prefixed string (e.g. `/C:/.../src/`). Passing that through `path.join`
produces `\C:\...`, which fs operations then resolve against the cwd drive into
the invalid doubled-drive path `C:\C:\...`. This makes the SQLite persistence
layer fail to initialize at startup ("Failed to initialize pooled persistence …
ENOENT … mkdir 'C:\C:\...\data'") and also breaks WASM / checksum path
resolution.

Fix by using `fileURLToPath()` (the correct file: URL -> path API) instead of
`.pathname`. This is correct on all platforms and a no-op on POSIX.

Affected modules: persistence.js, persistence-pooled.js, index.js, security.js,
wasm-loader2.js, sqlite-pool.js (8 path constructions total).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@k2jac9

k2jac9 commented Jun 18, 2026

Copy link
Copy Markdown
Author

Quick context for triage: this hits every Windows user on ruv-swarm@1.0.20 — persistence fails to init on any invocation (e.g. ruv-swarm init mesh 3ENOENT ... mkdir 'C:\C:\...\data'), so swarm state/memory never persists, and the same .pathname pattern also breaks the WASM + checksum paths.

Root cause is just new URL('.', import.meta.url).pathname (yields /C:/... on Windows) → swapped to fileURLToPath(). No-op on POSIX, no API/dep changes — 8 spots across 6 files. Verified locally on Win11 + Node 25: persistence + WASM + neural all load clean after the change.

Happy to add a regression test or split per-file if you'd prefer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant