Skip to content

[Serve] Preserve user-set gRPC status codes when exceptions are raised#60482

Merged
abrarsheikh merged 4 commits intomasterfrom
58851-abrar-grpc
Jan 28, 2026
Merged

[Serve] Preserve user-set gRPC status codes when exceptions are raised#60482
abrarsheikh merged 4 commits intomasterfrom
58851-abrar-grpc

Conversation

@abrarsheikh
Copy link
Contributor

Fixes #58851

Changes

  1. New gRPCStatusError exception class - Wraps exceptions with user-set gRPC status codes so they flow through Ray's error handling path.
  2. Exception wrapping in replica methods - handle_request, handle_request_streaming, and handle_request_with_rejection now wrap exceptions with gRPCStatusError when the user has set a status code on the gRPC context.
  3. Status code preservation in proxy - get_grpc_response_status() now detects gRPCStatusError and returns the user's intended status code instead of INTERNAL.
  4. Message truncation - Added _truncate_message() to limit error details to 4KB, avoiding HTTP/2 trailer size limits.
  5. Documentation updates - Updated the gRPC guide to document the new behavior.

Signed-off-by: abrar <abrar@anyscale.com>
@abrarsheikh abrarsheikh added the go add ONLY when ready to merge, run all tests label Jan 25, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 valuable feature to preserve user-set gRPC status codes when exceptions are raised in Ray Serve deployments. The implementation is well-structured, introducing a gRPCStatusError to carry the context, updating replica methods to wrap exceptions, and modifying the proxy to respect the user's intended status code. The addition of message truncation is a thoughtful improvement to prevent issues with large error messages. The documentation and tests are comprehensive and clearly cover the new functionality.

I've found one potential issue related to handling asyncio.CancelledError on older Python versions, which could lead to inconsistent behavior. My specific comments provide suggestions to address this. Overall, this is a great enhancement to Ray Serve's gRPC capabilities.

@abrarsheikh abrarsheikh marked this pull request as ready for review January 26, 2026 17:38
@abrarsheikh abrarsheikh requested a review from a team as a code owner January 26, 2026 17:38
@ray-gardener ray-gardener bot added serve Ray Serve Related Issue docs An issue or change related to documentation labels Jan 26, 2026
Signed-off-by: abrar <abrar@anyscale.com>
Signed-off-by: abrar <abrar@anyscale.com>
Copy link
Contributor

@harshit-anyscale harshit-anyscale left a comment

Choose a reason for hiding this comment

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

one minor comment, else LGTM

@abrarsheikh abrarsheikh merged commit 221a193 into master Jan 28, 2026
6 checks passed
@abrarsheikh abrarsheikh deleted the 58851-abrar-grpc branch January 28, 2026 07:43
jinbum-kim pushed a commit to jinbum-kim/ray that referenced this pull request Jan 29, 2026
ray-project#60482)

Fixes ray-project#58851

### Changes

1. **New `gRPCStatusError` exception class** - Wraps exceptions with
user-set gRPC status codes so they flow through Ray's error handling
path.
2. **Exception wrapping in replica methods** - `handle_request`,
`handle_request_streaming`, and `handle_request_with_rejection` now wrap
exceptions with `gRPCStatusError` when the user has set a status code on
the gRPC context.
3. **Status code preservation in proxy** - `get_grpc_response_status()`
now detects `gRPCStatusError` and returns the user's intended status
code instead of `INTERNAL`.
4. **Message truncation** - Added `_truncate_message()` to limit error
details to 4KB, avoiding HTTP/2 trailer size limits.
5. **Documentation updates** - Updated the gRPC guide to document the
new behavior.

---------

Signed-off-by: abrar <abrar@anyscale.com>
Signed-off-by: jinbum-kim <jinbum9958@gmail.com>
limarkdcunha pushed a commit to limarkdcunha/ray that referenced this pull request Jan 29, 2026
ray-project#60482)

Fixes ray-project#58851

### Changes

1. **New `gRPCStatusError` exception class** - Wraps exceptions with
user-set gRPC status codes so they flow through Ray's error handling
path.
2. **Exception wrapping in replica methods** - `handle_request`,
`handle_request_streaming`, and `handle_request_with_rejection` now wrap
exceptions with `gRPCStatusError` when the user has set a status code on
the gRPC context.
3. **Status code preservation in proxy** - `get_grpc_response_status()`
now detects `gRPCStatusError` and returns the user's intended status
code instead of `INTERNAL`.
4. **Message truncation** - Added `_truncate_message()` to limit error
details to 4KB, avoiding HTTP/2 trailer size limits.
5. **Documentation updates** - Updated the gRPC guide to document the
new behavior.

---------

Signed-off-by: abrar <abrar@anyscale.com>
400Ping pushed a commit to 400Ping/ray that referenced this pull request Feb 1, 2026
ray-project#60482)

Fixes ray-project#58851

### Changes

1. **New `gRPCStatusError` exception class** - Wraps exceptions with
user-set gRPC status codes so they flow through Ray's error handling
path.
2. **Exception wrapping in replica methods** - `handle_request`,
`handle_request_streaming`, and `handle_request_with_rejection` now wrap
exceptions with `gRPCStatusError` when the user has set a status code on
the gRPC context.
3. **Status code preservation in proxy** - `get_grpc_response_status()`
now detects `gRPCStatusError` and returns the user's intended status
code instead of `INTERNAL`.
4. **Message truncation** - Added `_truncate_message()` to limit error
details to 4KB, avoiding HTTP/2 trailer size limits.
5. **Documentation updates** - Updated the gRPC guide to document the
new behavior.

---------

Signed-off-by: abrar <abrar@anyscale.com>
Signed-off-by: 400Ping <jiekaichang@apache.org>
ans9868 pushed a commit to ans9868/ray that referenced this pull request Feb 18, 2026
ray-project#60482)

Fixes ray-project#58851

### Changes

1. **New `gRPCStatusError` exception class** - Wraps exceptions with
user-set gRPC status codes so they flow through Ray's error handling
path.
2. **Exception wrapping in replica methods** - `handle_request`,
`handle_request_streaming`, and `handle_request_with_rejection` now wrap
exceptions with `gRPCStatusError` when the user has set a status code on
the gRPC context.
3. **Status code preservation in proxy** - `get_grpc_response_status()`
now detects `gRPCStatusError` and returns the user's intended status
code instead of `INTERNAL`.
4. **Message truncation** - Added `_truncate_message()` to limit error
details to 4KB, avoiding HTTP/2 trailer size limits.
5. **Documentation updates** - Updated the gRPC guide to document the
new behavior.

---------

Signed-off-by: abrar <abrar@anyscale.com>
Signed-off-by: Adel Nour <ans9868@nyu.edu>
peterxcli pushed a commit to peterxcli/ray that referenced this pull request Feb 25, 2026
ray-project#60482)

Fixes ray-project#58851

### Changes

1. **New `gRPCStatusError` exception class** - Wraps exceptions with
user-set gRPC status codes so they flow through Ray's error handling
path.
2. **Exception wrapping in replica methods** - `handle_request`,
`handle_request_streaming`, and `handle_request_with_rejection` now wrap
exceptions with `gRPCStatusError` when the user has set a status code on
the gRPC context.
3. **Status code preservation in proxy** - `get_grpc_response_status()`
now detects `gRPCStatusError` and returns the user's intended status
code instead of `INTERNAL`.
4. **Message truncation** - Added `_truncate_message()` to limit error
details to 4KB, avoiding HTTP/2 trailer size limits.
5. **Documentation updates** - Updated the gRPC guide to document the
new behavior.

---------

Signed-off-by: abrar <abrar@anyscale.com>
Signed-off-by: peterxcli <peterxcli@gmail.com>
peterxcli pushed a commit to peterxcli/ray that referenced this pull request Feb 25, 2026
ray-project#60482)

Fixes ray-project#58851

### Changes

1. **New `gRPCStatusError` exception class** - Wraps exceptions with
user-set gRPC status codes so they flow through Ray's error handling
path.
2. **Exception wrapping in replica methods** - `handle_request`,
`handle_request_streaming`, and `handle_request_with_rejection` now wrap
exceptions with `gRPCStatusError` when the user has set a status code on
the gRPC context.
3. **Status code preservation in proxy** - `get_grpc_response_status()`
now detects `gRPCStatusError` and returns the user's intended status
code instead of `INTERNAL`.
4. **Message truncation** - Added `_truncate_message()` to limit error
details to 4KB, avoiding HTTP/2 trailer size limits.
5. **Documentation updates** - Updated the gRPC guide to document the
new behavior.

---------

Signed-off-by: abrar <abrar@anyscale.com>
Signed-off-by: peterxcli <peterxcli@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs An issue or change related to documentation 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.

[Serve] Improve ray serve gRPC support

2 participants