Repository navigation
Description
Problem
When the Celery task that tracks a task starts, it sets the state to INITIALIZING unconditionally (pro_tes/tasks/track_task_progress.py, db_client.update_task_state(state=TesState.INITIALIZING.value)). The state reported by the backend is only stored after the first poll in the loop, polling.wait seconds later; the get_task before the loop doesn't store it.
With #275, new tasks are stored with the state that their backend reports (e.g., QUEUED or RUNNING), and tasks can be canceled right after creation (CANCELED), before a worker picks up the tracking job. The tracker then overwrites these states:
- For
polling.waitseconds (or longer while the workers are busy),GET /tasks/{id}showsINITIALIZINGfor a task that is running, or for one that was canceled. - A second cancel request in that window passes the check and cancels the task at the backend again.
- If the backend doesn't report
CANCELEDafterwards (e.g., its cancel was a no-op, or tracking ends withSYSTEM_ERROR), the cancel is lost.
Before #275, the overwrite only replaced UNKNOWN, so it did no harm.
Found in the review of the fix for #275.
Proposed change
- Set
INITIALIZINGonly on tasks that are stillUNKNOWN:DbDocumentConnector.update_task_state(..., if_state="UNKNOWN"), added in fix: store and cancel new tasks at backends #275. Or drop the write. - Store the state of the
get_taskbefore the loop. - Never move tasks out of a final state, such as
CANCELED. - Handle states that the tracker doesn't know (e.g., a backend serving
DONE):update_task_stateraisesValueError, so tracking ends and the task keeps its last state, e.g.,INITIALIZING. Since fix: submit tasks to backends exactly once #274, such tasks are stored with their backend (instead of a 500 that orphaned them), so the tracker should keep polling them, or log them and keep them cancelable (Sourcery review of fix: submit tasks to backends exactly once #282).
This belongs to the redesign of task tracking (findings 3 to 5 of the pre-release review), which changes track_task_progress.py.
Activity
uniqueg commentedon Oct 24, 2026
Done in #288. Checked against
dev(28a49c6):INITIALIZINGoverwrite: the tracker no longer writesINITIALIZINGat all. Each run oftasks.track_run_progresspolls once and stores the backend's state if it differs from the stored one, so the firstget_taskis stored too.CANCELEDis kept until the backend reports a finished state (_store_state(..., keep_canceled=True), a conditional update that also covers a cancel committed while a poll runs). Only then is the backend's final state stored, e.g.,CANCELED, orCOMPLETEif the cancel came too late. Tasks stored in other final states are not tracked: tracking ends once a task is finished, and resumed tracking only picks up unfinished tasks.DONE): py-tes rejects them inget_task(ValueError, raised by its attrs validator), so the poll counts as a failed poll. Tracking goes on: afterpolling.attemptsconsecutive failures the task becomesUNKNOWN(cancelable since fix: store and cancel new tasks at backends #291), and polls back off topolling.max_wait. Unknown states are never stored.