{"record":{"id":"c570c8cfd70d7371","repo":"abhigyanpatwari/GitNexus","slug":"ladybugdb-wal-corruption-detected-for-repoid-r","errorCode":null,"errorMessage":"LadybugDB WAL corruption detected for ${repoId}. Run `gitnexus analyze` to rebuild the index. (quarantine failed)","messagePattern":"LadybugDB WAL corruption detected for (.+?)\\. Run `gitnexus analyze` to rebuild the index\\. \\(quarantine failed\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"gitnexus/src/core/lbug/pool-adapter.ts","lineNumber":699,"sourceCode":"  } catch (err) {\n    if (db) await db.close().catch(() => {});\n    throw err;\n  } finally {\n    restoreStdout();\n  }\n}\n\n/**\n * Quarantine the .wal file and retry opening the database.\n * Used when the initial open fails with a WAL corruption error.\n */\nasync function tryQuarantineAndReopen(dbPath: string, repoId: string): Promise<lbug.Database> {\n  const walPath = dbPath + '.wal';\n  const quarantineName = `${walPath}.corrupt.${Date.now()}-${Math.random().toString(36).slice(2)}`;\n  try {\n    await fs.rename(walPath, quarantineName);\n  } catch {\n    throw new Error(\n      `LadybugDB WAL corruption detected for ${repoId}. ` +\n        `Run \\`gitnexus analyze\\` to rebuild the index. (quarantine failed)`,\n    );\n  }\n  realStderrWrite(\n    `GitNexus: LadybugDB WAL quarantined for ${repoId}; graph may be stale. ` +\n      `Run \\`gitnexus analyze\\` to rebuild the index.\\n`,\n  );\n  return await openReadOnlyDatabase(dbPath);\n}\n\n// Serializes pool mutations (evict / close / native open / register) across\n// concurrent callers. Awaiting closeOne/evictLRU closes the race within a\n// single call; this mutex makes those mutations mutually exclusive across\n// repos so two inits cannot race each other's checkpoint.\nlet poolLock: Promise<unknown> = Promise.resolve();\nfunction withPoolLock<T>(fn: () => Promise<T>): Promise<T> {\n  const run = poolLock.then(fn, fn);","sourceCodeStart":681,"sourceCodeEnd":717,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/ac9a4e9abd8fd3058c070b72c23402a4f887929a/gitnexus/src/core/lbug/pool-adapter.ts#L681-L717","documentation":"tryQuarantineAndReopen (gitnexus/src/core/lbug/pool-adapter.ts:636): the initial read-only open failed with a WAL-corruption-shaped engine error, and moving the .wal aside to a .corrupt.<timestamp> quarantine file also failed. Recovery is impossible in-process, so the caller is told to rebuild the index.","triggerScenarios":"initLbug opening a repo whose .wal is corrupted (torn write, crash mid-checkpoint) while the quarantine rename fails — the file is locked, the volume is read-only, or the directory is not writable.","commonSituations":"Hard power-off during analyze writeback followed by a locked file (AV, another serve process); storage directory with wrong ownership after a user or container change.","solutions":["Run `gitnexus analyze` for that repo — a fresh build replaces the corrupted file family","If analyze cannot clear it either, stop competing processes, fix permissions, or manually delete the <db>, .wal and .shadow files and re-analyze","If WAL corruption recurs across rebuilds, test the disk (smartctl) — repeated corruption usually means failing hardware"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":"const isQuarantineFailedWalCorruption = (e: unknown): boolean =>\n  e instanceof Error &&\n  e.message.includes('WAL corruption detected') &&\n  e.message.includes('(quarantine failed)');","tryCatchPattern":"try {\n  await initLbug(repoId, dbPath);\n} catch (e) {\n  if (isQuarantineFailedWalCorruption(e)) {\n    // automatic recovery is exhausted — rebuild the index, then retry\n    throw new Error('run gitnexus analyze to rebuild this index before serving it');\n  }\n  throw e;\n}","preventionTips":["Ensure the storage directory is writable and unlocked so automatic WAL quarantine can work","Avoid hard power-loss during writebacks; use graceful shutdown","Recurring WAL corruption across rebuilds points at failing storage — test the disk"],"tags":["gitnexus","ladybugdb","wal","corruption","quarantine"],"backgroundTag":"wal-corruption","analyzedSha":"ac9a4e9abd8fd3058c070b72c23402a4f887929a","analyzedAt":"2026-08-20T23:29:22.980Z","contentChangedAt":"2026-08-20T23:29:22.980Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}