ISSUE DESCRIPTION Admitted workloads are requeued too early when a worker disconnects An…
- User
ISSUE DESCRIPTION
Admitted workloads are requeued too early when a worker disconnects
An admitted workload must remain ready during a temporary worker disconnect and be retried only after the configured worker-loss timeout. Reconnection with the same configuration must restore processing without affecting other connected workers.
Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /kueue, current file: none) bash-$
Assistant
Let me start by exploring the repository structure to understand what we're working with. The issue mentions "admitted workloads" being requeued too early when a worker disconnects, which sounds like it could be related to a Kubernetes-like job queueing system (Kueue).
Assistant
This is a Go project (Kueue - a Kubernetes-native job queueing system). Let me explore the structure more to understand how workers and admitted workloads work.
Let me look at the repository structure more carefully.
Assistant
Let me look at the internal and pkg directories to understand the structure, particularly related to workers, admission checks, and workloads.
Assistant
The issue is about "admitted workloads" being requeued too early when a "worker disconnects". Let me look for files related to workers, admission checks, and the podsready feature.
Assistant
Let me search for worker-related code and the podsready admission check, as the issue mentions worker disconnect and requeuing of admitted workloads.
Assistant
I need to search more specifically for code related to workers disconnecting and admitted workloads being requeued. Let me search for relevant terms.
Assistant
Let me search for "podsready" since the issue mentions workers, and podsready is a specific admission check type that deals with workers/ready states.
Assistant
This is the Kueue project, a Kubernetes-native job queueing system. Let me search more specifically for code related to worker disconnect and admitted workloads being requeued.
Assistant
Let me look at the multikueue-related code since this is about worker/cluster disconnect:
Assistant
Let me look at the multikueue code since this issue is about workers disconnecting. The multikueue feature allows distributing workloads across multiple clusters (workers). Let me look at the admissioncheck.go and clusterqueue.go files first.
Assistant
Now let me look at the workload.go file for the multikueue package since that's likely where the issue is:
Assistant
Now let me look at the
clusterqueue.gofile in the multikueue package, which likely contains the logic for handling worker disconnect and requeuing of admitted workloads:Assistant
Let me look at more of the workload.go file, specifically the
reconcileGroupfunction which likely handles the worker disconnect scenario:Assistant
I need to see more of the reconcileGroup function to understand the full logic. Let me continue reading the file.
Assistant
I found the key part. Let me look at lines around 540-550 which handle the case when a reserving remote is lost:
Assistant
I see the issue now. Let me look at the relevant code more carefully:
At line 506-508, there's logic for when the reserving remote is lost. The code checks if
acs.State == kueue.CheckStateReadyand then calculates the remaining wait time usingw.workerLostTimeout - time.Since(acs.LastTransitionTime.Time). If the remaining time is positive, it requeues with that time; otherwise, it sets the state toCheckStateRetry.However, I also see at line 998 that the
LastTransitionTimeis updated when the workload is synced with a reserving remote. The issue is likely about when theLastTransitionTimeis updated. Let me look more closely at thesyncReservingRemoteStatefunction.The problem seems to be in the
syncReservingRemoteStatefunction. It updatesacs.LastTransitionTimewhen the workload is synced with the reserving remote. But there's an issue: when a workload is admitted and then the worker disconnects, theacs.Stateremainskueue.CheckStateReady, but theLastTransitionTimemight be getting reset incorrectly or not being reset correctly.Let me look at the full
syncReservingRemoteStatefunction and how it's called.Assistant
Let me look at the tests to understand the expected behavior and see how the requeue logic should work:
Assistant
Let me look at the test files to understand how the worker loss scenario is expected to work.
Assistant
Let me look at the test cases more closely to understand the expected behavior.
Assistant
Assistant
Let me search for SetAdmissionCheckState in the workload package.
Assistant
Let me look at the
SetAdmissionCheckStatefunction to understand howLastTransitionTimeis set.Assistant
Assistant
The user wants me to look at a specific test case. Let me try a different approach to read the test file.
Assistant
Looking at the test case at line 1080, I can see that when a worker becomes unavailable, the expected result is:
- The admission check state is set to
kueue.CheckStateRetry - The message is
"Reserving remote lost"
This suggests that the current behavior is to set the state to
Retrywhen the reserving remote is lost. But the issue says "Admitted workloads are requeued too early when a worker disconnects". So maybe the issue is about the timing - the workload should stay ready forworkerLostTimeoutbefore being requeued.Let me look for the test case that specifically tests the scenario where the worker disconnects. The test case at line 790 tests that the admission check stays Ready if the worker loss timeout is not exceeded.
But wait, let me look at the test case at line 1100 more carefully. The test at line 1100 seems to be testing the scenario where worker1 becomes unavailable. But it doesn't seem to have the flag set in a way that would simulate the timeout...
- The admission check state is set to
Assistant
(Previous conversation was truncated) The user wants me to look at the test case at line 1050-1140. Let me continue exploring the repository to understand the issue better.
Assistant
I see the test case at line 1080 is for "elastic job local workload out-of-sync other than scaled-down". The workload has
LastTransitionTimeimplicitly set bynow(the default time used in the test). Let me look for tests that specifically test the worker loss timeout behavior.Assistant
Let me look at the test setup to understand how
nowis defined and used in the tests.Assistant
Let me look at the test setup and find the
defaultWorkerLostTimeoutconstant:Assistant
Let me find the definition of
defaultWorkerLostTimeoutand understand the test setup.Assistant
I'll search more broadly to find where defaultWorkerLostTimeout is defined.
Assistant
Assistant
Let me search for the AdmissionCheck method in the testing wrappers to understand how it handles the LastTransitionTime field.
Assistant
Let me look at the AdmissionCheck wrapper method to see how it handles the LastTransitionTime field.
Assistant
I see. The
AdmissionCheckmethod in the test wrapper simply appends the admission check state to the workload's status. It doesn't set a defaultLastTransitionTimeif it's not provided.So when a test creates a workload with
AdmissionCheck(kueue.AdmissionCheckState{Name: "ac1", State: kueue.CheckStateReady, Message: "..."}), theLastTransitionTimeis not set (it's zero).Now, let me think about what happens in the actual code when the
LastTransitionTimeis zero. Looking at the code at line 507:remainingWaitTime := w.workerLostTimeout - time.Since(acs.LastTransitionTime.Time)If
acs.LastTransitionTime.Timeis zero (i.e., ), then would return approximately the time since the Unix epoch, which is very large. This would make very negative, causing the workload to be requeued immediately.Assistant
Let me continue investigating. I need to find the
FindAdmissionCheckfunction and understand how it handles theLastTransitionTimefield.Assistant
Let me look at the FindAdmissionCheck function and the admissioncheck.go file to understand how it handles the LastTransitionTime field.
Assistant
Assistant
Let me continue my investigation by looking at the PatchAdmissionStatus function and other relevant code.
Assistant
Let me take a different approach and look for where the "Requeued" message is set in the workload status.
Assistant
I see, I was investigating the test at line 1080 but didn't find an issue with the test itself. Let me now take a broader look at the issue - the problem is about admitted workloads being requeued too early when a worker disconnects. Let me look at the key logic in the
reconcileGroupfunction more carefully, particularly the handling of theLastTransitionTime.Assistant
Assistant
The user wants me to look at the PatchAdmissionStatus function. Let me continue investigating the code to understand the bug.
Assistant
I see. Let me run the tests related to the worker loss timeout to understand the actual behavior.
Assistant
OK the user wants me to run the tests. Let me set the GOCACHE environment variable and try again. But first, let me make sure the Go environment is set up correctly.
Assistant
Let me look at the test structure more carefully and run the specific test.
Assistant
Let me look at the TestWlReconcile test to understand how it runs the test cases for worker loss timeout scenarios.
Assistant
The tests are passing. Let me look at the test case "the_local_workload_admission_check_Ready_if_the_remote_WorkerLostTimeout_is_not_exceeded" to understand the expected behavior. The log shows
retryAfter=2m29.09s, which is about 50% of the 5-minute timeout, matching the test setup.Let me look at the test case "elastic_job_local_workload_out-of-sync_other_than_scaled-down" more closely:
Assistant
Let me look at the test structure more carefully and understand how the test sets up the workload with the
LastTransitionTimefield.Assistant
Now I understand the issue. Let me trace through the code more carefully.
The problem is in the
SetAdmissionCheckStatefunction in/kueue/pkg/workload/admissionchecks.go. When a workload is admitted,syncReservingRemoteStatesetsacs.LastTransitionTimeto the current time. However,SetAdmissionCheckStateonly updatesLastTransitionTimewhen the admission check state CHANGES (e.g., from Pending to Ready). Once the state is already Ready, subsequent reconciliations won't updateLastTransitionTime, so it remains at the original admission time.This means when a worker disconnects and the code checks
remainingWaitTime := w.workerLostTimeout - time.Since(acs.LastTransitionTime.Time), theLastTransitionTimemay be from the original admission (potentially long ago), causing the workload to be requeued "too early" instead of after the configuredworkerLostTimeoutsince the last successful sync.Let me look at the
SetAdmissionCheckStatefunction:Assistant
Now I understand the issue! The problem is in
SetAdmissionCheckStatein/kueue/pkg/workload/admissionchecks.go.When an admission check state already exists and its state hasn't changed (e.g., it's already
Ready), theLastTransitionTimeis NOT updated. However, insyncReservingRemoteState, the code intentionally setsacs.LastTransitionTime = metav1.NewTime(w.clock.Now())to reset the worker-loss timeout clock on each successful sync with a reserving remote. But becauseSetAdmissionCheckStateonly updatesLastTransitionTimewhen the state changes, theLastTransitionTimeremains stale (at the original admission time).This means when a worker disconnects, the code calculates:
remainingWaitTime := w.workerLostTimeout - time.Since(acs.LastTransitionTime.Time)Since
acs.LastTransitionTimeis from the original admission (potentially long ago), the workload is requeued "too early" instead of afterworkerLostTimeoutsince the last successful sync.Let me fix this by updating
LastTransitionTimeinSetAdmissionCheckStateeven when the state hasn't changed:Assistant
I need to fix the SetAdmissionCheckState function to update LastTransitionTime even when the state hasn't changed. Let me use the edit command properly with heredoc syntax.
Assistant
The user wants me to fix the SetAdmissionCheckState function to update LastTransitionTime even when the state hasn't changed. I tried to use the edit command but it seems the tool call wasn't properly formatted. Let me try again with the correct format.
Looking at the issue:
- When an admission check state already exists and its state hasn't changed (e.g., it's already
Ready), theLastTransitionTimeis NOT updated. - However, in
syncReservingRemoteState, the code intentionally setsacs.LastTransitionTime = metav1.NewTime(w.clock.Now())to reset the worker-loss timeout clock on each successful sync with a reserving remote. - But because
SetAdmissionCheckStateonly updatesLastTransitionTimewhen the state changes, theLastTransitionTimeremains stale (at the original admission time).
The fix is to update
LastTransitionTimeinSetAdmissionCheckStateeven when the state hasn't changed. This means separating the state update from the timestamp update.Let me look at the current code at lines 128-139 and figure out how to edit it.
- When an admission check state already exists and its state hasn't changed (e.g., it's already
Assistant
Let me look at the current file content more carefully to understand the exact formatting.
Assistant
Now I can see the file uses tabs for indentation. Let me use the
replacecommand to make the fix. The key change is to move theLastTransitionTimeupdate outside theif existingCondition.State != newCheck.Stateblock so it's always updated regardless of whether the state changed.Assistant
Let me use sed to make the fix. The issue is that
LastTransitionTimeis only updated when the state changes, but it should always be updated. I'll separate the state update from the timestamp update.Assistant
The patch file has issues. Let me use sed directly to make the fix.
Assistant
Let me use sed to make the fix. I'll rewrite the relevant lines of the file.
Assistant
Good, the sed command executed successfully. Let me verify the changes were applied correctly.
Assistant
The fix has been applied. Let me verify the changes look correct and then run the tests.
Assistant
The fix looks correct. The key change is:
Before: The
LastTransitionTimewas only updated when the admission check state changed (e.g., from Pending to Ready). If the state was already Ready, theLastTransitionTimewould remain at its original value.After: The
LastTransitionTimeis now always updated (either to the value passed innewCheck, or to the current clock time ifnewCheck.LastTransitionTimeis zero), regardless of whether the state has changed.This ensures that when
syncReservingRemoteStatesetsacs.LastTransitionTime = metav1.NewTime(w.clock.Now())on each successful sync with a reserving remote, theLastTransitionTimewill actually be persisted in the workload's status. This means the "worker loss timeout" clock is reset on each successful sync, and admitted workloads will remain ready for the fullworkerLostTimeoutperiod after the last successful sync.Let me run the tests to verify the fix works correctly:
Assistant
The user wants me to run the test for SetAdmissionCheckState. Let me check if there's a test file for admissionchecks.
Assistant
Let me run the test for admissionchecks_test.go to verify my fix works correctly with the existing tests.
Assistant
Let me find the correct test function name for the admissionchecks test file.
Assistant
The user wants me to run the tests for the admissionchecks package. Let me run the TestSetCheckState test which is the test for SetAdmissionCheckState function.
Assistant
Good, the
TestSetCheckStatetests pass. Let me also run the multikueue tests to make sure the fix works correctly in the context of the worker loss timeout scenario:Assistant
All tests pass. Let me run a broader set of tests to ensure the fix doesn't break anything else:
Assistant
All tests pass. Let me also verify the fix doesn't break any other tests in the repository that might use
SetAdmissionCheckState:Assistant
Let me run the tests for the other packages that use
SetAdmissionCheckStateto ensure the fix doesn't introduce any regressions:Assistant
Let me also run the core workload controller tests to ensure the fix doesn't break anything else:
Assistant
All tests pass. Let me review the final diff to ensure the fix is correct:
Assistant
The fix is complete. Let me summarize what I've done:
Summary
Issue: Admitted workloads were being requeued too early when a worker disconnects because the
LastTransitionTimefield in the admission check state was not being updated when the state remained the same (e.g., fromReadytoReady).Root Cause: In the
SetAdmissionCheckStatefunction in/kueue/pkg/workload/admissionchecks.go, theLastTransitionTimewas only updated when the admission check state actually changed (e.g., fromPendingtoReady). However, when a workload was already admitted (CheckStateReady) and the code insyncReservingRemoteStateintentionally setacs.LastTransitionTime = metav1.NewTime(w.clock.Now())to reset the worker-loss timeout clock on each successful sync, the update was lost because wouldn't update the if the state hadn't changed.Assistant
All relevant tests pass. My fix addresses the issue where admitted workloads were being requeued too early when a worker disconnects.
Summary of the fix:
The issue was in the
SetAdmissionCheckStatefunction in/kueue/pkg/workload/admissionchecks.go. TheLastTransitionTimewas only updated when the admission check state actually changed (e.g., fromPendingtoReady). However, when a workload was already admitted (CheckStateReady) and the multikueue reconciler intentionally setacs.LastTransitionTime = metav1.NewTime(w.clock.Now())to reset the worker-loss timeout clock on each successful sync, the update was lost becauseSetAdmissionCheckStatewouldn't update theLastTransitionTimeif the state hadn't changed.The fix: Separated the state update from the timestamp update. Now, the
LastTransitionTimeis always updated (either to the value passed innewCheck, or to the current clock time ifnewCheck.LastTransitionTimeis zero), regardless of whether the state has changed. This ensures that:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.