diff --git a/gitnexus/src/core/lbug/lbug-adapter.ts b/gitnexus/src/core/lbug/lbug-adapter.ts index b0154f233..43a8af09f 100644 --- a/gitnexus/src/core/lbug/lbug-adapter.ts +++ b/gitnexus/src/core/lbug/lbug-adapter.ts @@ -1902,18 +1902,21 @@ export const safeClose = async (): Promise => { export const closeLbug = async (options: { skipNativeClose?: boolean } = {}): Promise => { if (options.skipNativeClose) { - // The caller is about to exit the process (CLI analyze success/error/SIGINT - // all end in process.exit). CHECKPOINT for durability, then DELIBERATELY skip - // conn.close()/db.close(): LadybugDB's ClientContext/Connection destructor can - // double-free after large --pdg writes (gdb: `double free or corruption` in - // ClientContext::~ClientContext via NodeConnection::Close), aborting the - // process AFTER a fully-written, checkpointed index. flushWAL above already - // persisted the data; process exit reclaims the native handles. We leave - // conn/db referenced and module state intact so a GC finalizer cannot run the - // same destructor before exit, and any post-analyze read reuses the live - // connection. Mirrors the pool adapter's fire-and-forget native close - // (pool-adapter.ts) and the ONNX native-cleanup philosophy. This is a - // workaround for a LadybugDB engine bug — see the upstream report. + // The caller guarantees a process.exit afterward (CLI analyze success path). + // CHECKPOINT for durability via flushWAL, then DELIBERATELY skip the native + // connection and database teardown: LadybugDB's ClientContext/Connection + // destructor can double-free after large --pdg writes (gdb: `double free or + // corruption` in ClientContext::~ClientContext via NodeConnection::Close), + // aborting the process AFTER a fully-written, checkpointed index. flushWAL + // already persisted the data; process exit reclaims the native handles. We + // leave the handles referenced and module state intact so a GC finalizer + // cannot run the same destructor before exit, and any post-analyze read + // reuses the live connection. Mirrors the pool adapter's fire-and-forget + // native teardown (pool-adapter.ts) and the ONNX native-cleanup philosophy. + // Workaround for a LadybugDB engine bug (to be reported upstream). + // SAFETY: only valid when a process.exit is guaranteed to follow — the + // runFullAnalysis ERROR path intentionally does NOT pass this (it closes for + // real, so a soft-returning caller still releases handles and terminates). await flushWAL(); return; }