Skip to content

[train] Add end-to-end tests for elastic runs, Ctrl-C while waiting, and losing the coordinator's node - #67481

Closed
pseudo-rnd-thoughts wants to merge 4 commits into
ray-project:masterfrom
pseudo-rnd-thoughts:train-autoscaler/scheduling-e2e-tests
Closed

pseudo-rnd-thoughts wants to merge 4 commits into
ray-project:masterfrom
pseudo-rnd-thoughts:train-autoscaler/scheduling-e2e-tests

Conversation

@pseudo-rnd-thoughts

@pseudo-rnd-thoughts pseudo-rnd-thoughts commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Description

End-to-end tests for the fixes in #67478, #67479 and #67480, which #67421 left out because they only pass with those fixes.

Stacked on #67421. Its commits come first here, because these tests use its helpers in test_scheduling.py. The last commit is this PR. It merges after #67421, #67478, #67479 and #67480; I'll rebase then. Until then, the tests listed below fail in CI by design.

Test Scenario Needs
test_elastic_run_starts_when_a_node_is_unusable[draining] Elastic run of 1–2 workers; node X is draining #67479. Without it the run retries two workers forever
test_elastic_run_starts_when_a_node_is_unusable[slot_held_outside_the_coordinator] Same, with X's slot held by an actor the coordinator doesn't know about xfail(strict=True): elastic runs size themselves from total capacity, so this still retries forever. Records the known gap
test_ctrl_c_aborts_a_run_waiting_for_workers A real driver process waits for min_workers, then gets SIGINT #67478. Without it the run ignores Ctrl-C for over 30s
test_run_restarts_after_the_coordinators_first_caller_dies Coordinator created from node X; a run starts on X and Y; X dies #67480. Without it the run never restarts
test_higher_priority_request_is_reserved_first (unit, test_autoscaling_coordinator.py) Two requests whose bundles don't both fit Nothing; priority ordering had no test

The Ctrl-C test uses a real driver subprocess, because a Ray task blocked in ray.get doesn't run Python signal handlers and so can't stand in for one.

Series

This splits #67422 into reviewable pieces:

  1. [train] Yield the controller while waiting for a scaling decision, and fix the elastic node-killing release test #67478: controller yield + release harness
  2. [data] Keep the autoscaling coordinator's view of the cluster up-to-date #67479: coordinator's view of the cluster
  3. [data] Run the autoscaling coordinator actor on the head node #67480: coordinator actor on the head node
  4. [train] Add end-to-end tests for elastic runs, Ctrl-C while waiting, and losing the coordinator's node #67481 (this PR): end-to-end tests covering 1–3, stacked on [train] Add end-to-end scheduling tests for Train V2 worker placement #67421

Testing

All local on macOS:

# This branch alone (#67421 + this commit): the three tests that need the fixes fail, as expected
pytest python/ray/train/v2/tests/test_scheduling.py
#   3 failed, 18 passed, 1 xfailed
#   FAILED test_elastic_run_starts_when_a_node_is_unusable[draining]
#   FAILED test_ctrl_c_aborts_a_run_waiting_for_workers
#   FAILED test_run_restarts_after_the_coordinators_first_caller_dies
pytest python/ray/data/tests/test_autoscaling_coordinator.py   # 56 passed

# This branch merged with #67478, #67479 and #67480
pytest python/ray/train/v2/tests/test_scheduling.py            # 21 passed, 1 xfailed
pytest python/ray/data/tests/test_autoscaling_coordinator.py   # 69 passed

Not a duplicate. These tests were in #67422, which this series replaces. #67421 explicitly leaves them out.

AI assistance (Claude Code) was used to write these tests, check them against broken code, and write this description.

🤖 Generated with Claude Code

Mark Towers and others added 4 commits October 27, 2026 10:06
…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]>
…eing, release and STRICT_PACK cases

The tests check scheduling cases Train V2 must handle, so they belong with
the existing placement tests rather than in a file of their own.

- Merge the occupied-node and draining-node tests into one parametrized
  test, test_starts_when_a_node_is_unusable.
- Add test_runs_queue_for_a_single_slot: a run waiting for a slot another
  run holds keeps retrying, then starts on that node once it frees up.
- Add test_a_finished_run_releases_its_resources: a finished run gives back
  its placement group and its coordinator request, so a new request at the
  same priority gets the slot and a second run lands on the same node.
- Add test_strict_pack_starts_on_an_autoscaling_cluster: the autoscaler
  launches a node with room for every STRICT_PACK worker.
- The PACK/SPREAD and label-selector tests don't change their cluster, so
  they share one class-scoped cluster instead of starting five.
- Remove the test_scheduling_regressions target and make test_scheduling
  large.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
…and losing the coordinator's node

Each test fails without the fix in this branch that it covers:

- test_elastic_run_starts_when_a_node_is_unusable[draining]: an elastic
  run of one or two workers starts with one worker when the other node is
  draining. Without the draining exclusion it retries two workers forever.
- test_elastic_run_starts_when_a_node_is_unusable[slot_held_outside_the_coordinator]:
  marked xfail(strict=True). Elastic runs still size themselves from total
  capacity, so they retry two workers forever. This records the known gap.
- test_ctrl_c_aborts_a_run_waiting_for_workers: Ctrl-C on a real driver
  process aborts an elastic run waiting for min_workers within 30s. Without
  the controller yield, the abort never reaches the controller. A Ray task
  can't stand in for the driver, because a task blocked in ray.get doesn't
  run Python signal handlers.
- test_run_restarts_after_the_coordinators_first_caller_dies: the
  coordinator is created from node X, a run starts on X and Y, then X dies.
  The run, which holds a handle to the coordinator, restarts on Y. Without
  the head-node placement the coordinator dies with X and the run never
  restarts.
- test_higher_priority_request_is_reserved_first: when two requests'
  bundles don't both fit, a later HIGH request is reserved ahead of an
  earlier MEDIUM one. Nothing tested the priority ordering before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
pseudo-rnd-thoughts added a commit that referenced this pull request Oct 29, 2026
…d fix the elastic node-killing release test (#67478)

## Description

This PR fixes two issues with the controller.

1. **Controller busy-wait:** In `INITIALIZING`, `RESTARTING` and
`RESCHEDULING`, `TrainController._step` never awaits, yielding the event
loop. While the scaling policy keeps returning `NoopDecision` (an
elastic run waiting for `min_workers` to fit, or a failed coordinator
query), `run()` loops without yielding the event loop meaning that the
controller actor spins a full core and that an `abort()` can't reach it,
so Ctrl-C on the driver doesn't stop the run.

This has been true for elastic runs since #60721. This PR updates
`_step` to now sleeps `RAY_TRAIN_HEALTH_CHECK_INTERVAL_S` before asking
the policy again, matching the running path's poll interval. Once
`abort()` can run during that sleep, the control loop must not overwrite
the `AbortedState` it set with the state computed before the abort, so a
terminal state set concurrently is left in place.

2. **Elastic node-killing release test:** `terminate_node` in
`elastic_util.py` runs its killer task on the node it terminates, with
hard affinity and default retries. When the task dies with the node, Ray
retries it, and the retry can never be scheduled, so `ray.get` raises
`TaskUnschedulableError` and `train_elastic_e2e_with_node_killing` fails
after training already succeeded (failure mode A). The killer task is no
longer retried, and `NodeDiedError`, `WorkerCrashedError` and
`TaskUnschedulableError` count as the node having gone down.

New test: `test_abort_while_waiting_for_a_scaling_decision` in
`test_controller.py`. It raises `TimeoutError` without the fix. The
end-to-end version, `test_ctrl_c_aborts_a_run_waiting_for_workers` (a
real driver process receiving SIGINT), is in #67481.

AI assistance (Claude Code) was used to write these changes and tests,
run the suites, and write this description.

---------

Signed-off-by: Mark Towers <[email protected]>
Co-authored-by: Mark Towers <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
pseudo-rnd-thoughts added a commit that referenced this pull request Oct 30, 2026
## Summary

Runs the shared AutoscalingCoordinator actor on the head node instead of
the first caller's node, so losing a worker node no longer takes the
coordinator with it for every Ray Data and Ray Train requester on the
cluster.

## Before

`get_or_create_autoscaling_coordinator` created the detached actor with
hard node affinity to the caller's node and `max_restarts=-1`. The
original PR (#59353) noted "Create the actor on the local node, to
reduce network overhead".

The problem is that the coordinator, though, is shared by every
requester on the cluster. The first caller can be on any node, for
example a Train controller or a Ray Data executor inside a Train worker.
If that node dies, the actor can't be rescheduled
(`ActorUnschedulableError`). Requesters that already hold a handle, such
as Train's coordinator client, lose it for good, so a running elastic
run can't resize or restart.

Soft affinity doesn't help:
`ClusterResourceScheduler::GetBestSchedulableNode` places an actor that
requests no resources on a random node unless its affinity is hard, so
it could land on an autoscaled worker and restart elsewhere every time
that worker scales down.

## After

The actor requests `node:__internal_head__: 0.001` and uses
`scheduling_strategy="DEFAULT"`. This is the same pattern as the Serve
controller (`serve/_private/default_impl.py`) and both Train state
actors (`train/_internal/state/state_actor.py`,
`train/v2/_internal/state/state_actor.py`). The head node lives as long
as the cluster. With GCS fault tolerance, a restarted head has the same
resource, so the actor can restart there.

The explicit `"DEFAULT"` strategy matters. Without it, a caller in a
placement group that captures child tasks (Tune trials, Train V1
workers) makes the actor join that group. The bundles don't hold the
head-node resource, so creation fails with `ValueError: Cannot schedule
_AutoscalingCoordinatorActor with the placement group` and a detached
actor shouldn't die with someone else's group anyway.

## New tests 

In `test_autoscaling_coordinator.py`:
- `test_coordinator_actor_runs_on_the_head_node`: created from a worker
node, the actor runs on the head and survives that worker's removal.
- `test_coordinator_actor_escapes_the_callers_placement_group`: created
from a task in a placement group that captures child tasks, the actor
runs on the head and survives the group's removal. It fails without
`scheduling_strategy="DEFAULT"`.

The end-to-end case,
`test_run_restarts_after_the_coordinators_first_caller_dies`, is in
#67481.

AI assistance (Claude Code) was used to write these changes and tests,
run the suites, and write this description.

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

---------

Signed-off-by: Mark Towers <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
Co-authored-by: Mark Towers <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Chi-Sheng Liu <[email protected]>
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale The issue is stale. It will be closed within 7 days unless there are further conversation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant