Repository navigation
Fix KubernetesExecutor leaving invalid-config tasks stuck in queued - #74512
Merged
kaxil merged 1 commit intoOct 9, 2026
Merged
Conversation
sjyangkevin
marked this pull request as ready for review
October 9, 2026 19:00
sjyangkevin
requested review from
hussein-awala,
jedcunningham and
jscheffl
as code owners
October 9, 2026 19:00
When execute_async rejected a task's executor_config, it failed the task before the key was recorded as running, and the key was then added to running anyway. The scheduler saw the executor still owning the task and ignored the FAILED event, so the task instance stayed queued until task_queued_timeout and its parallelism slot was never released.
sjyangkevin
force-pushed
the
fix-k8s-executor-invalid-config-stuck-queued
branch
from
October 9, 2026 19:00
6138b1c to
07a7c25
Compare
kaxil
approved these changes
Oct 9, 2026
28 of 93 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
closes: #67643
When a task's
executor_configcan't be converted to a pod (for example the legacy{"KubernetesExecutor": {...}}dict),KubernetesExecutorreports the task as failed, but the scheduler ignores that event. The task instance staysqueueduntil[scheduler] task_queued_timeoutcleans it up, and one executor parallelism slot leaks for the life of the scheduler process. With this change the task is marked failed right away.Root cause
runningmeans "this executor owns the task and hasn't reported its final state yet". Every exit path removes the key fromrunningat the same time it writes the final state toevent_buffer(fail()/success()/change_state()/_change_state())._process_workloads()broke that rule by recording ownership after dispatch:When the scheduler processes the FAILED event,
executor.has_task(ti)returnsTruebecause the key is inrunning. The scheduler then treats the event as "task requeued" (scheduler_job_runner.py,ti_requeued) and skips failure handling. Nothing ever removes the key, because no pod was created, so there's no watcher event.Fix
Add the key to
runningbefore callingexecute_async(). Afail()insideexecute_async()then removes it through the existingchange_state()path. Pod-creation failures insync()already work this way: they callfail()while the key is inrunning._process_workloads()runs synchronously in the scheduler thread, and after it returnsrunningholds the same keys as before. The existingtest_process_workloadspasses unchanged.fail(); returninsideexecute_async()is covered without further changes.execute_async()raised an unexpected exception (not a handledfail()), the key would now be inrunningwhile the exception propagates. That exception already aborts the scheduler loop, and executor state is rebuilt through adoption on restart, so this doesn't make things worse.Tests
New regression test:
test_process_workloads_invalid_executor_config_is_not_tracked_as_running: it runs anExecuteTaskwith the legacy config through_process_workloads(), using the realexecute_async(). It asserts that the FAILED event is buffered and that the key is not inrunning. It fails onmainand passes with the fix. The existingtest_invalid_executor_configcallsexecute_async()directly, which is why it never caught this.Results:
providers/cncf/kubernetes/tests/unit/cncf/kubernetes/executors/: 266 passed, 14 skippedprek run --stage pre-commit --files <changed files>: all hooks passedbreeze k8s tests -- -k test_kubernetes_executoron kind (KubernetesExecutor, fixedimage): 9 passed
Reproduction on kind (KubernetesExecutor)
Dag from the issue:
Before (main): the task is reported failed but stays queued, and the key leaks in
running:No worker pod was created, there was no "state mismatch" handling, and the task was
still
queuedmore than 10 minutes later.After (this PR): the scheduler reconciles the event and fails the task immediately:
The task UUID is no longer in
self.running.Commands used
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 5.5) following the guidelines