CryoSparc 5.0.6 start fails after OS Reboot

The server has both cryosparc 5.0.6 and 4.7.1 installed. After directly executing reboot on the OS, 4.7.1 starts normally, but 5.0.6 reports the following error upon startup.
And downgrading from 5.0.6 to 4.7.1 fixed it.
Please help to see how to fix it, much appreciated!

Starting CryoSPARC master services...
CryoSPARC is not already running.
Configuring database... OK
database: started
Checking database... OK
cache: started
    ✓ cache connection succeeded
╭─────────────────────────────────────────────────── Traceback (most recent call last) ────────────────────────────────────────────────────╮
│ /work/home/wanglf/cryosparc/cryosparc_master/cli/cryosparcm.py:200 in start                                                              │
│                                                                                                                                          │
│    197 │                                                                                                                                 │
│    198 │   if startup:                                                                                                                   │
│    199 │   │   # Pre-api setup                                                                                                           │
│ ❱  200 │   │   instance.startup()                                                                                                        │
│    201 │                                                                                                                                 │
│    202 │   # start api                                                                                                                   │
│    203 │   start_service(Service.api)                                                                                                    │
│                                                                                                                                          │
│ ╭───────────────────────────────────────────────────── locals ─────────────────────────────────────────────────────╮                     │
│ │              app = True                                                                                          │                     │
│ │             core = <core.core.Core object at 0x7fdea33eab10>                                                     │                     │
│ │          db_path = PosixPath('/localdata/cryosparc_db/wanglf/database')                                          │                     │
│ │         instance = <module 'core.instance' from '/work/home/wanglf/cryosparc/cryosparc_master/core/instance.py'> │                     │
│ │ legacy_nostartup = False                                                                                         │                     │
│ │  legacy_nowebapp = False                                                                                         │                     │
│ │          service = None                                                                                          │                     │
│ │          startup = True                                                                                          │                     │
│ │          systemd = False                                                                                         │                     │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                     │
│                                                                                                                                          │
│ /work/home/wanglf/cryosparc/cryosparc_master/core/instance.py:173 in startup                                                             │
│                                                                                                                                          │
│   170 │   config.write_legacy_job_types_available()                                                                                      │
│   171 │                                                                                                                                  │
│   172 │   logger.info("Now performing migrations")                                                                                       │
│ ❱ 173 │   migrations.migrate()                                                                                                           │
│   174 │   logger.info("Migrations complete")                                                                                             │
│   175 │                                                                                                                                  │
│   176 │   job_registers.save_job_registers()                                                                                             │
│                                                                                                                                          │
│ ╭────────────────────────────────────────── locals ──────────────────────────────────────────╮                                           │
│ │ instance_information_dict = {                                                              │                                           │
│ │                             │   'platform_node': 'login01',                                │                                           │
│ │                             │   'platform_release': '4.18.0-348.el8.0.2.x86_64',           │                                           │
│ │                             │   'platform_version': '#1 SMP Sun Nov 14 00:51:12 UTC 2021', │                                           │
│ │                             │   'platform_architecture': 'x86_64',                         │                                           │
│ │                             │   'cpu_model': 'Intel(R) Xeon(R) Gold 5218 CPU @ 2.30GHz',   │                                           │
│ │                             │   'physical_cores': 32,                                      │                                           │
│ │                             │   'max_cpu_freq': 3900.0,                                    │                                           │
│ │                             │   'total_memory': '251.29GB',                                │                                           │
│ │                             │   'available_memory': '175.58GB',                            │                                           │
│ │                             │   'used_memory': '74.16GB',                                  │                                           │
│ │                             │   ... +8                                                     │                                           │
│ │                             }                                                              │                                           │
│ ╰────────────────────────────────────────────────────────────────────────────────────────────╯                                           │
│                                                                                                                                          │
│ /work/home/wanglf/cryosparc/cryosparc_master/core/migrations.py:40 in migrate                                                            │
│                                                                                                                                          │
│    37 def migrate():                                                                                                                     │
│    38 │   logger.info("Running migrations")                                                                                              │
│    39 │   disable_long_running_task_flags()                                                                                              │
│ ❱  40 │   counters.sync_uid_counters()                                                                                                   │
│    41 │   migrate_configs()                                                                                                              │
│    42 │   migrate_tag_counts()                                                                                                           │
│    43 │   migrate_users()                                                                                                                │
│                                                                                                                                          │
│ /work/home/wanglf/cryosparc/cryosparc_master/core/counters.py:178 in sync_uid_counters                                                   │
│                                                                                                                                          │
│   175 │   logger.debug(f"Synced project uid counter to {highest_project_uid_num}")                                                       │
│   176 │   project_projections = Project.find_with_projection({}, {"uid": 1})                                                             │
│   177 │   for project_projection in project_projections:                                                                                 │
│ ❱ 178 │   │   sync_project_counters(project_projection["uid"])                                                                           │
│   179 │   logger.info("Finished syncing uid counters")                                                                                   │
│   180                                                                                                                                    │
│                                                                                                                                          │
│ ╭──────────────────────────────────────── locals ────────────────────────────────────────╮                                               │
│ │ highest_project_uid_num = 26                                                           │                                               │
│ │     highest_tag_uid_num = 1                                                            │                                               │
│ │      project_projection = {'_id': ObjectId('69d0885e38c509b4fcccd14c'), 'uid': 'P24'}  │                                               │
│ │     project_projections = <pymongo.synchronous.cursor.Cursor object at 0x7fde941871a0> │                                               │
│ ╰────────────────────────────────────────────────────────────────────────────────────────╯                                               │
│                                                                                                                                          │
│ /work/home/wanglf/cryosparc/cryosparc_master/core/counters.py:164 in sync_project_counters                                               │
│                                                                                                                                          │
│   161 │   session_projections = Session.find_with_projection({"project_uid": project_uid}, {"s                                           │
│   162 │   for session_projection in session_projections:                                                                                 │
│   163 │   │   session_uid = session_projection["session_uid"]                                                                            │
│ ❱ 164 │   │   highest_exposure_group_id = sync_exposure_group_id_counter(project_uid, session_                                           │
│   165 │   │   logger.debug(f"Synced exp_group_id counter for {project_uid}-{session_uid} to {h                                           │
│   166 │   │   highest_exposure_id = sync_exposure_uid_counter(project_uid, session_uid)                                                  │
│   167 │   │   logger.debug(f"Synced exposure id counter for {project_uid}-{session_uid} to {hi                                           │
│                                                                                                                                          │
│ ╭──────────────────────────────────────────── locals ────────────────────────────────────────────╮                                       │
│ │ highest_exposure_group_id = 1                                                                  │                                       │
│ │       highest_exposure_id = 1003                                                               │                                       │
│ │       highest_job_uid_num = 216                                                                │                                       │
│ │   highest_session_uid_num = 3                                                                  │                                       │
│ │ highest_workspace_uid_num = 3                                                                  │                                       │
│ │               project_uid = 'P24'                                                              │                                       │
│ │        session_projection = {'_id': ObjectId('6a492103c7951eba25f7c3fa'), 'session_uid': 'S2'} │                                       │
│ │       session_projections = <pymongo.synchronous.cursor.Cursor object at 0x7fde94185790>       │                                       │
│ │               session_uid = 'S2'                                                               │                                       │
│ ╰────────────────────────────────────────────────────────────────────────────────────────────────╯                                       │
│                                                                                                                                          │
│ /work/home/wanglf/cryosparc/cryosparc_master/core/counters.py:120 in sync_exposure_group_id_counter                                      │
│                                                                                                                                          │
│   117 │   │   {"project_uid": project_uid, "session_uid": session_uid}, {"exposure_groups": 1}                                           │
│   118 │   )                                                                                                                              │
│   119 │   highest_exposure_group_number = (                                                                                              │
│ ❱ 120 │   │   max(group.get("exp_group_id", 0) for group in session.get("exposure_groups", [])                                           │
│   121 │   │   if session is not None                                                                                                     │
│   122 │   │   else 0                                                                                                                     │
│   123 │   )                                                                                                                              │
│                                                                                                                                          │
│ ╭────────────────────────────────────── locals ──────────────────────────────────────╮                                                   │
│ │ project_uid = 'P24'                                                                │                                                   │
│ │     session = {'_id': ObjectId('6a492103c7951eba25f7c3fa'), 'exposure_groups': []} │                                                   │
│ │ session_uid = 'S2'                                                                 │                                                   │
│ ╰────────────────────────────────────────────────────────────────────────────────────╯                                                   │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: max() iterable argument is empty

@wsatbluesky Thanks for this bug report. You may encounter this problem when a project contains a Live session that does not have any exposure group.
Until we release a fix for this bug, you may try the following workaround, based on information in the error message and involving the manual creation of an exposure group

In a Linux shell on the CryoSPARC master host

cryosparcm stop
cryosparcm start database
cryosparcm start cache
cryosparcm start api
cryosparcm icli # enter the CryoSPARC interactive cli

Inside the interactive cli

project_uid = 'P24' # from error message
session_uid = 'S2' # from error message
from core import sessions
session = sessions.find_session(project_uid, session_uid)
sessions.create_exposure_group(session)
exit() # exit the cli

Back inside the Linux shell on the CryoSPARC master

cryosparcm restart

Have updated to v5.0.7. But the error still exist. Seems no project, do I need delete the Project from database ?

[longfeng@login01 ~]$ cryosparcm icli
Python 3.12.11 | packaged by conda-forge | (main, Jun  4 2025, 14:45:31) [GCC 13.3.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.37.0 -- An enhanced Interactive Python. Type '?' for help.
 Connected to login01:40902
 api, db, gfs ready to use

In [1]: project_uid = 'P48'

In [2]: session_uid = 'S5'

In [3]: from core import sessions
   ...: 
   ...: session = sessions.find_session(project_uid, session_uid)
   ...: 
   ...: sessions.create_exposure_group(session)
   ...: 
   ...: exit()
---------------------------------------------------------------------------
NotFoundException                         Traceback (most recent call last)
Cell In[3], line 3
      1 from core import sessions
----> 3 session = sessions.find_session(project_uid, session_uid)
      5 sessions.create_exposure_group(session)
      7 exit()

File ~/cryosparc/cryosparc_master/core/sessions.py:106, in find_session(project_uid, session_uid, deleted)
    104 session = Session.find_by_uid(project_uid, session_uid, deleted=deleted)
    105 if session is None:
--> 106     raise NotFoundException(f"Session {project_uid}-{session_uid} not found")
    107 return session

NotFoundException: Session P48-S5 not found

Did you encounter the exactly same error

ValueError: max() iterable argument is empty

now in a different project? Please can you post the outputs of these commands in a Linux shell on your CryoSPARC master computer:

cryosparcm cli "api.projects.find_one('P48').deleted"
cryosparcm cli "api.sessions.find_one('P48', 'S5').deleted"