Compare commits

...
Author SHA1 Message Date
copilot-swe-agent[bot]andmagyargergo 3875f5c027 fix: add CHECKPOINT before closeLbug to prevent WAL corruption on Windows
On Windows with LadybugDB 0.16.0, the non-blocking checkpoint thread can
outlive the close() call and leave WAL/sidecar pages pending on disk.
When a subsequent read-side open occurs (e.g. gitnexus query/cypher after
analyze --embeddings), it races with the WAL replay or trips the database-id
check on the sidecars, triggering the UNREACHABLE_CODE assertion.

Fix: issue CHECKPOINT before closing the connection in closeLbug() and in
doInitLbug() (when switching databases), matching the pattern already used
in closeBridgeDb() in bridge-db.ts. CHECKPOINT is a no-op when nothing is
pending, so it is safe on all platforms and LadybugDB versions.

Agent-Logs-Url: https://github.com/abhigyanpatwari/GitNexus/sessions/6d853496-e7b9-4e98-a906-475a756a05c5

Co-authored-by: magyargergo <11230420+magyargergo@users.noreply.github.com>
2026-05-05 11:35:46 +00:00
copilot-swe-agent[bot] 926f59146b Initial plan 2026-05-05 11:30:31 +00:00
+20
View File
@@ -294,6 +294,14 @@ const ensureLbugInitialized = async (dbPath: string) => {
const doInitLbug = async (dbPath: string) => {
// Different database requested — close the old one first
if (conn || db) {
// CHECKPOINT before close so WAL contents are flushed into the main
// database file (mirrors the closeLbug() contract; same LadybugDB
// 0.16.0 WAL-flush issue on Windows applies here).
try {
if (conn) await conn.query('CHECKPOINT');
} catch {
/* ignore */
}
try {
if (conn) await conn.close();
} catch {}
@@ -1049,6 +1057,18 @@ export const fetchExistingEmbeddingHashes = async (
export const closeLbug = async (): Promise<void> => {
if (conn) {
// CHECKPOINT before close so WAL contents are flushed into the main
// database file. Without this, LadybugDB 0.16.0's non-blocking
// checkpoint thread can outlive the close call and leave sidecar pages
// pending on disk, which makes a subsequent read-side open race with
// the WAL replay or trip the database-id check — triggering the
// UNREACHABLE_CODE assertion seen on Windows after analyze --embeddings.
// CHECKPOINT is a no-op when nothing is pending, so it's always safe.
try {
await conn.query('CHECKPOINT');
} catch {
/* ignore — older LadybugDB or in-memory DB may not accept it */
}
try {
await conn.close();
} catch {}