Repository navigation
[serve] Correct the DeploymentResponse.cancel docstring's exception - #67531
Merged
Merged
Conversation
The cancel docstring said a request cancelled before replica assignment raises asyncio.CancelledError, or concurrent.futures.CancelledError from synchronous methods such as .result(), and that one cancelled after assignment raises TaskCancelledError. Every path raises RequestCancelledError, a TaskCancelledError subclass: _fetch_future_result_sync, the replica result's _process_response, and __await__ all convert the cancellation. test_handle_cancellation.py already asserts this for all four cases. Docstring-only change. @rtd-build Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Douglas Strodtman <[email protected]>
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the docstring of the cancel method in python/ray/serve/handle.py to clarify that ray.serve.exceptions.RequestCancelledError is raised when a request is successfully cancelled, regardless of whether it was cancelled before or after assignment. There are no review comments to evaluate, and no additional feedback is provided.
akyang-anyscale
approved these changes
Oct 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Corrects the exception that the
DeploymentResponse.canceldocstring says later operations raise after a successful cancel. This is a docstring-only change. Behavior is unchanged.The docstring sits on
_DeploymentResponseBase, soDeploymentResponseGenerator.cancelinherits the fix.Before
A reader following this writes
except concurrent.futures.CancelledError:around.result(), orexcept asyncio.CancelledError:aroundawait response. Neither clause catches what Serve raises.What the code does
Every path raises
ray.serve.exceptions.RequestCancelledError, which subclassesTaskCancelledError(exceptions.py#L101):_fetch_future_result_synccatches the cancelled routing future'sconcurrent.futures.CancelledErrorand raisesRequestCancelledError(handle.py#L394-L395).ActorReplicaResult._process_responseconvertsTaskCancelledErrortoRequestCancelledError(replica_result.py#L159-L165). The gRPC replica result does the same forconcurrent.futures.CancelledError(replica_result.py#L388-L389).await, either side. The async path surfaces anasyncio.CancelledErrorinternally (replica_result.py#L172), andDeploymentResponse.__await__re-raises it asRequestCancelledErrorwhen the response was cancelled (handle.py#L548-L556).DeploymentResponseGenerator.__anext__does the same (handle.py#L715-L721).test_handle_cancellation.pyalready assertsRequestCancelledErrorfor all four cases: sync and async, during assignment and during execution (L17, L46, L82, L118).After
Subsystems
Serve (docstrings only)
Not a duplicate
I searched open PRs for
DeploymentResponse cancel,RequestCancelledError, and Servehandle.pydocstring changes. #66643 editshandle.pyto let a handler claim an unrouted call, and #67109 and #67210 change cancellation handling in the proxy and gRPC stream paths. None of them changes this docstring or the exception the publiccancelpath raises.Testing
pre-commit run --files python/ray/serve/handle.pypasses, including ruff, black, pydoclint, mypy and pyrefly for Serve, and the Ray docstyle check.ray[serve]==2.59.0wheel, whose cancellation paths match master. It cancels a request queued behind a full replica (max_ongoing_requests=1) and one already running on it, from a driver with.result()and from inside a deployment withawait. All four raisedray.serve.exceptions.RequestCancelledError, and none was an instance ofasyncio.CancelledErrororconcurrent.futures.CancelledError.The
docstring-onlylabel is applied to skip the heavy Serve test suites, and the commit carries an@rtd-buildline to build the API reference preview.I wrote this with AI assistance (Claude Code). I reviewed every changed line and can defend the change.
🤖 Generated with Claude Code