Skip to content

fix: await router.route_request and pass request_json in proxy_multipart_request [FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH] - #1020

Open
waterWang wants to merge 2 commits into
vllm-project:mainfrom
waterWang:fix/issue-1019
Open

waterWang wants to merge 2 commits into
vllm-project:mainfrom
waterWang:fix/issue-1019

Conversation

@waterWang

Copy link
Copy Markdown

Fixes #1019

What does this PR do?

Fixes a bug in proxy_multipart_request where SessionRouter.route_request() was called without the required request_json argument, and without await.

Root Cause

The proxy_multipart_request function (used for audio transcription and image edit requests) called router.route_request() synchronously without request_json:

chosen_url = router.route_request(
    endpoints,
    engine_stats,
    request_stats,
    request,
)

However, SessionRouter, KvawareRouter, and PrefixAwareRouter all have an async route_request method that requires a request_json argument. The regular route_general_request function already handles this correctly with an isinstance guard.

Fix

Mirrors the pattern used in route_general_request:

  • If the router is a SessionRouter, KvawareRouter, or PrefixAwareRouter, call await router.route_request(...) with {} as request_json (multipart/form-data requests have no JSON body).
  • Otherwise, call router.route_request(...) synchronously without request_json.

Testing

  • The fix follows the exact same pattern as route_general_request (lines 561-570), which is already well-tested.
  • Only affects multipart routes (/v1/audio/transcriptions, /v1/images/edits) when using session/kv-aware/prefix-aware routing.
  • roundrobin routing is unaffected.

…er/KvawareRouter/PrefixAwareRouter in proxy_multipart_request

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

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.

Code Review

This pull request updates proxy_multipart_request to support asynchronous routing for KvawareRouter, PrefixAwareRouter, and SessionRouter. However, a critical issue was identified where passing an empty dictionary as the request JSON will cause a KeyError in PrefixAwareRouter because it attempts to access the "prompt" key.

Comment on lines +1245 to +1259
if isinstance(router, (KvawareRouter, PrefixAwareRouter, SessionRouter)):
chosen_url = await router.route_request(
endpoints,
engine_stats,
request_stats,
request,
{},
)
else:
chosen_url = router.route_request(
endpoints,
engine_stats,
request_stats,
request,
)

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.

high

There are two issues with the current implementation of proxy_multipart_request when routing requests:

  1. KeyError in PrefixAwareRouter: Passing an empty dictionary {} as request_json will cause a KeyError in PrefixAwareRouter.route_request (line 500) because it attempts to access request_json["prompt"] when `

@ruizhang0101

Copy link
Copy Markdown
Collaborator

Duplicate with #1021

@ErenAta16 ErenAta16 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Confirmed the crash rather than inferring it from the signature. Reproducing the call exactly as proxy_multipart_request makes it on main:

SessionRouter.route_request signature:
    (self, endpoints, engine_stats, request_stats, request, request_json) -> str
is coroutine function: True

sr.route_request(endpoints, engine_stats, request_stats, request)
    TypeError: SessionRouter.route_request() missing 1 required positional argument: 'request_json'

So it fails at the call, before the missing await even becomes relevant. Every multipart request, audio transcription and image edit, is a hard 500 whenever the router is one of the three async ones. RoundRobinRouter.route_request is not a coroutine and takes four arguments, which is why the plain path never noticed.

The isinstance dispatch matches what services/request_service/request.py already does around line 561, so this keeps the two call sites in step rather than inventing a second convention. That is the right call, though it does mean the tuple (KvawareRouter, PrefixAwareRouter, SessionRouter) now appears in two places and will need updating in both when a fourth async router lands. A small helper, or an is_async flag on RoutingInterface, would remove that trap. Not a blocker, and probably better as a follow-up than bundled here.

One behavioural consequence worth writing down. Passing {} is correct in the sense that extract_session_id calls request_json.get(...) and would raise on None, so it has to be a mapping. But it means session extraction on these endpoints is header-only:

val = request.headers.get(session_key)
return val if val is not None else request_json.get(session_key, None)

For a JSON endpoint the body is the fallback. For multipart there is no JSON body to read, so {} is honest, but a client that puts its session id in a multipart form field rather than a header will now silently get QPS routing instead of session affinity. Silently, because a missing session id is a valid state that falls through to _qps_routing, not an error.

If transcription is expected to participate in session affinity at all, parsing the session key out of the form data and passing {session_key: value} would close that. If it is not expected to, a line in the docstring saying multipart requests are header-only would save someone the debugging session. Either way I would not hold the PR for it, since header-only affinity is strictly better than a 500.

Fix looks right to me.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: SessionRouter.route_request() missing request_json argument in proxy_multipart_request

3 participants