Skip to content

[Feat][Core] Don't count task retries due to node preemption - #54182

Merged
edoakes merged 8 commits into
ray-project:masterfrom
MortalHappiness:feature/dont-count-drain-node-task-retry
Aug 1, 2025
Merged

edoakes merged 8 commits into
ray-project:masterfrom
MortalHappiness:feature/dont-count-drain-node-task-retry

Conversation

@MortalHappiness

Copy link
Copy Markdown
Member

Why are these changes needed?

We decided that task retries due to node preemption should not count toward max_retries.

Related issue number

N/A

Checks

@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 Jul 12, 2025
@MortalHappiness MortalHappiness removed the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Jul 25, 2025
@rueian
rueian force-pushed the feature/dont-count-drain-node-task-retry branch from e1c68df to 8e97c94 Compare July 25, 2025 19:53
@rueian
rueian force-pushed the feature/dont-count-drain-node-task-retry branch from 8e97c94 to 7802f77 Compare July 25, 2025 19:57
@rueian
rueian force-pushed the feature/dont-count-drain-node-task-retry branch from ed1fe17 to 7e1ff81 Compare July 26, 2025 03:00
@rueian rueian added the go add ONLY when ready to merge, run all tests label Jul 26, 2025
@rueian
rueian marked this pull request as ready for review July 26, 2025 05:52
@rueian
rueian requested a review from a team as a code owner July 26, 2025 05:52
node_info->death_info().reason() ==
rpc::NodeDeathInfo::AUTOSCALER_DRAIN_PREEMPTED;
}
if (num_retries_left > 0 || (is_preempted && task_entry.spec.IsRetriable())) {

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.

Even when num_retries_left == 0, we should still retry the task if it was preempted.

@rueian
rueian requested a review from Copilot July 27, 2025 18:09

Copilot AI 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.

Pull Request Overview

This PR implements a feature to exclude task retries due to node preemption from counting against the max_retries limit. When a task fails due to a node being preempted by the autoscaler, the task is retried without decrementing the retry counter, allowing for more resilient task execution in autoscaling environments.

  • Modifies the task retry logic to check if a node failure was due to preemption using GCS client node information
  • Adds death info handling to the NodeInfoAccessor for tracking preemption reasons
  • Updates TaskManager constructor to include GCS client dependency for node status queries

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/ray/core_worker/task_manager.cc Core retry logic to check node preemption status and bypass retry counter
src/ray/core_worker/task_manager.h Constructor signature update to accept GCS client
src/ray/core_worker/core_worker.cc Passes GCS client to TaskManager constructor
src/ray/gcs/gcs_client/accessor.cc Copies death info when handling dead node notifications
src/ray/gcs/gcs_client/test/accessor_test.cc Test for death info handling in NodeInfoAccessor
src/ray/core_worker/test/task_manager_test.cc Unit tests for preemption retry behavior
python/ray/tests/test_draining.py Integration test for task retry behavior during node draining
Comments suppressed due to low confidence (1)

python/ray/tests/test_draining.py:460

  • The test only covers the case where max_retries=1. Consider adding test cases with max_retries=0 and max_retries>1 to ensure the preemption retry logic works correctly across different retry configurations.
    @ray.remote(max_retries=1, resources={"worker": 1})

Comment thread src/ray/core_worker/task_manager.cc Resolved
Comment thread src/ray/core_worker/task_manager.cc Resolved
@rueian
rueian requested review from a team and MengjinYan July 28, 2025 06:11
@edoakes
edoakes enabled auto-merge (squash) July 31, 2025 22:32
@rueian
rueian force-pushed the feature/dont-count-drain-node-task-retry branch from 65da5ac to 17e7736 Compare August 1, 2025 03:12
@github-actions
github-actions Bot disabled auto-merge August 1, 2025 03:12
@rueian
rueian force-pushed the feature/dont-count-drain-node-task-retry branch from 17e7736 to 0e8378c Compare August 1, 2025 04:46
@rueian

rueian commented Aug 1, 2025

Copy link
Copy Markdown
Contributor

Hi @edoakes, I've resolved all merge conflicts and all tests have passed successfully. Could you please take another look? Thanks!

@rueian
rueian requested a review from edoakes August 1, 2025 18:56
@edoakes
edoakes merged commit feb1c61 into ray-project:master Aug 1, 2025
avibasnet31 pushed a commit to avibasnet31/ray that referenced this pull request Aug 2, 2025
…ject#54182)

We decided that task retries due to node preemption should not count
toward `max_retries`.
---------

Signed-off-by: Rueian <[email protected]>
Signed-off-by: Rueian <[email protected]>
Co-authored-by: Rueian <[email protected]>
Co-authored-by: Rueian <[email protected]>
Signed-off-by: avigyabb <[email protected]>
kamil-kaczmarek pushed a commit that referenced this pull request Aug 4, 2025
We decided that task retries due to node preemption should not count
toward `max_retries`.
---------

Signed-off-by: Rueian <[email protected]>
Signed-off-by: Rueian <[email protected]>
Co-authored-by: Rueian <[email protected]>
Co-authored-by: Rueian <[email protected]>
Signed-off-by: Kamil Kaczmarek <[email protected]>
mjacar pushed a commit to mjacar/ray that referenced this pull request Aug 5, 2025
…ject#54182)

We decided that task retries due to node preemption should not count
toward `max_retries`.
---------

Signed-off-by: Rueian <[email protected]>
Signed-off-by: Rueian <[email protected]>
Co-authored-by: Rueian <[email protected]>
Co-authored-by: Rueian <[email protected]>
Signed-off-by: Michael Acar <[email protected]>
jugalshah291 pushed a commit to jugalshah291/ray_fork that referenced this pull request Sep 11, 2025
…ject#54182)

We decided that task retries due to node preemption should not count
toward `max_retries`.
---------

Signed-off-by: Rueian <[email protected]>
Signed-off-by: Rueian <[email protected]>
Co-authored-by: Rueian <[email protected]>
Co-authored-by: Rueian <[email protected]>
Signed-off-by: jugalshah291 <[email protected]>
dstrodtman pushed a commit that referenced this pull request Oct 6, 2025
We decided that task retries due to node preemption should not count
toward `max_retries`.
---------

Signed-off-by: Rueian <[email protected]>
Signed-off-by: Rueian <[email protected]>
Co-authored-by: Rueian <[email protected]>
Co-authored-by: Rueian <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
rueian pushed a commit that referenced this pull request Nov 25, 2026
… passed (#68457)

## Why are these changes needed?

Closes #68304.

On SIGTERM, `ray start --block` drains the local node with
`DRAIN_NODE_REASON_PREEMPTION` and a deadline of `now +
RAY_GRACEFUL_SHUTDOWN_DRAIN_TIMEOUT_S` (#64454). If the node is still
busy when that time is up, `_drain_node_before_shutdown` returns and
`kill_all_processes()` sends SIGTERM to the raylet right away.

The raylet records the node as preempted only if the drain deadline is
strictly in the past when it receives SIGTERM (`deadline_timestamp_ms <
now`, `src/ray/raylet/main.cc`). The poll loop ends on the monotonic
clock at about the same instant as the wall-clock deadline, so the
raylet often sees `deadline == now` and records `EXPECTED_TERMINATION`.
Owners then count the failed tasks against `max_retries` (`TaskManager`
only skips the count for `AUTOSCALER_DRAIN_PREEMPTED`), so #54182 does
not take effect for busy nodes.

This PR keeps the raylet's rule as it is and fixes the caller: after the
poll loop times out, it sleeps until wall-clock time is 10 ms past the
deadline it sent, then kills local processes. The extra wait is capped
at 1 s so that a backwards wall-clock jump cannot stall teardown.
Nothing changes when the raylet exits on its own after draining, because
in that case it takes the death reason from the drain request.

## Related issue number

Closes #68304

## Testing

Unit tests (`python/ray/tests/test_draining.py`):

- `_run_drain` now fakes the wall clock in lockstep with the monotonic
clock.
- `test_drain_timeout_kills_only_after_deadline` (16 cases over timeout
and poll interval) checks that a timed-out drain ends strictly after the
deadline sent to the GCS, by at most the margin. Without the fix in
`node.py`, all 16 cases fail.
- `test_drain_early_exit_does_not_wait_for_deadline` checks that an
early exit does not wait.
- `test_wait_until_past_drain_deadline` covers the helper: before, at
and after the deadline, and a backwards clock jump.

```
python -m pytest python/ray/tests/test_draining.py -k "drain_ or sigterm or wait_until"
35 passed, 10 deselected
```

End to end on Kubernetes (minikube, KubeRay v1.6.2,
`rayproject/ray:2.60.0`, `RAY_GRACEFUL_SHUTDOWN_DRAIN_TIMEOUT_S=3`,
grace period 10 s). A task pinned to each worker keeps the node busy,
the worker pods are deleted, and the head reads each node's death reason
from the GCS. Both runs mount `node.py` from a ConfigMap: the stock
2.60.0 file (same sha256 as the image) or the same file with this patch
applied (the hunk applies to 2.60.0 unchanged).

Each run deletes 2 busy workers per round, for 15 rounds (30 nodes):

| `node.py` | `AUTOSCALER_DRAIN_PREEMPTED` | `EXPECTED_TERMINATION` |
|---|---|---|
| stock 2.60.0 | 24 | 6 |
| with this PR | 30 | 0 |

With the stock file, 6 of 30 busy nodes are recorded as
`EXPECTED_TERMINATION` ("received SIGTERM"). With the patch, all 30 are
recorded as preempted.

## Duplicate check

- No open or closed PR references #68304 or touches
`_drain_node_before_shutdown` apart from #64454, which introduced it.
- @MaiAditya offered to work on this in the issue. I replied there
before opening this PR, and the PR follows the approach they outlined
(option 1).
- Option 3 from the issue (treating any `PREEMPTION` drain as preempted
in the raylet) is intentionally left out; it overlaps with #66901.

## AI assistance

I used an AI coding assistant (Claude Code) to draft the change, the
tests and this description. I reviewed every changed line and ran the
tests and the Kubernetes check above myself.

## Checks

- [x] I've signed off every commit (by using the -s flag, i.e., `git
commit -s`) in this PR.
- [x] I've run `black` and `ruff` (pre-commit versions) on the changed
files.
- [x] Unit tests
- [ ] Release tests
- [ ] This PR is not tested :(

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

Signed-off-by: zhangsikai123 <[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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants