Skip to content

[serve] add ability to track child requests#53941

Merged
zcin merged 1 commit intoray-project:masterfrom
zcin:cancel-request-improve
Jun 19, 2025
Merged

[serve] add ability to track child requests#53941
zcin merged 1 commit intoray-project:masterfrom
zcin:cancel-request-improve

Conversation

@zcin
Copy link
Copy Markdown
Contributor

@zcin zcin commented Jun 19, 2025

Why are these changes needed?

Track child requests in Ray Serve.

Signed-off-by: Cindy Zhang <cindyzyx9@gmail.com>
Copilot AI review requested due to automatic review settings June 19, 2025 01:54
@zcin zcin requested a review from a team as a code owner June 19, 2025 01:54
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds the ability to track child Serve requests so that when a parent request is cancelled, all its in-flight children are also cancelled.

  • Introduce in-flight request bookkeeping in the request context and ReplicaResult.
  • Update handle logic to catch and translate asyncio.CancelledError into RequestCancelledError based on the cancellation flag.
  • Adjust existing HTTP and iterator cancellation tests to use a URL helper and new error naming.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
python/ray/serve/tests/test_http_cancellation.py Replace hardcoded URL with get_application_url and update expected cancellation tag name.
python/ray/serve/tests/test_handle_cancellation.py Remove unnecessary assert inside pytest.raises for async iterator cancellation.
python/ray/serve/handle.py Add try/except around __await__/__anext__ to rethrow RequestCancelledError when needed.
python/ray/serve/context.py Add cancel_on_parent_request_cancel flag and helper functions to track in-flight requests.
python/ray/serve/_private/replica_result.py Register and clean up in-flight child requests; adjust cancellation error mapping.
python/ray/serve/_private/replica.py Extend _on_request_cancelled to cancel both pending and in-flight child requests.
Comments suppressed due to low confidence (4)

python/ray/serve/_private/replica.py:896

  • [nitpick] The parameter was renamed from request_metadata to metadata, which is inconsistent with other methods in this class. Consider aligning on one name (e.g., request_metadata) for clarity.
    ):

python/ray/serve/context.py:282

  • [nitpick] These new helper functions lack type hints and docstrings. Adding a return type annotation and a brief docstring would improve readability and maintainability.
def _get_in_flight_requests(parent_request_id):

python/ray/serve/handle.py:282

  • The removal of the try/except around the wrap_future call means asyncio.CancelledError will bypass the original cancellation handling in _fetch_future_result_async. Consider reinstating the catch to raise RequestCancelledError when self._cancelled is true, preserving the intended semantics.
            self._replica_result = await asyncio.wrap_future(

python/ray/serve/_private/replica_result.py:112

  • Catching TaskCancelledError and rethrowing a bare asyncio.CancelledError loses the original request ID context. It may be better to rethrow RequestCancelledError(self._request_id) here to maintain consistency in cancellation reporting.
                raise asyncio.CancelledError()

@zcin zcin added the go add ONLY when ready to merge, run all tests label Jun 19, 2025
Comment on lines +282 to +284
self._replica_result = await asyncio.wrap_future(
self._replica_result_future
)
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.

curious why did we have to move the exception handling to the caller?

@zcin zcin merged commit 50d860a into ray-project:master Jun 19, 2025
5 checks passed
@zcin zcin deleted the cancel-request-improve branch June 19, 2025 18:51
minerharry pushed a commit to minerharry/ray that referenced this pull request Jun 27, 2025
## Why are these changes needed?

Track child requests in Ray Serve.

Signed-off-by: Cindy Zhang <cindyzyx9@gmail.com>
elliot-barn pushed a commit that referenced this pull request Jul 2, 2025
## Why are these changes needed?

Track child requests in Ray Serve.

Signed-off-by: Cindy Zhang <cindyzyx9@gmail.com>
Signed-off-by: elliot-barn <elliot.barnwell@anyscale.com>
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants