Skip to content

[Core][Jobs] Use the worker-local GCS client in JobSupervisor - #65686

Merged
rueian merged 1 commit into
ray-project:masterfrom
roshaninfordham:fix/job-supervisor-stale-gcs-client
Sep 2, 2026
Merged

rueian merged 1 commit into
ray-project:masterfrom
roshaninfordham:fix/job-supervisor-stale-gcs-client

Conversation

@roshaninfordham

Copy link
Copy Markdown
Contributor

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:

# 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:

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.

JobManager recorded the head's GCS address at construction and passed it to
every detached JobSupervisor, which built its own GcsClient from it. 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 then exits with code 0, put_status(SUCCEEDED) times out, the
broad exception handler writes FAILED, and a job that succeeded is reported as
JOB_SUPERVISOR_ACTOR_DIED.

Use the GCS client already configured for the worker process hosting the actor.
gcs_address and cluster_id_hex existed only to build that client, so they are
removed from the supervisor signature and from the JobManager side.

Signed-off-by: Roshan Sharma <[email protected]>
@roshaninfordham
roshaninfordham requested a review from a team as a code owner August 23, 2026 18:45
roshaninfordham added a commit to roshaninfordham/opensource-contributions that referenced this pull request Aug 23, 2026
A job supervisor held a GCS client pinned to the head's address, so a successful
job was reported FAILED after the head pod was replaced. The writeup covers the
bug class -- a cached endpoint outliving what it points at -- and the two
measurement mistakes the work nearly shipped: a linter run with default config
rather than the project's, and a test run that was hung rather than slow.

Also escape brackets in generated link text. Projects that prefix titles with
tags like "[Core][Jobs]" produced nested brackets inside the markdown link,
which parses wrong.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8cf0bc4f0e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ray-gardener ray-gardener Bot added core Issues that should be addressed in Ray Core community-contribution Contributed by the community labels Aug 23, 2026
@Kunchd

Kunchd commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

@rueian @MortalHappiness, could you guys take a look.

@Kunchd Kunchd self-assigned this Aug 31, 2026
@MortalHappiness MortalHappiness self-assigned this Sep 1, 2026
@MortalHappiness MortalHappiness added the go add ONLY when ready to merge, run all tests label Sep 1, 2026
@rueian
rueian merged commit ea85a26 into ray-project:master Sep 2, 2026
6 checks passed
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]>
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Core][Jobs] Successful submission job is marked FAILED after GCS-FT head replacement due to a stale JobSupervisor GCS address

4 participants