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:consolemetadata.generation: 273390 kueue.x-k8s.io/raycluster-generation: "273389"A later read showed the same pattern:
consolemetadata.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:
yamlmetadata: annotations: kueue.x-k8s.io/elastic-job: "true" labels: kueue.x-k8s.io/queue-name: <local-queue>- Inspect the RayCluster generation and annotation repeatedly:
sh - Install Kueue v0.16.5 with
Assistant
Let me analyze this issue. The problem is that:
- Kueue-managed elastic RayCluster is continuously updating itself
- The
kueue.x-k8s.io/raycluster-generationannotation tracks the RayCluster's ownmetadata.generation, but remains one value behind - This creates a self-triggered loop where Kueue patches the RayCluster, advancing its generation, which makes the annotation stale again
The fix suggested is to omit
kueue.x-k8s.io/raycluster-generationwhen thejobObjectis the same standalone RayCluster asrayClusterName.Let me start by exploring the repository structure to understand the codebase and find the relevant files.
Assistant
The issue mentions
GetCustomAnnotationsandGetWorkloadslicingRayClusterCustomAnnotations. Let me search for these functions in the codebase.<tool_call> <function=bash_terminal> <parameter=command> grep -r "GetWorkloadslicingRayClusterCustomAnnotations" /kueue --include="*.go" 2>/dev/null </tool_call>
Assistant
Let me search for the function name properly.
Assistant
Good! Now let me look at the
GetCustomAnnotationsfunction and the raycluster common.go file to understand how this works.<tool_call> <function=bash_terminal> <parameter=command> grep -r "GetCustomAnnotations" /kueue --include="*.go" 2>/dev/null </tool_call>
Assistant
Let me search for GetCustomAnnotations with proper quoting.
Assistant
Now let me look at the raycluster common.go file to see the
GetWorkloadslicingRayClusterCustomAnnotationsfunction and understand how it works.Assistant
I need to use the bash_terminal command to view the file content first.
Assistant
Now let me look at how this function is called and what happens with RayCluster objects themselves. Let me search for the raycluster controller to understand the context.
<tool_call> <function=bash_terminal> <parameter=command> ls -la /kueue/pkg/controller/jobs/raycluster/ </tool_call>
Assistant
Let me search for files related to raycluster controller.
Assistant
Let me look at the raycluster_controller.go file to understand how GetCustomAnnotations is called for standalone RayClusters.
Assistant
Now I can see the issue. The RayCluster job implementation in
raycluster_controller.godoesn't have aGetCustomAnnotationsmethod. When a RayCluster is used as a standalone job (not as a RayJob or RayService), the framework code callsGetCustomAnnotations, which will invoke the method on the RayCluster object.Since RayCluster doesn't implement
GetCustomAnnotations, it won't return any custom annotations. Let me check the jobframework reconciler to understand how custom annotations are handled.Actually, wait - let me re-read the issue description more carefully:
Assistant
Let me use bash command properly to view the file.
Assistant
Now I see. In RayJob, the
GetCustomAnnotationsmethod calls:goreturn raycluster.GetWorkloadslicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Status.RayClusterName)Where
j.Object()is the RayJob object, andj.Status.RayClusterNameis the RayCluster name. This is correct because the RayJob and RayCluster are different objects.Now let me look at the RayService controller to see how it handles this.
<tool_call> <function=bash_terminal> <parameter=command> cat /kueue/pkg/controller/jobs/rayservice/rayservice_controller.go </tool_call>
Assistant
Let me use a different approach - I'll write the output to a file and then view it, or use head to limit the output.
Assistant
The RayService also has the same pattern - it calls
GetWorkloadslicingRayClusterCustomAnnotationswithj.Status.ActiveServiceStatus.RayClusterName.Now let me check if RayCluster implements GetCustomAnnotations or if it uses a default. The issue says that for standalone RayClusters, the function is being called, but RayCluster doesn't have a
GetCustomAnnotationsmethod. Let me check the interface implementation in the raycluster_controller.go file more carefully.Looking at raycluster_controller.go again, I see that RayCluster doesn't implement
JobWithCustomAnnotationsinterface. Let me check how the framework handles this.Let me look at the reconciler code to understand how custom annotations are handled.
Assistant
The file is quite long. Let me search for the specific code that handles custom annotations and how it calls GetCustomAnnotations.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "GetCustomAnnotations" /kueue/pkg/controller/jobframework/reconciler.go </tool_call>
Assistant
Let me try again with a proper bash command to search for GetCustomAnnotations.
Assistant
Let me look at the context around line 962 to understand how custom annotations are handled.
Assistant
Let me try a different approach - use head and tail to get a range of lines.
Assistant
Now I understand the code flow. The key section is:
goif jobWithCustomAnnotations, ok := job.(JobWithCustomAnnotations); ok { customAnnotations, err := jobWithCustomAnnotations.GetCustomAnnotations(ctx, r.client, podSets) if err != nil { return nil, fmt.Errorf("failed to get custom annotations based on pod sets from job %s: %w", job.Object().GetName(), err) } if newAnnotations, updated := mergeAnnotations(job, customAnnotations); updated { if err := clientutil.Patch(ctx, r.client, object, func() (bool, error) { job.Object().SetAnnotations(newAnnotations) return true, nil }); err != nil { return nil, fmt.Errorf("failed to update custom annotations on job %s: %w", job.Object().GetName(), err) } } }Assistant
Let me run the grep command properly.
Assistant
Looking at the issue description again, it says:
For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadslicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name).This suggests that the issue might be that RayCluster DOES have a GetCustomAnnotations method that calls this function. Let me check the raycluster_controller.go again to see if I missed the GetCustomAnnotations method.
Actually wait - I just realized I might be missing something. Let me check if RayCluster implements the JobWithCustomAnnotations interface or if there's a default implementation somewhere.
Looking at raycluster_controller.go again:
govar _ jobframework.GenericJob = (*RayCluster)(nil) var _ jobframework.JobWithManagedBy = (*RayCluster)(nil)There's no
var _ jobframework.JobWithCustomAnnotations = (*RayCluster)(nil)line, so RayCluster doesn't explicitly implement this interface.But the issue clearly states that standalone RayClusters are being patched with the
kueue.x-k8s.io/raycluster-generationannotation. Let me search for where this annotation is being set or updated.Assistant
Let me search for the annotation name more carefully.
Assistant
Assistant
The output shows no line numbers were returned, meaning
GetCustomAnnotationsis not defined in raycluster_controller.go. Let me double check by using a different approach.Assistant
Let me look at the issue description again more carefully.
The issue says:
For standalone RayClusters,
GetCustomAnnotationscalls .Assistant
Let me check the file length with wc -l command properly.
Assistant
Let me view the entire raycluster_controller.go file line by line.
Assistant
Assistant
Let me search for GetWorkloadNameExtraPart properly.
Assistant
<tool_call> <function=bash_terminal> <parameter=command> grep -n "ElasticWorkloadNameProvider" /kueue/pkg/controller/jobs/raycluster/raycluster_controller.go </tool_call>
Assistant
Let me use a simpler grep to check if RayCluster implements the ElasticWorkloadNameProvider interface.
Assistant
Let me try a different approach - check the entire file for any interface implementations.
<tool_call> <function=bash_terminal> <parameter=command> grep "_ jobframework" /kueue/pkg/controller/jobs/raycluster/raycluster_controller.go </tool_call>
Assistant
Let me try a different approach - I'll use the grep command to search for the specific patterns I'm looking for.
Assistant
Now I can see that RayCluster only implements
GenericJobandJobWithManagedBy. It doesn't implementJobWithCustomAnnotationsorElasticWorkloadNameProvider.So how is the issue happening? The issue says that the annotation IS being set, but I don't see how. Let me check if there's a webhook or some other mechanism that might be setting this annotation.
Actually, wait. Let me re-read the issue description one more time:
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.Hmm, the issue says the annotation tracks the RayCluster's own metadata.generation. This suggests that the annotation IS being set, but with a stale value.
Let me check the raycluster webhook to see if it sets this annotation.
<tool_call> <function=bash_terminal> <parameter=command> cat /kueue/pkg/controller/jobs/raycluster/raycluster_webhook.go </tool_call>
Assistant
Let me search for the raycluster_webhook.go file contents properly.
Assistant
The annotation is not in the webhook. Let me look at the interface to understand the
JobWithCustomAnnotationsinterface better. Perhaps there's a default implementation or the interface is implemented in a way I'm not seeing.Let me check the jobframework interface file.
<tool_call> <function=bash_terminal> <parameter=command> grep -A 5 "JobWithCustomAnnotations" /kueue/pkg/controller/jobframework/interface.go </tool_call>
Assistant
Let me try the grep command properly.
Assistant
Now I understand the interface better.
JobWithCustomAnnotationsis an OPTIONAL interface that needs to be explicitly implemented. If RayCluster doesn't implement it, thenGetCustomAnnotationswon't be called.But the issue clearly states that the annotation IS being set. Let me think about this differently.
Wait - I just realized something. Let me re-read the issue description one more time:
For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadslicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name).I think the issue description might be describing what SHOULD happen (after the fix), not what IS happening. Or maybe there's a different interpretation.
Actually, let me look at the
ElasticWorkloadNameProviderinterface which is related to the workload name:<tool_call> <function=bash_terminal> <parameter=command> grep -B 2 -A 5 "ElasticWorkloadNameProvider" /kueue/pkg/controller/jobframework/interface.go </tool_call>
Assistant
Let me try to run the grep command properly to find the ElasticWorkloadNameProvider interface.
Assistant
Now I understand the interfaces better. The issue says that for standalone RayClusters, the annotation is being set and causing the self-update loop. Let me check if maybe the issue is that a GetCustomAnnotations method needs to be ADDED to RayCluster to support the ElasticWorkloadNameProvider interface, and this is causing the issue.
Actually, wait - I think I might have been looking at this wrong. Let me re-read the issue description one more time:
For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadslicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name).I think this is actually describing a method that SHOULD be added to RayCluster, and the fix is to make sure that when
jobObjectis a RayCluster andrayClusterNameequalsj.Name, we don't set theRayClusterGenerationAnnotation.Let me check if there's a recent commit or change that added a GetCustomAnnotations method to RayCluster.
Actually, let me look at the test file to see if there's a test case that shows how RayCluster's GetCustomAnnotations is being used:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "GetCustomAnnotations" /kueue/pkg/controller/jobs/raycluster/raycluster_controller_test.go </tool_call>
Assistant
The issue is that the raycluster_controller.go file doesn't implement GetCustomAnnotations for RayCluster, so the issue described in the problem statement may be about the need to add this method. Let me verify by checking the common_test.go file to see how GetWorkloadslicingRayClusterCustomAnnotations is tested.
Assistant
Let me run a simpler search command.
Assistant
The output shows that there are 0 occurrences of "GetCustomAnnotations" in the test file. This confirms that RayCluster doesn't implement GetCustomAnnotations.
Let me take a step back and understand the issue better. The issue says:
For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadslicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name).I think the issue is that the description is describing the problem, and the fix is to either:
- Not implement GetCustomAnnotations for RayCluster (which would prevent the issue), OR
- Add GetCustomAnnotations for RayCluster but with a fix to not set the annotation when it's the same RayCluster
But since there's no GetCustomAnnotations in RayCluster, I'm confused about how the issue is happening.
Let me check if maybe there's a recent commit that added this functionality. Let me look at the git log.
<tool_call> <function=bash_terminal> <parameter=command> cd /kueue && git log --oneline -10 </tool_call>
Assistant
Let me check the git log to see recent changes.
Assistant
Let me search for recent commits related to raycluster or elastic jobs.
Assistant
Now I see the key commit
80b04a2c8 Generate elastic workload name based on raycluster generation (#9960)- this is likely the commit that introduced the issue! Let me look at this commit to understand what changes were made.Assistant
Let me look at the changes in raycluster/common.go to see what was added.
<tool_call> <function=bash_terminal> <parameter=command> cd /kueue && git show 80b04a2c8 -- pkg/controller/jobs/raycluster/common.go </tool_call>
Assistant
Let me use a different approach to view the commit changes.
Assistant
Let me continue viewing the commit changes to see the GetWorkloadslicingRayClusterCustomAnnotations function.
<tool_call> <function=bash_terminal> <parameter=command> cd /kueue && git show 80b04a2c8 -- pkg/controller/jobs/raycluster/common.go 2>/dev/null | tail -100 </tool_call>
Assistant
Let me continue to view more of the commit changes. I'll use head to get more lines.
Assistant
Now let me look at the changes to the interface.go file to see how the ElasticWorkloadNameProvider interface was added:
<tool_call> <function=bash_terminal> <parameter=command> cd /kueue && git show 80b04a2c8 -- pkg/controller/jobframework/interface.go 2>/dev/null </tool_call>
Assistant
Let me try to view the interface.go changes with a different command.
Assistant
Assistant
Let me check the git log for recent changes to the raycluster_controller.go file.
Assistant
I don't see any commit that added GetCustomAnnotations to RayCluster. Let me check if maybe there's a different file or mechanism that's setting the annotation.
Actually, I think I need to reconsider the issue. Let me check if maybe the issue is that when GetCustomAnnotations is implemented for RayCluster (which might be the intended fix for ElasticWorkloadNameProvider support), it would cause the self-update loop. The fix is to prevent this loop in GetWorkloadslicingRayClusterCustomAnnotations.
Let me look at the issue description one more time to understand what exactly needs to be fixed:
A fix is to omit
kueue.x-k8s.io/raycluster-generationwhen thejobObjectis the same standalone RayCluster as .Assistant
Let me view the GetWorkloadslicingRayClusterCustomAnnotations function to understand how to fix it.
Assistant
The issue is clear now. The
GetWorkloadslicingRayClusterCustomAnnotationsfunction always returns theRayClusterGenerationAnnotationwith the fetched RayCluster's generation. For standalone RayClusters, if someone were to call this function withjobObjectbeing the RayCluster itself and being the RayCluster's name, it would cause a self-update loop:Assistant
Let me try the grep command properly.
Assistant
There's no
GetCustomAnnotationsin the raycluster package. Let me re-read the issue description one more time to understand what exactly is happening.Actually, I think I finally understand the issue. The issue description might be describing the problem after someone has added
GetCustomAnnotationsto RayCluster. The fix is to modifyGetWorkloadslicingRayClusterCustomAnnotationsto prevent the self-update loop.But since
GetCustomAnnotationsis not implemented for RayCluster in the current codebase, the issue might be theoretical (i.e., someone wants to add this feature and the fix is to prevent the self-update loop).OR, there might be a different code path that I'm not seeing. Let me check if maybe there's a webhook or some other mechanism that's setting the annotation.
Actually, let me just implement the fix as described in the issue. The fix is to omit the
kueue.x-k8s.io/raycluster-generationannotation when thejobObjectis the same standalone RayCluster asrayClusterName.Here's my plan:
- Modify to check if the is a RayCluster and if its name matches .
Assistant
Now I need to implement the fix. The issue is that when
GetWorkloadslicingRayClusterCustomAnnotationsis called with a standalone RayCluster as thejobObjectand the RayCluster's name asrayClusterName, it would cause a self-update loop. The fix is to check ifjobObjectis a RayCluster and if its name matchesrayClusterName, and if so, not return theRayClusterGenerationAnnotation.Let me implement the fix:
Assistant
The fix was applied. Now let me verify that the fix was applied correctly:
Assistant
The fix looks correct. Now let me verify that the code compiles correctly by running
go build:<tool_call> <function=bash_terminal> <parameter=command> cd /kueue && go build ./pkg/controller/jobs/raycluster/... </tool_call>
Assistant
Let me run the go build command properly.
Assistant
Let me set the GOCACHE environment variable and try again.
<tool_call> <function=bash_terminal> <parameter=command> cd /kueue && export GOCACHE=/tmp/go-cache && mkdir -p $GOCACHE && go build ./pkg/controller/jobs/raycluster/... </tool_call>
Assistant
Let me try to run the go build command properly.
Assistant
The code compiles successfully. Now let me run the tests to make sure the fix doesn't break any existing functionality:
<tool_call> <function=bash_terminal> <parameter=command> cd /kueue && export GOCACHE=/tmp/go-cache && go test ./pkg/controller/jobs/raycluster/... 2>&1 </tool_call>
Assistant
Let me try the go test command properly with stderr redirect.
Assistant
All tests pass. Now let me also run the tests for the rayjob and rayservice packages to make sure the fix doesn't break anything there:
Assistant
Now let me look at the test for
GetWorkloadslicingRayClusterCustomAnnotationsto understand how it's tested and see if I need to add a test case for the standalone RayCluster scenario:Assistant
Let me look at the test function to understand the test cases:
Assistant
I need to see more of the test cases to understand the full context. Let me view the beginning of the test function.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '1000,1100p' /kueue/pkg/controller/jobs/raycluster/common_test.go </tool_call>
Assistant
Let me search for the test function definition to understand the test structure.
Assistant
Let me try the grep command properly.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "func Test.*GetWorkloadslicingRayClusterCustomAnnotations" /kueue/pkg/controller/jobs/raycluster/common_test.go </tool_call>
Assistant
The grep command is having trouble. Let me try a different approach - I'll search for the test function name using a simpler grep.
Assistant
Now let me see the test function to understand the test cases better:
Assistant
Now I understand the test structure. The tests use a
corev1.ConfigMapas thejobObject, which is a different type fromrayv1.RayCluster. This means the current tests don't cover the case where thejobObjectis a standalone RayCluster.Let me check if the tests I ran earlier still pass after my fix. The tests use a ConfigMap as the jobObject, so they should still work because the GVK would not match the RayCluster GVK.
Now let me think about edge cases:
- RayJob with RayCluster:
jobObjectis RayJob,rayClusterNameis RayCluster name. The GVK won't match, so the annotation will be set correctly. - RayService with RayCluster:
jobObjectis RayService,rayClusterNameis RayCluster name. The GVK won't match, so the annotation will be set correctly. - Standalone RayCluster with itself:
jobObjectis RayCluster,rayClusterNameis the same RayCluster name. The GVK will match, so the annotation will NOT be set (fixing the self-update loop).
The fix looks correct. Let me also make sure that the tests still pass:
- RayJob with RayCluster:
Assistant
Assistant
RayCluster doesn't implement
ElasticWorkloadNameProvider. Let me check if maybe it should:Assistant
RayCluster doesn't implement
GetWorkloadNameExtraParteither. So my fix is sufficient - it prevents the self-update loop for standalone RayClusters while still allowing the annotation to be set for RayJob and RayService.Let me now verify that the fix is complete by running all the ray-related tests:
Assistant
All tests pass. Now let me also think about edge cases and make sure my fix handles them correctly:
-
RayJob with RayCluster: The
jobObjectis RayJob,rayClusterNameis the RayCluster name. The GVK of RayJob is different from RayCluster's GVK (gvk), so the checkjobObject.GetObjectKind().GroupVersionKind() == gvkwill be false, and the annotation will be set correctly. -
RayService with RayCluster: Same as above - the GVK of RayService is different from RayCluster's GVK, so the annotation will be set correctly.
-
Assistant
Let me try to run the test properly with error output.
Assistant
The jobframework tests also pass. Let me now review my changes to make sure the fix is complete and correct.
<tool_call> <function=bash_terminal> <parameter=command> cd /kueue && git diff pkg/controller/jobs/raycluster/common.go </tool_call>
Assistant
I need to use a proper bash command to view the git diff. Let me run it correctly.
Assistant
The diff looks correct. The fix adds a check to skip setting the
RayClusterGenerationAnnotationwhen thejobObjectis a standalone RayCluster (i.e., when the GVK matches the RayCluster GVK and the name matches therayClusterName).Now let me think about whether there are any other changes needed. Looking at the issue description again:
A standalone Kueue-managed elastic RayCluster is continuously updated by Kueue.
This suggests that the issue IS happening in practice. But the current codebase doesn't have
GetCustomAnnotationsimplemented for RayCluster. So either:- The issue was already fixed by not implementing
GetCustomAnnotationsfor RayCluster, OR - The issue is happening through a different code path that I'm not seeing, OR
- The issue description is describing a scenario where someone wants to add
GetCustomAnnotationsto RayCluster, and the fix is to prevent the self-update loop
Given that the tests pass and the code compiles, I believe my fix is correct. However, I should also check if maybe the issue is that someone wants to add to RayCluster to support the interface.
- The issue was already fixed by not implementing
Assistant
Let me run the grep command properly.
Assistant
So only RayJob and RayService implement
GetWorkloadNameExtraPart. RayCluster doesn't. This confirms that thekueue.x-k8s.io/raycluster-generationannotation is only needed for RayJob and RayService to track the underlying RayCluster's generation.My fix is correct - it prevents the self-update loop for standalone RayClusters while still allowing the annotation to be set for RayJob and RayService.
Let me now verify that my fix is complete by running the full test suite for the ray-related packages:
<tool_call> <function=bash_terminal> <parameter=command> cd /kueue && export GOCACHE=/tmp/go-cache && go test ./pkg/controller/jobs/raycluster/... ./pkg/controller/jobs/rayjob/... ./pkg/controller/jobs/rayservice/... -v 2>&1 | head -100 </tool_call>
Assistant
Let me run the tests properly to ensure they all pass.
Assistant
The tests pass. Let me also check if there are any other tests related to the ray integration that I should run:
<tool_call> <function=bash_terminal> <parameter=command> cd /kueue && export GOCACHE=/tmp/go-cache && go test ./pkg/... -run "Ray" 2>&1 | head -50 </tool_call>
Assistant
Let me run the test properly to check for any Ray-related tests.
Assistant
Assistant
Let me run the git status command to check the current state of the repository.
Assistant
I have made the fix to the
common.gofile. Let me verify the changes one more time and then submit.<tool_call> <function=bash_terminal> <parameter=command> cd /kueue && git diff pkg/controller/jobs/raycluster/common.go </tool_call>
Assistant
The git diff command is having issues with the terminal. Let me try a simpler approach to verify the changes.
Assistant
The fix looks correct. Let me now submit the changes.
Assistant
Let me try submitting again. The submit command might need to be run properly.
<tool_call> <function=bash_terminal> <parameter=command> submit </tool_call>
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.