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.
Assistant
This is the Kueue project (Kubernetes batch queueing). Let me understand the issue. The issue is about admitted workloads being requeued too early when a worker disconnects. This relates to MultiKueue likely. Let me explore the relevant code.
Assistant
Let me look at the workload.go file in detail, especially around the worker loss logic.
Assistant
Let me look at how the group is built and how remote clients are populated, especially around worker connection/disconnection.
Assistant
Let me look at the multikueuecluster.go to understand connection/disconnection handling.
Assistant
Let me look at the test file to understand expected behavior around worker loss.
Assistant
Let me look at the remoteClient struct more and the controllerFor / clusters management.
Assistant
Let me look at the git history of the relevant code to understand the intended design.
Assistant
Let me look at the KEP documentation for the worker-loss timeout design.
Assistant
Let me check the CHANGELOG for any related entries.
Assistant
Let me look at the integration tests to understand the expected behavior with a temporary worker disconnect.
Assistant
Now let me look at the test at line 2161 to understand more about the expected behavior.
Assistant
Let me look at how the reserving remote (assigned worker) is tracked in the local workload.
Assistant
Let me look at the test setup for these worker-loss tests in detail.
Assistant
Let me look at the full test cases for worker-loss.
Assistant
Let me look at the
bestMatchByConditionfunction.Assistant
Let me look at the full Reconcile function and the beginning of the workload.go to understand the structure.
Assistant
Let me look at
SetAdmissionCheckStateto understand LastTransitionTime updates.Assistant
Let me check what consumes
watchEndedChand how workload reconciliation is triggered on disconnect.Assistant
Let me look at the multikueuecluster_test.go to understand the watch-end and clock usage.
Assistant
OK. Now let me think about the implementation again. I'll keep it focused and minimal.
Let me reconsider: there might be a subtlety. The watch-end goroutine records disconnectAt using
rc.clock.Now(). In production this is RealClock. In the multikueuecluster tests, the watch-end goroutine isn't really exercised (they use "nowatch" kubeconfig which fails at build, not at watch-end). So the watch-end path with disconnectAt recording is mostly tested via integration tests.Now, the workload_test.go sets
w1remoteClient.connecting.Store(false)and doesn't set disconnectedAt. In the worker-loss tests, the worker is connected (in remotes). So my logic uses LastTransitionTime fallback. Good.But wait - in workload_test.go, the worker-loss tests don't set ClusterName. So even if I look up the reserving remote via ClusterName, it's nil -> fallback to LastTransitionTime.
Now let me also check: the workload_test uses
w.clusters.controllerFor? The reconciler hasclusters *clustersReconciler(cRec). AndcontrollerForis a method on clustersReconciler. Let me verify the field name. The wlReconciler hasclusters *clustersReconciler. Yes (line 60: ).Assistant
Now I have a clear understanding. Let me implement the fix. First, let me add a
disconnectedAtfield to theremoteClientand helper methods.Assistant
Now let me add the
disconnectedAtfield and helper methods:Assistant
Now let me add helper methods near the existing connection-related methods:
Assistant
Now let me update the watch-end goroutine to record the disconnect time, and
setConfigto reset it on successful reconnection:Assistant
The whitespace might differ. Let me check the exact text.
Assistant
Let me use the edit command instead. First let me open the file at the right line.
Assistant
I introduced an extra
}. Let me fix the closing braces:Assistant
Now let me update
setConfigto reset the disconnect time on successful reconnection:Assistant
Let me add a
clearDisconnectedmethod and call it on successful reconnect. First, add the method near the others:Assistant
Now let me update the
setConfigsuccess path to clear the disconnect time:Assistant
Now let me update the worker-loss branch in workload.go:
Assistant
Now let me rewrite the worker-loss branch (lines 504-514). I'll add a helper to determine the grace start time.
Let me write a helper method
workerLossGraceStart(group, acs) time.Timethat:- defaults to acs.LastTransitionTime.Time
- if group.local.Status.ClusterName is set, look up the remote client via w.clusters.controllerFor; if found and isDisconnected() and getDisconnectedAt() is non-zero, use getDisconnectedAt().
Let me implement.
Assistant
Now let me add the
workerLossGraceStarthelper method. Let me add it near theupdateACSmethod:Assistant
The
!caused parsing issues. Let me use a python script instead.Assistant
Let me verify
w.clockis always set and check thenewWlReconciler:Assistant
Let me verify the
clock.Clockinterface has aSincemethod:Assistant
Now let me build to check for compilation errors:
Assistant
Build succeeds. Now let me run the existing unit tests for the multikueue package:
Assistant
All unit tests pass. Now let me check the integration test setup for
workerLostTimeoutand timeouts:Assistant
Let me check what
util.BreakConnectiondoes to ensure the disconnect path is exercised:Assistant
Let me look at
stopAndRemoveClusterandloadClientConfigbehavior:Assistant
Let me look for other disconnect simulation utilities in the test infrastructure:
Assistant
Let me check the clustersReconciler struct and its construction for a clock field:
Assistant
Let me check all callers of
stopAndRemoveCluster:Assistant
Let me check if there are tests for cluster deletion affecting workload requeue:
Assistant
I realize the
BreakConnectionintegration test removes the client from the map (config-load failure), so a client-level field would be lost. I need a persistent tracker inclustersReconcilerthat survives client removal. Let me revert the client-level changes and implement a persistent map approach.First, let me revert the client-level
disconnectedAtfield and helpers:Assistant
Now let me implement the persistent map approach. First, add the
clustersfield toremoteClient:Assistant
Now set
rc.clustersinfindOrCreateRemoteClient:Assistant
Now let me add the persistent map and methods to
clustersReconciler. First, add the field:Assistant
Now initialize the map in
newClustersReconciler:Assistant
Now add the methods
recordDisconnection,clearDisconnection,disconnectionTimenearcontrollerFor:Assistant
Now update the watch-end goroutine to record the disconnect time:
Assistant
I introduced an extra
}again. Let me fix the closing braces:Assistant
Now update
setConfigsuccess path to clear the disconnect time:Assistant
Now update
stopAndRemoveClusterto record the disconnect time:Assistant
Let me reconsider:
stopAndRemoveClusteris also called for cluster deletion, where adding a grace period might be undesired. Let me record only for the config-load-failure case (temporary disconnect), not for deletion. Let me revert thestopAndRemoveClusterchange and record at the config-load-failure call site instead:Assistant
Now record the disconnect at the config-load-failure call site. Let me look at it:
Assistant
Let me check the imports in multikueuecluster.go include
time:Assistant
Good. Now let me update the workload.go worker-loss branch and add the
workerLossGraceStarthelper. Let me look at the original branch:Assistant
Now add the
workerLossGraceStarthelper nearupdateACS:Assistant
Now let me build and run the unit tests:
Assistant
The unit tests pass. Now let me write a temporary test to verify the fix handles the bug scenario (long-admitted workload + recent disconnect). Let me check the test helpers first:
Assistant
Let me look at how
readGrouperrors (e.g. ErrNoActiveClusters) are handled in Reconcile:Assistant
Let me write a temporary test to verify the fix. First, let me check the test helpers used:
Assistant
Now let me create a temporary test file:
Assistant
The temp test passes with the fix. Let me verify it FAILS without the fix (to confirm it reproduces the bug). Let me temporarily revert the grace-start logic:
Assistant
The test correctly reproduces the bug without the fix (RequeueAfter=0, immediate requeue). Now let me restore the fix:
Assistant
Let me add the "exceeded" case to verify requeue still happens after the timeout from disconnect:
Assistant
Let me add a reconnect-restores-processing case to verify reconnection restores processing:
Assistant
All three scenarios pass. Now let me run the full unit test suite for the package and the broader affected packages:
Assistant
All scenarios pass. Now let me remove the temporary test file and run the broader checks:
Assistant
Let me run the full multikueue unit tests once more and a broader set of tests:
Assistant
Let me review the full diff to ensure everything is clean:
Assistant
Let me run gofmt to ensure formatting is correct:
Assistant
Let me check if
time.Now()is used elsewhere in non-test code in this package (lint compliance):Assistant
Let me check the golangci config for any rule against
time.Now()usage:Assistant
Let me check
time.Now()usage in broader pkg to confirm it's an accepted pattern:Assistant
For consistency and testability, let me add a clock to
clustersReconcilerinstead of usingtime.Now(). Let me check wherenewClustersReconcileris called:Assistant
Let me check the timeout constants used in integration tests:
Assistant
The integration test uses
MediumTimeout=45s, well above the 3sworkerLostTimeout, so the fix is compatible. Let me run the full multikueue test suite once more (without the temp file) to confirm:Assistant
Let me verify the integration test helper
admitWorkloadAndCheckWorkerCopiesto understand which worker is admitted:Assistant
Let me check the e2e multikueue tests for any worker-loss expectations:
Assistant
This e2e test disconnects worker1's APIServer (a real network disconnect). Let me look at the full test to understand expectations:
Assistant
Let me verify there are no deadlock concerns and check all callers of
setConfig:Assistant
Let me run vet, gofmt check, and tests one final time:
Assistant
Let me verify the git status to ensure no leftover temp files and review final changes:
Assistant
Let me do a final review of the complete diff:
Assistant
The diff is clean and complete. Let me do a final verification by running the full multikueue test suite and a broad build:
Assistant
Let me verify no leftover helpers from the earlier reverted approach remain:
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.