Repository navigation
fix: complete cancelled tasks after failed worker assignment - #20867
Conversation
FrankChen021
left a comment
There was a problem hiding this comment.
🟢 Approval recommended
No actionable issues found in this review. The synchronized shutdown/assignment handoff correctly completes rejected in-flight assignments outside statusLock, and the focused test covers both accepted and rejected outcomes.
Reviewed 2 of 2 changed files.
This is an automated review by Codex GPT-5.6-Luna(max)
amaechler
left a comment
There was a problem hiding this comment.
Thanks for picking this up! A couple of bot comments to consider.
FrankChen021
left a comment
There was a problem hiding this comment.
🟡 Changes recommended
A cancellation race remains in the accepted-assignment path. If the worker's initial RUNNING announcement arrives before its local RunNotice starts the task, the shutdown request can be ignored; the later RUNNING announcement does not retry it, allowing a cancelled task to execute.
Reviewed 2 of 2 changed files; findings in 1 file.
Validation: git diff --check passed. No builds or tests were run; this was a static review.
| Severity | Findings |
|---|---|
| P0 | 0 |
| P1 | 1 |
| P2 | 0 |
| P3 | 0 |
| Total | 1 |
This is an automated review by Codex GPT-5.6-Luna(max)
After addressing the findings or replying to the comments, you can request another review from me to trigger a new automated review.
| case PENDING_WORKER_ASSIGN: | ||
| taskItem.setWorker(worker); | ||
| taskItem.setState(HttpRemoteTaskRunnerWorkItem.State.RUNNING); | ||
| shouldShutdownTask = taskItem.shutdownStatus != null; |
There was a problem hiding this comment.
[P1] Retry shutdown after an early RUNNING announcement
Finding: The cancellation marker is checked only when the first RUNNING announcement transitions the work item from PENDING or PENDING_WORKER_ASSIGN. A worker can publish that first RUNNING update while the task is still only in its assigned queue; cancellation then sends a shutdown request before the worker task runner knows the task, so the request is ignored. The later RUNNING update sees an already-RUNNING work item and does not retry shutdown, allowing the cancelled task to execute.
Suggestion: Preserve cancellation intent for already-RUNNING work items and retry shutdown on subsequent RUNNING announcements until a terminal update is observed; add a test covering this ordering.
There was a problem hiding this comment.
Pushed 3a87965 to this branch. shutdown() now records the kill for RUNNING work items too, and the RUNNING arm resends the shutdown on every RUNNING report until the worker reports the task complete. The worker's second RUNNING report is published after taskRunner.run() has the task, so the resend lands. Both orderings have a test. Without it, the cancelled task runs until TaskQueue's storage sync (PT1M by default) drops the entry and the next management pass shuts it down.
There was a problem hiding this comment.
Thanks @amaechler for pushing 3a87965, resending the shutdown on every RUNNING report until a terminal update covers the early announcement ordering
@FrankChen021 this should address the P1, could you take another look when you have a moment
There was a problem hiding this comment.
Reviewed 2 of 2 changed files at head 3a87965cba2ebda8424ee9afd91b8fa15117a552. The prior P1 is addressed: cancellation is recorded for RUNNING work items and later RUNNING reports resend shutdown, covering the assigned-queue announcement race. I found no further actionable issues.
A worker announces an assigned task as RUNNING before its RunNotice hands the task to the task runner, and the runner ignores a shutdown request for a task it does not know yet. Record the kill for RUNNING work items as well, and send the shutdown again on every RUNNING report until the worker reports the task complete.
FrankChen021
left a comment
There was a problem hiding this comment.
Follow-up assessment
The prior P1 is resolved: cancellation is retained for RUNNING work items and subsequent RUNNING announcements retry shutdown, covering the early assigned-queue announcement race. No further actionable issues were found.
Reviewed 2 of 2 changed files.
Validation: git diff --check 490cbf0035e0c988c141ef146566706854811097..HEAD passed. No builds or tests were run; this was a static review.
This is an automated review by Codex GPT-5.6-Luna(max)
Fixes #20773
Description
Record the cancellation status when a task is shut down during worker assignment so that a rejected assignment immediately completes the original future as FAILED and removes the task from both pending-task views
The assigning thread reads the cancellation status and decides whether to retry under
statusLock, then completes the cancelled task outside the lock to avoid invoking completion callbacks while holding itIf the worker accepts the assignment, check the cancellation marker when it reports RUNNING and send the shutdown request outside the lock rather than waiting for the next TaskQueue management pass
Extend the existing in-flight shutdown test to cover both accepted and rejected assignments, including actual worker receipt of the shutdown request, the cancellation reason and release of the worker reservation for another task
Validation
HttpRemoteTaskRunnerTestandWorkerHolderTest: 30 tests pass with retries disabledSeekableStreamSupervisorStateTest.testEmitNoticesQueueSizeandWorkerTaskManagerTest.testTaskRun, then both suites passed separately with retries disabled, totaling 103 testsSeekableStreamSupervisorSpecTestand two parameter cases ofWorkerTaskManagerTest.testTaskRun, with no changes to those unrelated testsRelease note
Tasks cancelled during worker assignment are promptly marked failed when assignment is rejected, so they no longer inflate pending-task demand until the next storage sync
If the worker accepts the assignment, the cancellation is sent as soon as the task reports RUNNING instead of waiting for a later cleanup pass
Key changed classes
HttpRemoteTaskRunnerHttpRemoteTaskRunnerTestThis PR has: