Moodle allows admins to delete themselves in 2 different ways:
1) GDPR deletion, info at
2) A Moodle backup restore that includes user information: details unknown, but we see this all the time in MoodleCloud where the only site admin has deleted=1, the username is changed from "admin" to "email@example.com" and email is changed to a hash of some sort (this is what restore does i think?)
We then run the CLI upgrade script which triggers an exception on this line:
!!! Exception - Argument 1 passed to core\\session
manager::set_user() must be an instance of stdClass, boolean given, called in [dirroot]/admin/cli/upgrade.php on line 189 !!!