Skip to content

[data] Run the autoscaling coordinator actor on the head node - #67480

Merged
pseudo-rnd-thoughts merged 8 commits into
ray-project:masterfrom
pseudo-rnd-thoughts:train-autoscaler/coordinator-head-node
Oct 30, 2026
Merged

pseudo-rnd-thoughts merged 8 commits into
ray-project:masterfrom
pseudo-rnd-thoughts:train-autoscaler/coordinator-head-node

Conversation

@pseudo-rnd-thoughts

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

Copy link
Copy Markdown
Member

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

Mark Towers and others added 2 commits October 27, 2026 15:36
`get_or_create_autoscaling_coordinator` created the detached coordinator
with hard node affinity to the first caller's node and
`max_restarts=-1`. That caller can be on any node, for example a Train
controller or a Ray Data executor running inside a Train worker. If
that node died, the actor couldn't be rescheduled
(`ActorUnschedulableError`), and every Ray Data and Ray Train requester
on the cluster lost the coordinator for good.

Soft affinity doesn't keep the local-node preference for this actor:
`ClusterResourceScheduler::GetBestSchedulableNode` places an actor that
requests no resources on a random node unless its affinity is hard. So
the actor would land on any node, including autoscaled workers it would
restart off whenever they scale down.

Pin it to the head node instead, with a tiny amount of the head node's
`node:__internal_head__` resource, the way Ray Serve places its
controller. The head node lives as long as the cluster, and a restarted
head, with GCS fault tolerance, has the same resource, so the actor can
restart there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
… group

Pinning the coordinator to the head node with the `node:__internal_head__`
resource dropped its explicit scheduling strategy. A caller running in a
placement group that captures child tasks (Tune trials, Train V1 workers)
then made the actor join that group, whose bundles don't hold the head
node resource, so creating it raised `ValueError: Cannot schedule
_AutoscalingCoordinatorActor with the placement group`. This broke
test_new_dataset_config.py::test_basic and
test_torch_transformers_train.py::test_e2e_ray_data.

Use the "DEFAULT" strategy, as the Train state actors do, so the
detached actor escapes the group and doesn't die when it's removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
@pseudo-rnd-thoughts pseudo-rnd-thoughts added the go add ONLY when ready to merge, run all tests label Oct 27, 2026
@pseudo-rnd-thoughts
pseudo-rnd-thoughts marked this pull request as ready for review October 27, 2026 22:15
@pseudo-rnd-thoughts
pseudo-rnd-thoughts requested a review from a team as a code owner October 27, 2026 22:15

@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 modifies the AutoscalingCoordinator to be created on the head node as a detached actor, rather than being pinned to the local node of the initial caller. This ensures that the coordinator remains available even if the initiating worker node is lost. The scheduling strategy was updated to use the default strategy with a head node resource requirement. Two new unit tests were added to verify that the coordinator runs on the head node and escapes caller placement groups. There are no review comments to address, and the changes look solid.

# on the cluster shares this detached actor.
actor_cls = ray.remote(
num_cpus=0,
resources={HEAD_NODE_RESOURCE_LABEL: 0.001},

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.

Without this label, was it not guaranteed to run on the head node? I thought num_cpus=0 meant that it must go onto the head node, since worker nodes should have non-zero cpus

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Interesting question, checking, when you request num_cpu=0 and no hard affinity, then GetBestSchedulableNode will pick a random feasible node which could be the head node but not guaranteed.

assert ray.get([res1, res2]) == ["ok"] * 2


def test_coordinator_actor_runs_on_the_head_node(cluster):

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.

Is this test a subset of the next one?
When can the remove_node / remove_placement_group tails in both tests fail btw?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sort of, the first test is a basic check that the AutoscalingCoordinator is scheduled on the head node and if the worker node is deleted, the coordinator still exists. While for the second test is a more realistic variant using a PlacementGroup to check that when a placement group is killed then the coordinator isn't lost as well.
Happy to delete the first test

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.

Would be great; thanks

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Will do, added in the latest commit

@pseudo-rnd-thoughts
pseudo-rnd-thoughts requested a review from a team as a code owner October 29, 2026 11:48
Comment thread python/ray/_private/test_utils.py Resolved
Co-authored-by: Chi-Sheng Liu <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
@pseudo-rnd-thoughts
pseudo-rnd-thoughts merged commit f3efaeb into ray-project:master Oct 30, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data Ray Data-related issues go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants