Skip to content

[Jobs] Making sure JobManager retries JobSupervisor.ping before declaring job as failed - #47166

Open
alexeykudinkin wants to merge 12 commits into
ray-project:masterfrom
alexeykudinkin:ak/jbm-png-ret-fix
Open

alexeykudinkin wants to merge 12 commits into
ray-project:masterfrom
alexeykudinkin:ak/jbm-png-ret-fix

Conversation

@alexeykudinkin

@alexeykudinkin alexeykudinkin commented Aug 15, 2024 •

Copy link
Copy Markdown
Contributor

Why are these changes needed?

These changes add retries to JobManager when pinging JobSupervisor to prevent occasions when a single RPC failure leads to a job wrongfully being declared as failed.

Related issue number

Checks

Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
Added timeout handling

Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
@alexeykudinkin alexeykudinkin added the go add ONLY when ready to merge, run all tests label Aug 15, 2024
Signed-off-by: Alexey Kudinkin <[email protected]>
Comment on lines +82 to +83
else:
raise e

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: wrap the exception with something saying it was retried X times or total duration

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, i see where you're coming from but am wary to wrap exceptions as that would mean that starting to use this util will mandate updating every try-catch block to accommodate for the same exceptions


return async_call_with_retry(
_ping,
exception_classes=(ray.exceptions.RpcError, asyncio.TimeoutError),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think this can/should ever raise an RpcError. It would raise a RayTaskError or RayActorError (and retries for those are handled by/configured in Ray)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

do we have a traceback showing that this codepath raised an RpcError?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So we don't have the traceback unfortunately but this is what made me think that it was wrapped into RpcError

  • "Deadline Exceeded" is typical gRPC client-side exception (timeout)
  • We seem to wrap transport failures into RpcError here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, and also to clarify: i don't think the issue here is on the JobSupervisor end -- my hypothesis is that we're stalling the event-loop/GIL in the Agent itself therefore making it gRPC client timeout even before it's able to process response from the supervisor

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, boy, i've just realized it couldn't happen for actor call b/c we never set timeout on those -- it's definitely one of the GCS RPCs

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This doesn't really make sense for actor calls. They will never raise RpcError because retries/grpc connection details are abstracted by the c++ layer

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it is indeed the GCS RPCs that we should be retrying not the actor calls

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

e.g., stack trace that I saw:

2024-08-14 23:24:49	ray.exceptions.RpcError: Deadline Exceeded
2024-08-14 23:24:49	  File "python/ray/_raylet.pyx", line 586, in ray._raylet.check_status
2024-08-14 23:24:49	  File "python/ray/_raylet.pyx", line 2794, in ray._raylet.GcsClient.internal_kv_get
2024-08-14 23:24:49	  File "python/ray/_raylet.pyx", line 2689, in ray._raylet._auto_reconnect.wrapper
2024-08-14 23:24:49	  File "python/ray/_raylet.pyx", line 2712, in ray._raylet._auto_reconnect.wrapper
2024-08-14 23:24:49	    result = self.fn(*self.args, **self.kwargs)
2024-08-14 23:24:49	  File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run
2024-08-14 23:24:49	    return await self.loop.run_in_executor(self.executor, func, *args, **kwargs)
2024-08-14 23:24:49	  File "/home/ray/virtualenv/lib/python3.10/site-packages/ray/_private/gcs_aio_client.py", line 33, in wrapper
2024-08-14 23:24:49	    return await self._async_proxy.internal_kv_get(key, namespace, timeout)
2024-08-14 23:24:49	  File "/home/ray/virtualenv/lib/python3.10/site-packages/ray/_private/gcs_aio_client.py", line 85, in internal_kv_get
2024-08-14 23:24:49	    serialized_info = await self._gcs_aio_client.internal_kv_get(
2024-08-14 23:24:49	  File "/home/ray/virtualenv/lib/python3.10/site-packages/ray/dashboard/modules/job/common.py", line 218, in get_info
2024-08-14 23:24:49	    job_info = await self.get_info(job_id)
2024-08-14 23:24:49	  File "/home/ray/virtualenv/lib/python3.10/site-packages/ray/dashboard/modules/job/common.py", line 268, in get_status
2024-08-14 23:24:49	    job_status = await self._job_info_client.get_status(job_id)
2024-08-14 23:24:49	  File "/home/ray/virtualenv/lib/python3.10/site-packages/ray/dashboard/modules/job/job_manager.py", line 159, in _monitor_job_internal
2024-08-14 23:24:49	Traceback (most recent call last):
2024-08-14 23:24:49	future: <Task finished name='Task-38' coro=<JobManager._monitor_job() done, defined at /home/ray/virtualenv/lib/python3.10/site-packages/ray/dashboard/modules/job/job_manager.py:127> exception=RpcError('Deadline Exceeded')>

it's in the job_info_client

@stale

stale Bot commented Apr 26, 2025

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

  • If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@stale stale Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Apr 26, 2025
@github-actions

github-actions Bot commented Jun 2, 2025

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 Jun 2, 2025
@alexeykudinkin
alexeykudinkin requested a review from a team as a code owner July 28, 2025 21:31
@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 Jul 29, 2025
@ray-gardener ray-gardener Bot added the core Issues that should be addressed in Ray Core label Aug 15, 2025
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]>
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

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.

2 participants