Skip to content

[core] Export the cluster ID to node-spawned processes instead of fetching it from the GCS - #65156

Closed
xyuzh wants to merge 1 commit into
ray-project:masterfrom
xyuzh:gcs-clusterid-distribute
Closed

xyuzh wants to merge 1 commit into
ray-project:masterfrom
xyuzh:gcs-clusterid-distribute

Conversation

@xyuzh

@xyuzh xyuzh commented Jul 31, 2026 •

Copy link
Copy Markdown
Member

Why are these changes needed?

Every process that connects to the GCS without a cluster ID issues a NodeInfoGcsService.GetClusterId RPC during Connect(). During mass cluster bring-up the GCS is busy with node registrations, those fetches time out, and DEADLINE_EXCEEDED is fatal to the connecting process — we hit this as fleet-wide bring-up deaths at 400 nodes on Ray 2.56 (see #64845 / #64847 for the server- and client-side halves of that incident).

The most effective fix is to not fetch a constant at scale: the node that spawns a process already knows the cluster ID. Workers, raylets, the dashboard, and both agents already receive it on their command line; this PR covers the remaining node-spawned processes through the environment (no new CLI flags), and fixes a latent bug that made two more paths fetch unnecessarily:

  1. Bug fix (python/ray/includes/common.pxi): GcsClientOptions.create passed allow_cluster_id_nil twice to the C++ constructor, silently ignoring fetch_cluster_id_if_nil. Every caller requesting fetch_cluster_id_if_nil=False with a nil ID — services._get_gcs_client_options and services.wait_for_node, i.e. every ray start on every node — actually fetched. That is an O(nodes) unnecessary GetClusterId storm during exactly the bring-up window where the GCS is most backlogged.
  2. Env-based distribution: the node exports RAY_CLUSTER_ID via start_ray_process(env_updates=...) when spawning the log monitor and the autoscaler monitor (v1 and v2), and Python GcsClient falls back to that variable when constructed without a cluster ID (_raylet.pyx). The spawned processes therefore need zero code changes — no argparse, no constructor plumbing — and any future process spawned with the variable set is covered for free. An unset variable (drivers, external tools, kuberay-launched monitors) keeps today's fetch-from-GCS fallback.

Remaining fetchers after this PR (intentionally out of scope — not spawned by a node that knows the ID): drivers connecting via ray.init(address=...), CLI tools (ray status etc.), and the ray client proxy. #64845/#64847 keep those robust.

Related issue number

None found — searched open PRs/issues for GetClusterId / cluster ID distribution before opening (companion PRs #64845, #64847 cover the same incident's server/client halves; no overlap in files or mechanism). 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 python/ray/tests/test_cluster_id_distribution.py asserts start_log_monitor / start_monitor (v1 and v2) pass env_updates={"RAY_CLUSTER_ID": ...} when given a cluster ID and omit it otherwise (registered in python/ray/tests/BUILD.bazel, small).
    • Verified the spawn-side assertions locally against a nightly-wheel venv (the GcsClient env fallback in _raylet.pyx requires a built wheel and is exercised in CI by every test that starts a cluster and a log monitor/monitor).
    • The common.pxi change is exercised by every CI test that calls ray start/wait_for_node; the C++ flag semantics (ShouldFetchClusterId) are already unit-tested.

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.

@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 optimizes the startup of node-spawned processes (such as the log monitor and monitor processes) by passing the cluster ID hex string directly via command-line arguments. This avoids an extra GCS RPC that could potentially time out during large cluster bring-ups. Additionally, a bug in GcsClientOptions initialization was fixed, and new unit tests were added to verify the cluster ID distribution. There are no review comments, so I have no feedback to provide.

…ching it from the GCS

Every process that connects to the GCS without a cluster ID issues a
NodeInfoGcsService.GetClusterId RPC during Connect(). During mass cluster
bring-up the GCS is busy with node registrations, those fetches time out,
and DEADLINE_EXCEEDED is fatal to the connecting process (observed as
fleet-wide bring-up deaths at 400 nodes on Ray 2.56). Workers, raylets,
dashboard, and both agents already receive the ID on their command line;
this PR covers the remaining node-spawned processes through the
environment and fixes a bug that made two more paths fetch unnecessarily:

- GcsClientOptions.create (common.pxi) passed allow_cluster_id_nil twice,
  silently ignoring fetch_cluster_id_if_nil — so callers requesting
  fetch_cluster_id_if_nil=False (services._get_gcs_client_options and
  wait_for_node, i.e. every 'ray start') fetched anyway. Pass the right
  argument.
- The node now exports RAY_CLUSTER_ID (via start_ray_process env_updates)
  when spawning the log monitor and the autoscaler monitor (v1 and v2),
  and GcsClient falls back to that variable when constructed without a
  cluster ID — so the spawned processes need no flag or code changes and
  anything else the node spawns this way is covered for free. Unset env
  (drivers, external tools, kuberay-launched monitors) keeps the
  fetch-from-GCS fallback.

Signed-off-by: xyuzh <[email protected]>
@xyuzh
xyuzh force-pushed the gcs-clusterid-distribute branch from 448cde6 to 40ec01a Compare July 31, 2026 21:32
@xyuzh xyuzh changed the title [core] Pass the cluster ID to node-spawned processes instead of fetching it from the GCS [core] Export the cluster ID to node-spawned processes instead of fetching it from the GCS Jul 31, 2026
@ray-gardener ray-gardener Bot added the core Issues that should be addressed in Ray Core label Aug 1, 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 15, 2026
@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
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 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.

1 participant