Skip to content

[core] Isolate NodeInfoGcsService.GetClusterId on a dedicated lightweight-reads io_context - #64845

Closed
xyuzh wants to merge 1 commit into
ray-project:masterfrom
xyuzh:gcs-getclusterid-starvation
Closed

xyuzh wants to merge 1 commit into
ray-project:masterfrom
xyuzh:gcs-getclusterid-starvation

Conversation

@xyuzh

@xyuzh xyuzh commented Jul 17, 2026 •

Copy link
Copy Markdown
Member

Why are these changes needed?

GetClusterId is a lock-free read of an immutable value (gcs_node_manager.cc), but its handler is posted to the single-threaded node_manager_io_context shared with RegisterNode, GetAllNodeInfo, CheckAlive, etc. During mass node registration the loop's queue delay exceeds client deadlines, and DEADLINE_EXCEEDED maps to TimedOut which IsGrpcRetryableStatus deliberately never retries — so every connecting process's cluster-ID fetch dies on a constant-value read:

[gcs_client.cc] Failed to get cluster ID from GCS server: TimedOut: RPC error: Deadline Exceeded

We hit this as a full cluster bring-up collapse at 400 nodes (~60k potential worker processes) on Ray 2.56. gcs_server_rpc_server_thread_num cannot help (it only sizes completion-queue polling threads, which never run handlers).

Fix: isolate on an existing axis instead of adding dispatch machinery. The GCS already isolates workloads with dedicated io_contexts (GcsServerIOContextPolicy). This PR adds a lightweight_rpc_reads_io_context entry there, plus a small RPC_SERVICE_HANDLER_CUSTOM_AUTH_IN_IO_CONTEXT macro variant that posts one handler to an explicit io_context (_RPC_SERVICE_HANDLER now delegates with the service's main_service_, so all other handlers are unchanged). GetClusterId is the only opt-in; CheckAlive — which is starved by the same storms and causes false node-death — can follow in a later PR.

An earlier revision of this PR ran the handler inline on the gRPC polling thread. That worked, but it created a new hazard class: any future inline handler that gets slow stalls completion-queue polling for the whole server — exactly the failure mode of #55904, reverted in #59448. A dedicated io_context gets identical starvation immunity while a slow handler hurts only itself, and it reuses the GCS's existing isolation pattern (~10-line server diff instead of a new template axis through ServerCallImpl).

The new io_context is lag-probed and health-check-critical (it sits on every client's Connect() path).

Companion PR (client-side half, independently mergeable/revertable): #64847.

Related issue number

None found — searched open PRs/issues for GetClusterId / io_context starvation before opening (closest, orthogonal: #64422 GCS passive-mode refactor). Not a duplicate of in-flight work.

Checks

  • I've signed off every commit (DCO).
  • I've run pre-commit on the changed files.
  • Testing strategy:
    • New //src/ray/rpc/tests:grpc_server_client_test case DedicatedIoContextHandlerRepliesWhileServiceIoContextNeverRuns: the service's main io_context is never run; only a handler posted to the dedicated io_context can reply.
    • New //src/ray/gcs/tests:gcs_server_rpc_test case GetClusterIdNotDelayedByNodeManagerIoContextBacklog: blocks the node_manager io_context with a task that waits until released and asserts a 2s-deadline SyncGetClusterId still succeeds (fails with DEADLINE_EXCEEDED pre-fix).
    • Ran locally (macOS, --dynamic_mode=off): both targets pass.

Per the repo's AI contribution policy: AI assistance was used to develop this change; every changed line was reviewed and the tests above were run locally.

@xyuzh

xyuzh commented Jul 17, 2026

Copy link
Copy Markdown
Member Author

Companion PR for the Ray Data half of the same incident (one engine-boot failure killing an entire Dataset job): #64846.

@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

Reviewed by Cursor Bugbot for commit 5412c2b. Configure here.

Comment thread src/ray/gcs_rpc_client/gcs_client.cc Resolved

@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 inline dispatching for trivial, thread-safe gRPC service handlers (such as GetClusterId) to run directly on the gRPC polling threads, bypassing the main single-threaded io_context queue to prevent delays during high-load events. It also updates GcsClient::FetchClusterId to split the connection timeout budget into bounded per-attempt deadlines. The review feedback highlights two important issues: first, potential RPC storms or silent failures in FetchClusterId if the timeout is misconfigured or set to zero; second, a potential use-after-free or crash during server shutdown because inline dispatch bypasses the io_service_ stop check.

Comment thread src/ray/gcs_rpc_client/gcs_client.cc Outdated
Comment on lines +214 to +228
if (timeout_ms < 0) {
// Defensive: Connect() already normalizes a negative timeout.
timeout_ms = RayConfig::instance().gcs_rpc_server_connect_timeout_s() * 1000;
}
// Split the overall budget into bounded per-attempt deadlines and retry on
// TimedOut. DEADLINE_EXCEEDED is deliberately not retried by
// RetryableGrpcClient (it feeds an unbounded retry queue), so without this
// loop a single deadline spent queueing on a busy GCS is fatal to the whole
// connect. Attempt counting keeps the total at ~timeout_ms without reading
// any clock.
const int64_t per_attempt_ms = std::max<int64_t>(
1,
std::min<int64_t>(RayConfig::instance().gcs_rpc_server_connect_timeout_s() * 1000,
timeout_ms));
const int64_t num_attempts = (timeout_ms + per_attempt_ms - 1) / per_attempt_ms;

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

There are two potential issues with the current attempt/timeout calculation:

  1. RPC Storm / High CPU on Misconfiguration: If gcs_rpc_server_connect_timeout_s is configured to 0 (or a very small value), per_attempt_ms will be evaluated as 1. If timeout_ms is large (e.g., 30000), num_attempts will be 30000. This results in a tight loop of 30,000 attempts, flooding the GCS server with RPCs and consuming 100% CPU.
  2. Silent Failure on Zero Timeout: If timeout_ms is 0, num_attempts will be 0. The loop will be skipped entirely, and the function will return Status::OK() without actually fetching the cluster ID, leaving it Nil.

To prevent these issues, we should defensively normalize timeout_ms and enforce a reasonable minimum for per_attempt_ms (e.g., 1000ms) to avoid tight-loop RPC storms, while ensuring num_attempts is at least 1.

  int64_t config_timeout_ms = RayConfig::instance().gcs_rpc_server_connect_timeout_s() * 1000;
  if (config_timeout_ms <= 0) {
    config_timeout_ms = 5000;
  }
  if (timeout_ms <= 0) {
    timeout_ms = config_timeout_ms;
  }
  // Split the overall budget into bounded per-attempt deadlines and retry on
  // TimedOut. DEADLINE_EXCEEDED is deliberately not retried by
  // RetryableGrpcClient (it feeds an unbounded retry queue), so without this
  // loop a single deadline spent queueing on a busy GCS is fatal to the whole
  // connect. Attempt counting keeps the total at ~timeout_ms without reading
  // any clock.
  const int64_t per_attempt_ms = std::max<int64_t>(
      1000,
      std::min<int64_t>(config_timeout_ms, timeout_ms));
  const int64_t num_attempts = std::max<int64_t>(1, (timeout_ms + per_attempt_ms - 1) / per_attempt_ms);

Comment thread src/ray/rpc/server_call.h Outdated
Comment on lines +284 to +294
if constexpr (DispatchPolicy == ServerCallDispatchPolicy::kInline) {
static_assert(!std::is_base_of_v<DelayedServiceHandler, ServiceHandler>,
"Inline dispatch would block a gRPC polling thread until the "
"service handler finishes initializing; use kPosted instead.");
// Run the handler inline on the gRPC polling thread, skipping the
// io_context so this call cannot queue behind unrelated work. The
// handler must be non-blocking, O(1), and thread-safe (it may run
// concurrently on every polling thread). RAY_testing_asio_delay_us does
// not apply to inline methods: there is no post to delay.
HandleRequestImpl(auth_success, token_auth_failed, cluster_id_auth_failed);
} else if (!io_service_.stopped()) {

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

During server shutdown, io_service_ is stopped, which prevents new posted handlers from executing. However, because inline dispatch bypasses the io_service_ post queue, an inline handler could still execute HandleRequestImpl even if io_service_.stopped() is true. This can lead to use-after-free bugs or crashes if the underlying service handler (e.g., GcsNodeManager) is already being destroyed.

We should check !io_service_.stopped() before executing the inline handler to ensure safe shutdown behavior.

    if constexpr (DispatchPolicy == ServerCallDispatchPolicy::kInline) {
      static_assert(!std::is_base_of_v<DelayedServiceHandler, ServiceHandler>,
                    "Inline dispatch would block a gRPC polling thread until the "
                    "service handler finishes initializing; use kPosted instead.");
      // Run the handler inline on the gRPC polling thread, skipping the
      // io_context so this call cannot queue behind unrelated work. The
      // handler must be non-blocking, O(1), and thread-safe (it may run
      // concurrently on every polling thread). RAY_testing_asio_delay_us does
      // not apply to inline methods: there is no post to delay.
      if (!io_service_.stopped()) {
        HandleRequestImpl(auth_success, token_auth_failed, cluster_id_auth_failed);
      }
    } else if (!io_service_.stopped()) {

@xyuzh xyuzh added the go add ONLY when ready to merge, run all tests label Jul 17, 2026
@xyuzh
xyuzh force-pushed the gcs-getclusterid-starvation branch from 5412c2b to 57b768e Compare July 17, 2026 16:13
@xyuzh xyuzh changed the title [core] Fix GetClusterId starvation on the GCS node_manager io_context [core] Add opt-in inline dispatch for gRPC server calls; answer NodeInfoGcsService.GetClusterId on the polling thread Jul 17, 2026
@xyuzh

xyuzh commented Jul 17, 2026 •

Copy link
Copy Markdown
Member Author

Split per review preference: this PR now carries only the server-side inline-dispatch change; the client-side bounded connect retry moved to its own independently mergeable PR: #64847. The retry PR also hardens the attempt math against zero/negative timeout configs (no silent-OK skip, no 1 ms-attempt RPC storm), with regression tests.

@ray-gardener ray-gardener Bot added the core Issues that should be addressed in Ray Core label Jul 17, 2026
@robertnishihara robertnishihara self-assigned this Jul 22, 2026
…ight-reads io_context

GetClusterId is a lock-free read of an immutable value, but its handler is
posted to the single-threaded node_manager_io_context shared with
RegisterNode/GetAllNodeInfo/CheckAlive. During mass node registration the
loop's queue delay exceeds client deadlines, and DEADLINE_EXCEEDED maps to
TimedOut which IsGrpcRetryableStatus deliberately never retries — so every
connecting process's cluster-ID fetch dies on a constant-value read
(observed as cluster bring-up collapse at 400 nodes).

Fix by isolation on an existing axis instead of new dispatch machinery: add
a dedicated lightweight_rpc_reads_io_context to GcsServerIOContextPolicy
(the GCS's existing mechanism for isolating workloads), and a
RPC_SERVICE_HANDLER_CUSTOM_AUTH_IN_IO_CONTEXT macro variant that posts one
handler to an explicit io_context (_RPC_SERVICE_HANDLER now delegates with
the service's main_service_). GetClusterId is the only opt-in; CheckAlive,
which is starved by the same storms, can follow. A slow handler on the
dedicated loop hurts only itself — unlike inline dispatch on the gRPC
polling thread, which ray-project#55904 tried wholesale and ray-project#59448 reverted for a 2x
plasma-put regression.

Tests: an rpc-layer test proving a handler bound to a dedicated io_context
replies while the service's io_context never runs, and a GCS-layer
regression test that blocks the node_manager io_context and asserts a
2s-deadline SyncGetClusterId still succeeds (fails pre-fix).

Signed-off-by: xyuzh <[email protected]>
@xyuzh
xyuzh force-pushed the gcs-getclusterid-starvation branch from 57b768e to d437c45 Compare July 31, 2026 20:14
@xyuzh xyuzh changed the title [core] Add opt-in inline dispatch for gRPC server calls; answer NodeInfoGcsService.GetClusterId on the polling thread [core] Isolate NodeInfoGcsService.GetClusterId on a dedicated lightweight-reads io_context Jul 31, 2026
@xyuzh

xyuzh commented Jul 31, 2026

Copy link
Copy Markdown
Member Author

Reworked per design review: replaced the inline-dispatch template machinery with a dedicated lightweight_rpc_reads_io_context (the GCS's existing isolation pattern) — see the updated PR description. Strategic companion that removes most of the fetch load altogether: #65156.

goutamvenkat-anyscale pushed a commit that referenced this pull request Aug 3, 2026
…DataContext.max_consecutive_actor_init_deaths (#64846)

## Why are these changes needed?

A single actor whose `__init__` fails (e.g. an LLM engine failing to
boot) kills the whole Dataset job: the readiness ref resolves with
`ActorDiedError`, `_ActorPool.pending_to_running` re-raises it, and the
metadata-task branch of `process_completed_tasks` has no guard
(`max_errored_blocks` only protects the `DataOpTask` branch), so the
exception fails the execution. `max_restarts=-1` (Ray Data's own
default) cannot help because Ray Core does not restart actors whose
creation task failed — the death is a `USER_ERROR` and
`gcs_actor_manager` zeroes `remaining_restarts`. At an N-actor pool, any
per-boot flake probability p becomes job-death probability 1-(1-p)^N: at
1,600 vLLM engines, three separate boot-flake classes (port races, VRAM
residue, ramp-wave timeouts) each repeatedly killed full production
runs.

This PR catches the failure at the pool boundary (`_task_done_callback`)
and charges it against a new per-operator budget,
`DataContext.max_consecutive_actor_init_deaths` (env
`RAY_DATA_MAX_CONSECUTIVE_ACTOR_INIT_DEATHS`; default `0` preserves
today's fail-fast behavior; `-1` = unlimited). The counter is
**consecutive**: it resets whenever any actor of the operator
initializes successfully — the same semantics as the existing
`actor_init_max_retries`. Sporadic boot flakes in a progressing pipeline
are tolerated indefinitely within the budget, while a systemically
broken UDF (bad model path) never resets the counter and exhausts the
budget, so no separate systemic-failure heuristic or hardcoded threshold
is needed. Tolerated failures are logged with a running count and the
actor autoscaler starts a replacement (the pool is below target size,
and the below-min branch runs before the no-input guard, so no explicit
re-provision is needed). Counting is per actor incarnation, after any
in-actor `actor_init_retry_on_errors` retries.

## Production-scale evidence

Two byte-identical 1,600-engine / 70M-caption video-captioning runs on
Anyscale (CoreWeave, RTX PRO 6000 fleet), same input corpus and knobs;
the only variable is boot-failure handling (run against the earlier
cumulative-budget revision of this patch; the consecutive-counting
revision is strictly more permissive for the interleaved-flake pattern
observed):

| | Baseline (app-level workaround that swallows pending_to_running
errors) | This patch (workaround disabled, budget=200) |
|---|---|---|
| Outcome | SUCCEEDED | SUCCEEDED |
| Captions written | 69,982,028 | 69,982,028 (identical) |
| Wall time | 5,525 s | 5,778 s |
| Real engine-boot failures absorbed | 2 | 8 (single ramp-wave burst;
every one logged and the pool recovered to its full 1,500 floor) |

A separate fault-injection job validated both semantics
deterministically on the same stack: 3 injected creation-task failures
with budget 5 → dataset completes with correct output; budget 1 →
tolerates one, then re-raises the original `ActorDiedError` after
exactly 2 incarnations.

Companion PR for the GCS-side half of the same incident: #64845.

## Related issue number

None found — searched open PRs/issues for actor init/boot failure
tolerance before opening; no in-flight work. Adjacent context: the vLLM
batch stage's `os._exit(1)` workaround handles post-boot engine death
via `max_restarts` (see #59522), but nothing covers creation-task
failures.

## Checks

- [x] I've signed off every commit (DCO).
- [x] I've run pre-commit on the changed files.
- [x] Testing strategy:
- New tests in `python/ray/data/tests/test_actor_pool_map_operator.py`:
`test_actor_init_death_budget` (parametrized: budget covers / exceeded /
unlimited), `test_actor_init_death_budget_with_in_actor_retries` (proves
incarnation-level counting), `test_on_actor_init_death_unit` (raise
timing against the consecutive budget, reset-on-success, re-raise
identity).
- `python -m pytest
python/ray/data/tests/test_actor_pool_map_operator.py -k "init_death or
init_failure"` → 8 passed (pytest 7.4.4). Existing
`test_actor_init_failure_retry` and `test_actor_pool_map_operator_init`
pass unchanged.

Per the repo's AI contribution policy: AI assistance was used to develop
this change; every changed line was reviewed, the tests above were run
locally, and the change was exercised end-to-end at production scale as
described.

---------

Signed-off-by: xyuzh <[email protected]>
Artimislyy pushed a commit to Artimislyy/ray that referenced this pull request Aug 11, 2026
…DataContext.max_consecutive_actor_init_deaths (ray-project#64846)

## Why are these changes needed?

A single actor whose `__init__` fails (e.g. an LLM engine failing to
boot) kills the whole Dataset job: the readiness ref resolves with
`ActorDiedError`, `_ActorPool.pending_to_running` re-raises it, and the
metadata-task branch of `process_completed_tasks` has no guard
(`max_errored_blocks` only protects the `DataOpTask` branch), so the
exception fails the execution. `max_restarts=-1` (Ray Data's own
default) cannot help because Ray Core does not restart actors whose
creation task failed — the death is a `USER_ERROR` and
`gcs_actor_manager` zeroes `remaining_restarts`. At an N-actor pool, any
per-boot flake probability p becomes job-death probability 1-(1-p)^N: at
1,600 vLLM engines, three separate boot-flake classes (port races, VRAM
residue, ramp-wave timeouts) each repeatedly killed full production
runs.

This PR catches the failure at the pool boundary (`_task_done_callback`)
and charges it against a new per-operator budget,
`DataContext.max_consecutive_actor_init_deaths` (env
`RAY_DATA_MAX_CONSECUTIVE_ACTOR_INIT_DEATHS`; default `0` preserves
today's fail-fast behavior; `-1` = unlimited). The counter is
**consecutive**: it resets whenever any actor of the operator
initializes successfully — the same semantics as the existing
`actor_init_max_retries`. Sporadic boot flakes in a progressing pipeline
are tolerated indefinitely within the budget, while a systemically
broken UDF (bad model path) never resets the counter and exhausts the
budget, so no separate systemic-failure heuristic or hardcoded threshold
is needed. Tolerated failures are logged with a running count and the
actor autoscaler starts a replacement (the pool is below target size,
and the below-min branch runs before the no-input guard, so no explicit
re-provision is needed). Counting is per actor incarnation, after any
in-actor `actor_init_retry_on_errors` retries.

## Production-scale evidence

Two byte-identical 1,600-engine / 70M-caption video-captioning runs on
Anyscale (CoreWeave, RTX PRO 6000 fleet), same input corpus and knobs;
the only variable is boot-failure handling (run against the earlier
cumulative-budget revision of this patch; the consecutive-counting
revision is strictly more permissive for the interleaved-flake pattern
observed):

| | Baseline (app-level workaround that swallows pending_to_running
errors) | This patch (workaround disabled, budget=200) |
|---|---|---|
| Outcome | SUCCEEDED | SUCCEEDED |
| Captions written | 69,982,028 | 69,982,028 (identical) |
| Wall time | 5,525 s | 5,778 s |
| Real engine-boot failures absorbed | 2 | 8 (single ramp-wave burst;
every one logged and the pool recovered to its full 1,500 floor) |

A separate fault-injection job validated both semantics
deterministically on the same stack: 3 injected creation-task failures
with budget 5 → dataset completes with correct output; budget 1 →
tolerates one, then re-raises the original `ActorDiedError` after
exactly 2 incarnations.

Companion PR for the GCS-side half of the same incident: ray-project#64845.

## Related issue number

None found — searched open PRs/issues for actor init/boot failure
tolerance before opening; no in-flight work. Adjacent context: the vLLM
batch stage's `os._exit(1)` workaround handles post-boot engine death
via `max_restarts` (see ray-project#59522), but nothing covers creation-task
failures.

## Checks

- [x] I've signed off every commit (DCO).
- [x] I've run pre-commit on the changed files.
- [x] Testing strategy:
- New tests in `python/ray/data/tests/test_actor_pool_map_operator.py`:
`test_actor_init_death_budget` (parametrized: budget covers / exceeded /
unlimited), `test_actor_init_death_budget_with_in_actor_retries` (proves
incarnation-level counting), `test_on_actor_init_death_unit` (raise
timing against the consecutive budget, reset-on-success, re-raise
identity).
- `python -m pytest
python/ray/data/tests/test_actor_pool_map_operator.py -k "init_death or
init_failure"` → 8 passed (pytest 7.4.4). Existing
`test_actor_init_failure_retry` and `test_actor_pool_map_operator_init`
pass unchanged.

Per the repo's AI contribution policy: AI assistance was used to develop
this change; every changed line was reviewed, the tests above were run
locally, and the change was exercised end-to-end at production scale as
described.

---------

Signed-off-by: xyuzh <[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 Aug 15, 2026
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
…DataContext.max_consecutive_actor_init_deaths (ray-project#64846)

## Why are these changes needed?

A single actor whose `__init__` fails (e.g. an LLM engine failing to
boot) kills the whole Dataset job: the readiness ref resolves with
`ActorDiedError`, `_ActorPool.pending_to_running` re-raises it, and the
metadata-task branch of `process_completed_tasks` has no guard
(`max_errored_blocks` only protects the `DataOpTask` branch), so the
exception fails the execution. `max_restarts=-1` (Ray Data's own
default) cannot help because Ray Core does not restart actors whose
creation task failed — the death is a `USER_ERROR` and
`gcs_actor_manager` zeroes `remaining_restarts`. At an N-actor pool, any
per-boot flake probability p becomes job-death probability 1-(1-p)^N: at
1,600 vLLM engines, three separate boot-flake classes (port races, VRAM
residue, ramp-wave timeouts) each repeatedly killed full production
runs.

This PR catches the failure at the pool boundary (`_task_done_callback`)
and charges it against a new per-operator budget,
`DataContext.max_consecutive_actor_init_deaths` (env
`RAY_DATA_MAX_CONSECUTIVE_ACTOR_INIT_DEATHS`; default `0` preserves
today's fail-fast behavior; `-1` = unlimited). The counter is
**consecutive**: it resets whenever any actor of the operator
initializes successfully — the same semantics as the existing
`actor_init_max_retries`. Sporadic boot flakes in a progressing pipeline
are tolerated indefinitely within the budget, while a systemically
broken UDF (bad model path) never resets the counter and exhausts the
budget, so no separate systemic-failure heuristic or hardcoded threshold
is needed. Tolerated failures are logged with a running count and the
actor autoscaler starts a replacement (the pool is below target size,
and the below-min branch runs before the no-input guard, so no explicit
re-provision is needed). Counting is per actor incarnation, after any
in-actor `actor_init_retry_on_errors` retries.

## Production-scale evidence

Two byte-identical 1,600-engine / 70M-caption video-captioning runs on
Anyscale (CoreWeave, RTX PRO 6000 fleet), same input corpus and knobs;
the only variable is boot-failure handling (run against the earlier
cumulative-budget revision of this patch; the consecutive-counting
revision is strictly more permissive for the interleaved-flake pattern
observed):

| | Baseline (app-level workaround that swallows pending_to_running
errors) | This patch (workaround disabled, budget=200) |
|---|---|---|
| Outcome | SUCCEEDED | SUCCEEDED |
| Captions written | 69,982,028 | 69,982,028 (identical) |
| Wall time | 5,525 s | 5,778 s |
| Real engine-boot failures absorbed | 2 | 8 (single ramp-wave burst;
every one logged and the pool recovered to its full 1,500 floor) |

A separate fault-injection job validated both semantics
deterministically on the same stack: 3 injected creation-task failures
with budget 5 → dataset completes with correct output; budget 1 →
tolerates one, then re-raises the original `ActorDiedError` after
exactly 2 incarnations.

Companion PR for the GCS-side half of the same incident: ray-project#64845.

## Related issue number

None found — searched open PRs/issues for actor init/boot failure
tolerance before opening; no in-flight work. Adjacent context: the vLLM
batch stage's `os._exit(1)` workaround handles post-boot engine death
via `max_restarts` (see ray-project#59522), but nothing covers creation-task
failures.

## Checks

- [x] I've signed off every commit (DCO).
- [x] I've run pre-commit on the changed files.
- [x] Testing strategy:
- New tests in `python/ray/data/tests/test_actor_pool_map_operator.py`:
`test_actor_init_death_budget` (parametrized: budget covers / exceeded /
unlimited), `test_actor_init_death_budget_with_in_actor_retries` (proves
incarnation-level counting), `test_on_actor_init_death_unit` (raise
timing against the consecutive budget, reset-on-success, re-raise
identity).
- `python -m pytest
python/ray/data/tests/test_actor_pool_map_operator.py -k "init_death or
init_failure"` → 8 passed (pytest 7.4.4). Existing
`test_actor_init_failure_retry` and `test_actor_pool_map_operator_init`
pass unchanged.

Per the repo's AI contribution policy: AI assistance was used to develop
this change; every changed line was reviewed, the tests above were run
locally, and the change was exercised end-to-end at production scale as
described.

---------

Signed-off-by: xyuzh <[email protected]>
Signed-off-by: 400Ping <[email protected]>
@github-actions

Copy link
Copy Markdown

This pull request has been automatically closed because there has been no more activity in the 14 days
since being marked stale.

Please feel free to reopen or open a new pull request if you'd still like this to be addressed.

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

Thanks again for your contribution!

@github-actions github-actions Bot closed this Aug 29, 2026
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…DataContext.max_consecutive_actor_init_deaths (ray-project#64846)

## Why are these changes needed?

A single actor whose `__init__` fails (e.g. an LLM engine failing to
boot) kills the whole Dataset job: the readiness ref resolves with
`ActorDiedError`, `_ActorPool.pending_to_running` re-raises it, and the
metadata-task branch of `process_completed_tasks` has no guard
(`max_errored_blocks` only protects the `DataOpTask` branch), so the
exception fails the execution. `max_restarts=-1` (Ray Data's own
default) cannot help because Ray Core does not restart actors whose
creation task failed — the death is a `USER_ERROR` and
`gcs_actor_manager` zeroes `remaining_restarts`. At an N-actor pool, any
per-boot flake probability p becomes job-death probability 1-(1-p)^N: at
1,600 vLLM engines, three separate boot-flake classes (port races, VRAM
residue, ramp-wave timeouts) each repeatedly killed full production
runs.

This PR catches the failure at the pool boundary (`_task_done_callback`)
and charges it against a new per-operator budget,
`DataContext.max_consecutive_actor_init_deaths` (env
`RAY_DATA_MAX_CONSECUTIVE_ACTOR_INIT_DEATHS`; default `0` preserves
today's fail-fast behavior; `-1` = unlimited). The counter is
**consecutive**: it resets whenever any actor of the operator
initializes successfully — the same semantics as the existing
`actor_init_max_retries`. Sporadic boot flakes in a progressing pipeline
are tolerated indefinitely within the budget, while a systemically
broken UDF (bad model path) never resets the counter and exhausts the
budget, so no separate systemic-failure heuristic or hardcoded threshold
is needed. Tolerated failures are logged with a running count and the
actor autoscaler starts a replacement (the pool is below target size,
and the below-min branch runs before the no-input guard, so no explicit
re-provision is needed). Counting is per actor incarnation, after any
in-actor `actor_init_retry_on_errors` retries.

## Production-scale evidence

Two byte-identical 1,600-engine / 70M-caption video-captioning runs on
Anyscale (CoreWeave, RTX PRO 6000 fleet), same input corpus and knobs;
the only variable is boot-failure handling (run against the earlier
cumulative-budget revision of this patch; the consecutive-counting
revision is strictly more permissive for the interleaved-flake pattern
observed):

| | Baseline (app-level workaround that swallows pending_to_running
errors) | This patch (workaround disabled, budget=200) |
|---|---|---|
| Outcome | SUCCEEDED | SUCCEEDED |
| Captions written | 69,982,028 | 69,982,028 (identical) |
| Wall time | 5,525 s | 5,778 s |
| Real engine-boot failures absorbed | 2 | 8 (single ramp-wave burst;
every one logged and the pool recovered to its full 1,500 floor) |

A separate fault-injection job validated both semantics
deterministically on the same stack: 3 injected creation-task failures
with budget 5 → dataset completes with correct output; budget 1 →
tolerates one, then re-raises the original `ActorDiedError` after
exactly 2 incarnations.

Companion PR for the GCS-side half of the same incident: ray-project#64845.

## Related issue number

None found — searched open PRs/issues for actor init/boot failure
tolerance before opening; no in-flight work. Adjacent context: the vLLM
batch stage's `os._exit(1)` workaround handles post-boot engine death
via `max_restarts` (see ray-project#59522), but nothing covers creation-task
failures.

## Checks

- [x] I've signed off every commit (DCO).
- [x] I've run pre-commit on the changed files.
- [x] Testing strategy:
- New tests in `python/ray/data/tests/test_actor_pool_map_operator.py`:
`test_actor_init_death_budget` (parametrized: budget covers / exceeded /
unlimited), `test_actor_init_death_budget_with_in_actor_retries` (proves
incarnation-level counting), `test_on_actor_init_death_unit` (raise
timing against the consecutive budget, reset-on-success, re-raise
identity).
- `python -m pytest
python/ray/data/tests/test_actor_pool_map_operator.py -k "init_death or
init_failure"` → 8 passed (pytest 7.4.4). Existing
`test_actor_init_failure_retry` and `test_actor_pool_map_operator_init`
pass unchanged.

Per the repo's AI contribution policy: AI assistance was used to develop
this change; every changed line was reviewed, the tests above were run
locally, and the change was exercised end-to-end at production scale as
described.

---------

Signed-off-by: xyuzh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests 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.

2 participants