← Back to Pull requests

[ray-operator] Clean up batch scheduler resources on suspend #4940

Closed
unknown closed this pull request without merging on Jun 24, 2026 16:42 UTC
View on GitHub
unknown unknown commented on Jun 23, 2026 08:46 UTC
Author

Why are these changes needed?

When a RayJob is suspended, the reconciler deletes its RayCluster to release
compute resources. However, when gang scheduling is enabled, the Volcano
PodGroup for a RayJob is owned by the RayJob itself, not by the RayCluster.
As a result it is not garbage-collected when the cluster is deleted, and its
MinMember / MinResources stay at the pre-suspend values.

Volcano keeps reserving that capacity against the queue for a job that no longer
has any running pods, so a suspended RayJob silently holds queue resources and
can block other jobs in the same queue.

The terminal (Complete/Failed) path already cleans this up via
batchSchedulerOnCompletion, but the Suspending/Retrying path did not.

This PR:

  • Invokes the batch scheduler's CleanupOnCompletion in the

  • Suspending/Retrying branch, before Status.RayClusterName is reset
    (the cleanup relies on it to locate the PodGroup). With the cluster gone, the
    PodGroup is recalculated to empty resources, so it no longer reserves queue
    capacity.
  • Requeues on cleanup failure while still in Suspending, so the cleanup is

  • retried instead of leaking the PodGroup once the status transitions to
    Suspended (which is no longer requeued).
  • Refactors the shared logic into cleanupBatchSchedulerResources, which returns

  • an error. The suspend path propagates it (requeue); the terminal path keeps the
    previous log-and-continue behavior via batchSchedulerOnCompletion, since a
    terminal RayJob is not requeued.

    This is a no-op when no batch scheduler is configured (the default scheduler
    performs no cleanup).

    Related issue number

    Closes #4939

    Checks

  • I've made sure the tests are passing.

  • Testing Strategy

  • - [x] Unit tests
    - [x] Manual tests
    - [ ] This PR is not tested :(

    Unit test: TestBatchSchedulerCleanupCalledWhenRayJobSuspending covers that the
    batch scheduler cleanup is invoked on the Suspending/Retrying path, transitions
    the status on success, and requeues (returns an error) without transitioning to
    Suspended when cleanup fails.

    Manual test: with --batch-scheduler=volcano, ran a RayJob with a Volcano queue,
    then set suspend: true. Before the change the RayJob's PodGroup remained with
    its old MinMember/MinResources (still reserving queue capacity); after the
    change the PodGroup is recalculated to empty resources on suspend.

    Diff: 307 lines (+230 / -77) across 3 files Reviewer: Future-Outlier Review duration: 1916m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 307 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.343
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #4940"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.2% (MEDIUM) · Higher = larger blast radius
    40.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.9% · Safe to merge
    15.9%