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 explore the repository structure to understand what we're working with.
Assistant
This is the Kueue project (Kubernetes batch queueing). The issue is about "Admitted workloads are requeued too early when a worker disconnects". This sounds like it's related to MultiKueue, where there are workers that can disconnect. Let me explore the relevant code.
Assistant
This is the key file. Let me look at the workload.go file in detail, especially around lines 480-540 where the worker lost logic is.
Assistant
Now I see the key logic. Let me understand the issue:
When a worker disconnects, an admitted workload should remain ready during the temporary disconnect and be retried only after the configured worker-loss timeout. The current code at line ~503 returns
reconcile.Result{RequeueAfter: w.workerLostTimeout}when there IS a reserving/admitted remote. And the else branch (line ~505) handles the case where there's no reserving remote but the AC state is ready.The issue says "Admitted workloads are requeued too early when a worker disconnects". Let me look at the logic more carefully.
Let me understand the flow:
-
When there's a reserving/admitted remote workload (line 461
remoteCond, reservingRemote := group.bestMatchByCondition(conditionToCheck)returns non-nil), it syncs and returns with .
-
Assistant
Now I understand the flow. Let me trace what happens when a worker disconnects:
readGroupis called. It callsremoteClientsForACwhich skips clients that are currently (reconnecting). So when a worker is disconnected and reconnecting, won't include that worker.
Assistant
Let me look at the existing tests for this worker lost scenario.
Assistant
Let me look at the test structure to understand how worker disconnect is simulated.
Assistant
Let me look at the worker-lost test cases more closely to understand how disconnect is simulated.
Assistant
Assistant
So
SetAdmissionCheckStateonly updatesLastTransitionTimeif the state changes. If the state stays the same (Ready), it doesn't update the LastTransitionTime.So in the current logic, when the worker is lost:
- The first reconcile after the disconnect:
bestMatchByConditionreturns nil (worker not in remotes),acs.State == Ready, soremainingWaitTime := workerLostTimeout - time.Since(acs.LastTransitionTime). If the workload was admitted a long time ago, this is negative, immediately requeued.
The fix needs to track the moment the worker disconnect was first observed.
Let me think about the cleanest approach that fits "No new interfaces are introduced."
One approach: When we detect the reserving remote is lost (the
else if acs.State == kueue.CheckStateReadybranch), record the current time somewhere. But we need to persist this across reconciles.Hmm, we could use the
RequeueAfterSecondsfield of the AdmissionCheckState, but that's a duration, not a timestamp.Wait, maybe the approach is different. Let me reconsider. Let me look at how the existing tests set up the "worker lost" scenario. In the tests, is the admission time, and the test verifies the timeout based on that. But the issue says the behavior is wrong.
- The first reconcile after the disconnect:
Assistant
Let me look at how disconnect events trigger workload reconciles and the clusters reconciler.
Assistant
Let me look at how the workload reconciler is set up and how it watches cluster disconnect events.
Assistant
Let me look at the CHANGELOG and any related KEPs for context on the intended behavior.
Assistant
Let me look at the KEP for multikueue to understand the worker-lost timeout design.
Assistant
So the design: "WorkerLostTimeout - defines the time a local workload's admission check state is kept Ready if the connection with its reserving worker cluster is lost." So the timeout should be from when the connection is LOST, not from when admitted.
Now let me check the git history of the worker-lost logic to see if it changed recently. Let me look at the blame for line 507.
Assistant
Let me look at the test runner to understand how workers are set up and how disconnect is simulated.
Assistant
Let me find the test runner where the cases are executed.
Assistant
Let me look at the clusters reconciler Reconcile and how disconnect/reconnect could enqueue workloads.
Assistant
Now let me look at the watch loop to understand disconnect detection and how it could enqueue workloads.
Assistant
Let me check when the "update the transition time" comment was added to syncReservingRemoteState.
Assistant
Let me check the test runner to see what it asserts (especially the reconcile result).
Assistant
The test runner does NOT check the reconcile.Result (RequeueAfter). It only checks the resulting workloads, jobs, events, and errors. So I have flexibility on the requeue timing. But it DOES check the manager workloads (state, message).
Let me look at the remoteClient struct and queueWorkloadEvent.
Assistant
Let me look at the integration tests for the worker-lost scenario to understand the expected behavior better.
Assistant
Let me check the WorkerLostTimeout configured in the integration test setup.
Assistant
Let me check for indexers on ClusterName and how workloads are indexed.
Assistant
Let me search for unit tests that simulate a reconnecting (disconnected) worker with an admitted workload.
Assistant
Let me look at the test cases with ClusterName set to understand them.
Assistant
Let me look at the elastic test case around line 1089-1120 that expects "Reserving remote lost" with ClusterName set.
Assistant
Let me check what the AdmissionCheck builder sets for LastTransitionTime by default.
Assistant
Let me look at the existing message constants and patterns in the multikueue package.
Assistant
Let me write a temporary reproduction test to confirm the bug with a disconnected (reconnecting) worker and a long-admitted workload.
Assistant
Let me check
defaultWorkerLostTimeoutvalue in tests.Assistant
Let me create a temporary reproduction test to confirm the bug.
Assistant
I've reproduced the bug. Now let me look at
PatchAdmissionStatusand related helpers to implement the fix.Assistant
OK. Now let me look at
PrepareWorkloadPatchto understand how it builds the patch — does it preserve the AC's LastTransitionTime? This matters because if I directly modifywl.Status.AdmissionChecks[i].LastTransitionTimein the update func, thenPrepareWorkloadPatchis called which might reset things.Let me look at PrepareWorkloadPatch.
Assistant
Now I understand the patch mechanics. Let me view the exact current else branch with line numbers to edit it.
Assistant
Now I have a clear plan. Let me verify
admissioncheck.FindAdmissionCheckreturns a pointer.Assistant
Now let me implement the fix. First, let me add the constant near the existing vars.
Assistant
Now let me modify the else branch:
Assistant
Now let me add the helper functions. Let me place them right after
syncReservingRemoteState(which ends around theupdateDelayedTopologyRequestdefinition). Let me find a good insertion point.Assistant
I used
logr.Logger- let me check iflogris imported in the file.Assistant
logris not imported. Let me derive the logger from ctx inside the helper instead of passing it, to avoid the import.Assistant
Build succeeds. Now let me run the repro test to confirm the fix.
Assistant
The fix works. Now let me extend the repro test to verify timeout expiry and reconnection restore.
Assistant
My test assertion was too strict. Let me fix it.
Assistant
Wait, the step 2 reconcile happens after stepping W/2. But there's a subtlety: the first reconcile recorded the loss time at
now(fakeClock). But the SECOND reconcile: the fakeClock is atnow + W/2. The AC's LastTransitionTime was recorded asnow(from the first reconcile's patch, usingw.clock.Now()= fakeClock atnow). So elapsed = (now+W/2) - now = W/2. remaining = W - W/2 = W/2 = 2m30s. So requeue after 2m30s. My condition now:res.RequeueAfter > defaultWorkerLostTimeout/2→2m30s > 2m30s= false → OK (not fail). And<= 0false. So passes.But wait, there's a subtlety: the second reconcile's
handleReservingRemoteUnavailablecomputesnow := w.clock.Now()= fakeClock at now+W/2. Andacs.LastTransitionTime= now (recorded). But isacs(read from the live object) reflecting the recorded LastTransitionTime? The first reconcile patched the live object (managerClient) with LastTransitionTime = now. The second reconcile re-reads the workload from managerClient (via Reconcile → w.client.Get). So acs.LastTransitionTime = now (the recorded value). Good. elapsed = W/2. remaining = W/2.Assistant
All my reproduction tests pass. Now let me run the existing tests to ensure I didn't break anything.
Assistant
All existing tests in the multikueue package pass. Now let me remove my temporary repro test and run a broader test set.
Assistant
Let me reconsider the edge cases and run a broader test suite to make sure nothing else breaks.
Assistant
All tests pass. Now let me review the full diff of my changes.
Assistant
There's a double blank line after the const block. Let me run gofmt to clean up formatting.
Assistant
Let me run go vet and the build to verify.
Assistant
Let me verify
controllerForto ensure my distinction is correct.Assistant
The distinction using
group.remoteClientswould also catch "cluster removed from config" cases, which could be a regression. Let me refine the check to only apply to actual disconnects (reconnecting clients) usingcontrollerFor+ theconnectingflag.Assistant
Let me rebuild and recreate a quick repro test to verify the refined check.
Assistant
All three repro tests pass, confirming:
- Disconnect → stays Ready for the full timeout (not requeued too early).
- Timeout expiry → Retry.
- Reconnect → processing restored (message cleared back to reservation).
- Connected worker with workload gone → legacy admission-time-based behavior preserved.
Now let me remove the temporary repro test and run the full multikueue test suite once more.
Assistant
Let me reconsider the
controllerForlock concern and run broader tests including cache and scheduler packages.Assistant
All tests pass. Let me review the final diff once more.
Assistant
The diff looks clean. Let me check if there's a CHANGELOG convention for unreleased changes that I should follow.
Assistant
There's a CHANGELOG-0.17.md with "Changes by Kind" / "Bug or Regression" section. The top section appears to be unreleased (above "## v0.17.2"). Let me check the very top to confirm it's the unreleased section.
Assistant
Let me do a final verification - run the multikueue tests, gofmt, and vet.
Assistant
Let me verify git status to ensure only the intended file is changed and no temp files remain in the repo.
Assistant
Only the intended file is changed and the temp test file is removed. Let me do a final confirmation run of the relevant existing tests (the worker-lost ones specifically) to ensure they pass.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.