Skip to content

[Serve] Add on_request_completed hook and supports_rejection_protocol to custom request router API#60845

Draft
abrarsheikh wants to merge 2 commits intomasterfrom
SERVE-1555-abrar-routing
Draft

[Serve] Add on_request_completed hook and supports_rejection_protocol to custom request router API#60845
abrarsheikh wants to merge 2 commits intomasterfrom
SERVE-1555-abrar-routing

Conversation

@abrarsheikh
Copy link
Contributor

  • Add on_request_completed(replica_id, internal_request_id) lifecycle hook to RequestRouter, called when a request finishes (success or failure). This enables custom routers to perform cleanup such as releasing capacity tokens.
  • Always register a done-callback on ReplicaResult (not just when autoscaling metrics are enabled) so the router is notified of every completion. Add a finally guard for the error path where the callback couldn't be registered.
  • Add supports_rejection_protocol property so custom routers that guarantee capacity client-side can opt out of the rejection round-trip.
  • Extract inline backoff logic into overridable _compute_backoff_s / _backoff helpers.

… to custom request router API

Signed-off-by: abrar <abrar@anyscale.com>
@abrarsheikh abrarsheikh added the go add ONLY when ready to merge, run all tests label Feb 8, 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 several valuable enhancements to the custom request router API. The addition of the on_request_completed lifecycle hook, along with the robust implementation that ensures it's called even in failure scenarios, is a great improvement for custom routers needing cleanup logic. The new supports_rejection_protocol property provides useful flexibility for routers that manage capacity client-side. Extracting the backoff logic into _compute_backoff_s and _backoff helpers is a good design choice that improves extensibility.

The changes are well-implemented and accompanied by thorough tests. My review includes a few minor suggestions to add return type hints for better code clarity and type safety. Overall, this is a solid contribution.

Signed-off-by: abrar <abrar@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.

1 participant