abhigyanpatwari/GitNexus · error
LadybugDB not initialized. Call initLbug first.
Error message
LadybugDB not initialized. Call initLbug first.
What it means
deleteAllDestinations requires the module-level LadybugDB connection (conn) to have been established by initLbug. The adapter stores the connection in a module global; every query helper guards on it. Calling any query before initialization means there is no database to run the MATCH delete against, so it throws immediately.
Source
Thrown at gitnexus/src/core/lbug/lbug-adapter.ts:3195
* by files outside the write set — which also means it is never deleted when it
* SHOULD be, so a destination whose last referrer stopped naming it survived as
* an edgeless orphan that still carried `address`, the cross-repository join
* key, accumulating on every run. The mirror defect was worse: without a
* matching graph-wide re-include, a newly added file publishing to a NEW topic
* wrote neither the destination nor the publisher's edge, silently and with a
* zero exit.
*
* The `springDestinations` phase runs on every persisting analyze and recomputes
* the full set from the whole file list, so delete-then-re-include is complete.
* `extractChangedSubgraph` treats `Destination` as graph-wide to supply the
* other half; the two must be changed together. DETACH DELETE also takes the
* `CONSUMES_FROM` / `PUBLISHES_TO` edges, which the re-include restores because
* every one of them has the destination as an endpoint.
*/
export const deleteAllDestinations = async (): Promise<{ nodesDeleted: number }> => {
const c = conn;
if (!c) {
throw new Error('LadybugDB not initialized. Call initLbug first.');
}
return withConnLock(async () => {
let countResult: lbug.QueryResult | lbug.QueryResult[] | undefined;
try {
countResult = await c.query('MATCH (n:Destination) RETURN count(n) AS cnt');
const result = Array.isArray(countResult) ? countResult[0] : countResult;
const rows = await result.getAll();
const count = Number(rows[0]?.cnt ?? rows[0]?.[0] ?? 0);
if (count > 0) {
await closeQueryResults(await c.query('MATCH (n:Destination) DETACH DELETE n'));
}
if (countResult) await closeQueryResults(countResult);
return { nodesDeleted: count };
} catch (err) {
if (countResult) await closeQueryResults(countResult);
if (classifyDeleteAllError(err) === 'benign-missing-table') {
return { nodesDeleted: 0 };
}View on GitHub (pinned to 0d1aed942f)
Solutions
- Call await initLbug(...) once at startup before any adapter query.
- Guard call sites: if the adapter exposes an initialized/conn accessor, check it before querying.
- Ensure initLbug and the queries run in the same process/module instance (same import path).
- Check that the initLbug call did not fail earlier — fix the root init error first.
Example fix
// before
const { deleteAllDestinations } = await import('./lbug-adapter');
await deleteAllDestinations(); // conn undefined
// after
const lbug = await import('./lbug-adapter');
await lbug.initLbug(dbPath);
await lbug.deleteAllDestinations(); Defensive patterns
Strategy: try-catch
Validate before calling
if (typeof (adapter as { conn?: unknown }).conn === 'undefined') {
await adapter.initLbug(dbPath);
} Try / catch
try {
await deleteAllDestinations();
} catch (err) {
if (String(err.message).includes('not initialized. Call initLbug')) {
await initLbug(dbPath);
return deleteAllDestinations();
}
throw err;
} Prevention
- Initialize the DB in a single startup/bootstrap path before any query.
- Centralize init in one module so all importers share the connection.
- Fail fast if initLbug rejects — never swallow init errors.
When it happens
Trigger: Calling deleteAllDestinations (or any lbug-adapter query helper) before calling initLbug, or after a failed/never-completed initLbug left conn undefined.
Common situations: Importing the adapter and calling queries in a script that skips setup; initLbug called in a different process/module instance; an earlier init failure was swallowed so conn never got set.
Related errors
- LadybugDB not initialized for repo "${repoId}". Call initLbu
- [embed] Failed to delete stale embedding rows — aborting to
- Bridge query prepare failed: ${errMsg}
- GitNexus: unable to acquire init lock after ${INIT_LOCK_MAX_
- [embed] could not count persisted embeddings; leaving stats.
AI-assisted analysis of abhigyanpatwari/GitNexus@0d1aed942f (2026-09-08).
Data as JSON: /api/errors/ee7feae7a1a23681.
Report an issue: GitHub.