{"record":{"id":"634cf8bc833c4938","repo":"microsoft/qlib","slug":"the-fetched-task-must-be-status-waiting-or-stat","errorCode":null,"errorMessage":"The fetched task must be `STATUS_WAITING` or `STATUS_PART_DONE`!","messagePattern":"The fetched task must be `STATUS_WAITING` or `STATUS_PART_DONE`!","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/workflow/task/manage.py","lineNumber":542,"sourceCode":"        the params for `task_func`\n    \"\"\"\n    tm = TaskManager(task_pool)\n\n    ever_run = False\n\n    while True:\n        with tm.safe_fetch_task(status=before_status, query=query) as task:\n            if task is None:\n                break\n            get_module_logger(\"run_task\").info(task[\"def\"])\n            # when fetching `WAITING` task, use task[\"def\"] to train\n            if before_status == TaskManager.STATUS_WAITING:\n                param = task[\"def\"]\n            # when fetching `PART_DONE` task, use task[\"res\"] to train because the middle result has been saved to task[\"res\"]\n            elif before_status == TaskManager.STATUS_PART_DONE:\n                param = task[\"res\"]\n            else:\n                raise ValueError(\"The fetched task must be `STATUS_WAITING` or `STATUS_PART_DONE`!\")\n            if force_release:\n                with concurrent.futures.ProcessPoolExecutor(max_workers=1) as executor:\n                    res = executor.submit(task_func, param, **kwargs).result()\n            else:\n                res = task_func(param, **kwargs)\n            tm.commit_task_res(task, res, status=after_status)\n            ever_run = True\n\n    return ever_run\n\n\nif __name__ == \"__main__\":\n    # This is for using it in cmd\n    # E.g. : `python -m qlib.workflow.task.manage list`\n    auto_init()\n    fire.Fire(TaskManager)\n","sourceCodeStart":524,"sourceCodeEnd":559,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/workflow/task/manage.py#L524-L559","documentation":"Raised in qlib.workflow.task.manage.run_task when the fetched task's trigger status is neither TaskManager.STATUS_WAITING nor STATUS_PART_DONE. The loop only knows how to build train parameters from task['def'] (waiting) or task['res'] (part done); any other status reaching the branch is a programming/config error.","triggerScenarios":"Calling run_task(task_func, before_status=TaskManager.STATUS_DONE) or any status other than WAITING/PART_DONE — the while loop fetches a task with that status and then hits the else branch immediately.","commonSituations":"Custom task lifecycle code that passes STATUS_RUNNING/STATUS_DONE as before_status; tasks whose status was mutated concurrently by another worker between fetch and dispatch; copy-paste of the run_task loop with a new status value without extending the branch.","solutions":["Pass before_status=TaskManager.STATUS_WAITING (default) or TaskManager.STATUS_PART_DONE to run_task; these are the only supported fetch states.","If you need a custom lifecycle, wrap task_func so it saves intermediate results and re-fetch as PART_DONE rather than inventing new before_status values.","Ensure no other process flips fetched tasks to a different status mid-run (use safe_fetch_task locking semantics)."],"exampleFix":"// before\nrun_task(task_func, before_status=TaskManager.STATUS_DONE)\n\n// after\nrun_task(task_func, before_status=TaskManager.STATUS_WAITING)","handlingStrategy":"validation","validationCode":"from qlib.workflow.task.manage import TaskManager\nassert before_status in (TaskManager.STATUS_WAITING, TaskManager.STATUS_PART_DONE), f\"unsupported before_status: {before_status}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only fetch tasks in WAITING or PART_DONE state.","Use save_task with intermediate results to leverage PART_DONE instead of custom statuses.","Document task lifecycle in your team so run_task callers don't invent statuses."],"tags":["qlib","task-manager","workflow","status"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}