Skip to content

[ray-operator] Fail RayJob when the selected RayCluster is suspended - #5491

Open
HsiaoHungKai wants to merge 5 commits into
kuberay-project:masterfrom
HsiaoHungKai:fix/rayjob-fail-on-suspended-selected-cluster
Open

HsiaoHungKai wants to merge 5 commits into
kuberay-project:masterfrom
HsiaoHungKai:fix/rayjob-fail-on-suspended-selected-cluster

Conversation

@HsiaoHungKai

Copy link
Copy Markdown
Contributor

Why are these changes needed?

A RayJob that uses clusterSelector stays in Initializing until the selected RayCluster is Ready. If that RayCluster has spec.suspend=true or spec.idleSuspend=true, it never becomes Ready by itself. The RayJob then stays in Initializing forever, and nothing tells the user why.

This PR adds a check in the Initializing step, before the controller waits for the RayCluster to be ready. The check is in a new helper, checkSelectedClusterSuspendedAndUpdateStatusIfNeeded. The helper does these things:

  • It runs only when the RayJob uses clusterSelector. RayJobs that create their own RayCluster do not change.
  • It sets jobDeploymentStatus to Failed when the selected RayCluster has spec.suspend or spec.idleSuspend set.
  • It sets the new reason SelectedRayClusterSuspended. The status message names the RayCluster and lists which suspend fields are set.

Related issue number

Closes #5476

Labels

  • If this PR has user-facing changes that require documentation updates at release time, I have added the doc-updates-required label.
  • If this PR contains breaking changes, I have added the breaking-change label.

AI assistance

Yes. I used Claude Code to help write the code and this description. I read every changed line myself.

Checks

  • I've made sure the tests are passing.
  • Testing Strategy
    • Unit tests
    • Manual tests
    • This PR is not tested :(

How I tested

cd ray-operator
go test ./controllers/ray/ -run 'TestCheckSelectedClusterSuspendedAndUpdateStatusIfNeeded|TestRayJobFailsWhenSelectedRayClusterIsSuspended'
golangci-lint run ./controllers/ray/ ./apis/ray/v1/
make test WHAT=./controllers/ray/

golangci-lint reports 1 existing issue not from this PR (gofumpt, rayjob_controller_test.go:203).

…ector is suspended

A RayJob that uses clusterSelector waits in Initializing until the selected
RayCluster becomes Ready. A suspended RayCluster (spec.suspend or spec.idleSuspend) never becomes Ready by itself, so the RayJob waits forever.

Move the RayJob to Failed with the new reason SelectedRayClusterSuspended.
The status message names the RayCluster and the suspend fields that are set.

Signed-off-by: HungKai Hsiao <hsiaohungkai@gmail.com>
@elyall

elyall commented Nov 3, 2026 •

Copy link
Copy Markdown

Failing fast is better than leaving a RayJob in Initializing without an explanation, however I think the two suspend fields need different handling, though:

Proposal: keep this PR's failure for spec.suspend. When only spec.idleSuspend is true, have the RayJob controller patch it to false (the resume mechanism described in ray-project/ray#65763), record an event, and keep waiting for the cluster to become Ready. A configured preRunningDeadlineSeconds or activeDeadlineSeconds still bounds that wait.

Worth covering in tests:

  • Concurrent RayJobs selecting the same idle-suspended cluster.
  • Short idle timeouts. The resumed head's autoscaler can suspend the cluster again before submission completes, and timeoutSeconds: 0 is currently valid.

If mutating a selected cluster is considered inappropriate, the safer fallback is to keep the RayJob waiting rather than fail it, and show in its status that the cluster is idle-suspended, so another controller can resume it.

AI assistance: Claude Opus 5.5.

@HsiaoHungKai

Copy link
Copy Markdown
Contributor Author

@elyall Thanks for the review!

I’d like to keep failing on idleSuspend in this PR. A RayJob in clusterSelector mode doesn’t own the selected RayCluster, so it shouldn’t patch that cluster’s spec.
Since clusterSelector is a less common feature, I’d like to keep this change minimal. Failing the RayJob, as a maintainer suggested. I don’t think a shared cluster with idleSuspend is a recommended setup, so failing right away with a clear reason seemed better than waiting.

@elyall

elyall commented Nov 4, 2026

Copy link
Copy Markdown

Thanks, the ownership concern is fair. I agree the RayJob controller shouldn't mutate a selected RayCluster, so I'll withdraw that part of the proposal.

I still think failing on idleSuspend deserves an explicit decision. Unlike spec.suspend, it is recoverable: it marks a cluster that is meant to be resumed. Failing on it means a clusterSelector RayJob can only use a policy: Suspend cluster that something has already resumed, and the same RayJob succeeds or fails depending on whether the cluster happened to idle out first.

Could this PR fail only for spec.suspend, and for idleSuspend keep the RayJob in Initializing with a clear status message and an event? That preserves external resume without mutating the cluster: once something resumes the cluster, the same RayJob proceeds without being recreated, and a configured preRunningDeadlineSeconds or activeDeadlineSeconds still bounds the wait. It wouldn't wake the cluster by itself, and a very short idle timeout can still race submission, but it keeps a recoverable cluster state from becoming an irreversible RayJob failure.

The example in #5476 is exactly a shared cluster with policy: Suspend. If that combination is meant to be unsupported, I think it should be documented or rejected explicitly, rather than show up as a terminal failure that depends on timing.

@machichima, would failing only for spec.suspend, while reporting and waiting for idleSuspend, work for you?

@machichima

Copy link
Copy Markdown
Collaborator

I think by design #5210 we require user to change idleSuspend to False manually. In this case, the behavior of suspend and idleSuspend should be the same, so I think we should have the same behavior for the two.

cc author of idle termination @win5923 @justinyeh1995 for your thoughts

@justinyeh1995

justinyeh1995 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

My understanding of @elyall's proposal is to let RayJob stays in Initialising status if the RayCluster is idle suspended, and let the RayCluster owner patch the idleSuspend to False manually. This way, for example the platform team, has a way to unblock the RayJob. IMO, it's a balanced solution, which does not break idle termination's semantic and gives users a way to work around it.

@HsiaoHungKai

Copy link
Copy Markdown
Contributor Author

@elyall @justinyeh1995 My understanding is that clusterSelector is meant to target a cluster that's already running.

// clusterSelector is used to select running rayclusters by labels
// +optional
ClusterSelector map[string]string `json:"clusterSelector,omitempty"`

I understand the concern about the RayJob failing right away, but I think that's the expected outcome here, since the selected cluster isn't running.

It wouldn't wake the cluster by itself, and a very short idle timeout can still race submission, but it keeps a recoverable cluster state from becoming an irreversible RayJob failure.

The failure is cheap to recover from, because the job hasn't been submitted yet. Users can patch idleSuspend back to false to resume the cluster, then resubmit the RayJob.

@justinyeh1995

Copy link
Copy Markdown
Contributor

SG. I think your point is valid.

@machichima

Copy link
Copy Markdown
Collaborator

After discussing with @kevin85421 offline, we do not plan to add auto un-suspend to RayCluster. Users should be the ones to un-suspend it on their own.

Comment on lines +1392 to +1399
{
// BackoffLimit is incompatible with ClusterSelector mode, so the RayJob must not retry.
name: "selected cluster is suspended and backoffLimit is 0",
clusterSuspend: new(true),
backoffLimit: new(int32(0)),
expectedStatus: rayv1.JobDeploymentStatusFailed,
expectedReason: rayv1.SelectedRayClusterSuspended,
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious about the reason to check backoffLimit here. it doesn't seem connected to the changes in this pr, and backoffLimit: 0 already disables retries, so it's a bit redundant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! My intent was to show the RayJob doesn’t retry in ClusterSelector mode, but backoffLimit > 0 is already rejected by validation and covered in validation_test.go, so this case was redundant. Removed it in dee6c86

Signed-off-by: HungKai Hsiao <hsiaohungkai@gmail.com>
…n-suspended-selected-cluster

Signed-off-by: HungKai Hsiao <hsiaohungkai@gmail.com>

# Conflicts:
#	ray-operator/controllers/ray/rayjob_controller_unit_test.go
Signed-off-by: HungKai Hsiao <hsiaohungkai@gmail.com>
@CheyuWu
CheyuWu self-requested a review November 20, 2026 17:08

@justinyeh1995 justinyeh1995 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. left a small nit.

logger.Info("The RayCluster selected by clusterSelector is suspended. Transition the status to `Failed`.", "RayCluster", rayCluster.Namespace+"/"+rayCluster.Name, "suspendFields", suspendFields)
rayJob.Status.JobDeploymentStatus = rayv1.JobDeploymentStatusFailed
rayJob.Status.Reason = rayv1.SelectedRayClusterSuspended
rayJob.Status.Message = fmt.Sprintf("The RayCluster %s/%s selected by clusterSelector is suspended (%s), so it cannot run the RayJob.", rayCluster.Namespace, rayCluster.Name, strings.Join(suspendFields, ", "))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we add a hint at the end of the message so users know how to recover? For example,

rayJob.Status.Message = fmt.Sprintf("The RayCluster %s/%s ... Resume the RayCluster and resubmit the RayJob.", rayCluster.Namespace, rayCluster.Name, strings.Join(suspendFields, ", "))

WDYT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The message now ends with "Resume the RayCluster and resubmit the RayJob." in 13b3892. I think this is a nice improvement. Users can now see both why the RayJob failed and how to fix it.

Signed-off-by: HungKai Hsiao <hsiaohungkai@gmail.com>
@HsiaoHungKai

Copy link
Copy Markdown
Contributor Author

cc @CheyuWu This PR has been approved by @justinyeh1995. Could you take a look when you have time? Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] RayJob with clusterSelector stays in Initializing forever when the selected RayCluster is suspended

4 participants