diff --git a/navi/core/pg_session_store.py b/navi/core/pg_session_store.py index 55cfd03..c23160f 100644 --- a/navi/core/pg_session_store.py +++ b/navi/core/pg_session_store.py @@ -823,10 +823,16 @@ return await _build_sessions(conn, rows) async def delete(self, session_id: str) -> bool: + # A never-persisted session lives only in _pending (lazy persistence: + # create() defers the row until the first save()), so the bare DB + # DELETE alone reports 0 rows for a very real session. Pop the + # pending entry first, then count the DB result. + async with self._pending_lock: + pending = self._pending.pop(session_id, None) pool = await self._get_pool() async with pool.acquire() as conn: result = await conn.execute("DELETE FROM sessions WHERE id = $1", session_id) - return result == "DELETE 1" + return pending is not None or result == "DELETE 1" async def count_all( self,