Skip to content

[core] Add tests for worker gRPC thread count selection - #64898

Open
atharv0o wants to merge 5 commits into
ray-project:masterfrom
atharv0o:atharv/grpc-cgroup-thread-limit
Open

atharv0o wants to merge 5 commits into
ray-project:masterfrom
atharv0o:atharv/grpc-cgroup-thread-limit

Conversation

@atharv0o

Copy link
Copy Markdown

Description

This PR adds unit tests for the worker gRPC internal thread count selection logic to improve coverage around CPU limit detection and configuration precedence.

Changes

  • Added a mock CPU limit mechanism to CpuMonitorUtils for deterministic testing.
  • Added unit tests covering:
    • Default CPU limit detection.
    • Mocked cgroup CPU limit.
    • Explicit worker_num_grpc_internal_threads override.
  • Updated the worker startup path to use the testable CPU limit helper.

Why

The worker gRPC thread count depends on CPU limit detection and configuration precedence. Without deterministic tests, validating these scenarios requires relying on the host environment, making the behavior difficult to verify consistently.

These tests ensure that:

  • The default CPU limit is used when no override is configured.
  • A cgroup CPU limit is respected when available.
  • An explicit user configuration always takes precedence.

This improves confidence in the worker thread sizing logic and helps prevent regressions as the implementation evolves.

Related issues

Related to #64834

Testing

Verified by running the existing worker pool unit tests with the newly added test cases covering all three scenarios.

Additional information

This PR does not change the intended production behavior. The mock CPU limit helper exists solely to enable deterministic unit testing of the worker gRPC thread count selection logic.
Screenshot 2026-07-21 120148
Screenshot 2026-07-21 120207

@atharv0o
atharv0o requested a review from a team as a code owner July 21, 2026 06:40

@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 introduces a mechanism to mock the CPU limit in CpuMonitorUtils and updates WorkerPool to fallback to the CPU limit when configuring the worker's internal gRPC thread count if no explicit override is set. It also adds a comprehensive test suite to verify this behavior. The review feedback highlights two critical improvements: first, mock_cpu_limit_ should be made thread-safe using std::atomic to prevent potential data races; second, the new tests should utilize RAII guards for resetting the mock CPU limit and restoring global configuration state to prevent test pollution in the event of assertion failures.

Comment on lines +42 to +46
static void SetMockCpuLimit(int64_t mock_limit) { mock_cpu_limit_ = mock_limit; }
static void ClearMockCpuLimit() { mock_cpu_limit_ = -1; }

private:
static int64_t mock_cpu_limit_;

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

The static member variable mock_cpu_limit_ is accessed and modified across multiple threads (e.g., during concurrent test execution or background Raylet tasks calling GetCpuLimit). Accessing it without synchronization is a data race, which is undefined behavior in C++. Please use std::atomic<int64_t> to ensure thread safety. Note that you will also need to #include <atomic> at the top of this header file.

Suggested change
static void SetMockCpuLimit(int64_t mock_limit) { mock_cpu_limit_ = mock_limit; }
static void ClearMockCpuLimit() { mock_cpu_limit_ = -1; }
private:
static int64_t mock_cpu_limit_;
static void SetMockCpuLimit(int64_t mock_limit) { mock_cpu_limit_.store(mock_limit, std::memory_order_relaxed); }
static void ClearMockCpuLimit() { mock_cpu_limit_.store(-1, std::memory_order_relaxed); }
private:
static std::atomic<int64_t> mock_cpu_limit_;

Comment on lines +115 to +120
int64_t CpuMonitorUtils::mock_cpu_limit_ = -1;

int64_t CpuMonitorUtils::GetCpuLimit(const std::string &root_cgroup_path) {
if (mock_cpu_limit_ > 0) {
return mock_cpu_limit_;
}

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

Update the definition and read path of mock_cpu_limit_ to use std::atomic<int64_t> with relaxed memory order for thread safety.

Suggested change
int64_t CpuMonitorUtils::mock_cpu_limit_ = -1;
int64_t CpuMonitorUtils::GetCpuLimit(const std::string &root_cgroup_path) {
if (mock_cpu_limit_ > 0) {
return mock_cpu_limit_;
}
std::atomic<int64_t> CpuMonitorUtils::mock_cpu_limit_ = -1;
int64_t CpuMonitorUtils::GetCpuLimit(const std::string &root_cgroup_path) {
int64_t mock_limit = mock_cpu_limit_.load(std::memory_order_relaxed);
if (mock_limit > 0) {
return mock_limit;
}

Comment on lines +870 to +882
int64_t mock_cgroup_limit = 4;
CpuMonitorUtils::SetMockCpuLimit(mock_cgroup_limit);

LeaseSpecification lease_spec = ExampleLeaseSpec(ActorID::Nil(), Language::PYTHON, job_id);
ASSERT_NE(worker_pool_->PopWorkerSync(lease_spec), nullptr);
const ProcessEnvironment &env =
worker_pool_->GetWorkerEnv(*worker_pool_->LastStartedWorkerProcess());

auto it = env.find(kEnvVarKeyGrpcThreadCount);
ASSERT_NE(it, env.end());
ASSERT_EQ(it->second, std::to_string(mock_cgroup_limit));

CpuMonitorUtils::ClearMockCpuLimit();

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.

medium

If any of the ASSERT_* macros fail, the test will abort immediately, skipping the call to CpuMonitorUtils::ClearMockCpuLimit(). This will leave the mock CPU limit set for subsequent tests, causing test pollution and potential failures in unrelated tests. Use a local RAII guard to guarantee that the mock CPU limit is cleared when exiting the scope.

    int64_t mock_cgroup_limit = 4;
    struct CpuLimitGuard {
      ~CpuLimitGuard() { CpuMonitorUtils::ClearMockCpuLimit(); }
    } guard;
    CpuMonitorUtils::SetMockCpuLimit(mock_cgroup_limit);

    LeaseSpecification lease_spec = ExampleLeaseSpec(ActorID::Nil(), Language::PYTHON, job_id);
    ASSERT_NE(worker_pool_->PopWorkerSync(lease_spec), nullptr);
    const ProcessEnvironment &env =
        worker_pool_->GetWorkerEnv(*worker_pool_->LastStartedWorkerProcess());

    auto it = env.find(kEnvVarKeyGrpcThreadCount);
    ASSERT_NE(it, env.end());
    ASSERT_EQ(it->second, std::to_string(mock_cgroup_limit));

Comment on lines +888 to +901
int64_t original_value = RayConfig::instance().worker_num_grpc_internal_threads();
RayConfig::instance().initialize(R"({"worker_num_grpc_internal_threads": 5})");

LeaseSpecification lease_spec = ExampleLeaseSpec(ActorID::Nil(), Language::PYTHON, job_id);
ASSERT_NE(worker_pool_->PopWorkerSync(lease_spec), nullptr);
const ProcessEnvironment &env =
worker_pool_->GetWorkerEnv(*worker_pool_->LastStartedWorkerProcess());

auto it = env.find(kEnvVarKeyGrpcThreadCount);
ASSERT_NE(it, env.end());
ASSERT_EQ(it->second, std::to_string(user_override));

RayConfig::instance().initialize(
R"({"worker_num_grpc_internal_threads": )" + std::to_string(original_value) + R"(})");

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.

medium

If any of the ASSERT_* macros fail, the test will abort immediately, skipping the restoration of the original worker_num_grpc_internal_threads configuration. This will pollute the global RayConfig singleton and potentially break other tests. Use a local RAII guard to guarantee that the original configuration is restored when exiting the scope.

    int64_t original_value = RayConfig::instance().worker_num_grpc_internal_threads();
    struct ConfigGuard {
      int64_t val;
      ~ConfigGuard() {
        RayConfig::instance().initialize(
            R"({"worker_num_grpc_internal_threads": )" + std::to_string(val) + R"(})");
      }
    } guard{original_value};
    RayConfig::instance().initialize(R"({"worker_num_grpc_internal_threads": 5})");

    LeaseSpecification lease_spec = ExampleLeaseSpec(ActorID::Nil(), Language::PYTHON, job_id);
    ASSERT_NE(worker_pool_->PopWorkerSync(lease_spec), nullptr);
    const ProcessEnvironment &env =
        worker_pool_->GetWorkerEnv(*worker_pool_->LastStartedWorkerProcess());

    auto it = env.find(kEnvVarKeyGrpcThreadCount);
    ASSERT_NE(it, env.end());
    ASSERT_EQ(it->second, std::to_string(user_override));

@atharv0o
atharv0o force-pushed the atharv/grpc-cgroup-thread-limit branch from 27a4f9d to efaf2af Compare July 21, 2026 07:00
auto it = env.find(kEnvVarKeyGrpcThreadCount);
ASSERT_NE(it, env.end());
ASSERT_EQ(it->second, std::to_string(user_override));
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cached workers skew gRPC tests

Medium Severity

Scenarios (b) and (c) call PopWorkerSync again with the same job after scenario (a), but RAY_num_grpc_internal_threads is fixed when the worker process starts. Reused idle workers skip StartProcess, so LastStartedWorkerProcess / GetWorkerEnv can reflect scenario (a)'s spawn env while the mock or RayConfig changed—assertions may pass without validating new startup logic.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit efaf2af. Configure here.

@atharv0o
atharv0o force-pushed the atharv/grpc-cgroup-thread-limit branch from efaf2af to 65f52cd Compare July 21, 2026 07:05
@ray-gardener ray-gardener Bot added core Issues that should be addressed in Ray Core community-contribution Contributed by the community labels Jul 21, 2026
@atharv0o
atharv0o force-pushed the atharv/grpc-cgroup-thread-limit branch from b9f39dc to 700241c Compare July 21, 2026 13:26
@atharv0o
atharv0o force-pushed the atharv/grpc-cgroup-thread-limit branch 2 times, most recently from 362accf to 4d32441 Compare July 21, 2026 14:53
@atharv0o

Copy link
Copy Markdown
Author

Will some one help me whit build kit ,, it is failing even after working on this for 8 hours?

@atharv0o
atharv0o force-pushed the atharv/grpc-cgroup-thread-limit branch from d0fe58b to 04476cc Compare July 21, 2026 15:52
atharv0o referenced this pull request Jul 21, 2026
…r tests (#64762)

## Description
The scripts in `test_runtime_env_container` run inside a Ray image,
which does not have pytest installed, so we can't add at the top level
file but inside functions which only be called in pytest environment.

Signed-off-by: yicheng <[email protected]>
Co-authored-by: yicheng <[email protected]>
@atharv0o

Copy link
Copy Markdown
Author

@elliot-barn @OneSizeFitsQuorum @Kunchd can you revive and help me here !
I've been working on this for the past 8+ hours and have tried my best to understand the codebase and implement the changes. Unfortunately, I'm currently stuck because my implementation keeps failing the Buildkite CI checks.

Would you mind pointing me in the right direction or suggesting what I might be overlooking? Even a small hint about the failing tests or the expected approach would be incredibly helpful.

Thank you for your time—I really want to get this contribution merged and learn from the process.

@atharv0o

Copy link
Copy Markdown
Author

Hi @bveeramani @edoakes @dstrodtman @elliot-barn @OneSizeFitsQuorum @Kunchd,
or any other reviewer or maintainer ,,

The CI has successfully passed for my PR. When you have a chance, could someone please review the changes? If everything looks good, I'd really appreciate it if the PR could be merged.

Thank you for your time and for maintaining Ray!

@atharv0o

Copy link
Copy Markdown
Author

Hi everyone,

Just wanted to summarize where I think this PR fits after the recent discussion in #64834.

This PR is intentionally focused on the Ray side. It adds deterministic test coverage for the worker gRPC thread-count selection logic by:

  • introducing a mock CPU-limit mechanism for testing,
  • validating the default CPU-limit path,
  • validating mocked cgroup CPU limits,
  • validating that explicit worker_num_grpc_internal_threads overrides always take precedence.

Although this doesn't address the larger EventEngine thread amplification problem by itself, it provides test infrastructure around the existing worker thread-selection logic, making future changes safer and easier to validate.

Based on the discussion in #64834, my plan is to continue working on the Ray-side improvements (such as the per-worker-share sizing heuristic) separately, while the EventEngine thread-growth discussion continues upstream in gRPC (#41169 / #37180).

If this test infrastructure looks reasonable, I'd appreciate any feedback or review. I'm happy to iterate on this PR or build the follow-up work on top of it.

Thanks!

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

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 83cac95. Configure here.

int64_t user_override = 5;
int64_t original_value = RayConfig::instance().worker_num_grpc_internal_threads();
RayConfigRestoreGuard config_guard(original_value);
RayConfig::instance().initialize(R"({"worker_num_grpc_internal_threads": 5})");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Test resets suite RayConfig state

Medium Severity

RayConfig::initialize always reloads every config from defaults/env before applying the JSON, so calling it with only worker_num_grpc_internal_threads drops the values WorkerPoolTest::SetUp installed (object_spilling_config, max_io_workers, worker_register_timeout_seconds, etc.). The restore guard repeats that wipe and does not put the suite config back.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 83cac95. Configure here.

@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 19, 2026
@Kunchd

Kunchd commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

This PR modifies the default value resolution process of worker_num_grpc_internal_threads from the default thread limit of grpc to the cgroup cpu limit. Per #64834 (comment), we want to avoid changing the default behavior at this time, and we are instead adding a warning for high grpc thread count in #65637.

Because of the discussion on the issue linked above. Unfortunately, we have decided to pause this PR at this time. Though we really appreciate your time and effort for this investigation 🙂. If you believe this PR should be continued, please feel free to continue the discussion on the issue above, and we will coordinate there.

If you are looking for other issues to contribute to, please feel free to reach out!

@github-actions github-actions Bot removed the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Aug 25, 2026
@github-actions github-actions Bot added the unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it. label Aug 25, 2026
richardliaw pushed a commit that referenced this pull request Aug 31, 2026
## Description

Each Ray worker process has its own gRPC runtime, so high-worker-density
nodes can accumulate a large number of gRPC threads. Maintainers decided
not to change the default `worker_num_grpc_internal_threads` value
because that could be breaking.

This PR implements the non-breaking follow-up requested in #64834:

- Log a raylet warning when the node has more than 16 detected CPUs and
`RAY_worker_num_grpc_internal_threads` is not set to a positive value.
- Document how to configure the worker gRPC thread setting on Ray nodes.
- Add a dedicated troubleshooting guide for inspecting worker threads,
distinguishing a separately loaded Python `grpcio` runtime, and checking
process and thread limits.
- Add unit coverage for the threshold boundary, warning text, and
explicit-configuration behavior.

The worker gRPC thread default and runtime sizing behavior are
unchanged.

## Related issues

Related to #64834.

## Additional information

### Duplicate-work check

I reviewed the issue discussion and searched open PRs by issue number
and worker gRPC warning/documentation keywords before opening this PR.
The only related open PR is #64898, which covers CPU-limit-based default
selection and its tests. It does not implement the maintainer-requested
warning or documentation, and this PR deliberately leaves the default
unchanged.

### Testing

- `bazel build //src/ray/raylet:raylet` — passed.
- `bazel test //src/ray/raylet/tests:worker_pool_test
--test_output=errors` — passed (1/1 test target).
- `pre-commit run` with pre-commit 3.5.0 — passed, including cpplint,
clang-format, semgrep, and core C++ inclusion checks.
- `python doc/test_no_new_rst.py --base master --remote origin --commit
HEAD` — passed.
- MyST front matter, code fences, toctree entry, and cross-reference
consistency check — passed.
- `git diff --check` — passed.

### AI assistance

AI assistance was used to trace the relevant code path, draft the
implementation, tests, and documentation, and run validation. The human
submitter reviewed every changed line and understands and can defend the
change end-to-end.

---------

Signed-off-by: OneSizeFitsQuorum <[email protected]>
Co-authored-by: Douglas Strodtman <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…65637)

## Description

Each Ray worker process has its own gRPC runtime, so high-worker-density
nodes can accumulate a large number of gRPC threads. Maintainers decided
not to change the default `worker_num_grpc_internal_threads` value
because that could be breaking.

This PR implements the non-breaking follow-up requested in ray-project#64834:

- Log a raylet warning when the node has more than 16 detected CPUs and
`RAY_worker_num_grpc_internal_threads` is not set to a positive value.
- Document how to configure the worker gRPC thread setting on Ray nodes.
- Add a dedicated troubleshooting guide for inspecting worker threads,
distinguishing a separately loaded Python `grpcio` runtime, and checking
process and thread limits.
- Add unit coverage for the threshold boundary, warning text, and
explicit-configuration behavior.

The worker gRPC thread default and runtime sizing behavior are
unchanged.

## Related issues

Related to ray-project#64834.

## Additional information

### Duplicate-work check

I reviewed the issue discussion and searched open PRs by issue number
and worker gRPC warning/documentation keywords before opening this PR.
The only related open PR is ray-project#64898, which covers CPU-limit-based default
selection and its tests. It does not implement the maintainer-requested
warning or documentation, and this PR deliberately leaves the default
unchanged.

### Testing

- `bazel build //src/ray/raylet:raylet` — passed.
- `bazel test //src/ray/raylet/tests:worker_pool_test
--test_output=errors` — passed (1/1 test target).
- `pre-commit run` with pre-commit 3.5.0 — passed, including cpplint,
clang-format, semgrep, and core C++ inclusion checks.
- `python doc/test_no_new_rst.py --base master --remote origin --commit
HEAD` — passed.
- MyST front matter, code fences, toctree entry, and cross-reference
consistency check — passed.
- `git diff --check` — passed.

### AI assistance

AI assistance was used to trace the relevant code path, draft the
implementation, tests, and documentation, and run validation. The human
submitter reviewed every changed line and understands and can defend the
change end-to-end.

---------

Signed-off-by: OneSizeFitsQuorum <[email protected]>
Co-authored-by: Douglas Strodtman <[email protected]>
elliot-barn added a commit that referenced this pull request Nov 13, 2026
… gRPC to 1.69.0 (#66483)

## Why

This PR moves Ray to **Bazel 8.8.1**, still in WORKSPACE mode, together
with the dependency bumps that Bazel 8 forces. It is the Bazel 8 step of
the Bazel 7.5 → 8 → 9 migration. The earlier steps (#66160, #66207,
#66305) got the tree as far as letting Bazel 8 start.

Bazel 8 needs `rules_java` 8.x. Every `rules_java` 8.x release loads
`@com_google_protobuf//bazel:java_proto_library.bzl`, and that file does
not exist in the v23.4-era protobuf commit Ray pins. So `rules_java` and
protobuf have to move together, and protobuf ≥ 29 then pulls gRPC and
abseil along.

## Split for review

The parts that work on master on their own are split out into separate
PRs. **Please review those first.** Once they merge, this PR is rebased
and those commits drop out of the diff.

| PR | What |
|---|---|
| #67717 | Deflake four timing-sensitive tests that the gRPC bump made
fail more often |
| #67718 | A gRPC client with calls in flight is never idle (actor task
ordering fix, see below) |
| #67719 | Keep gRPC's absl logging at ERROR unless `GRPC_VERBOSITY` is
set (see below) |
| #67720 | `Arena::CreateMessage` → `Arena::Create`, and pin Java 8
bytecode ahead of `rules_java` 8 |
| #67721 | `bazel_skylib` 1.7.1 and `rules_pkg` 0.9.1 |

What stays here: the Bazel version, the protobuf / `rules_java` / gRPC /
abseil / `rules_cc` bumps, the code and patch changes they need, the
glibc 2.17 Bazel build for CI, and the Windows / sanitizer / test fixes
for gRPC 1.69.

## Versions

| Repo | Before | After | Why it moves |
|---|---|---|---|
| Bazel | 7.5.0 | **8.8.1** | The goal. See "Bazel 8" below |
| `com_google_protobuf` | `2c5fa078` (~v23.4) | **v29.6** | `rules_java`
8.x loads from its `bazel/` package |
| `rules_java` | 7.12.4 | **8.12.0** | Needed for Bazel 8. 8.12.0 is the
ceiling: from 8.13.0 on, the prebuilt `java_tools` (`singlejar`, `ijar`,
`one_version`) need `GLIBCXX_3.4.21`, newer than manylinux2014's
libstdc++. 8.x also changed the default Java language level from 8 to
11, so `.bazelrc` pins `--java_language_version=8` (#67720). |
| `com_github_grpc_grpc` | 1.58.0 | **1.69.0** | gRPC < 1.69 builds a
standalone `@upb` that fails to compile against protobuf 29's
`descriptor.proto` (`FileDescriptorProto.edition` is now an enum).
1.69.0 is the first gRPC whose `grpc_deps.bzl` pins protobuf 29. |
| `com_google_absl` | 20230802.1 | **20240722.2** | Matches gRPC 1.69.0.
Patch release 2 fixes a security issue in hash container create/resize.
|
| `rules_proto` | 6.0.2 (from `grpc_deps()`) | **7.1.0** | 6.0.2 reads
native `proto_common.ProtoLangToolchainInfo`, which Bazel 8 removed |
| `rules_cc` | 0.0.13 (transitive) | **0.0.16** | What protobuf 29
declares |
| `bazel_skylib` | 1.6.1 (in name only) | **1.7.1** | Protobuf 29 calls
`paths.is_normalized()` (#67721) |
| `rules_pkg` | 0.7.0 (transitive) | **0.9.1** | Ceiling, see below
(#67721) |
| `boringssl` | `2ff4b968` | `2ff4b968` (unchanged) | Deliberately older
than gRPC 1.69.0's `b8b3e6e1`. Every later boringssl requires C11
`<stdalign.h>` on MSVC, which the Windows CI SDK (10.0.19041) doesn't
ship. |

## Bazel 8

- `.bazelversion` 7.5.0 → 8.8.1. Bzlmod stays off (`--noenable_bzlmod
--enable_workspace`), so every external repo still comes from WORKSPACE
and there is exactly one copy of protobuf, `rules_java` and
`rules_python`.
- `--noincompatible_disallow_empty_glob`: the root `BUILD.bazel` globs
platform-specific paths that are empty on other platforms.
- `--noincompatible_disallow_ctx_resolve_tools`: the 2021
`rules_proto_grpc` pin still calls `ctx.resolve_tools`.
- **glibc 2.17.** Official Bazel 8 binaries need glibc ≥ 2.25 and can't
start inside the manylinux2014 (CentOS 7) images that build Ray's Linux
wheels. A new wanda image, `ci/docker/bazel-glibc217`, builds
`bazel_nojdk` from the release's dist zip inside
`rayproject/manylinux2014` (devtoolset-10) and ships it with Temurin JDK
21. The ray-core, ray-cpp-core, ray-java and manylinux images put it
behind `bazelisk`. Rebuilding Bazel only happens when `.bazelversion`
changes. Wheels still target manylinux2014, so the user glibc floor is
unchanged.
- `ci/ray_ci/test_bazel_sharding.py` shares one mock workspace across
its tests. Each test used to start a new Bazel server, which on Bazel 8
also re-fetches `rules_python` for autoloads and pushed it past its 60s
timeout.

## Declaration order: the first declaration of a repo wins

Several bumps only take effect because of where they are declared. In
WORKSPACE, a repo keeps its first declaration: a `maybe()` skips a repo
that already exists, and a later plain `http_archive` is ignored.

- **`bazel_skylib` / `rules_cc` are declared at the top of
`WORKSPACE`.** `py_repositories()` (rules_python 0.40.0) declares skylib
**1.3.0** and rules_cc 0.0.13 before `ray_deps_setup()` runs, so the
skylib pin in `ray_deps_setup.bzl` has had no effect since #66207.
- **`rules_java_dependencies()` runs after `ray_deps_setup()`.** It
declares its own `com_google_protobuf` (**29.0-rc2**) through `maybe()`.
If it ran first, it would silently replace Ray's pin.
- **`rules_pkg` is pinned to 0.9.1** before `protobuf_deps()` runs,
which would otherwise declare 1.0.1. The v3.20.3 protobuf that
`rules_proto_grpc` uses loads the root `@rules_pkg//:providers.bzl`
stub, which was deleted in 0.10.0.
- **`rules_proto` 7.1.0 is declared before `grpc_deps()`** for the same
reason.

The versions that actually resolved were verified by reading each
fetched repo's `MODULE.bazel` / `version.json`. `bazel query` does not
catch these swaps.

## Code changes needed by the new versions

- `.bazelrc` defines `PROTOBUF_FUTURE_REMOVE_CREATEMESSAGE`, which
compiles out protobuf's deprecated `Arena::CreateMessage` shim. GCC 10
(the manylinux2014 devtoolset) warns on the shim's own body in every
file that includes `arena.h`, and `-Werror` makes that fatal.
- `JsonPrintOptions::always_print_primitive_fields` →
`always_print_fields_with_no_presence` (`event.cc`, one test). **The
export-event JSON does not change**: unset proto3 `optional` fields were
omitted before and still are.
- `cc_proto_library` loads from
`@com_google_protobuf//bazel:cc_proto_library.bzl` rather than
`@rules_cc` (3 BUILD files).
- gRPC's health service C++ target is `health_cc_grpc` in 1.69 (2 BUILD
files).
- UBSan: GCC rejects abseil's hash containers under the `null`,
`nonnull-attribute` and `returns-nonnull-attribute` checks, so those
three are off. GCC 11 also reports a false `-Wmaybe-uninitialized` in
protobuf 29's generated move-assignment under ubsan; it is no longer
fatal there.

## gRPC 1.69 behaviour changes

**Actor task ordering (real runtime bug, #67718).** gRPC 1.69 leaves a
channel `IDLE` for a moment after its first call starts.
`CoreWorkerClientPool` evicts idle clients, so the client that sent an
actor's first task could be evicted before the second task, which then
went out on a new client with fresh sequence state. The actor ran the
second task first and cancelled the first as stale (`Task canceled due
to stale sequence number`). Fix: `GrpcClient` counts calls in flight and
is only idle when none are. Local repro: 11/20 out of order before, 0/30
after.

**gRPC INFO logs reach the driver (#67719).** gRPC ≥ 1.65 logs through
absl and leaves absl's INFO default alone when `GRPC_VERBOSITY` is
unset, so lines such as `chttp2_transport.cc ... Got goaway` were
forwarded to drivers as `(raylet) ...`. Ray now sets absl's minimum
level to ERROR unless `GRPC_VERBOSITY` is set.

**Windows EventEngine.** gRPC 1.69 turns on the EventEngine client and
listener on Windows (1.58 marked them broken), and they abort at
teardown (`win_socket.cc` "Check failed: is_shutdown_"). They stay off
on Windows, and so does the EventEngine callback CQ: without it,
callback-API code got no polling thread and `pubsub_integration_test`
could never connect. Posix keeps 1.69's defaults.

**Test timing.** gRPC 1.69 makes some existing races easy to hit.
`test_broadcast` (LLM) and the Serve replica-death test now let the
dying replica's "accepted" message go out before it exits. The rest are
in #67717.

## Patches

| Patch | Action |
|---|---|
| `protobuf-bazel7.patch` | **Deleted.** v29.6 has no `exec_tools` left.
|
| gRPC's `third_party/protobuf.patch` | **No longer applied.** It only
touches protobuf's Python package, which Ray doesn't build from Bazel. |
| `grpc-disable-layering-check.patch` | Ported (`gsm` → `csm`; fuzzers
package gone). Without it macOS fails on gRPC's own missing deps. |
| `grpc-configurable-thread-count.patch` | Ported: `cpu.cc` moved to
`src/core/util/linux/`. Behaviour unchanged. |
| `grpc-nextresult-cancelled-init.patch` | Ported. |
| `grpc-python-plugin-no-registered-method.patch` | **New.** gRPC's
Python plugin (from 1.63) emits `_registered_method=True` and
`server.add_registered_method_handlers()`, which need grpcio >= 1.64.
The patch leaves both out, so the `*_pb2_grpc.py` stubs match what the
1.58 plugin generated and keep working with the `grpcio >= 1.42.0` that
`setup.py` allows. Checked on grpcio 1.42.0, 1.62.3, 1.64.3 and 1.75.0;
without the patch the stubs fail on 1.62 and 1.63. |
| `grpc-zlib-fdopen.patch` | Regenerated. The old hunk applied with fuzz
to the wrong `http_archive`. |
| `grpc-cython-copts.patch`, `abseil-cpp-shadow.patch` | Unchanged. |

## What stays the same

- **Runtime protobuf floor for users.** The Python and Java bindings are
still generated by `com_google_protobuf_rules_proto_grpc` (v3.20.3).
- **grpcio floor for users.** Still `grpcio >= 1.42.0`. See
`grpc-python-plugin-no-registered-method.patch` above; CI pins grpcio
1.75, so only a test with an old grpcio shows this.
- **Wheel glibc floor.** Still manylinux2014.
- **WORKSPACE.** Bzlmod is a later step (required by Bazel 9).

## Please review closely

- **gRPC 1.58 → 1.69 is 11 minor versions of core runtime.** Watch
#65984 / #65982 (gRPC fork handling) and #64898 (worker gRPC thread
count). Release perf benchmarks on 1.69 are in the comments: all 13 core
perf tests passed, with no regressions beyond what master nightly
already shows.
- macOS and Windows are verified by CI only.
- `bazel build //...` on Bazel 8 reports conflicting actions for
`//cpp:plus.so` / `//cpp:counter.so` (built in two test configurations).
The targets CI builds are not affected. `//release:requirements_*`
already fails to analyze on master's Bazel 7.5.

## Tests run

| Command | Result |
|---|---|
| Bazel 8.8.1: `bazel build --nobuild //:ray_pkg_zip //:ray_py_proto_zip
//java:gen_ray_java_pkg //cpp:ray_cpp_pkg_zip` | analysis passes |
| Bazel 8.8.1: `bazel build //:ray_py_proto_zip
//src/ray/gcs_rpc_client/tests:gcs_client_test` | build completed
successfully (8,426 actions from cold) |
| Bazel 8.8.1: `bazel build --nobuild -k //...` | passes apart from the
two known issues above |
| Premerge on Bazel 7.5 with every gate unblocked (sanitizers, aarch64,
Windows, macOS) | green: build 75992 |
| Release perf benchmarks (13 core tests) | passed: release build 113271
|
| Premerge on Bazel 8.8.1 with every gate unblocked (sanitizers,
aarch64, Windows, macOS) | green: build 76206 (733 jobs passed, no
retries) |

The Bazel 8 parts were first run in full CI on the PyO3 POC (#66875):
all 14 native images built on Bazel 8 inside CentOS 7, and the remaining
failures were the gRPC ones fixed here.

AI assistance was used for the analysis and for drafting this change.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: elliot-barn <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[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 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