Repository navigation
Conversation
Make RoutingInterface.route_request an async method that always accepts request_json (Optional[Dict] = None, normalized inside the routers that use it, to avoid a mutable default argument). All six router implementations now share the same coroutine signature, so call sites in route_general_request and proxy_multipart_request can always await route_request and always pass request_json, removing the fragile isinstance dispatch guards that broke proxy_multipart_request for SessionRouter (missing request_json and missing await). Routing behavior is unchanged: previously-sync routers simply do not await anything internally. Fixes vllm-project#1022 Fixes vllm-project#1019 Signed-off-by: Mohith Gajjela <[email protected]>
Add tests asserting that every router's route_request is a coroutine function with a request_json parameter, that RoundRobinRouter routes correctly via the awaited path, and that route_general_request and proxy_multipart_request await route_request and pass request_json for any RoutingInterface implementation (no isinstance-dependent dispatch). Relates to vllm-project#1022 Signed-off-by: Mohith Gajjela <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request standardizes the route_request method signature across all routers to be asynchronous and accept an optional request_json parameter, which simplifies call-site dispatching by removing isinstance checks. Feedback highlights a potential KeyError in PrefixAwareRouter when request_json is empty (e.g., during multipart requests), and suggests omitting the redundant empty dictionary argument in proxy_multipart_request since the parameter is optional.
| if request_json is None: | ||
| request_json = {} |
There was a problem hiding this comment.
If 'request_json' is empty (for example, when passed as '{}' from 'proxy_multipart_request' during audio transcription), 'messages' will not be present. This causes the router to fall through to the 'else' block at line 512: 'prompt = request_json["prompt"]', which will raise a 'KeyError' and crash the request. To prevent this, we should ensure that 'prompt' is initialized to an empty string if neither 'messages' nor 'prompt' is present in 'request_json'.
| if request_json is None: | |
| request_json = {} | |
| if request_json is None: | |
| request_json = {} | |
| if "messages" not in request_json and "prompt" not in request_json: | |
| request_json["prompt"] = "" |
| chosen_url = await router.route_request( | ||
| endpoints, | ||
| engine_stats, | ||
| request_stats, | ||
| request, | ||
| {}, # multipart/form-data requests carry no JSON body | ||
| ) |
There was a problem hiding this comment.
|
Hi, could you resolve the conflict when you have time? |
Make RoutingInterface.route_request a coroutine with an optional
request_json parameter, and give every router that signature, including
PriorityRouter and LoadAwareRouter, which arrived after the original
branch. Both dispatch sites in request.py then await the router directly:
route_general_request and the failover loop drop their isinstance chains,
and proxy_multipart_request makes one awaited call that passes {}.
The DisaggregatedPrefill* handler dispatch in route_general_request stays,
because those routers go to different request handlers.
Rebased from vllm-project#1023.
Fixes vllm-project#1022
Co-authored-by: Mohith Gajjela <[email protected]>
Signed-off-by: Christopher Krah <[email protected]>
Implements #1022, proposed by @shernshiou.
route_requestwas inconsistent across the 6 router implementations (some sync, some async, some withoutrequest_json), which forced isinstance dispatch guards at every call site and would break silently whenever a new router is added.Changes:
RoutingInterface.route_requestis nowasync defand takesrequest_json; all 6 routers share the signature. Sync routers just do not await internally; no routing behavior changed.route_general_request(initial + failover call sites) andproxy_multipart_requestalways await and always passrequest_json; the(KvawareRouter, PrefixAwareRouter, SessionRouter)isinstance guards are gone. TheDisaggregatedPrefill*isinstance checks stay because they dispatch to different request handlers, notroute_requestvariants.request_json: Optional[Dict] = None(normalized inside) instead of the mutabledict = {}default, matching the repo's existing typing style and avoiding the shared-default hazard. Happy to change if you prefer the literal proposal.Tests: new
test_route_request_signature.py(16 tests) checks every router's signature plus behavioral probes proving the call sites really await and forward the body (via a router subclass that is not in any old isinstance whitelist). Existing roundrobin/auth-header tests updated for async. Full suite: 186 passed, 0 failed (baseline on main was 170 passed, 0 failed). black/isort/ruff clean.Relates to #1019: this standardizes the surface that made that bug possible. PRs #1020/#1021 fix the immediate call-site bug; this PR is complementary and rebases cleanly in either order.