Skip to content

[serve] Add opt-in gRPC server reflection to the gRPC proxy - #65854

Merged
elliot-barn merged 3 commits into
ray-project:masterfrom
qishengxhe:serve/grpc-reflection
Sep 17, 2026
Merged

elliot-barn merged 3 commits into
ray-project:masterfrom
qishengxhe:serve/grpc-reflection

Conversation

@qishengxhe

@qishengxhe qishengxhe commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Why

Feature Request: https://anyscale1.atlassian.net/browse/CI-1545

gRPC Serve apps have no equivalent of FastAPI's /docs. With server reflection enabled, standard tools (grpcurl, grpcui, Postman) can discover and call services with no local proto files:

$ grpcurl -plaintext localhost:9000 list
grpc.reflection.v1alpha.ServerReflection
userdefinedprotos.UserDefinedService

What

  • A new enable_reflection option in gRPCOptions (on by default, per review), mirrored in the config schema and as --grpc-enable-reflection/--grpc-disable-reflection on serve start / serve build.

  • The proxy's gRPCGenericServer normally rewrites every registered handler to route to replicas. Reflection must run on the proxy itself, so this PR adds a passthrough mechanism: services marked via add_passthrough_service() keep their real handlers. When the flag is set, the proxy derives service names from the registered handlers, excludes Serve's built-in RayServeAPIService, and registers the reflection servicer as a passthrough. This all happens once at server startup; the per-request path is unchanged, and with the option disabled no new code runs.

  • grpcio-reflection becomes a default Serve dependency in [serve] Add grpcio-reflection to the serve extra #66067, split out so the lock regeneration reviews on its own. This PR depends on [serve] Add grpcio-reflection to the serve extra #66067 and should merge after it.

Security stance

Reflection exposes service/method/message names and types, the same class of info FastAPI's default-on /docs already exposes for HTTP.

Known limitation to be resolved in follow-up PRs

In HAProxy mode with multiple apps, reflection requests must carry application metadata; header-less requests get NOT_FOUND from HAProxy. Planned fix (separate PR): route /grpc.reflection. to the fallback proxy like ListApplications. Documented in the guide.

Duplicate check

No open PRs or issues for Serve gRPC reflection (gh pr list --repo ray-project/ray --state open --search "grpc reflection" — one unrelated hit). Coordinated on the internal FR ticket.

Tests

  • pytest python/ray/serve/tests/unit/test_grpc_util.py: 13 passed (passthrough survives unmodified, service-name derivation, built-in excluded from advertisement). The reflection tests no longer importorskip, so they run in CI now that the package is in the Serve CI locks.
  • pytest python/ray/serve/tests/unit/test_schema.py -k grpc: passed (config/schema round-trip)
  • pytest python/ray/serve/tests/test_grpc.py: 5 passed, incl. new e2e: reflection client lists/describes with flag on, UNIMPLEMENTED with reflection disabled, user RPCs still route either way
  • Manually verified on a real multi-node cluster and through an ALB: grpcurl list/describe, unary and server-streaming RPCs invoked purely via reflection, and the grpcui web UI.
image

AI assistance was used for this PR; every changed line was reviewed and all tests were run by the submitter.

🤖 Generated with Claude Code

@qishengxhe
qishengxhe marked this pull request as ready for review September 2, 2026 17:27
@qishengxhe
qishengxhe requested review from a team as code owners September 2, 2026 17:27

@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 support for the gRPC server reflection protocol on Ray Serve's gRPC proxy, allowing tools like grpcurl and grpcui to discover and call registered services. It adds an enable_reflection option to gRPCOptions, updates dependencies to include grpcio-reflection, and implements a passthrough mechanism in gRPCGenericServer so reflection requests execute directly on the proxy. The feedback highlights two important improvements: first, the passthrough check should be performed per-method rather than per-sequence to prevent user-defined services from accidentally bypassing routing overrides if registered together; second, defensive checks should be added to get_service_names to safely handle empty sequences or unexpected method key formats and avoid potential IndexErrors.

Comment thread python/ray/serve/_private/grpc_util.py Resolved
Comment thread python/ray/serve/_private/grpc_util.py Resolved
@qishengxhe
qishengxhe marked this pull request as draft September 2, 2026 17:36
@qishengxhe
qishengxhe marked this pull request as ready for review September 2, 2026 18:11

@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 adds support for the gRPC server reflection protocol to Ray Serve's gRPC proxy, allowing tools like grpcurl and grpcui to discover and call registered gRPC services. It introduces an enable_reflection option in gRPCOptions, updates the CLI and schema, and adds the grpcio-reflection dependency. To support reflection, a passthrough mechanism is added to gRPCGenericServer so reflection requests execute directly on the proxy rather than routing to replicas. Feedback on the changes suggests making the get_service_names helper function more robust by defensively checking for empty handler sequences, verifying the presence of private attributes, and safely parsing service names to prevent potential runtime errors.

Comment thread python/ray/serve/_private/grpc_util.py Resolved
@ray-gardener ray-gardener Bot added the serve Ray Serve Related Issue label Sep 2, 2026
@YashwanthRanjanSingaravel YashwanthRanjanSingaravel added the go add ONLY when ready to merge, run all tests label Sep 3, 2026

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

overall looks good to me; from functionality pov, i would advise to have it review from @abrarsheikh as he had made changes in this area recently.

Comment thread python/ray/serve/schema.py Resolved

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

it would be nice if we can thread the url into application_details docs_path https://github.com/ray-project/ray/blob/master/python/ray/serve/schema.py#L1562. i think this happens for the fastapi case as well, but you should test that.

is this compatible with haproxy?

Comment thread python/ray/serve/tests/test_grpc.py Resolved
Comment thread python/ray/serve/schema.py Resolved
@qishengxhe
qishengxhe force-pushed the serve/grpc-reflection branch from 5910b78 to 37be06a Compare September 10, 2026 23:33
@qishengxhe
qishengxhe requested review from a team, edoakes and richardliaw as code owners September 10, 2026 23:33

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

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 37be06a. Configure here.

@qishengxhe

Copy link
Copy Markdown
Contributor Author

it would be nice if we can thread the url into application_details docs_path https://github.com/ray-project/ray/blob/master/python/ray/serve/schema.py#L1562. i think this happens for the fastapi case as well, but you should test that.

I'd love that, but grpc-reflection is not a webpage, it's a grpc service running on the proxy's grpc port. grpcui is a tool users can run themselves, which connects to the server over reflection and serves its own local web UI (as shown in the PR description).
Maybe as a workaround we can display a copyable grpcui command?

is this compatible with haproxy?

yes according to my testing it works with single app, but requires a bit more work for multi apps. I listed it a followup in the description:

In HAProxy mode with multiple apps, reflection requests must carry application metadata; header-less requests get NOT_FOUND from HAProxy. Planned fix (separate PR): route /grpc.reflection. to the fallback proxy like ListApplications. Documented in the guide.

@qishengxhe
qishengxhe force-pushed the serve/grpc-reflection branch 2 times, most recently from 5f813ca to db47c35 Compare September 11, 2026 00:40
qishengxhe added a commit to qishengxhe/ray that referenced this pull request Sep 14, 2026
Add `grpcio-reflection` as a default Serve dependency: the `serve` extra
in setup.py (mirrored in python/requirements.txt), pinned in
test-requirements.txt alongside grpcio-tools and grpcio-status, mirrored
into the compiled constraints, and the lock files regenerated with
`raydepsets build --all-configs` (`--check` passes).

This is the dependency half of ray-project#65854 (gRPC server reflection on the
Serve gRPC proxy), split out so the lock regeneration reviews on its own.

grpcio-reflection tracks grpcio, so it takes the same three-way pin that
ray-project#66119 gave grpcio-tools and grpcio-status: 1.71.2 below Python 3.12
(1.72+ requires protobuf>=6.30, incompatible with the protobuf 5.27.5 pin
on that track), 1.75.0 on 3.12-3.13, and 1.76.0 on 3.14. No lock moves
protobuf or grpcio.

Lock changes: every lock that installs the serve extra gains exactly one
grpcio-reflection line, matched to its existing grpcio pin. The two
`expand` depsets with no constraints file (tests/data/datatfds_py3.12,
byod/audio_transcription_py3.10) resolve the newest grpcio-reflection
(1.83.1) and follow it to grpcio 1.83.1, protobuf 7.36.1, and newer
google-cloud/opentelemetry pins; this is inherent to unconstrained
expand depsets and matches the pre-rebase version of this change.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Qisheng He <[email protected]>
richardliaw pushed a commit that referenced this pull request Sep 15, 2026
## Why

Prerequisite for #65854, which adds gRPC server reflection to Serve's
gRPC proxy. Reviewers there asked for `grpcio-reflection` to be a
default Serve dependency rather than an optional install, and for the
lock regeneration to be reviewed on its own, so the dependency change is
split out here.

## What

- `grpcio-reflection` added to the `serve` extra in `setup.py`, mirrored
in `python/requirements.txt` (same shape as the `jinja2` addition in
#65542).
- Pinned in `test-requirements.txt` next to `grpcio-tools` /
`grpcio-status`, with the same three-way split #66119 gave those two:
**1.71.2 on py<3.12**, 1.75.0 on py3.12–3.13, 1.76.0 on py3.14.
grpcio-reflection ≥ 1.72 requires protobuf ≥ 6.30, so 1.71.2 is the
newest release compatible with the protobuf 5.27.5 pin on the py<3.12
track. Mirrored into `requirements_compiled.txt` (py<3.12 branch, as
pip-compile emits it) and `requirements_compiled_py3.14.txt`.
- Lock files regenerated with `bazelisk run //ci/raydepsets:raydepsets
-- build --all-configs`; `--check` passes locally.

No code changes. The feature that uses the package lands in #65854.

**Rebased on 2026-09-14 after #66119 landed.** Master now pins protobuf
5.27.5 on py<3.12, which is exactly the constraint the earlier
`py310_protobuf_overrides.txt` / `--override` mechanism was working
around, so that mechanism is gone: no override file, no depset config
edits. The branch is a single commit again.

## Lock changes vs master

- 92 locks gain exactly one `grpcio-reflection` line, matched to the
grpcio already pinned in that lock (1.71.2, 1.75.0, 1.76.0, or
1.78.0/1.80.0/1.62.3 in the few locks on a different grpcio). **No lock
moves protobuf or grpcio.**
- **Two `expand` depsets with no constraints file**
(`tests/data/datatfds_py3.12`, `byod/audio_transcription_py3.10`)
resolve the newest grpcio-reflection (1.83.1) and follow it to grpcio
1.83.1, protobuf 7.36.1, and newer google-cloud/opentelemetry pins. Same
as before the rebase: a pre-existing gap in those depset definitions;
happy to add a constraints file to them if preferred.

## Tests

- `bazelisk run //ci/raydepsets:raydepsets -- build --all-configs` then
`--check`: "Lock files are up to date."
- `pre-commit run --files` on the edited source and compiled files:
passed.
- The `pip-compile dependencies` CI job validates the hand-added
`requirements_compiled*.txt` entries.

AI assistance was used for this PR; every changed line was reviewed and
all checks were run by the submitter.

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

---------

Signed-off-by: Qisheng He <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
Serve's gRPC proxy now serves the gRPC server reflection protocol, so
standard tools (grpcurl, grpcui, Postman) can discover and call the
registered user-defined gRPC services without local proto files, similar
to FastAPI's /docs page for HTTP.

- `enable_reflection` option in `gRPCOptions` (on by default), mirrored in
  the config schema and as `--grpc-enable-reflection/--grpc-disable-reflection`
  on `serve start` / `serve build`.
- The reflection service must execute on the proxy rather than being
  routed to a replica, so `gRPCGenericServer` gains a passthrough
  mechanism: handlers for registered passthrough services are added
  unmodified while all other handlers keep the replica-routing override.
  Advertised service names are derived from the registered method
  handlers, excluding Serve's built-in `RayServeAPIService`.
- `grpcio-reflection` (added to the `serve` extra in a separate PR) is
  imported lazily inside `enable_server_reflection`, following the jinja2
  precedent in ray-project#65542, so a plain `import ray.serve` doesn't require it.
  If it's missing, reflection is skipped with a warning instead of
  failing proxy startup.
- Guide section covering the flag, grpcurl/grpcui usage, and the HAProxy
  multi-app limitation (reflection requests need `application` metadata;
  routing the `/grpc.reflection.` prefix to the fallback proxy is a
  follow-up).

@MicroCheck //python/ray/serve/tests:test_grpc //python/ray/serve/tests/unit:test_grpc_util //python/ray/serve/tests/unit:test_schema

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Qisheng He <[email protected]>
@qishengxhe
qishengxhe force-pushed the serve/grpc-reflection branch from db47c35 to 928a4a7 Compare September 15, 2026 00:27
Comment thread python/ray/serve/_private/grpc_util.py Resolved
….67.1 on py<3.12

Address review: import grpc_reflection at the top of grpc_util.py instead
of lazily inside enable_server_reflection, and drop the ImportError
fallback and its unit test now that grpcio-reflection ships in ray[serve].

Fix premerge: grpcio-reflection 1.71.2 bundles protobuf gencode 5.29.0,
which the py3.10/3.11 CI images (protobuf 5.27.5) reject with
VersionError on import, failing every gRPC proxy startup. 1.67.1 is the
newest release generated with protobuf 5.27.x, so pin it on py<3.12 and
regenerate the affected locks.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Qisheng He <[email protected]>
@abrarsheikh

Copy link
Copy Markdown
Contributor

why are the hashes back? is that a bad merge?

grpc_util now imports grpc_reflection at module top, and the Read the Docs
environment does not install grpcio-reflection (grpc itself is mocked
there), so autosummary failed to import ray.serve. Mock grpc_reflection
alongside grpc.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Qisheng He <[email protected]>
@qishengxhe
qishengxhe requested a review from a team as a code owner September 15, 2026 03:11
@qishengxhe

Copy link
Copy Markdown
Contributor Author

why are the hashes back? is that a bad merge?

I had to pin grpcio-reflection down to 1.67.1 from master's 1.71.2 for py<3.12 and regenerate those affected locks to pass premerge.

#66067 only installs grpcio-reflection but nothing imports it. the gencode/runtime check is a runtime check so the version mismatch is only triggered in this PR

@elliot-barn
elliot-barn merged commit 31302d3 into ray-project:master Sep 17, 2026
6 checks passed
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
## Why

Prerequisite for ray-project#65854, which adds gRPC server reflection to Serve's
gRPC proxy. Reviewers there asked for `grpcio-reflection` to be a
default Serve dependency rather than an optional install, and for the
lock regeneration to be reviewed on its own, so the dependency change is
split out here.

## What

- `grpcio-reflection` added to the `serve` extra in `setup.py`, mirrored
in `python/requirements.txt` (same shape as the `jinja2` addition in
ray-project#65542).
- Pinned in `test-requirements.txt` next to `grpcio-tools` /
`grpcio-status`, with the same three-way split ray-project#66119 gave those two:
**1.71.2 on py<3.12**, 1.75.0 on py3.12–3.13, 1.76.0 on py3.14.
grpcio-reflection ≥ 1.72 requires protobuf ≥ 6.30, so 1.71.2 is the
newest release compatible with the protobuf 5.27.5 pin on the py<3.12
track. Mirrored into `requirements_compiled.txt` (py<3.12 branch, as
pip-compile emits it) and `requirements_compiled_py3.14.txt`.
- Lock files regenerated with `bazelisk run //ci/raydepsets:raydepsets
-- build --all-configs`; `--check` passes locally.

No code changes. The feature that uses the package lands in ray-project#65854.

**Rebased on 2026-09-14 after ray-project#66119 landed.** Master now pins protobuf
5.27.5 on py<3.12, which is exactly the constraint the earlier
`py310_protobuf_overrides.txt` / `--override` mechanism was working
around, so that mechanism is gone: no override file, no depset config
edits. The branch is a single commit again.

## Lock changes vs master

- 92 locks gain exactly one `grpcio-reflection` line, matched to the
grpcio already pinned in that lock (1.71.2, 1.75.0, 1.76.0, or
1.78.0/1.80.0/1.62.3 in the few locks on a different grpcio). **No lock
moves protobuf or grpcio.**
- **Two `expand` depsets with no constraints file**
(`tests/data/datatfds_py3.12`, `byod/audio_transcription_py3.10`)
resolve the newest grpcio-reflection (1.83.1) and follow it to grpcio
1.83.1, protobuf 7.36.1, and newer google-cloud/opentelemetry pins. Same
as before the rebase: a pre-existing gap in those depset definitions;
happy to add a constraints file to them if preferred.

## Tests

- `bazelisk run //ci/raydepsets:raydepsets -- build --all-configs` then
`--check`: "Lock files are up to date."
- `pre-commit run --files` on the edited source and compiled files:
passed.
- The `pip-compile dependencies` CI job validates the hand-added
`requirements_compiled*.txt` entries.

AI assistance was used for this PR; every changed line was reviewed and
all checks were run by the submitter.

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

---------

Signed-off-by: Qisheng He <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…ect#65854)

## Why

Feature Request: https://anyscale1.atlassian.net/browse/CI-1545

gRPC Serve apps have no equivalent of FastAPI's `/docs`. With [server
reflection](https://grpc.io/docs/guides/reflection/) enabled, standard
tools (grpcurl, grpcui, Postman) can discover and call services with no
local proto files:

```bash
$ grpcurl -plaintext localhost:9000 list
grpc.reflection.v1alpha.ServerReflection
userdefinedprotos.UserDefinedService
```

## What

- A new `enable_reflection` option in `gRPCOptions` (on by default, per
review), mirrored in the config schema and as
`--grpc-enable-reflection/--grpc-disable-reflection` on `serve start` /
`serve build`.

- The proxy's `gRPCGenericServer` normally rewrites every registered
handler to route to replicas. Reflection must run on the proxy itself,
so this PR adds a passthrough mechanism: services marked via
`add_passthrough_service()` keep their real handlers. When the flag is
set, the proxy derives service names from the registered handlers,
excludes Serve's built-in `RayServeAPIService`, and registers the
reflection servicer as a passthrough. This all happens once at server
startup; the per-request path is unchanged, and with the option disabled
no new code runs.

- `grpcio-reflection` becomes a default Serve dependency in ray-project#66067,
split out so the lock regeneration reviews on its own. **This PR depends
on ray-project#66067 and should merge after it.**

## Security stance

Reflection exposes service/method/message names and types, the same
class of info FastAPI's default-on `/docs` already exposes for HTTP.

## Known limitation to be resolved in follow-up PRs

In HAProxy mode with multiple apps, reflection requests must carry
`application` metadata; header-less requests get NOT_FOUND from HAProxy.
Planned fix (separate PR): route `/grpc.reflection.` to the fallback
proxy like `ListApplications`. Documented in the guide.

## Duplicate check

No open PRs or issues for Serve gRPC reflection (`gh pr list --repo
ray-project/ray --state open --search "grpc reflection"` — one unrelated
hit). Coordinated on the internal FR ticket.

## Tests

- `pytest python/ray/serve/tests/unit/test_grpc_util.py`: 13 passed
(passthrough survives unmodified, service-name derivation, built-in
excluded from advertisement). The reflection tests no longer
`importorskip`, so they run in CI now that the package is in the Serve
CI locks.
- `pytest python/ray/serve/tests/unit/test_schema.py -k grpc`: passed
(config/schema round-trip)
- `pytest python/ray/serve/tests/test_grpc.py`: 5 passed, incl. new e2e:
reflection client lists/describes with flag on, `UNIMPLEMENTED` with
reflection disabled, user RPCs still route either way
- Manually verified on a real multi-node cluster and through an ALB:
grpcurl `list`/`describe`, unary and server-streaming RPCs invoked
purely via reflection, and the grpcui web UI.
<img width="1276" height="911" alt="image"
src="https://github.com/user-attachments/assets/648635e9-3001-4691-97ef-470c76d8596a"
/>


AI assistance was used for this PR; every changed line was reviewed and
all tests were run by the submitter.

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

---------

Signed-off-by: Qisheng He <[email protected]>
Co-authored-by: Claude <[email protected]>
pcmoritz pushed a commit that referenced this pull request Oct 27, 2026
…67444)

## Description

Since #65854, `ray/serve/_private/grpc_util.py` imports
`grpc_reflection` at module load, so `import ray.serve` needs
grpcio-reflection even when reflection is off. That package only comes
with the `serve` extra. vLLM's Ray metrics
(`vllm/v1/metrics/ray_wrappers.py`) import `ray.serve` and
`ray.util.metrics` in one `try` block, so in a `ray[default]`
environment a vLLM engine with `RayPrometheusStatLogger` fails to start
with "RayPrometheusMetric requires Ray to be installed." I hit this on
Ray nightly with SkyRL, which turns that logger on by default. Ray
2.59.0 doesn't have the import, so the next release would be the first
one affected.

This PR moves the import into `enable_server_reflection()`, its only
user. If reflection is turned on without the package, the error names it
and points to `pip install "ray[serve]"`, the hint Serve already adds at
import time.

## Related issues

None filed. Found while running SkyRL's Harbor integration on Ray
nightly (skyrl-project/SkyRL#2467).

## Additional information

- Not a duplicate: I searched PRs and issues for `grpc_reflection`,
`grpcio-reflection` and the vLLM error, and none moves this import.
#66067 added grpcio-reflection to the `serve` extra, which doesn't cover
environments without that extra.
- Tests: `test_serve_imports_without_grpc_reflection` imports Serve in a
subprocess with `grpc_reflection` blocked, and
`test_enable_server_reflection_without_grpc_reflection` checks the error
message. Both fail on master.
- Tested on macOS arm64 and Python 3.12 with today's nightly wheel
(3608367, whose `grpc_util.py` matches master) and the two changed
files linked in. `pytest python/ray/serve/tests/unit/test_grpc_util.py`:
18 passed. `pytest python/ray/serve/tests/test_grpc.py`: 45 passed. With
grpcio-reflection uninstalled, vLLM's imports fail on master and work
with this change. pre-commit passes.
- I used Claude Code to help write and test this change.

---------

Signed-off-by: xyuzh <[email protected]>
justinyeh1995 pushed a commit to justinyeh1995/ray that referenced this pull request Oct 28, 2026
…ay-project#67444)

## Description

Since ray-project#65854, `ray/serve/_private/grpc_util.py` imports
`grpc_reflection` at module load, so `import ray.serve` needs
grpcio-reflection even when reflection is off. That package only comes
with the `serve` extra. vLLM's Ray metrics
(`vllm/v1/metrics/ray_wrappers.py`) import `ray.serve` and
`ray.util.metrics` in one `try` block, so in a `ray[default]`
environment a vLLM engine with `RayPrometheusStatLogger` fails to start
with "RayPrometheusMetric requires Ray to be installed." I hit this on
Ray nightly with SkyRL, which turns that logger on by default. Ray
2.59.0 doesn't have the import, so the next release would be the first
one affected.

This PR moves the import into `enable_server_reflection()`, its only
user. If reflection is turned on without the package, the error names it
and points to `pip install "ray[serve]"`, the hint Serve already adds at
import time.

## Related issues

None filed. Found while running SkyRL's Harbor integration on Ray
nightly (skyrl-project/SkyRL#2467).

## Additional information

- Not a duplicate: I searched PRs and issues for `grpc_reflection`,
`grpcio-reflection` and the vLLM error, and none moves this import.
ray-project#66067 added grpcio-reflection to the `serve` extra, which doesn't cover
environments without that extra.
- Tests: `test_serve_imports_without_grpc_reflection` imports Serve in a
subprocess with `grpc_reflection` blocked, and
`test_enable_server_reflection_without_grpc_reflection` checks the error
message. Both fail on master.
- Tested on macOS arm64 and Python 3.12 with today's nightly wheel
(3608367, whose `grpc_util.py` matches master) and the two changed
files linked in. `pytest python/ray/serve/tests/unit/test_grpc_util.py`:
18 passed. `pytest python/ray/serve/tests/test_grpc.py`: 45 passed. With
grpcio-reflection uninstalled, vLLM's imports fail on master and work
with this change. pre-commit passes.
- I used Claude Code to help write and test this change.

---------

Signed-off-by: xyuzh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests serve Ray Serve Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants