Repository navigation
[Job] Retry transient RPC errors in job monitor during GCS failover - #65027
f0rest9999 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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.
| except Exception: | ||
| if _is_transient_rpc_error(e): |
There was a problem hiding this comment.
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.
| 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): |
d3c9ac4 to
5e37735
Compare
5e37735 to
10bc199
Compare
10bc199 to
1bc8a61
Compare
1bc8a61 to
b14f616
Compare
b14f616 to
6354315
Compare
02b4177 to
9cf3114
Compare
740589c to
01ad234
Compare
01ad234 to
51b4421
Compare
51b4421 to
30674da
Compare
|
This pull request has been automatically marked as stale because it has not had 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. |
|
I'm still waiting for reviewer feedback~ |
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]>
| if isinstance(exc, RpcError): | ||
| error_msg = str(exc).lower() | ||
| return "cancelled" in error_msg or "unavailable" in error_msg |
| _MAX_TRANSIENT_ERROR_RETRIES = ray_constants.env_integer( | ||
| "RAY_JOB_MONITOR_MAX_TRANSIENT_ERROR_RETRIES", 40 | ||
| ) |
There was a problem hiding this comment.
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): | |||
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
30674da to
b0aeebe
Compare
b0aeebe to
efcce29
Compare
efcce29 to
cda6eed
Compare
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]>
cda6eed to
ce8bdb9
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
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 |
There was a problem hiding this comment.
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)
Reviewed by Cursor Bugbot for commit ce8bdb9. Configure here.
…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]>


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:
Changes:
Configurable via RAY_JOB_MONITOR_MAX_TRANSIENT_ERROR_RETRIES env var (default 40).
Related issues
Fixes #65025
Additional information