Skip to content

[Job] Retry transient RPC errors in job monitor during GCS failover - #65027

Open
f0rest9999 wants to merge 1 commit into
ray-project:masterfrom
f0rest9999:fix/job-monitor-gcs-ft-transient-retry
Open

f0rest9999 wants to merge 1 commit into
ray-project:masterfrom
f0rest9999:fix/job-monitor-gcs-ft-transient-retry

Conversation

@f0rest9999

Copy link
Copy Markdown

Description:

During GCS HA failover (kill head pod), the job monitoring loop in dashboard_agent receives gRPC CANCELLED/UNAVAILABLE errors. The current except Exception handler does not distinguish transient errors from permanent failures, immediately marking jobs as FAILED — even though the Driver process and Worker Actors remain alive on the worker node.

This is inconsistent with how other Ray components handle GCS disconnections:

  • Raylet (C++): has NotifyGCSRestart reconnection mechanism
  • CoreWorker (C++): has automatic reconnection
  • job_manager.py (Python): no retry ← this PR fixes it

Changes:

  • Add _is_transient_rpc_error() to identify CANCELLED (code 1) and UNAVAILABLE (code 14) gRPC errors
  • Wrap get_status() in try/except — if GCS is also unreachable and error is transient, retry
  • If get_status() succeeds but original error is transient, retry instead of marking FAILED
  • Exponential backoff: min(2^n, 30)s, max 40 attempts (~20min)
  • Reset retry counter on successful supervisor ping
  • Add unit test for _is_transient_rpc_error() helper

Configurable via RAY_JOB_MONITOR_MAX_TRANSIENT_ERROR_RETRIES env var (default 40).

Related issues

Fixes #65025

Additional information

  • Verified on a production GCS HA cluster with a high-frequency actor workload (256 actors batch create/kill)
  • Kill head pod → job stays RUNNING → GCS recovers → monitoring resumes
  • Non-transient errors still immediately mark FAILED (no behavior change)
  • Test: pytest python/ray/dashboard/modules/job/tests/test_job_manager.py::test_job_monitor_retries_transient_rpc_errors -v

@f0rest9999
f0rest9999 requested a review from a team as a code owner July 27, 2026 07:26

@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 enhances the Ray job manager's fault tolerance by retrying transient RPC errors (such as CANCELLED or UNAVAILABLE) during GCS failover with exponential backoff. A critical issue was identified in the error handling logic: if get_status fails with a transient RPC error while handling a non-transient original exception, the monitoring loop can still crash. It is recommended to check if either the original exception or the status-retrieval exception is transient to prevent this crash.

Comment on lines +302 to +303
except Exception:
if _is_transient_rpc_error(e):

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

If get_status fails due to a transient RPC error (e.g., GCS is undergoing failover), but the original exception e is a non-transient error (such as ActorDiedError), the current implementation will not retry. Instead, it will set job_status = None and attempt to call put_status later in the block. Since GCS is down, put_status will also fail with a transient RPC error, which is not caught and will propagate, crashing the job monitoring loop entirely.

To prevent the monitoring loop from crashing when GCS is temporarily unreachable, we should retry if either the original exception e is transient or the exception raised by get_status is transient.

Suggested change
except Exception:
if _is_transient_rpc_error(e):
except Exception as get_status_exc:
if _is_transient_rpc_error(e) or _is_transient_rpc_error(get_status_exc):

@f0rest9999
f0rest9999 force-pushed the fix/job-monitor-gcs-ft-transient-retry branch from d3c9ac4 to 5e37735 Compare July 27, 2026 07:37
@f0rest9999
f0rest9999 force-pushed the fix/job-monitor-gcs-ft-transient-retry branch from 5e37735 to 10bc199 Compare July 27, 2026 07:44
@ray-gardener ray-gardener Bot added core Issues that should be addressed in Ray Core community-contribution Contributed by the community labels Jul 27, 2026
@f0rest9999
f0rest9999 force-pushed the fix/job-monitor-gcs-ft-transient-retry branch from 10bc199 to 1bc8a61 Compare July 27, 2026 08:17
@f0rest9999
f0rest9999 force-pushed the fix/job-monitor-gcs-ft-transient-retry branch from 1bc8a61 to b14f616 Compare July 27, 2026 08:23
@f0rest9999
f0rest9999 force-pushed the fix/job-monitor-gcs-ft-transient-retry branch from b14f616 to 6354315 Compare July 27, 2026 08:36
@f0rest9999
f0rest9999 force-pushed the fix/job-monitor-gcs-ft-transient-retry branch 2 times, most recently from 02b4177 to 9cf3114 Compare July 27, 2026 09:14
@f0rest9999
f0rest9999 force-pushed the fix/job-monitor-gcs-ft-transient-retry branch 2 times, most recently from 740589c to 01ad234 Compare July 27, 2026 14:02
@f0rest9999
f0rest9999 force-pushed the fix/job-monitor-gcs-ft-transient-retry branch from 01ad234 to 51b4421 Compare August 3, 2026 02:53

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

Stale Bugbot comment from a previous run.

@f0rest9999
f0rest9999 force-pushed the fix/job-monitor-gcs-ft-transient-retry branch from 51b4421 to 30674da Compare August 3, 2026 06:25
@rueian rueian added the go add ONLY when ready to merge, run all tests label Aug 3, 2026
@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 18, 2026
@f0rest9999

Copy link
Copy Markdown
Author

I'm still waiting for reviewer feedback~

@github-actions github-actions Bot added unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it. and removed stale The issue is stale. It will be closed within 7 days unless there are further conversation labels Aug 18, 2026
rueian pushed a commit that referenced this pull request Sep 2, 2026
Fixes #65608.

## Problem

`JobManager` records the head's GCS address at construction and passes
it to
every detached `JobSupervisor`, which builds its own `GcsClient` from
it:

```python
# job_manager.py
self._gcs_address = gcs_client.address
...
supervisor = self._supervisor_actor_cls.options(...).remote(
    submission_id, entrypoint, metadata or {}, self._gcs_address, self._cluster_id_hex, self._logs_dir,
)

# job_supervisor.py
gcs_client = GcsClient(address=gcs_address, cluster_id=cluster_id_hex)
```

With GCS fault tolerance the head pod can be replaced while a job keeps
running
on a worker. The worker's raylet and CoreWorker reconnect through the
stable head
service, but the supervisor's separately constructed client stays pinned
to the
old address. When the entrypoint exits with code 0,
`put_status(SUCCEEDED)` times
out, the broad exception handler writes `FAILED`, and the job is
reported as
`JOB_SUPERVISOR_ACTOR_DIED` despite having succeeded.

## Fix

Use the GCS client already configured for the worker process hosting the
actor,
which reconnects through the stable head service:

```python
gcs_client = ray._private.worker.global_worker.gcs_client
```

`gcs_address` and `cluster_id_hex` existed only to build that client, so
they are
removed from the supervisor's signature and from the `JobManager` side.
The same
file already uses worker-local state a few lines below
(`ray._private.worker.global_worker.node`), so this follows existing
practice
here. Net -4 lines.

## Not a duplicate

`#65027` also concerns jobs during GCS failover, but patches
`job_manager.py`'s
monitor loop to retry transient gRPC errors. This patches
`job_supervisor.py`'s
client construction. They are complementary: retries in the monitor
cannot help a
supervisor whose own client is pinned to an address nothing is listening
on.

No other open PR references #65608. `gh pr list --search
"job_supervisor"` and
`--search "JobSupervisor gcs"` surfaced only #65006, #47166, #61099 and
#65027,
none of which touch this client construction.

## Testing

Added `test_job_succeeds_when_manager_gcs_address_is_stale` in
`python/ray/dashboard/modules/job/tests/test_job_manager.py`. The full
reported
path needs KubeRay with GCS FT and a head replacement; the essential
condition is
that the address the manager recorded is unusable while the worker's own
client
still works. `_StaleAddressGcsClient` wraps the live client and reports
`127.0.0.1:1`, which is reserved and never bound.

```
python -m pytest python/ray/dashboard/modules/job/tests/test_job_manager.py -k stale -q
```

- on master: `1 failed` — the supervisor cannot persist the terminal
status
- with this change: `1 passed` in 12.70s

Surrounding tests that exercise supervisor construction, job submission,
supervisor logging and the existing failover path:

```
python -m pytest python/ray/dashboard/modules/job/tests/test_job_manager.py -q -p no:randomly \
  -k "stale or network_fault_tolerance or supervisor_log_json or supervisor_logs_saved \
      or submit_no_ray_address or get_all_job_info"

7 passed, 63 deselected in 82.54s
```

Lint, using the repo's own configuration:

```
pre-commit run --files python/ray/dashboard/modules/job/job_supervisor.py \
  python/ray/dashboard/modules/job/job_manager.py \
  python/ray/dashboard/modules/job/tests/test_job_manager.py

ruff / pydoclint / black / Ray docstyle / semgrep / import order: all Passed
```

I did not get a clean full-module run locally: `test_job_manager.py` in
its
entirety stalls on this machine shortly after start (pytest idle at 0%
CPU, no
Ray processes alive) both with and without this change, so it looks
unrelated to
it. Happy to run anything specific a reviewer wants.

Ray installed as `ray[default]` 2.58.0 with `python/ray/setup-dev.py`
symlinks;
tested on macOS (Apple silicon).

## Out of scope

The `except Exception` handler in `JobSupervisor.run` reclassifies a
failure to
*persist* an already-known result as
`JOB_ENTRYPOINT_COMMAND_START_ERROR`. That
is a real second defect, but transient-error handling in this area is
the subject
of #65027, so it is left alone here to avoid a collision.

## AI usage

AI assistance was used for the investigation, the code change, and the
test. I
reviewed every changed line, ran the commands above myself, and can
explain and
defend the change.

Signed-off-by: Roshan Sharma <[email protected]>
Comment on lines +60 to +62
if isinstance(exc, RpcError):
error_msg = str(exc).lower()
return "cancelled" in error_msg or "unavailable" in error_msg

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.

why is this needed?

Comment on lines +51 to +53
_MAX_TRANSIENT_ERROR_RETRIES = ray_constants.env_integer(
"RAY_JOB_MONITOR_MAX_TRANSIENT_ERROR_RETRIES", 40
)

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.

We should not introduce a new RAY_JOB_MONITOR_MAX_TRANSIENT_ERROR_RETRIES but just derive that from RAY_gcs_rpc_server_reconnect_timeout_s.

@@ -1656,5 +1656,52 @@ async def test_no_task_events_exported(shared_ray_instance, tmp_path):
assert "JobSupervisor" not in t.name


@pytest.mark.asyncio
async def test_job_monitor_retries_transient_rpc_errors(job_manager, tmp_path):

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.

This test also passes on master, so it doesn't actually test your changes.

job_supervisor = self._get_actor_for_job(job_id)
if job_supervisor is not None:
ray.kill(job_supervisor, no_restart=True)
# Skip kill if we exited because GCS was unreachable — the job may still

@rueian rueian Sep 4, 2026 •

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.

If we exit the monitor, we should kill the job. We can't leave a job running without a monitor. If we want to keep the job running, we should also keep the monitor.

@f0rest9999
f0rest9999 force-pushed the fix/job-monitor-gcs-ft-transient-retry branch from 30674da to b0aeebe Compare September 5, 2026 06:57

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

Stale Bugbot comment from a previous run.

@f0rest9999
f0rest9999 force-pushed the fix/job-monitor-gcs-ft-transient-retry branch from b0aeebe to efcce29 Compare September 5, 2026 08:19

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

Stale Bugbot comment from a previous run.

@f0rest9999
f0rest9999 force-pushed the fix/job-monitor-gcs-ft-transient-retry branch from efcce29 to cda6eed Compare September 5, 2026 09:08

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

Stale Bugbot comment from a previous run.

During a GCS HA failover, RPCs issued by the job monitoring loop in the
dashboard agent fail with gRPC CANCELLED/UNAVAILABLE. Those codes only say
that the RPC never reached its destination, but the monitor's fallback
branch treats any unrecognized exception as "the JobSupervisor is gone": it
marks the job FAILED and kills the supervisor, even though the driver and
its actors are still alive. This makes a transient GCS restart look like a
job failure.

Exclude transient RPC errors from that fallback and keep monitoring instead.
The retry window is derived from RAY_gcs_rpc_server_reconnect_timeout_s
rather than from a new knob: once the GCS has been unreachable for longer
than that, the GCS client gives up and tears the process down anyway, so
there is nothing to be gained by retrying for longer. While the window is
open the monitor issues no GCS RPC of its own, since reading the job status
there would be one more RPC to the component that is currently unreachable.

The window measures only consecutive failed pings of the JobSupervisor,
because that is the one RPC the monitor makes that carries information about
it. A transient error from any other call means the iteration never got as
far as asking the supervisor anything, so it resets the streak and is simply
retried; a successful ping resets the streak as well, even after the window
has elapsed, since an answer is stronger evidence than a timeout. The one
asymmetry is that an elapsed window is not reset by transient errors, so
that the conclusion can still be recorded once the GCS answers.

Converging a job requires the GCS, because both the terminal status write
and the supervisor kill go through it, so an exhausted window cannot be
acted on while the GCS is still unreachable. The status read and the status
write in the error handler therefore retry on the next iteration instead of
letting a transient failure escape the monitor: a job is never left running
without a monitor, and the conclusion is recorded as soon as the GCS answers
again. The defensive ray.kill after the loop is guarded the same way, except
that it is only logged: the job already has a terminal status by then, so
there is nothing left to converge.

Signed-off-by: chengzitong <[email protected]>
Signed-off-by: f0rest9999 <[email protected]>
@f0rest9999
f0rest9999 force-pushed the fix/job-monitor-gcs-ft-transient-retry branch from cda6eed to ce8bdb9 Compare September 5, 2026 10:01

@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 ce8bdb9. Configure here.

# The supervisor answered, so it is alive and any earlier streak of
# failed pings is over -- including one long enough to have presumed
# it gone, since an answer is better evidence than a timed-out window.
first_failed_ping_time = None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Monitor ignores terminal status after retry

Medium Severity

A transient failure from put_status sends the loop back to the top, where a terminal job_status is never treated as done. If that write actually landed and the next ping succeeds, the monitor never breaks or kills the JobSupervisor, so a FAILED job can keep running with its monitor stuck in the loop.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit ce8bdb9. Configure here.

nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…oject#65686)

Fixes ray-project#65608.

## Problem

`JobManager` records the head's GCS address at construction and passes
it to
every detached `JobSupervisor`, which builds its own `GcsClient` from
it:

```python
# job_manager.py
self._gcs_address = gcs_client.address
...
supervisor = self._supervisor_actor_cls.options(...).remote(
    submission_id, entrypoint, metadata or {}, self._gcs_address, self._cluster_id_hex, self._logs_dir,
)

# job_supervisor.py
gcs_client = GcsClient(address=gcs_address, cluster_id=cluster_id_hex)
```

With GCS fault tolerance the head pod can be replaced while a job keeps
running
on a worker. The worker's raylet and CoreWorker reconnect through the
stable head
service, but the supervisor's separately constructed client stays pinned
to the
old address. When the entrypoint exits with code 0,
`put_status(SUCCEEDED)` times
out, the broad exception handler writes `FAILED`, and the job is
reported as
`JOB_SUPERVISOR_ACTOR_DIED` despite having succeeded.

## Fix

Use the GCS client already configured for the worker process hosting the
actor,
which reconnects through the stable head service:

```python
gcs_client = ray._private.worker.global_worker.gcs_client
```

`gcs_address` and `cluster_id_hex` existed only to build that client, so
they are
removed from the supervisor's signature and from the `JobManager` side.
The same
file already uses worker-local state a few lines below
(`ray._private.worker.global_worker.node`), so this follows existing
practice
here. Net -4 lines.

## Not a duplicate

`ray-project#65027` also concerns jobs during GCS failover, but patches
`job_manager.py`'s
monitor loop to retry transient gRPC errors. This patches
`job_supervisor.py`'s
client construction. They are complementary: retries in the monitor
cannot help a
supervisor whose own client is pinned to an address nothing is listening
on.

No other open PR references ray-project#65608. `gh pr list --search
"job_supervisor"` and
`--search "JobSupervisor gcs"` surfaced only ray-project#65006, ray-project#47166, ray-project#61099 and
ray-project#65027,
none of which touch this client construction.

## Testing

Added `test_job_succeeds_when_manager_gcs_address_is_stale` in
`python/ray/dashboard/modules/job/tests/test_job_manager.py`. The full
reported
path needs KubeRay with GCS FT and a head replacement; the essential
condition is
that the address the manager recorded is unusable while the worker's own
client
still works. `_StaleAddressGcsClient` wraps the live client and reports
`127.0.0.1:1`, which is reserved and never bound.

```
python -m pytest python/ray/dashboard/modules/job/tests/test_job_manager.py -k stale -q
```

- on master: `1 failed` — the supervisor cannot persist the terminal
status
- with this change: `1 passed` in 12.70s

Surrounding tests that exercise supervisor construction, job submission,
supervisor logging and the existing failover path:

```
python -m pytest python/ray/dashboard/modules/job/tests/test_job_manager.py -q -p no:randomly \
  -k "stale or network_fault_tolerance or supervisor_log_json or supervisor_logs_saved \
      or submit_no_ray_address or get_all_job_info"

7 passed, 63 deselected in 82.54s
```

Lint, using the repo's own configuration:

```
pre-commit run --files python/ray/dashboard/modules/job/job_supervisor.py \
  python/ray/dashboard/modules/job/job_manager.py \
  python/ray/dashboard/modules/job/tests/test_job_manager.py

ruff / pydoclint / black / Ray docstyle / semgrep / import order: all Passed
```

I did not get a clean full-module run locally: `test_job_manager.py` in
its
entirety stalls on this machine shortly after start (pytest idle at 0%
CPU, no
Ray processes alive) both with and without this change, so it looks
unrelated to
it. Happy to run anything specific a reviewer wants.

Ray installed as `ray[default]` 2.58.0 with `python/ray/setup-dev.py`
symlinks;
tested on macOS (Apple silicon).

## Out of scope

The `except Exception` handler in `JobSupervisor.run` reclassifies a
failure to
*persist* an already-known result as
`JOB_ENTRYPOINT_COMMAND_START_ERROR`. That
is a real second defect, but transient-error handling in this area is
the subject
of ray-project#65027, so it is left alone here to avoid a collision.

## AI usage

AI assistance was used for the investigation, the code change, and the
test. I
reviewed every changed line, ran the commands above myself, and can
explain and
defend the change.

Signed-off-by: Roshan Sharma <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Job] Job incorrectly marked FAILED during GCS failover due to unhandled transient RPC errors

2 participants