[Jobs] Guard recovered monitors against stale job state - #65262
Conversation
Signed-off-by: will <zzchun8@gmail.com>
There was a problem hiding this comment.
Code Review
This pull request introduces guarded status updates to the job manager to prevent race conditions when updating job statuses, particularly during recovery or concurrent deletions. It updates put_status to check if the job info exists and matches an expected status before writing, and adds comprehensive unit tests for these scenarios. The reviewer identified a critical issue in _monitor_job_internal where returning instead of continuing when a status update fails (due to a concurrent transition from PENDING to RUNNING) would stop monitoring the job entirely, leaving it unmonitored.
| if not status_updated: | ||
| logger.info( | ||
| "Stopping monitoring for job %s because its job " | ||
| "info was deleted or its status changed.", | ||
| job_id, | ||
| ) | ||
| return |
There was a problem hiding this comment.
If status_updated is False because the job status transitioned from PENDING to RUNNING concurrently, calling return here will stop the monitor and leave the running job completely unmonitored.
Instead of returning, we should continue the loop. In the next iteration, get_status will fetch the updated RUNNING status, and the monitor will correctly proceed to track the supervisor actor.
| if not status_updated: | |
| logger.info( | |
| "Stopping monitoring for job %s because its job " | |
| "info was deleted or its status changed.", | |
| job_id, | |
| ) | |
| return | |
| if not status_updated: | |
| logger.info( | |
| "Retrying monitoring for job %s because its job " | |
| "info was deleted or its status changed.", | |
| job_id, | |
| ) | |
| continue |
Signed-off-by: will <zzchun8@gmail.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit f39878f. Configure here.
| or JobErrorType.JOB_SUPERVISOR_ACTOR_UNKNOWN_FAILURE, | ||
| timeout=None, | ||
| ) | ||
| continue |
There was a problem hiding this comment.
Stale ping reused after retry
High Severity
After a guarded exception update loses its race, the monitor continues without clearing ping_obj_ref. A failed ping from the prior status can be reused immediately on the next iteration, re-raise, and mark the job FAILED even though it has advanced to a new non-terminal state such as RUNNING.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit f39878f. Configure here.
Signed-off-by: will <zzchun8@gmail.com>


Summary
Prevent recovered submission-job monitors from recreating deleted jobs or
overwriting jobs that have already reached a terminal state.
Problem
JobManager._recover_running_jobs()schedules monitors asynchronously fornon-terminal jobs. A job record can be deleted or transition to a terminal
state between the recovery scan and the monitor's reconciliation pass.
The existing monitor may then attempt to write
FAILED:put_status()may recreate it withentrypoint="Entrypoint not found.".incorrect terminal-state transition.
get_info()failure for aPENDINGjob may be treated as amonitor failure instead of being retried.
Changes
PENDINGjob metadata-read failures on the next monitoriteration.
failures, and guarded
Related issues
Fixes #65251
Additional information