Skip to content

[train] Pin Train V2 workers to autoscaling coordinator reservations … - #66002

Merged
goutamvenkat-anyscale merged 2 commits into
jhsu/per-node-ac-1-datafrom
jhsu/per-node-ac-2-train-v2
Sep 21, 2026
Merged

goutamvenkat-anyscale merged 2 commits into
jhsu/per-node-ac-1-datafrom
jhsu/per-node-ac-2-train-v2

Conversation

@iamjustinhsu

@iamjustinhsu iamjustinhsu commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Train V2 asked the coordinator for capacity but then let the placement group
schedule wherever it liked. Two concurrent runs could therefore both be scheduled onto the same capacity, even though the coordinator had reserved
distinct nodes for each of them.

Now that reservations are keyed by node (previous commit in this stack), turn
them into per-worker node pins:

  • ScalingPolicy.get_reserved_bundle_label_selectors() converts the reservation into one ray.io/node-id selector per worker. It returns None
    -- meaning "ask again later", not "no constraint" -- unless the reservation
    covers every worker, so a partially pinned worker group never starts. It
    also rejects a reservation whose layout contradicts the requested
    placement_strategy (e.g. STRICT_SPREAD workers stacked on one node)
    rather than silently downgrading it.
  • TrainController._start_worker_group applies those pins, and raises the
    new retryable WorkerGroupReservationNotReadyError while the reservation
    is still pending. Pinning is skipped for zero-resource workers (nothing to
    reserve), TPU (SlicePlacementGroup does its own reservation), and when the user set their own label_selector (the coordinator picks nodes by resource fit and never matches selectors against node labels, so its pins
    could contradict the user's).
  • The reserved-resources query and its caching move from ElasticScalingPolicy into TrainAutoscalingCoordinatorClient, so both the elastic path and the new pinning path share one cache. The client now
    takes prebuilt bundles rather than a ScalingConfig, which also drops
    V2's import of a V1 module.

Test: pytest python/ray/train/v2/tests/test_controller.py
python/ray/train/v2/tests/test_elastic_scaling_policy.py
python/ray/train/v2/tests/test_autoscaling_coordinator_client.py
python/ray/train/v2/tests/test_failure_policy.py
python/ray/train/tests/test_autoscaling_coordinator_client.py


Note

Medium Risk
Changes core Train V2 scheduling and worker-group startup (blocking
wait, node pins, placement-strategy gating); mis-pinning or timeout behavior could delay or misplace runs under contention, though coverage is heavily tested.

Overview
Train V2 now waits for coordinator reservations and pins each worker
to the reserved node
via ray.io/node-id label selectors, so concurrent runs are less likely to land on the same capacity after the coordinator has already committed nodes.

ScalingPolicy.get_reserved_bundle_label_selectors() polls reserved
capacity (with timeout, like placement_group.wait()), returns no pins unless every worker is covered, and refuses layouts that would violate STRICT_PACK / STRICT_SPREAD. If reservations are still pending, TrainController._start_worker_group raises retryable WorkerGroupStartupTimeoutError instead of starting an unpinned group. Pinning is skipped for zero-resource workers, TPU runs, and user label_selector configs.

Supporting changes: TrainAutoscalingCoordinatorClient now
accepts prebuilt resource bundles (plus placement_strategy on requests), centralizes cached get_reserved_resources, and shared helpers _floor_slots /
_reserved_resources_to_bundle_label_selectors fix fractional-resource float drift and V1 trainer-bundle subtraction on the correct node. Elastic scaling reuses the same slot math and client cache.

Reviewed by Cursor Bugbot for commit
d9214d0cb5c6eb24bd7d7561062bd7fab20df0fe. Bugbot is set up for automated code reviews on this repo. Configure
here.


Thank you for contributing to Ray! 🚀
Please review the Ray Contribution Guide before opening a pull request.

⚠️ Remove these instructions before submitting your PR.

💡 Tip: Mark as draft if you want early feedback, or ready for review when it's complete.

Description

Briefly describe what this PR accomplishes and why it's needed.

Related issues

Link related issues: "Fixes #1234", "Closes #1234", or "Related to #1234".

Additional information

Optional: Add implementation details, API changes, usage examples, screenshots, etc.

…4166)

Train V2 asked the coordinator for capacity but then let the placement
group
schedule wherever it liked. Two concurrent runs could therefore both be
scheduled onto the same capacity, even though the coordinator had
reserved
distinct nodes for each of them.

Now that reservations are keyed by node (previous commit in this stack),
turn
them into per-worker node pins:

- `ScalingPolicy.get_reserved_bundle_label_selectors()` converts the
reservation into one `ray.io/node-id` selector per worker. It returns
None
-- meaning "ask again later", not "no constraint" -- unless the
reservation
covers every worker, so a partially pinned worker group never starts. It
  also rejects a reservation whose layout contradicts the requested
  `placement_strategy` (e.g. STRICT_SPREAD workers stacked on one node)
  rather than silently downgrading it.
- `TrainController._start_worker_group` applies those pins, and raises
the
new retryable `WorkerGroupReservationNotReadyError` while the
reservation
is still pending. Pinning is skipped for zero-resource workers (nothing
to
reserve), TPU (`SlicePlacementGroup` does its own reservation), and when
the user set their own `label_selector` (the coordinator picks nodes by
resource fit and never matches selectors against node labels, so its
pins
  could contradict the user's).
- The reserved-resources query and its caching move from
`ElasticScalingPolicy` into `TrainAutoscalingCoordinatorClient`, so both
the elastic path and the new pinning path share one cache. The client
now
  takes prebuilt bundles rather than a `ScalingConfig`, which also drops
  V2's import of a V1 module.

Test: pytest python/ray/train/v2/tests/test_controller.py
      python/ray/train/v2/tests/test_elastic_scaling_policy.py
      python/ray/train/v2/tests/test_autoscaling_coordinator_client.py
      python/ray/train/v2/tests/test_failure_policy.py
      python/ray/train/tests/test_autoscaling_coordinator_client.py
Signed-off-by: iamjustinhsu <[email protected]>

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Changes core Train V2 scheduling and worker-group startup (blocking
wait, node pins, placement-strategy gating); mis-pinning or timeout
behavior could delay or misplace runs under contention, though coverage
is heavily tested.
> 
> **Overview**
> **Train V2 now waits for coordinator reservations and pins each worker
to the reserved node** via `ray.io/node-id` label selectors, so
concurrent runs are less likely to land on the same capacity after the
coordinator has already committed nodes.
> 
> `ScalingPolicy.get_reserved_bundle_label_selectors()` polls reserved
capacity (with timeout, like `placement_group.wait()`), returns **no
pins unless every worker is covered**, and refuses layouts that would
violate **STRICT_PACK** / **STRICT_SPREAD**. If reservations are still
pending, `TrainController._start_worker_group` raises retryable
**`WorkerGroupStartupTimeoutError`** instead of starting an unpinned
group. Pinning is skipped for zero-resource workers, TPU runs, and user
**`label_selector`** configs.
> 
> Supporting changes: **`TrainAutoscalingCoordinatorClient`** now
accepts prebuilt resource bundles (plus **`placement_strategy`** on
requests), centralizes cached **`get_reserved_resources`**, and shared
helpers **`_floor_slots`** /
**`_reserved_resources_to_bundle_label_selectors`** fix
fractional-resource float drift and V1 trainer-bundle subtraction on the
correct node. **Elastic** scaling reuses the same slot math and client
cache.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
d9214d0cb5c6eb24bd7d7561062bd7fab20df0fe. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Signed-off-by: iamjustinhsu <[email protected]>
@iamjustinhsu
iamjustinhsu requested a review from a team as a code owner September 8, 2026 19:00

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces changes to Ray Train's autoscaling coordinator client and scaling policies to pin workers to AutoscalingCoordinator reservations, preventing concurrent runs from scheduling onto the same capacity. It adds logic to convert coordinator reservations into per-worker node-id label selectors, handles fractional resources and float drift, and updates the TrainController to apply these pins during startup. The review feedback highlights critical concurrency and performance issues: the synchronous polling loop in get_reserved_bundle_label_selectors will block the TrainController asyncio actor's event loop, which should be resolved by running the blocking call in a separate thread via asyncio.to_thread. Additionally, returning NoopDecision when resources are not ready can trigger a tight CPU-burning loop in the controller, which requires rate-limiting or an asynchronous sleep.

Comment on lines +173 to +179
while True:
selectors = self._try_get_selectors(num_workers)
if selectors is not None:
return selectors
if time.monotonic() >= deadline:
return None
time.sleep(1)

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.

high

The synchronous get_reserved_bundle_label_selectors method contains a blocking while True loop with time.sleep(1) that can run for up to 60 seconds (the default timeout). Because the TrainController is an asyncio actor, calling this synchronous blocking method in the main thread will freeze the entire actor's event loop. During this time, the actor will be completely unresponsive and unable to process concurrent messages, such as abort() or GCS heartbeats, which can lead to actor death or failure to cancel jobs.

To resolve this, we should run this blocking polling loop in a separate thread using asyncio.to_thread from the controller, or make the polling loop asynchronous. Since _start_worker_group is called in _execute_resize_decision which is called in _step (an async context), we can easily make _start_worker_group async and run the blocking call via asyncio.to_thread.

Comment on lines +489 to +492
if can_pin_to_reservation:
reserved_node_label_selectors = (
self._scaling_policy.get_reserved_bundle_label_selectors(num_workers)
)

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.

high

Calling the synchronous blocking get_reserved_bundle_label_selectors method directly in the main thread of the TrainController (which is an asyncio actor) will freeze the event loop for up to 60 seconds. This prevents the actor from processing other concurrent messages like abort().

We should make _start_worker_group an async def and run the blocking call in a separate thread using asyncio.to_thread. Note that _execute_resize_decision (which calls _start_worker_group) and _step (which calls _execute_resize_decision) are already in an async context, so making _start_worker_group async is straightforward.

        if can_pin_to_reservation:
            import asyncio
            reserved_node_label_selectors = await asyncio.to_thread(
                self._scaling_policy.get_reserved_bundle_label_selectors, num_workers
            )

Comment on lines +165 to 166
if not reserved_resources:
return NoopDecision()

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.

medium

When make_decision_for_non_running_worker_group returns NoopDecision (because reserved resources are not ready yet), the controller transitions back to InitializingState (or RestartingState/ReschedulingState) and immediately runs the next control loop iteration.

Since get_reserved_resources caches the empty result for 1 second, the controller will spin in a tight CPU-burning loop for up to 1 second (or until resources are ready), executing _step millions of times and consuming 100% CPU of a core.

To prevent this tight looping, we should introduce a sleep (e.g., await asyncio.sleep(1)) in the controller's non-running states when a NoopDecision is returned, or rate-limit the non-running control loop iterations.

@ray-gardener ray-gardener Bot added the train Ray Train Related Issue label Sep 8, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 970fbb8. Configure here.

len(label_selectors),
num_workers,
)
return None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Extra reserved slots block pinning

High Severity

_try_get_selectors treats extra reserved capacity as not ready by requiring an exact worker count and exact STRICT_SPREAD node count. Elastic starts can therefore time out after ResizeDecision if the coordinator later reserves more than num_workers, burning a controller retry when the cluster gained capacity rather than lost it.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 970fbb8. Configure here.

@iamjustinhsu iamjustinhsu added the go add ONLY when ready to merge, run all tests label Sep 21, 2026
@goutamvenkat-anyscale
goutamvenkat-anyscale merged commit e39557f into master Sep 21, 2026
7 checks passed
@goutamvenkat-anyscale
goutamvenkat-anyscale deleted the jhsu/per-node-ac-2-train-v2 branch September 21, 2026 23:10
owenowenisme pushed a commit to owenowenisme/ray that referenced this pull request Sep 23, 2026
ray-project#66002)

Train V2 asked the coordinator for capacity but then let the placement
group
schedule wherever it liked. Two concurrent runs could therefore both be
scheduled onto the same capacity, even though the coordinator had
reserved
distinct nodes for each of them.

Now that reservations are keyed by node (previous commit in this stack),
turn
them into per-worker node pins:

- `ScalingPolicy.get_reserved_bundle_label_selectors()` converts the
reservation into one `ray.io/node-id` selector per worker. It returns
None
-- meaning "ask again later", not "no constraint" -- unless the
reservation
covers every worker, so a partially pinned worker group never starts. It
  also rejects a reservation whose layout contradicts the requested
  `placement_strategy` (e.g. STRICT_SPREAD workers stacked on one node)
  rather than silently downgrading it.
- `TrainController._start_worker_group` applies those pins, and raises
the
new retryable `WorkerGroupReservationNotReadyError` while the
reservation
is still pending. Pinning is skipped for zero-resource workers (nothing
to
reserve), TPU (`SlicePlacementGroup` does its own reservation), and when
the user set their own `label_selector` (the coordinator picks nodes by
resource fit and never matches selectors against node labels, so its
pins
  could contradict the user's).
- The reserved-resources query and its caching move from
`ElasticScalingPolicy` into `TrainAutoscalingCoordinatorClient`, so both
the elastic path and the new pinning path share one cache. The client
now
  takes prebuilt bundles rather than a `ScalingConfig`, which also drops
  V2's import of a V1 module.

Test: pytest python/ray/train/v2/tests/test_controller.py
      python/ray/train/v2/tests/test_elastic_scaling_policy.py
      python/ray/train/v2/tests/test_autoscaling_coordinator_client.py
      python/ray/train/v2/tests/test_failure_policy.py
      python/ray/train/tests/test_autoscaling_coordinator_client.py


<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Changes core Train V2 scheduling and worker-group startup (blocking
wait, node pins, placement-strategy gating); mis-pinning or timeout
behavior could delay or misplace runs under contention, though coverage
is heavily tested.
> 
> **Overview**
> **Train V2 now waits for coordinator reservations and pins each worker
to the reserved node** via `ray.io/node-id` label selectors, so
concurrent runs are less likely to land on the same capacity after the
coordinator has already committed nodes.
> 
> `ScalingPolicy.get_reserved_bundle_label_selectors()` polls reserved
capacity (with timeout, like `placement_group.wait()`), returns **no
pins unless every worker is covered**, and refuses layouts that would
violate **STRICT_PACK** / **STRICT_SPREAD**. If reservations are still
pending, `TrainController._start_worker_group` raises retryable
**`WorkerGroupStartupTimeoutError`** instead of starting an unpinned
group. Pinning is skipped for zero-resource workers, TPU runs, and user
**`label_selector`** configs.
> 
> Supporting changes: **`TrainAutoscalingCoordinatorClient`** now
accepts prebuilt resource bundles (plus **`placement_strategy`** on
requests), centralizes cached **`get_reserved_resources`**, and shared
helpers **`_floor_slots`** /
**`_reserved_resources_to_bundle_label_selectors`** fix
fractional-resource float drift and V1 trainer-bundle subtraction on the
correct node. **Elastic** scaling reuses the same slot math and client
cache.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
d9214d0cb5c6eb24bd7d7561062bd7fab20df0fe. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup> <!--
/CURSOR_SUMMARY -->

---------

> Thank you for contributing to Ray! 🚀
> Please review the [Ray Contribution
Guide](https://docs.ray.io/en/master/ray-contribute/getting-involved.html)
before opening a pull request.

> ⚠️ Remove these instructions before submitting your PR.

> 💡 Tip: Mark as draft if you want early feedback, or ready for review
when it's complete.

## Description
> Briefly describe what this PR accomplishes and why it's needed.

## Related issues
> Link related issues: "Fixes ray-project#1234", "Closes ray-project#1234", or "Related to
ray-project#1234".

## Additional information
> Optional: Add implementation details, API changes, usage examples,
screenshots, etc.

---------

Signed-off-by: iamjustinhsu <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
ray-project#66002)

Train V2 asked the coordinator for capacity but then let the placement
group
schedule wherever it liked. Two concurrent runs could therefore both be
scheduled onto the same capacity, even though the coordinator had
reserved
distinct nodes for each of them.

Now that reservations are keyed by node (previous commit in this stack),
turn
them into per-worker node pins:

- `ScalingPolicy.get_reserved_bundle_label_selectors()` converts the
reservation into one `ray.io/node-id` selector per worker. It returns
None
-- meaning "ask again later", not "no constraint" -- unless the
reservation
covers every worker, so a partially pinned worker group never starts. It
  also rejects a reservation whose layout contradicts the requested
  `placement_strategy` (e.g. STRICT_SPREAD workers stacked on one node)
  rather than silently downgrading it.
- `TrainController._start_worker_group` applies those pins, and raises
the
new retryable `WorkerGroupReservationNotReadyError` while the
reservation
is still pending. Pinning is skipped for zero-resource workers (nothing
to
reserve), TPU (`SlicePlacementGroup` does its own reservation), and when
the user set their own `label_selector` (the coordinator picks nodes by
resource fit and never matches selectors against node labels, so its
pins
  could contradict the user's).
- The reserved-resources query and its caching move from
`ElasticScalingPolicy` into `TrainAutoscalingCoordinatorClient`, so both
the elastic path and the new pinning path share one cache. The client
now
  takes prebuilt bundles rather than a `ScalingConfig`, which also drops
  V2's import of a V1 module.

Test: pytest python/ray/train/v2/tests/test_controller.py
      python/ray/train/v2/tests/test_elastic_scaling_policy.py
      python/ray/train/v2/tests/test_autoscaling_coordinator_client.py
      python/ray/train/v2/tests/test_failure_policy.py
      python/ray/train/tests/test_autoscaling_coordinator_client.py


<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Changes core Train V2 scheduling and worker-group startup (blocking
wait, node pins, placement-strategy gating); mis-pinning or timeout
behavior could delay or misplace runs under contention, though coverage
is heavily tested.
> 
> **Overview**
> **Train V2 now waits for coordinator reservations and pins each worker
to the reserved node** via `ray.io/node-id` label selectors, so
concurrent runs are less likely to land on the same capacity after the
coordinator has already committed nodes.
> 
> `ScalingPolicy.get_reserved_bundle_label_selectors()` polls reserved
capacity (with timeout, like `placement_group.wait()`), returns **no
pins unless every worker is covered**, and refuses layouts that would
violate **STRICT_PACK** / **STRICT_SPREAD**. If reservations are still
pending, `TrainController._start_worker_group` raises retryable
**`WorkerGroupStartupTimeoutError`** instead of starting an unpinned
group. Pinning is skipped for zero-resource workers, TPU runs, and user
**`label_selector`** configs.
> 
> Supporting changes: **`TrainAutoscalingCoordinatorClient`** now
accepts prebuilt resource bundles (plus **`placement_strategy`** on
requests), centralizes cached **`get_reserved_resources`**, and shared
helpers **`_floor_slots`** /
**`_reserved_resources_to_bundle_label_selectors`** fix
fractional-resource float drift and V1 trainer-bundle subtraction on the
correct node. **Elastic** scaling reuses the same slot math and client
cache.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
d9214d0cb5c6eb24bd7d7561062bd7fab20df0fe. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup> <!--
/CURSOR_SUMMARY -->

---------

> Thank you for contributing to Ray! 🚀
> Please review the [Ray Contribution
Guide](https://docs.ray.io/en/master/ray-contribute/getting-involved.html)
before opening a pull request.

> ⚠️ Remove these instructions before submitting your PR.

> 💡 Tip: Mark as draft if you want early feedback, or ready for review
when it's complete.

## Description
> Briefly describe what this PR accomplishes and why it's needed.

## Related issues
> Link related issues: "Fixes ray-project#1234", "Closes ray-project#1234", or "Related to
ray-project#1234".

## Additional information
> Optional: Add implementation details, API changes, usage examples,
screenshots, etc.

---------

Signed-off-by: iamjustinhsu <[email protected]>
matthewdeng pushed a commit that referenced this pull request Oct 9, 2026
…#66646)

## Description

`test_elastic_e2e` has been timing out on CI since #66002, which pins
Train V2 workers to AutoscalingCoordinator reservations. The elastic
worker group start waits the full 60s
(`RAY_TRAIN_WORKER_GROUP_START_TIMEOUT_S`) whenever the reservation
changes between the scaling decision and pinning. The decision is sized
from the cached reservation, while the pins come from a separate
`recompute=True` poll in `_try_get_selectors`, so:

1. **The reservation grows past the decision.** Elastic requests
`max_workers` bundles, so after `ResizeDecision(14)` the reservation can
reach 32 slots. `len(label_selectors) != num_workers` then never passes.
2. **The reservation shrinks below the decision.** After a node dies,
the cached view still counts it, and pinning waits for workers that
don't exist.

This PR takes the decision and the pins from the **same snapshot**, so
they can't disagree:

- **Pins on `ResizeDecision`.** `ResizeDecision.label_selectors` is
built by the scaling policy from the reservation that chose
`num_workers`, using the same `_floor_slots` math. The
STRICT_PACK/STRICT_SPREAD layout check from #66002 is kept. The
controller just applies the pins and no longer polls the coordinator.
- **Elastic** decides and pins from a fresh (`recompute=True`) view. In
the non-running path it reads the fresh view only once the cached one
looks ready, so waiting doesn't trigger a full coordinator tick every
loop.
- **Fixed** now waits for its reservation in
`make_decision_for_non_running_worker_group` (returning `NoopDecision`
until every worker is covered), the same way elastic waits for
`min_workers`. This removes `get_reserved_bundle_label_selectors`, its
60s poll loop, and the controller's `WorkerGroupStartupTimeoutError`
raise. Both policies log a rate-limited "Waiting for reserved resources"
message while they wait. Before, elastic logged nothing when nothing was
reserved.
- **Stop the placement group wait early when a pinned node dies.** The
coordinator drops nodes that `ray.nodes()` reports dead, but the GCS can
still report a just-removed node as alive for a short time. A pin made
in that window can never be placed, so `WorkerGroup` now polls
`pg_handle.wait()` in 1s intervals and stops as soon as a pinned node is
no longer alive. It raises the same retryable
`WorkerGroupStartupTimeoutError` instead of stalling for 60s.
`test_elastic_e2e` hits this window on purpose by removing every node
and restarting right away. Locally this went from a 60s stall to giving
up after about 1s.

Skipping pins (TPU, zero-resource workers, user `label_selector`) moves
into `ScalingPolicy._should_pin_to_reservation`. The controller still
lets a callback-provided `label_selector` win, because the policy can't
see those.

Behavior change: a fixed run waiting for capacity no longer fails and
retries every 60s through the failure policy. It waits in the controller
loop like elastic. With the default `controller_failure_limit=-1`, the
only visible difference is the log messages.

## Related issues

Alternative to #66601, which fixes the same `test_elastic_e2e` flake
differently: it picks a subset of a larger reservation with
`_compute_reservations` and adds a relative `_FIT_EPSILON` to the
coordinator's shared `_bundle_can_fit_on_node`. This PR avoids the Train
→ Ray Data `_compute_reservations` dependency and leaves the
coordinator's fit check, which every requester shares, unchanged. It
also avoids an extra restart when the reservation grows, because it
starts at the size the reservation supports now.

## Testing

All passing locally (macOS, `ray_dev_py311`):

```
pytest python/ray/train/v2/tests/test_autoscaling_coordinator_client.py \
       python/ray/train/v2/tests/test_elastic_scaling_policy.py              # 37 passed
pytest python/ray/train/v2/tests/test_controller.py \
       python/ray/train/v2/tests/test_controller_callback_behaviour.py \
       python/ray/train/v2/tests/test_failure_policy.py \
       python/ray/train/tests/test_autoscaling_coordinator_client.py         # 65 passed
pytest python/ray/train/v2/tests/test_scheduling.py \
       python/ray/train/v2/tests/test_elastic_e2e.py \
       python/ray/train/v2/tests/test_state.py                               # 34 passed
pytest python/ray/train/v2/tests/test_worker_group.py \
       python/ray/train/v2/tests/test_elastic_e2e.py                         # 43 passed
pre-commit run --files <changed files>                                       # clean
```

In the last `test_elastic_e2e` run, the controller log shows the "decide
4 right after every node was removed" restart stopping after about 1s
("Giving up on the placement group early…") instead of the 60s stall
seen before the early-stop change.

Known gap: when it stops early, the retried
`WorkerGroupStartupTimeoutError` still says "timed out after 60.0
seconds". The info log just before it gives the real reason.

AI assistance (Claude Code) was used to write this change.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Justin Yu <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Co-authored-by: Mark Towers <[email protected]>
Co-authored-by: Mark Towers <[email protected]>
sai-miduthuri added a commit that referenced this pull request Oct 26, 2026
Reverts #66002 on `releases/2.60.0`. This is the release-branch
counterpart of #67337, which reverts #66646 and then #66002 on master.
This branch never had #66646, so only #66002 is reverted here.

## Why

#66002 pins every Train V2 worker to a node from the
AutoscalingCoordinator's reservation. #67337 explains why that
reservation isn't accurate enough to pin to:

- It counts draining nodes and capacity held by work that never went
through the coordinator.
- It moves when nodes join.

When a pin is wrong, the pinned placement group never gets placed, and
the controller retries the same pins indefinitely.

On this branch, the `train_elastic_e2e_with_node_killing.aws` release
test failed in 3 of its 5 weekly release-pipeline runs. In builds 109533
and 111090 it looped on `WorkerGroupStartupTimeoutError` until the job
timed out. #66766, where STRICT_SPREAD runs can wait forever, also
bisects to #66002.

After this revert, Train V2 schedules workers the way it did in 2.59.
#66001 and #66370 stay, as in #67337, so Train still uses the
coordinator's reservation to count how many workers fit.

This is the alternative to #67327, which cherry-picks #66646 onto this
branch instead. If this PR merges, #67327 should be closed.

## Revert details

`git revert e39557f` applied with no conflicts, and git merged
#66225's later change to `controller.py` automatically. The revert
touches 11 files, with 70 insertions and 759 deletions.

- The diff is byte-identical to #67337's revert of #66002 (deb5235),
index lines included.
- Before the revert, the 11 files on this branch were identical to
master right after #67337 reverts #66646. After the revert, they match
#67337's head.
- No code on this branch references the functions or classes the revert
removes. The few names that still have references are definitions that
existed before #66002, such as the Ray Data coordinator's
`get_reserved_resources`.

Not a duplicate: no PR against `releases/2.60.0` reverts #66002. #67337
targets `master`.

## Testing

| Command | Result |
|---|---|
| pre-commit, run as the commit hook on the 11 changed files | Passed
(ruff, black, pydoclint, Ray Train circular imports, and the other
applicable hooks) |

I didn't run the unit tests locally. CI runs them on this PR:

- `:bullettrain_front: ml: train v2 tests` runs the `train_v2`-tagged
tests, including `test_controller.py`, `test_elastic_scaling_policy.py`,
`test_autoscaling_coordinator_client.py` and `test_failure_policy.py`.
- `:train: ml: train v1 tests` runs
`python/ray/train/tests/test_autoscaling_coordinator_client.py`.
- `:train: ml: data integration tests` runs `test_data_integration.py`.

#67337 ran the same test files against the same resulting code on
master, and they passed.

AI assistance was used to prepare this revert.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Sai Miduthuri <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
pseudo-rnd-thoughts pushed a commit to pseudo-rnd-thoughts/ray that referenced this pull request Oct 27, 2026
…oordinator's view is wrong

Train V2 sizes its worker group from the AutoscalingCoordinator's
reservation, which is built from each node's total capacity, counts
draining nodes as alive, and is recomputed from scratch when nodes join or
leave. Pinning workers to that reservation (ray-project#66002, reverted in ray-project#67337)
turned each of the following into a run that retried the same pins forever.
These tests assert that the run starts and finishes instead:

- Capacity held outside the coordinator: an actor holds node X's slot. The
  run must start on node Y.
- Draining node: X is draining after a preemption notice and is still
  reported alive. The run must start on Y.
- Node churn with two runs: a node joins and sorts first, then the node of
  the second run is removed. The second run must restart on the new node
  without disturbing the first, and both must finish.
- STRICT_SPREAD on an autoscaling cluster (ray-project#66766): the autoscaler must
  launch one node per worker, and the run must start on two nodes.

Each run's driver and controller stay on the head node, so the scenarios can
drain and remove worker nodes. Against the code before the revert, the
occupied and draining tests time out, the churn test's second run loops
on WorkerGroupStartupTimeoutError while the new node sits free, and the
STRICT_SPREAD run waits forever on a reservation that covers one node.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests train Ray Train Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ray fails to serialize self-reference objects

3 participants