Skip to content

[Router][Bugfix] Handle all router types correctly in proxy_multipart_request - #1021

Merged
ruizhang0101 merged 2 commits into
vllm-project:mainfrom
shernshiou:fix/missing_request_json
Jul 28, 2026
Merged

ruizhang0101 merged 2 commits into
vllm-project:mainfrom
shernshiou:fix/missing_request_json

Conversation

@shernshiou

@shernshiou shernshiou commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Description

proxy_multipart_request (used by /v1/audio/transcriptions and /v1/images/edits) was calling router.route_request() synchronously and without the required request_json argument, causing a TypeError when using SessionRouter, KvawareRouter, or PrefixAwareRouter.

Changes

  • Added the same isinstance(router, (KvawareRouter, PrefixAwareRouter, SessionRouter)) guard already used in route_general_request
  • For async routers: call with await and pass {} as request_json (no JSON body in multipart/form-data)
  • For other routers (e.g. RoundRobinRouter): keep the original synchronous call unchanged

Fixes #1019

BEFORE SUBMITTING, PLEASE READ THE CHECKLIST BELOW AND FILL IN THE DESCRIPTION ABOVE


  • Make sure the code changes pass the pre-commit checks.
  • Sign-off your commit by using -s when doing git commit
  • Try to classify PRs for easy understanding of the type of changes, such as [Bugfix], [Feat], and [CI].
Detailed Checklist (Click to Expand)

Thank you for your contribution to production-stack! Before submitting the pull request, please ensure the PR meets the following criteria. This helps us maintain the code quality and improve the efficiency of the review process.

PR Title and Classification

Please try to classify PRs for easy understanding of the type of changes. The PR title is prefixed appropriately to indicate the type of change. Please use one of the following:

  • [Bugfix] for bug fixes.
  • [CI/Build] for build or continuous integration improvements.
  • [Doc] for documentation fixes and improvements.
  • [Feat] for new features in the cluster (e.g., autoscaling, disaggregated prefill, etc.).
  • [Router] for changes to the vllm_router (e.g., routing algorithm, router observability, etc.).
  • [Misc] for PRs that do not fit the above categories. Please use this sparingly.

Note: If the PR spans more than one category, please include all relevant prefixes.

Code Quality

The PR need to meet the following code quality standards:

  • Pass all linter checks. Please use pre-commit to format your code. See README.md for installation.
  • The code need to be well-documented to ensure future contributors can easily understand the code.
  • Please include sufficient tests to ensure the change is stay correct and robust. This includes both unit tests and integration tests.

DCO and Signed-off-by

When contributing changes to this project, you must agree to the DCO. Commits must include a Signed-off-by: header which certifies agreement with the terms of the DCO.

Using -s with git commit will automatically add this header.

What to Expect for the Reviews

We aim to address all PRs in a timely manner. If no one reviews your PR within 5 days, please @-mention one of YuhanLiu11
, Shaoting-Feng or ApostaC.

@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 the proxy_multipart_request function to support asynchronous routing for KvawareRouter, PrefixAwareRouter, and SessionRouter by awaiting their route_request method with an additional empty JSON body argument. However, the review correctly points out that DisaggregatedPrefillOrchestratedRouter and DisaggregatedPrefillRouter also require five arguments (with the former being asynchronous), which would currently trigger a TypeError in the fallback else block. A code suggestion is provided to handle these additional router types safely.

@shernshiou
shernshiou force-pushed the fix/missing_request_json branch from b4822cd to de7d140 Compare July 28, 2026 12:17
…art_request

proxy_multipart_request was calling router.route_request() without await
and without the required request_json argument, causing a TypeError when
using SessionRouter, KvawareRouter, or PrefixAwareRouter for multipart
endpoints (/v1/audio/transcriptions, /v1/images/edits).

Add the same isinstance guard used in route_general_request to call the
async routers with await and pass {} as request_json (no JSON body for
multipart/form-data), while keeping the synchronous call for other routers.

Fixes vllm-project#1019

Signed-off-by: Shern Shiou Tan <[email protected]>
@shernshiou
shernshiou force-pushed the fix/missing_request_json branch from de7d140 to b675c83 Compare July 28, 2026 12:19
@shernshiou

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 modifies the proxy_multipart_request function to handle different router types by checking their classes with isinstance to determine if the routing call should be awaited and if an empty JSON body should be passed. The reviewer correctly points out that hardcoding these checks is fragile and violates the Open-Closed Principle, suggesting a dynamic approach using Python's inspect module to check the method signature and coroutine status instead.

Comment on lines +1245 to +1275
if isinstance(
router,
(
KvawareRouter,
PrefixAwareRouter,
SessionRouter,
DisaggregatedPrefillOrchestratedRouter,
),
):
chosen_url = await router.route_request(
endpoints,
engine_stats,
request_stats,
request,
{}, # no JSON body for multipart/form-data
)
elif isinstance(router, DisaggregatedPrefillRouter):
chosen_url = router.route_request(
endpoints,
engine_stats,
request_stats,
request,
{}, # no JSON body for multipart/form-data
)
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.

medium

Hardcoding specific router classes with isinstance checks is fragile and violates the Open-Closed Principle. If a new router is added in the future, this code will need to be manually updated, which is highly error-prone.

Instead, we can use Python's standard inspect module to dynamically determine if the route_request method is asynchronous and whether it accepts the request_json parameter. This makes the routing invocation completely generic and future-proof.

    import inspect

    route_fn = router.route_request
    sig = inspect.signature(route_fn)
    route_args = [endpoints, engine_stats, request_stats, request]
    if "request_json" in sig.parameters:
        route_args.append({})

    if inspect.iscoroutinefunction(route_fn):
        chosen_url = await route_fn(*route_args)
    else:
        chosen_url = route_fn(*route_args)

@shernshiou shernshiou changed the title fix: await router.route_request and pass request_json in proxy_multip… [Router][Bugfix] Handle all router types correctly in proxy_multipart_request Jul 28, 2026

@ruizhang0101 ruizhang0101 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

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

2 participants