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 repository (Kubernetes batch queueing). Let me search for relevant code related to worker disconnect, admitted workloads, requeue, and worker-loss timeout.
Assistant
The issue mentions "worker disconnect" which is likely related to MultiKueue. Let me explore that.
Assistant
Let me look at the multikueue workload.go file, which deals with workerLostTimeout and requeue logic.
Assistant
Now let me understand the logic around the workerLostTimeout and the requeue. The issue says: "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."
Let me look at the broader context of this reconcile function. Let me look at the
bestMatchByConditionand how the reserving remote is determined. Also let me look at the multikueuecluster.go for the disconnect detection.Assistant
Let me look at how
remotesis populated and how disconnection is detected.Assistant
Let me look at
remoteClientsForACand the multikueuecluster.go to understand disconnect handling.Assistant
Let me look at the multikueuecluster.go to understand the disconnect/reconnect handling and the
connectingflag.Assistant
Let me look at the test file to understand the expected behavior around worker disconnect and reconnect.
Assistant
So the existing tests show that the workerLostTimeout is measured from
acs.LastTransitionTime(when the AC became Ready). The test "the local workload admission check Ready if the remote WorkerLostTimeout is not exceeded" setsLastTransitionTimeto 50% of the timeout ago and expects the AC to remain Ready (with the LastTransitionTime being reset to now!).Wait, look at the
wantManagersWorkloads: the expected AC hasState: kueue.CheckStateReady, Message: 'The workload got reservation on "worker1"'but noLastTransitionTime. This is interesting.So when the reserving remote is still connected (worker1),
bestMatchByCondition(kueue.WorkloadAdmitted)finds worker1's admitted workload, and we go into the branch at line 461. We sync the job, sync reserving remote state, and returnRequeueAfter: workerLostTimeout. InsyncReservingRemoteState, it likely updates the AC's LastTransitionTime. Let me check.Assistant
Assistant
Let me look at the
nominateAndSynchronizeWorkersandsyncToSingleClusterfunctions related to the manager quota automation.Assistant
Let me look at the
controllerForfunction and how remote clients are managed, especially in the manager quota automation mode.Assistant
Let me look at the
setConfigfunction and the configChanged logic.Assistant
Let me look at the test setup to understand the worker configuration in these tests.
Assistant
Let me look at the test cases that involve worker reconnect and the second worker, particularly around the admitted/ready state.
Assistant
Let me search for related KEPs and changelog entries about worker loss / reconnect.
Assistant
Let me look at the incremental dispatcher, which is part of the manager quota automation.
Assistant
Let me look at
GetRemoteClustersin the admissioncheck package, which is used by the incremental dispatcher.Assistant
Let me trace how the watchEnded event triggers reconnection. Let me look at the controllers.go and how watchEndedCh is handled.
Assistant
Let me look at the fswatch.go which watches config files.
Assistant
Let me look at the multikueuecluster_test.go reconnect tests to understand the expected behavior.
Assistant
Let me look at the git blame for the workerLostTimeout handling section to understand recent changes.
Assistant
Let me look at the test runner code that sets up workers and the connecting state.
Assistant
Let me look at the wlReconciler struct and how it accesses the clusters.
Assistant
Let me look at the AdmissionCheckState type to understand available fields.
Assistant
Let me read the KEP section about WorkerLostTimeout.
Assistant
Let me look at the Reconcile method of wlReconciler.
Assistant
Let me look at integration tests for multikueue worker disconnect to understand expected behavior.
Assistant
Let me look at the "reconnecting clients are skipped" test and the defaultWorkerLostTimeout.
Assistant
Let me reproduce the bug with a temporary test. First, let me check the test helpers available.
Assistant
Let me create a reproduction test to confirm the bug.
Assistant
Let me check the correct import paths used in the existing test.
Assistant
So
ContextWithLogandTreatSSAAsStrategicMergeare inutiltesting "sigs.k8s.io/kueue/pkg/util/testing". Let me fix my imports. Let me rewrite the repro test with correct imports.Assistant
I've reproduced the bug. The workload is requeued after only 44ms even though the disconnect just happened. Now let me look at the
workload.ClusterNamehelper and the clock usage.Assistant
Now let me look at the remoteClient struct fields and the
clockfield, and where connecting is set/reset.Assistant
Now let me implement the fix. First, add a
connectingSincefield to the remoteClient struct.Assistant
Now let me implement the fix. First, add the
connectingSincefield to the remoteClient struct.Assistant
Now let me add helper methods to manage the connecting state with the timestamp. Let me add them near
resetFailedConnAttempt.Assistant
The edit duplicated the
resetFailedConnAttemptbody. Let me remove the leftover lines 258-262.Assistant
Now let me update
newRemoteClientto usemarkConnecting.Assistant
Now update the watch end to use
markConnecting. Let me find it.Assistant
The indentation got messed up. The original code was inside a goroutine with a tab indent. Let me fix the indentation. The block should be indented with 2 tabs (inside the anonymous func inside the goroutine). Let me look at the original structure. The
if ctx.Err() == nil {should be at 2-tab indent (it's inside thefunc() { ... }()which is inside the for loop... actually let me check the original indentation).Looking at the original (line 418-427 before my edit):
log.V(2).Info("Watch ended", "ctxErr", ctx.Err()) // If the context is not yet Done , queue a reconcile to attempt reconnection if ctx.Err() == nil { oldConnecting := rc.connecting.Swap(true) // reconnect if this is the first watch failing. if !oldConnecting { log.V(2).Assistant
The indentation is wrong. The
if ctx.Err() == nil {block should be at 2-tab indent (like thelog.V(2).Infoabove it). My edit put it at 1-tab. Let me fix the whole block.Assistant
Now update
setConfigto usemarkConnectedinstead ofrc.connecting.Store(false).Assistant
Line 245 is in
markConnected, line 330 is insetConfig. Let me update line 330.Assistant
Now let me check
markConnectedis at line 245 - it already usesrc.connecting.Store(false)which is fine. Now let me verifytimeis imported in multikueuecluster.go.Assistant
Now let me update the workload.go reconcile logic. Let me look at the current state of the relevant section.
Assistant
Now let me update the
else ifblock. I'll compute the effective disconnect time and the remaining wait.Assistant
There's an extra closing brace
}at line 526. The original code ended with one}closing theelse ifblock and then the outer block continued. My edit added a}at the end of theelse ifblock but there's an extra}. Let me check.Original was:
} else if acs.State == kueue.CheckStateReady { ... } }There were two
}- one closing the inner if/else and one closing theelse if. My replacement added the closing}for the else if, but the extra}at line 526 remains. Let me remove line 526.Assistant
Yes, line 526 (
^I}$) is extra. Let me remove it.Assistant
Now let me check
clock.Sinceis available. Let me check the clock package.Assistant
The
clock.Clockinterface doesn't haveSince. Let me usew.clock.Now().Sub(disconnectStart)instead.Assistant
Now let me build and run the reproduction test.
Assistant
Now it returns 1s requeue instead of 44ms. But the issue is the requeueAfter is 1s, not ~5m. Why? Because in my repro test, I set
w1remoteClient.connecting.Store(true)directly instead of usingmarkConnecting(). SoconnectingSinceis zero. Let me update my repro test to usemarkConnecting()so it records the timestamp.Assistant
Still 1s. The
disconnectStartshown isnow(the real clock now, not the fakeClock's frozen time). The issue:markConnecting()usesrc.clock.Now(), and therc.clockis the RealClock unless set. I setw1remoteClient.clock = fakeClockAFTER... wait, let me check the order. Actually I set it beforemarkConnecting(). But the disconnectStart log shows the real time. Wait, the fakeClock is frozen atnowwhich istime.Now()truncated. Sorc.clock.Now()returnsnow. But thew.clock.Now()in the reconciler also returnsnow(fakeClock). SodisconnectStart = now, , remainingWaitTime = T - 0 = T = 5m. But it shows 1s!Assistant
Still 1s and disconnectStart is now. So
connectingSinceIS set to now. disconnectStart = now, w.clock.Now() = now, remainingWaitTime should be T=5m. But it returns 1s. There must be something else returning 1s. Wait - the reconcile might return early before reaching my code, but the log shows it reached line 520. Let me re-read: the log saysretryAfter="1s"which is exactly the value logged. But how can T - 0 = 1s? Unlessw.clock.Now()is NOT the fakeClock.Wait - the reconciler's clock is set via
WithClock(t, fakeClock). Butw.clock.Now()- let me check the clock is actually used. Actually maybe the issue is the requeueAfter gets overwritten later? No, it returns at line 521.Let me add more debugging. Actually, wait - maybe the
eventsBatchPeriod(1 second) is involved? No. Let me check the actualremainingWaitTimeby printing it.Assistant
Interesting!
disconnectStartlog shows23:59:16butfakeClock nowis00:04:15. ThedisconnectStartisacs.LastTransitionTime(which isnow - (T-1s)=00:04:15 - 4m59s=23:59:16). SoconnectingSinceis NOT being used! That meansrc.connecting.Load()is false, ORfoundis false.Wait - the reserving remote is "worker1".
group.remoteClients["worker1"]- is worker1 ingroup.remoteClients? RecallremoteClientsForACSKIPS clients that are connecting! So worker1 (connecting=true) is NOT ingroup.remoteClients. That's whyfoundis false, and we fall back toacs.LastTransitionTime.This is the key insight! The connecting client is excluded from
group.remoteClients, so my lookupgroup.remoteClients[reservingRemoteName]fails. I need to look up the remote client from theclustersreconciler directly, not from the group.Let me check how to access the remote client by name. The
w.clustersis the clustersReconciler which hascontrollerFor.Assistant
controllerFortakes the cluster name (it's used asw.clusters.controllerFor(clusterName)inremoteClientsForAC). So I can usew.clusters.controllerFor(reservingRemoteName)to get the connecting remote client. Let me update the workload.go code.Assistant
Now let me build and run the repro tests.
Assistant
The fix works. Now the disconnect just happened and requeueAfter is 5m (full timeout) instead of 1s. Now let me run the existing tests to make sure nothing breaks.
Assistant
All tests pass. Now let me remove the repro test files and run the broader test suite to check for impacts.
Assistant
Now let me check the multikueuecluster_test.go tests that might test the
connectingbehavior, particularly theTestRemoteClientGCand the reconnect tests. Let me check the test that usesconnecting.Store(true).Assistant
These tests directly set
connecting.Store()which doesn't setconnectingSince. That's fine since those tests don't rely on the disconnect-time logic. Let me run the full multikueue test suite once more (it passed). Now let me also check the integration tests for the worker-loss behavior to understand if there's an existing test that validates this behavior. Let me look at the test "should keep multikueue admission check reference and properly clean up the remote workload when the connection to an admitting worker is lost".Assistant
Now let me check the
BreakConnectionutility to understand what it does.Assistant
Let me check
stopAndRemoveClusterto understand the BreakConnection scenario.Assistant
I need to refine the watch-end handler to preserve the original "only queue once" semantics. Let me update
markConnectingto return whether this was a new transition, and use that.Assistant
Now update the watch-end handler to use the returned bool, and
newRemoteClientto use the bool-returning markConnecting.Assistant
The edit got confused. Let me look at the full broken section and fix it properly.
Assistant
Let me restore from git and redo this edit cleanly.
Assistant
I see - the edit accidentally removed the closing braces
}}}of the for-loop/switch. Let me fix the broken section by viewing and correcting it.Assistant
I need to fix lines 418-429 (file lines). Line 418 (
for-range close) is at 5-tab indent but should close the for-range, then I need the switch close and for-loop body close braces. Let me replace lines 418-429 (file) with the correct structure.Assistant
I'll replace lines 418-429 (file) which is the 4th through 16th lines shown above. Let me do this with a precise edit using the file line numbers.
Assistant
This is getting messy. Let me revert the multikueuecluster.go file and redo all the edits cleanly.
Assistant
Now let me make the edits carefully using
replacefor the struct field andsedfor precise line operations. First, the struct field:Assistant
Now add the helper methods after
resetFailedConnAttempt:Assistant
Now I'll use
editfor the helper methods insertion (line 227-229 boundary) and the watch-end block (lines 388-397) and setConfig (line 300).Assistant
Now update
newRemoteClient(line 171),setConfigsuccess (line ~333), and the watch-end block (line ~421).Assistant
Line 248 is in
markConnected(correct). Line 333 is insetConfigsuccess - update tomarkConnected().Assistant
Now update the watch-end block.
Assistant
Now let me build and run tests.
Assistant
Now let me recreate the repro test and run it.
Assistant
Now let me also test the scenario where the disconnect happened long ago (exceeds timeout) - should requeue (Retry).
Assistant
Both scenarios work. Now let me also test the reconnect-restores-processing scenario: when the worker reconnects (connecting=false, connectingSince=zero), the workload should resume syncing with the reserving remote.
Assistant
All three scenarios pass. Now let me run the full multikueue test suite to ensure nothing broke.
Assistant
Now let me remove the repro test file and run the broader test suite.
Assistant
Now let me review the final diff.
Assistant
Let me verify the reconciler's clock defaults to a real clock (not nil) in production.
Assistant
clock: realClockis the default. Good. Now let me check there are no vet/lint issues.Assistant
Now let me check the issue number reference. I used
#11679in comments. Let me verify whether this is the actual issue number. Let me check git remotes / any issue reference. Since I can't access the internet, I'll use a more generic comment without a specific issue number to be safe. Let me update the comments to not reference a specific issue number that I'm guessing.Assistant
Let me reword the comment to be cleaner.
Assistant
Now let me reconsider one edge case: the
controllerFormethod usesc.lock.RLock(). Let me check it'sc.locknotc.lock.RLock- to ensure no deadlock withsetConfigLock.Assistant
Good -
controllerForusesc.lock.RLock(). TheconnectingSincefield is protected byrc.mu, notc.lock. So no deadlock concern.Now, there's one more consideration. The
controllerForparameter is namedacNamebut it's actually used with a cluster name (inremoteClientsForACit's called withclusterName). Let me double-checkremoteClientsForACusesw.clusters.controllerFor(clusterName).Assistant
Good -
controllerFor(clusterName)is the right usage. My code usesw.clusters.controllerFor(reservingRemoteName)wherereservingRemoteNameis the ClusterName. Correct.Now let me run the broader test suite one more time including cache and workload packages to ensure no regressions.
Assistant
Let me also run the multikueue cluster test specifically (the reconnect backoff tests).
Assistant
All tests pass. Let me check for the gofmt formatting.
Assistant
gofmt flags multikueuecluster.go. Let me check what's wrong.
Assistant
The struct field alignment needs adjustment. Let me apply gofmt.
Assistant
Now let me rebuild and run the tests once more to confirm everything still works after gofmt.
Assistant
Let me verify the goimports (import grouping) is fine. Let me check there are no unused imports introduced.
Assistant
Now let me reconsider the integration test scenario. There's an existing integration test "Should requeue the workload with a delay when the connection to the admitting worker is lost" that uses
BreakConnection. Let me verify my change doesn't alter that behavior. In that scenario,BreakConnectionchanges the kubeconfig to a bad secret, which causesloadClientConfigto fail andstopAndRemoveClusterremoves the remoteClient entirely. SocontrollerForreturns false, and we fall back toacs.LastTransitionTime. The behavior is unchanged.But wait - there's a subtle scenario. When the kubeconfig location changes to a bad secret, but before the reconcile that calls
stopAndRemoveCluster, the watch might still be alive. Actually, the config change triggers a reconcile via the secret handler / fs watcher. During that reconcile, fails (NotFound secret) → . So the remoteClient is removed. There's no window where is set with for the bad-secret scenario. Good.Assistant
All controller tests pass. Let me view the final diff once more to confirm everything is clean.
Assistant
The diff is clean and complete. Let me also double-check the
timeimport is still used in workload.go (since I removed thetime.Sincecall).Assistant
timeis still used. Now let me make sure I haven't left any temporary test files.Assistant
Only the two intended files are modified. Let me run the multikueue tests one final time to be sure, plus gofmt check.
Assistant
Everything passes and gofmt is clean. Let me do a final review of the complete changes by viewing the key sections once more.
Assistant
The implementation is complete and clean. Let me now address the checklist and submit.
Summary
Issue: Admitted MultiKueue workloads were requeued too early when a worker disconnected. The worker-loss grace period () was measured from , which is the time of the with the reserving worker (reset on every successful reconcile via ). So if the workload was synced shortly before a disconnect, almost no grace period remained, and the workload was requeued immediately rather than waiting the configured timeout.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.