diegosouzapw/OmniRoute · error

[DB] WAL checkpoint failed during close

Error message

[DB] WAL checkpoint failed during close (${checkpointMode}):

What it means

During graceful database shutdown (closeDbInstance), the final WAL checkpoint in the configured mode (default TRUNCATE) threw. The close path continues and closes the database anyway, so the WAL file may not have been fully checkpointed/truncated — potentially leaving a larger -wal file and a recovery pass on next open.

Solutions

  1. Ensure no concurrent connections hold the database during shutdown
  2. Run a manual checkpoint (PRAGMA wal_checkpoint(TRUNCATE)) before shutdown if it recurs
  3. Check disk space and file permissions on the database directory
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at src/lib/db/core.ts:1437 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25). Data as JSON: /api/errors/57fdb85851bf1828. Report an issue: GitHub.

Appendix: source

Thrown at src/lib/db/core.ts:1437

}

export function closeDbInstance(options?: { checkpointMode?: CheckpointMode | null }): boolean {
  clearDbHealthCheckScheduler();
  clearWalTruncateScheduler();
  const db = getDb();
  if (!db) return false;

  const checkpointMode = options?.checkpointMode ?? "TRUNCATE";

  try {
    if (checkpointMode) {
      try {
        if (checkpointDb(db, checkpointMode)) {
          console.log(`[DB] SQLite WAL checkpoint completed (${checkpointMode}).`);
        }
      } catch (error: unknown) {
        const message = error instanceof Error ? error.message : String(error);
        console.warn(`[DB] WAL checkpoint failed during close (${checkpointMode}):`, message);
      }
    }
  } finally {
    try {
      if (db.open) db.close();
    } finally {
      setDb(null);
      // Module-level caches (prepared statements, schema-check memos — e.g.
      // apiKeys.ts) are bound to the closed connection. Without this, a recreated
      // DB (tests, backup restore of an older snapshot) hits "no such column"
      // on the stale re-prepare path. backup.ts already does this on restore;
      // close/reset must too (found by the 6A.1 orphan-test re-wire, 2026-06-09).
      resetAllDbModuleState();
    }
  }

  return true;
}

View on GitHub (pinned to a179ffed5b)