Backporting regeneration of SID when session is missing

from #18