mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-23 21:59:14 +09:00
hasNativeWalSidecars() (#2735) refused every whole-image sql.js write/list against memory.db whenever -wal/-shm sidecars merely existed on disk, on the assumption that sidecars are only ever present while a native better-sqlite3 WAL connection is live. ruflo doctor breaks that assumption: it opens several readonly native connections for diagnostics and closes them with a plain .close(), which does not checkpoint and leaves orphaned sidecars behind. Once that happens, every later memory store/list in the project fails permanently with a misleading "active native WAL connection" error until someone deletes the sidecar files by hand — the tool users are told to run when something is wrong is what causes this. hasNativeWalSidecars() now probes liveness in two steps instead of trusting presence alone: 1) open our own connection and run wal_checkpoint(TRUNCATE) — busy !== 0 means a real holder has an open transaction right now, refuse immediately (also truncates a genuinely orphaned WAL as a side effect); 2) otherwise close our probe connection and re-check whether the sidecars are still on disk. SQLite only deletes -wal/-shm when the last connection closes, so if nothing else is attached, our own close is that last close and the sidecars vanish — safe to proceed. If they're still present after our own close, some other connection remains attached even though idle (holding no lock, so step 1 alone would have missed it) — still refuse. This preserves #2735's guarantee for a genuinely live holder (including the idle-but-attached case #3397's test exercises) while fixing the false positive from an orphan. The no-sidecar fast path is unchanged: a couple of existsSync calls, no database connection opened. Rewrote issue-2735's and memory-cli-mirror-removal's sidecar fixtures to use real WAL-mode databases with genuine transactions instead of empty touch-files, since presence-only fixtures no longer exercise anything meaningful against a liveness-based gate. Added issue-3161-doctor-leak- recovery.test.ts (reproduces doctor's actual leak pattern and confirms a subsequent store/list self-heals instead of failing permanently) and issue-3161-wal-liveness-probe.test.ts (genuine live writer still refused, concurrent callers, probe-error fail-closed, no-sidecar fast path never opens a connection). Co-Authored-By: RuFlo <ruv@ruv.net>