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 understanding the repository structure and the issue at hand. The issue is about "admitted workloads being requeued too early when a worker disconnects." This suggests there's some mechanism for handling worker disconnections and workload requeueing that needs to be fixed.
Let me first explore the repository to understand its structure.
- Assistant
Let me explore the repository structure more broadly.
- Assistant
Let me explore the repository structure and find the relevant code for handling worker disconnections and workload requeueing.
- Assistant
Let me look at the pkg directory and cmd directory to understand the main structure.
- Assistant
Let me look at the controller and workload related code to understand the requeueing mechanism.
- Assistant
Let me look at the relevant files for workload requeueing. The issue mentions:
- Admitted workloads being requeued too early when a worker disconnects
- Must remain ready during temporary worker disconnect
- Retried only after configured worker-loss timeout
- Reconnection with same configuration must restore processing without affecting other connected workers
This sounds like it could be related to MultiKueue, which involves worker clusters. Let me look at that.
- Assistant
Let me search for the MultiKueue-specific code related to worker disconnects and workload requeueing:
- Assistant
Let me focus on the MultiKueue workload and cluster controllers, as they seem most relevant to the issue.
- Assistant
Let me look at the full workload.go file to find the
reconcileGroupfunction and the logic around worker disconnects: - Assistant
Let me read the reconcileGroup function.
- Assistant
Let me read the reconcileGroup function and the surrounding logic.
- Assistant
Let me look at the clusters reconciler to understand how worker disconnections are handled:
- Assistant
Let me look at the
readGroupfunction and thenominateAndSynchronizeWorkersfunction: - Assistant
Let me read both functions:
- Assistant
- Assistant
Let me look at the
remoteClientsForACfunction: - Assistant
Let me now look at the git log to understand recent changes:
- Assistant
- Assistant
Let me look at the key section more carefully and understand how the worker connection and disconnection flow works:
- Assistant
Let me understand the watch lifecycle and how events flow when a worker disconnects:
- Assistant
Let me look at the
startWatcherand disconnect handling: - Assistant
Now let me look at the clustersReconciler's Reconcile function:
- Assistant
Let me read the clustersReconciler's Reconcile function:
- Assistant
- Assistant
Let me look at the
syncToSingleClusterfunction: - Assistant
- Assistant
Let me look at the full step 6 logic.
- Assistant
Let me see the rest of this else if block.
- Assistant
Now I have a clear picture. Let me look at the tests to understand expected behavior:
- Assistant
Let me look at the workload_test.go file for the multikueue controller:
- Assistant
Let me search for tests related to the "worker lost" scenario:
- Assistant
Let me look at the tests around line 841 and 1117:
- Assistant
Now let me look at the test around line 1117:
- Assistant
Let me look at the full test function to understand the test setup:
- Assistant
Let me find the test function:
- Assistant
Now I have a good understanding of the issue. Let me trace through the scenario:
- A workload is admitted on a worker, and
syncReservingRemoteStateupdatesacs.LastTransitionTime = now - The reconciler returns
RequeueAfter: w.workerLostTimeout - After
workerLostTimeout, the reconciler runs again, updatesLastTransitionTime, returnsRequeueAfter: w.workerLostTimeout - The worker disconnects sometime during the next
workerLostTimeoutperiod - After another
workerLostTimeout, the reconciler runs - Since the worker is disconnected, there's no reserving remote
- We reach the else-if branch:
remainingWaitTime = workerLostTimeout - time.Since(LastTransitionTime)≈ 0 - The workload is immediately retried!
The issue is that
LastTransitionTimeis from the last successful reconciliation, which wasworkerLostTimeoutago. So by the time we detect the disconnect, the timeout has already expired.The fix should be: when we first detect the disconnect, we should record a new timestamp and wait for the full
workerLostTimeoutfrom that point.Let me now implement this fix.
- A workload is admitted on a worker, and
- Assistant
Now let me look at the test structure to understand what "remote workloads" means in the tests:
- Assistant
Now let me understand the exact scenario from the tests. Let me look at the test for worker lost timeout:
- Assistant
Now I have a clear understanding of the issue. Let me trace the key scenario:
- A workload is admitted and
syncReservingRemoteStatesetsLastTransitionTime = now, message ="The workload got reservation on \"worker1\"" - Reconciler returns
RequeueAfter: workerLostTimeout(say 5 minutes) - After 5 minutes, reconciler runs again,
LastTransitionTimeupdated, anotherRequeueAfter: 5min - Worker disconnects 4 minutes into the next cycle
- After 1 more minute (total 5 min from last update), reconciler runs
- No reserving remote found → step 6 else-if:
remainingWaitTime = 5min - 5min = 0→ workload immediately requeued!
The workload should have waited 5 minutes from when the disconnect was detected, but instead was immediately retried because
LastTransitionTimewas stale.Now let me implement the fix. The key insight is that when we first detect the worker is gone (in the
else if acs.State == kueue.CheckStateReadybranch), we need to start a fresh timeout by updatingLastTransitionTime: - A workload is admitted and
- Assistant
Now I have a clear understanding of the issue. Let me trace through the key scenario:
- Workload is admitted on a worker,
syncReservingRemoteStatesetsLastTransitionTime = now, returnsRequeueAfter: workerLostTimeout - After
workerLostTimeout, reconciler runs again,LastTransitionTimeupdated, returnsRequeueAfter: workerLostTimeout - Worker disconnects during the next cycle
- After another
workerLostTimeout, reconciler runs - No reserving remote → step 6 else-if:
remainingWaitTime = workerLostTimeout - time.Since(LastTransitionTime) ≈ 0 - Workload is immediately requeued!
The problem is that
LastTransitionTimewas setworkerLostTimeoutago (at the last successful sync), so by the time we detect the disconnect, the timeout has already expired.The fix: when we first detect the worker is gone and
remainingWaitTime ≤ 0, we need to start a fresh timeout by updatingLastTransitionTimeto now. We use the AC message to distinguish between "first detection" and "timeout expired after previous detection."Let me look at the imports we'll need:
- Workload is admitted on a worker,
- Assistant
Now let me check if
stringsis already imported: - Assistant
Let me look at how the message is used throughout the codebase:
- Assistant
Let me also check if there are other places that check for "Reserving remote lost":
- Assistant
Now I understand the issue fully. Let me implement the fix. The core problem is that when a worker disconnects,
acs.LastTransitionTimewas set during the last successful sync (which wasworkerLostTimeoutago due toRequeueAfter), soremainingWaitTime ≈ 0and the workload is immediately requeued.The fix: when we first detect the worker is gone (message still says "The workload got reservation on..."), update
LastTransitionTimeto now and start a freshworkerLostTimeoutperiod. Use the message to distinguish between "first detection" and "timeout expired". - Assistant
First, let me add the
stringsimport: - Assistant
Good, the import was added. Now let me add a constant for the "worker lost detected, awaiting timeout" message and modify the
else ifblock. Let me first add the constant: - Assistant
Good, the constant is added. Now let me modify the
else ifblock. Let me find the current code: - Assistant
Let me see the full block:
- Assistant
Now let me modify the
else ifblock: - Assistant
I see there's an extra
}at line 542. Let me fix that: - Assistant
There's an extra
}on line 542 that was left from the originalelseblock. Let me remove it: - Assistant
I see a duplicate comment. Let me fix that:
- Assistant
Good, the code looks clean now. Let me verify the full block:
- Assistant
Now let me update the tests. First, let me look at the test that will be affected:
- Assistant
Now I need to understand how the tests work. Let me also check the elastic workload test that checks for retry:
- Assistant
I see that the elastic workload out-of-sync test also expects
CheckStateRetry. This is a different scenario from worker disconnect - the remote workload was found but removed because it's out of sync. I need to handle this differently from the worker disconnect case.Let me track whether step 5 removed any remote workloads and use that to decide whether to enter the "awaiting timeout" state:
- Assistant
Let me look at the full step 5:
- Assistant
Let me see the full transition from step 5 to step 6:
- Assistant
Now I need to add a flag to track whether step 5 removed any remote workloads. Let me modify step 5:
- Assistant
I see there's a duplicate. Let me fix that:
- Assistant
I need to remove the duplicate lines:
- Assistant
I see there's still a duplicate comment on line 466. Let me fix:
- Assistant
Good, the code structure looks correct now. But I need to also use the
removedOutOfSyncflag in theelse ifblock. Let me update the condition: - Assistant
I see there's a duplicate comment line. Let me fix:
- Assistant
Good. Now let me verify the code compiles:
- Assistant
Let me try setting the environment:
- Assistant
There's a syntax error. Let me check the area around line 566:
- Assistant
Let me check the full reconcileGroup function:
- Assistant
Let me check for any mismatched braces:
- Assistant
There's one more
{than}- a brace mismatch. Let me check the structure: - Assistant
I see the issue! The
if remoteEvictCond != nilblock is missing its closing}. Let me fix this: - Assistant
I see the problem. The
if remoteEvictCond != nilblock is missing its closing brace. Let me fix this: - Assistant
Good, the brace is fixed now. Let me try building again:
- Assistant
The code compiles. Now let me update the tests. Let me first run the existing tests to see what fails:
- Assistant
Good, the test failures are exactly what I expected. I need to update the test to reflect the new behavior. Now the workload enters the "awaiting timeout" state first, and only gets retried after the timeout expires. Let me update the test:
- Assistant
Now let me update the test. I need to change the expected result from Retry to Ready with the "awaiting timeout" message:
- Assistant
Now I need to update this test case to reflect the new behavior. The test should expect:
- State:
CheckStateReady(not Retry) - Message: "Reserving remote lost, awaiting timeout" (not "Reserving remote lost")
Let me update it:
- State:
- Assistant
I see the next test case "worker reconnects..." is missing its name. Let me check:
- Assistant
I see - the next test case lost its name. Let me fix it:
- Assistant
Let me check for a missing closing bracket:
- Assistant
I see - there's a missing
},before the next test case. Let me fix: - Assistant
Let me check the indentation and structure around the test cases:
- Assistant
Let me just run the test to see if there are syntax issues:
- Assistant
Good, it compiles. Let me run the tests:
- Assistant
All tests pass. Let me now run all the tests in the multikueue package to make sure nothing else is broken:
- Assistant
All tests pass. Let me also run the other test files:
- Assistant
All tests pass. Let me now verify the changes I made:
- Assistant
Let me see the full diff:
- Assistant
The diff looks good. Let me now run a broader set of tests to make sure nothing is broken:
- Assistant
All tests pass. Let me do a final check by running tests that might be affected:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.