Skip to content

[train] Yield the controller while waiting for a scaling decision, and fix the elastic node-killing release test - #67478

Merged
pseudo-rnd-thoughts merged 3 commits into
ray-project:masterfrom
pseudo-rnd-thoughts:train-autoscaler/controller-yield
Oct 29, 2026
Merged

pseudo-rnd-thoughts merged 3 commits into
ray-project:masterfrom
pseudo-rnd-thoughts:train-autoscaler/controller-yield

Conversation

@pseudo-rnd-thoughts

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

Copy link
Copy Markdown
Member

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.

  1. 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.

Mark Towers and others added 2 commits October 27, 2026 15:36
…ecision

In INITIALIZING, RESTARTING and RESCHEDULING, `TrainController._step` never
awaits. While the scaling policy keeps returning `NoopDecision` (an elastic
run waiting for `min_workers` to fit, or a failed coordinator query),
`run()` loops without giving up the event loop. The controller actor then
spins a full core, and calls like `abort()` can't reach it. This has been
the case for elastic runs since elastic training landed; it isn't caused
by the reservation pinning that was reverted.

`_step` 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 sets with the state the iteration computed
before the abort, or `run()` would go back to waiting. The loop now leaves a
terminal state set concurrently by `abort()` in place.

The yield is the control-loop change from ray-project#66763, split out so it can land
on its own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
…sk dies with its node

`terminate_node` runs `terminate_current_instance` on the node it
terminates, with hard node affinity and the default task retries. The task
usually dies with the instance, so Ray retries it, and the retry can never
be scheduled: its node is gone. `ray.get` then raises
`TaskUnschedulableError`, which fails `train_elastic_e2e_with_node_killing`
even when training finished successfully (failure mode A in the release
history).

Don't retry the killer task, and treat `NodeDiedError`,
`WorkerCrashedError` and `TaskUnschedulableError` as the node having gone
down, which is the intended outcome.

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

@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 ensures the Ray Train controller yields the event loop while waiting for scaling decisions, allowing concurrent operations like abort() to execute. It also prevents overwriting terminal states after awaiting and improves node termination resilience by handling expected task failures. The review feedback suggests two key improvements: adding a terminal state check within the control loop's exception handler to prevent exceptions from overwriting the state, and properly awaiting the cancelled task in the new unit tests to avoid unhandled exception warnings.

Comment on lines +951 to +954
if self.get_state().is_terminal():
# `abort()` ran while `_step` was awaiting. Don't overwrite its
# terminal state with the state this iteration computed.
return

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

While this check successfully prevents overwriting the terminal state when _step() returns normally, it does not protect against the case where _step() raises an exception (e.g., RayActorError or CancelledError due to the worker group being aborted concurrently).\n\nIf _step() raises an exception after abort() has run, the exception is caught by the outer except Exception as e: block. If the failure policy or its callbacks raise an exception during this handling, the fallback block will directly overwrite self._state with ErroredState (line 948), bypassing this terminal state check entirely.\n\nTo make this fully robust, we should also check if the state is terminal at the beginning of the except Exception as e: block:\n\npython\n except Exception as e:\n if self.get_state().is_terminal():\n return\n

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.

Addressed


assert not run_task.done()
assert isinstance(controller.get_state(), InitializingState)
run_task.cancel()

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 cancelling an asyncio task in tests, it is best practice to await the task and handle the asyncio.CancelledError to ensure proper cleanup and avoid noisy warnings about unretrieved task exceptions.

    run_task.cancel()\n    try:\n        await run_task\n    except asyncio.CancelledError:\n        pass

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.

Addressed

Signed-off-by: Mark Towers <[email protected]>
@pseudo-rnd-thoughts
pseudo-rnd-thoughts enabled auto-merge (squash) October 29, 2026 10:36
@pseudo-rnd-thoughts
pseudo-rnd-thoughts merged commit 30ca1d1 into ray-project:master Oct 29, 2026
7 checks passed
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.

2 participants