ISSUE DESCRIPTION Standalone elastic RayCluster self-updates raycluster-generation…
- User
ISSUE DESCRIPTION
Standalone elastic RayCluster self-updates raycluster-generation annotation What happened:
A standalone Kueue-managed elastic RayCluster is continuously updated by Kueue.
The
kueue.x-k8s.io/raycluster-generationannotation tracks the RayCluster's ownmetadata.generation, but remains one value behind. For example:metadata.generation: 273390 kueue.x-k8s.io/raycluster-generation: "273389"A later read showed the same pattern:
metadata.generation: 273462 kueue.x-k8s.io/raycluster-generation: "273461"Kueue logs showed repeated RayCluster reconciles followed by RayCluster update webhook calls from the Kueue controller manager.
This is a self-triggered loop in the RayCluster custom annotation path. For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadslicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name). That helper fetches the same RayCluster and returns the fetched RayCluster generation as an annotation to write back onto the RayCluster. The metadata patch then advances the RayCluster generation, making the annotation stale again.What you expected to happen:
Kueue should not continuously patch a standalone elastic RayCluster when its replica counts have not changed.
The
raycluster-generationannotation is useful for RayJob and RayService, where the top-level object needs to account for an underlying RayCluster generation. A standalone RayCluster should not write its own generation back onto itself.How to reproduce it (as minimally and precisely as possible):
- Install Kueue v0.16.5 with
ElasticJobsViaWorkloadSlices=true. - Enable the RayCluster integration.
- Create a standalone RayCluster with:
metadata: annotations: kueue.x-k8s.io/elastic-job: "true" labels: kueue.x-k8s.io/queue-name: <local-queue>- Inspect the RayCluster generation and annotation repeatedly:
kubectl get raycluster.ray.io <name> -n <namespace> \ -o jsonpath='{.metadata.generation}{"\t"}{.metadata.annotations.kueue\.x-k8s\.io/raycluster-generation}{"\n"}'Anything else we need to know?:
This may be related to #10160, which added generation-based elastic workload names on the release-0.16 branch.
A fix is to omit
kueue.x-k8s.io/raycluster-generationwhen the is the same standalone RayCluster as . - Install Kueue v0.16.5 with
Assistant
I'll analyze the issue and develop a fix. Let me start by exploring the repository structure.
Assistant
Now let me check how
GetCustomAnnotationsis called and where this is being used:Assistant
Let me also look at the raycluster controller to find its
GetCustomAnnotations(or lack thereof):Assistant
Now let me look at the rest of the file and find how this is used in the reconciler:
Assistant
Let me look at the interface to understand
JobWithCustomAnnotations:Assistant
Now let me look at how the RayJob and RayService call
GetWorkloadslicingRayClusterCustomAnnotations:Assistant
Now let me look at the issue context - how does the
RayClusterstandalone controller work? Looking at the controller, I see thatRayClusterdoes NOT have aGetCustomAnnotationsmethod. Let me confirm:Assistant
So
RayClusterdoesn't directly haveGetCustomAnnotations. But the issue says it does. Let me check how this might be getting called for standalone RayClusters.Assistant
The issue mentions: "For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadslicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name)."Let me check git log/blame for
GetWorkloadslicingRayClusterCustomAnnotationsand where it might be called from:Assistant
Let me look at the
mergeAnnotationsfunction to see how it merges annotations:Assistant
Now I understand the issue! Let me look at the actual error condition more carefully. The reconciler calls
GetCustomAnnotationson jobs that implementJobWithCustomAnnotations. Let me check ifRayClusterdoes NOT implement this directly, but maybe there's some indirect implementation:Assistant
Hmm, so
RayClusterstandalone doesn't implementJobWithCustomAnnotations. Wait - let me re-read the issue. The issue says:For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadslicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name).But that doesn't appear to exist in the current code. Let me check the actual version of the code - maybe the bug is in a different commit/version. Let me look at the recent commits:
Assistant
Let me check if there's a release-0.16 branch (since the issue references release-0.16):
Assistant
Only one commit branch. Let me look more carefully at the issue - maybe
RayClusterhas been updated to callGetWorkloadslicingRayClusterCustomAnnotations:Assistant
Now let me look at the issue again. The issue states "For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadslicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name)." Looking at the codebase, this method doesn't exist on the RayCluster. So the bug must come from a different mechanism. Let me look at the issue more carefully.Wait, looking at the issue again - it says the RayCluster's metadata.generation vs annotation mismatch happens with the standalone RayCluster. The reconciler triggers
GetCustomAnnotationsonly if the job implementsJobWithCustomAnnotations.Let me look at the entire
raycluster_controller.goto see if there's a method I missed:Assistant
So
RayClusterdoes NOT implementJobWithCustomAnnotations. The issue must be referring to a different version. Let me look at the issue description more carefully and also check the commit that the issue references.Let me check the issue PR
9960:Assistant
Now let me look at the issue more carefully. The issue says: "For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadslicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name)."But the current code doesn't have
GetCustomAnnotationsonRayCluster. Looking at the issue more carefully:Maybe a recent change (or an upcoming change in this repo) added it. Let me search recent commits:
Assistant
Hmm. Let me re-read the issue more carefully. It says:
A standalone Kueue-managed elastic RayCluster is continuously updated by Kueue.
Wait, maybe the issue describes a recently introduced bug in a feature branch. Let me look at the commit history of
raycluster_controller.goto see if something was recently changed/added:Assistant
Now let me understand the issue. Looking again at the issue, the
RayClusterstandalone controller likely recently got aGetCustomAnnotationsmethod that callsGetWorkloadslicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name).But the current code doesn't have this. Let me check the test for this:
Assistant
So
RayClusterstandalone does NOT implementGetCustomAnnotations. The bug described in the issue is hypothetical / about a release-0.16 branch state.But the issue says this is happening with v0.16.5. The version installed is v0.16.5 - this is from the
release-0.16branch. The bug is in that branch. But the current main branch doesn't have it.Wait - the issue description is the bug report. We need to FIX this on main. The bug is: a standalone RayCluster triggers
GetCustomAnnotationssomewhere. Let me check the codebase more carefully.Actually wait, let me re-read the issue. The issue says:
A fix is to omit
kueue.x-k8s.io/raycluster-generationwhen thejobObjectis the same standalone RayCluster asrayClusterName.This suggests the fix is in
GetWorkloadslicingRayClusterCustomAnnotationsitself - to not return theraycluster-generationannotation when the job IS the rayCluster. But this helper is also called from and , so the fix should be conditional.Assistant
So this annotation is only set on jobs that implement
JobWithCustomAnnotations. The currentRayClusterstandalone controller does NOT implement this. But the issue states it does. The fix description says:A fix is to omit
kueue.x-k8s.io/raycluster-generationwhen thejobObjectis the same standalone RayCluster asrayClusterName.So the fix should be in
GetWorkloadslicingRayClusterCustomAnnotations- if the job is itself a standalone RayCluster, don't include the generation annotation.But wait, the issue is that this only matters if
RayClusteractually implementsJobWithCustomAnnotations. Let me look at the code more carefully to see if the bug fix should be:- Apply a guard in
GetWorkloadslicingRayClusterCustomAnnotationsto skip the generation annotation when jobObject is the same as the rayClusterName - Or remove
GetCustomAnnotationsfrom standalone RayCluster
Let me look at what's happening currently more carefully:
- Apply a guard in
Assistant
Now let me check the test files to see what test cases are there:
Assistant
Now I understand the function signature. The function takes
jobObject client.Object, podSets, rayClusterName. The fix needs to check ifjobObjectIS the same object asrayClusterName(i.e., the same kind, namespace, and name).Let me now look at the actual call from
RayJobandRayService. For them, thejobObjectis the RayJob/RayService, not the RayCluster, so the check would correctly distinguish them. For a standalone RayCluster scenario, thejobObjectwould be a RayCluster AND therayClusterNamewould be the same name as the RayCluster.Now the question is: does the current main branch code have this scenario? Let me check if there's a more recent change in main that adds this scenario:
Assistant
Now let me look at the actual upstream commit fixing this issue (if it exists) to understand what the correct fix is. Let me check for the file "common.go" in commit history:
Assistant
Let me look at all the commits related to this:
Assistant
OK. Now I understand the situation. The current main branch doesn't have a
GetCustomAnnotationsmethod on theRayClusterstandalone controller. The bug as described in the issue may need a fix in the main branch to prevent the bug from being reintroduced.Looking at the issue more carefully, the bug is in
GetWorkloadslicingRayClusterCustomAnnotations. Even though the standalone RayCluster doesn't directly call it now, the function is designed to potentially be called for any job. The fix should be to not write the raycluster-generation annotation when the job IS the standalone RayCluster.But wait, the issue actually says "For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadslicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name)". This implies that there's aGetCustomAnnotationsmethod on the standalone RayCluster. Since this doesn't exist in the current main branch, maybe the fix should:- Add a
GetCustomAnnotationsmethod onRayCluster(since we need it to callUpdatePodSetsfor the standalone case) - OR just add the check in
GetWorkloadslicingRayClusterCustomAnnotationsto be safe
- Add a
Assistant
Now let me look at the test file for the standalone RayCluster:
Assistant
Now let me check the existing reconciler for how RayCluster gets handled with
WorkloadSliceEnabled:Assistant
Now let me see what jobs implement
JobWithCustomAnnotations. The reconciler callsGetCustomAnnotationsonly if the job implements that interface. So for the bug to manifest as described in the issue,RayCluster(standalone) must implementJobWithCustomAnnotations.Hmm, but the current main branch doesn't have this. Let me look at the latest commits in the issue's main branch context (or it could be that the main branch's recent commits added this and the bug exists):
Assistant
The current main branch is in May 2026. So this is an active dev branch. The bug is in v0.16.5 release-0.16 branch but the fix needs to be applied to main (the current repo).
Looking at the issue more carefully:
A fix is to omit
kueue.x-k8s.io/raycluster-generationwhen thejobObjectis the same standalone RayCluster asrayClusterName.This suggests the fix is in the
GetWorkloadslicingRayClusterCustomAnnotationsfunction. Let me check the function once more and then look at what needs to be done.Now thinking about the actual situation in the current main branch:
- The
RayClusterstandalone controller does NOT implementJobWithCustomAnnotations. So the bug as described doesn't currently exist. - The issue says "For standalone RayClusters,
GetCustomAnnotationscalls...". This implies the bug is in a different state of the code, perhaps a future change.
Wait, maybe the actual situation is that the function is called for the standalone RayCluster, but the
RayClustercontroller doesn't haveGetCustomAnnotations. Maybe there's aJobWithCustomAnnotationsinterface implementation elsewhere. Let me look:- The
Assistant
So the main branch is in a state where only
RayJobandRayServiceimplementJobWithCustomAnnotations. The issue is about the release-0.16 branch whereRayClusterwas different.Wait, I see
var _ jobframework.JobWithCustomAnnotations = (*RayJob)(nil). Let me check if there's an analogous statement for RayCluster:Assistant
So in the current main branch, the standalone
RayClusterdoes NOT implementJobWithCustomAnnotations. This means the bug described in the issue is hypothetical for main, but real for the release-0.16 branch.Assistant
No history of
GetCustomAnnotationsinraycluster_controller.go. Let me re-look at the issue and think about the broader context. The issue says:A fix is to omit
kueue.x-k8s.io/raycluster-generationwhen thejobObjectis the same standalone RayCluster asrayClusterName.So the fix is in
GetWorkloadslicingRayClusterCustomAnnotations. Even if the standalone RayCluster doesn't currently implementJobWithCustomAnnotations, the fix is still relevant. Let me apply the fix toGetWorkloadslicingRayClusterCustomAnnotations.Let me first look at the current function:
Assistant
Now let me check how the
RayClusterstandalone controller could be set up to use this. Let me look at the broader context:Assistant
OK, so
UpdatePodSetsis only called byRayJobandRayService, not by the standaloneRayCluster. So the issue is really about the release-0.16 branch state, not current main.Now let me think about what to do. The current main branch code doesn't have the bug as described. But:
- The fix should be defensive - ensure that even if standalone RayCluster ever calls
GetWorkloadslicingRayClusterCustomAnnotations, the annotation is not set to the wrong value - The issue clearly says to "omit
kueue.x-k8s.io/raycluster-generationwhen thejobObjectis the same standalone RayCluster asrayClusterName"
So the right approach is to add the fix in
GetWorkloadslicingRayClusterCustomAnnotationsitself. Let me implement it:- The fix should be defensive - ensure that even if standalone RayCluster ever calls
Assistant
Now let me think about how to check if
jobObjectis the same as therayCluster. The cleanest way is to check the GVK. IfjobObjectis aRayClusterand the name matches, then we should not write the generation annotation.Let me look at the imports:
Assistant
Let me now also check what the existing tests look like for this function:
Assistant
Now let me check the standalone RayCluster's controller for any "GetCustomAnnotations" potential or
UpdatePodSetsusage:Assistant
Assistant
OK. So
RayJobis aRayJobobject, andrayClusterNameis fromj.Status.RayClusterName. The check should work.Now let me write the fix. The check is:
jobObjectis of kindRayCluster(GVK check)jobObject.GetName() == rayClusterNamejobObject.GetNamespace() == jobObject.GetNamespace()(always true)
Let me apply the fix:
Assistant
Now I need to think about the best place to apply the fix. The issue says:
A fix is to omit
kueue.x-k8s.io/raycluster-generationwhen thejobObjectis the same standalone RayCluster asrayClusterName.So we need to detect if
jobObjectis the same standalone RayCluster. The cleanest way is to check:jobObjectis a*rayv1.RayCluster(we can use a type assertion or check the GVK)- The name matches
Let me think about the most reliable way:
- Use
client.Objectand check GVK or use type assertion
Since
client.Objectis an interface, we can use type assertion to check if it's a*rayv1.RayCluster. Let me write the fix:Assistant
OK, so
gvkis already defined. Let me now apply the fix:Assistant
Now let me apply the fix. I'll modify
GetWorkloadslicingRayClusterCustomAnnotationsto skip the generation annotation when the job is the same as the RayCluster.Assistant
Let me try a different approach with
replace:Assistant
Now let me verify the change:
Assistant
Now let me try to build the code to make sure it compiles:
Assistant
Let me now also build the entire repo to make sure nothing else is broken:
Assistant
Now let me run the existing tests to make sure I haven't broken anything:
Assistant
I need to look at the failing test case. The test expected an empty
RayClusterGenerationAnnotationwhen the RayCluster is not found, but my code now doesn't include that key at all (which is actually better). Let me check the test:Assistant
I need to update the test to reflect the new expected behavior. The test was using a
corev1.ConfigMapas thejobObject(not aRayCluster), so it should still include theRayClusterGenerationAnnotation(with empty value).Wait, let me re-read. The test uses
cm(acorev1.ConfigMap) asjobObject, andrayClusterNameisnonexistent-raycluster. SoisStandaloneRayClustershould returnfalsebecausecmis not aRayCluster.But my code returns the annotations without the
RayClusterGenerationAnnotationkey. Let me check:Looking at the diff:
- "kueue.x-k8s.io/raycluster-generation": "", "kueue.x-k8s.io/raycluster-podset-replica-sizes": `[{"name":"head","count":1},{"name":"worker","count":3}]`, }The expected has
RayClusterGenerationAnnotation: ""but my code doesn't include this key when the RayCluster is not found. Let me look at the code:Looking at the original code, when the RayCluster is not found, it sets
rayClusterGeneration = ""and then includes it in the map. My code only adds it if found successfully. I should fix that:Assistant
Let me look at the function and ensure the test case behavior is preserved (the empty
RayClusterGenerationAnnotationwhen not found):Assistant
I need to add
RayClusterGenerationAnnotationwith empty value when the RayCluster is not found. But actually, looking at this more carefully, I think the original behavior was buggy - it always sets the generation annotation, even with empty value when not found. My code only sets it when found. Let me think about this more carefully.Looking at the test case:
- "raycluster not found returns annotations with empty generation"
- The test expects
RayClusterGenerationAnnotation: ""to be in the result.
But from the original code:
if err != nil { if apierrors.IsNotFound(err) { log.V(3).Info("RayCluster not found, skipping generation annotation", "rayCluster", rayClusterName) } else { return nil, fmt.Errorf("failed to get RayCluster %s: %w", rayClusterName, err) } } else { rayClusterGeneration = strconv.FormatInt(rayClusterObj.GetGeneration(), 10) }The log message says "skipping generation annotation", but the code does set
rayClusterGeneration = ""(which is the zero value) and then includes it in the map. So the original code does include the empty key.I think this is just an existing minor inconsistency. Let me preserve the existing behavior for the not-found case:
Assistant
Wait, looking at the failing test more carefully:
"raycluster not found returns annotations with empty generation": { ... wantAnnotation: map[string]string{ RayClusterGenerationAnnotation: "", RayClusterPodsetReplicaSizesAnnotation: `[{"name":"head","count":1},{"name":"worker","count":3}]`, }, },The test expects the empty
RayClusterGenerationAnnotationto be present. The test is using acorev1.ConfigMapas thejobObjectandrayClusterName: "nonexistent-raycluster". So:isStandaloneRayCluster(cm, "nonexistent-raycluster")returnsfalsebecausecmis not a*rayv1.RayCluster- The code tries to get the RayCluster, fails with NotFound
- The code currently does NOT set the
RayClusterGenerationAnnotation
To preserve the test behavior, I need to set the empty
RayClusterGenerationAnnotationwhen not found. Let me update the code:Assistant
Now let me run the tests again:
Assistant
All tests pass. Now let me run all the tests in the raycluster package:
Assistant
All tests pass. Let me also run the tests in the rayjob and rayservice packages:
Assistant
Now let me also write a test to verify the fix. Let me first look at how the existing tests are structured:
Assistant
Now let me think about whether to add new tests. The existing tests pass with the fix. But I want to verify the fix actually works for the scenario in the issue. Let me create a temporary script to test it:
Assistant
Wait, the test file won't work outside of the project. Let me just write a test that runs in the actual project:
Assistant
Let me write a test in the actual project to verify the fix:
Assistant
Both tests pass:
TestVerifyStandaloneRayClusterDoesNotSetGenerationAnnotation- The fix correctly omits theRayClusterGenerationAnnotationfor a standalone RayClusterTestVerifyRayJobSetsGenerationAnnotation- The fix preserves the existing behavior for RayJob
Now let me clean up the temporary test file:
Assistant
Now let me verify the fix doesn't break anything by running all the relevant tests:
Assistant
All tests pass. Let me also run the tests for the jobframework to make sure nothing is broken:
Assistant
Let me also check the full test suite:
Assistant
No failures. Now let me look at the diff of my changes:
Assistant
Let me look at the existing tests once more to verify they pass:
Assistant
All existing tests pass. Now let me think about whether there are any edge cases I should consider:
- Empty
jobObject- Handled: the function returns false. jobObjectis aRayClusterwith different name - Handled: returns false.jobObjectis aRayClusterwith same name - Handled: returns true.jobObjectis aRayJoborRayServicewith same name asrayClusterName- This is an unusual case, but if someone names their RayJob the same as a RayCluster, the function would return false (since the type is not*rayv1.RayCluster). Good.jobObjectis aRayJobwith a different name from - Handled: returns false.
- Empty
Assistant
No e2e tests for this annotation. Let me also check the integration tests:
Assistant
No integration tests for this either. Let me also look at the unit tests to see if the existing test cases still align with my fix:
Assistant
These tests still pass because they're for
RayJob(not standalone RayCluster). Let me run the rayjob tests to confirm:Assistant
All tests pass. Let me also run all the related tests one more time:
Assistant
Let me look at the final fix one more time to make sure it's clean:
Assistant
The fix is clean. Let me also verify the fix works by running a final test:
Assistant
Both verification tests pass. The fix:
- Correctly identifies when the
jobObjectis the same standalone RayCluster asrayClusterName - Omits the
RayClusterGenerationAnnotationfor standalone RayClusters - Preserves the existing behavior for RayJob and RayService (they still get the generation annotation)
- Preserves the
RayClusterPodsetReplicaSizesAnnotationfor all cases (this is still useful for elastic scaling)
Let me verify the final state of the file:
- Correctly identifies when the
Assistant
Let me also make sure I haven't introduced any lint issues:
Assistant
No vet issues. Let me look at the final diff:
Assistant
The diff looks good. Let me also verify by running the full test suite one more time:
Assistant
All tests pass and no failures. Let me also run the integration tests for the related package:
Assistant
Let me look at those tests to ensure they don't break:
Assistant
This is an integration test that uses a real K8s cluster. It won't break my fix. Let me make sure the diff is what I want:
Assistant
The fix is in place. Let me now do a final comprehensive review of my changes:
Assistant
Now let me also run the linter to make sure the code style is consistent:
Assistant
Good, no formatting issues. Let me also check if there are golines issues:
Assistant
Those long lines are pre-existing and not related to my changes. Let me check my new lines:
Assistant
The only long line in my new code is the function signature, which was already long. Let me check the existing line length to see if this is the standard:
Assistant
The max line length is 200, so my changes are well within the limit. Let me run the test one more time to confirm everything is good:
Assistant
All tests pass. Let me also make sure the build is clean:
Assistant
Let me also run the build with all the tests:
Assistant
All checks pass. Let me do a final review of the diff:
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.