Login success but logout fails
The way you've structured the logic, your function will return "user is logged in" as long as your credentials are correct, not if the user session was created (i.e. the user logged in). Your subsequent error about an uninitialized session confirms that a session isn't being created (i.e. an entry being inserted into the sessions table) or your session key/cookie isn't persisting on the subsequent logout call.

You need to debug why this isn't happening. Check the drupal_session_regenerate() function call to make sure a session entry is created and that your browser/client is receiving SetCookie header with the newly created session key. If the session is created, you need check why your browser/client isn't storing and persisting the session key made on your subsequent logout call.