feat: add debug response headers with backend information#864
feat: add debug response headers with backend information#864NJX-njx wants to merge 1 commit intovllm-project:mainfrom
Conversation
…ct#683) Add X-Backend-Server, X-Backend-Id, X-Backend-Pod, and X-Routing-Logic response headers to help operators identify which backend processed a request and what routing logic was used. Headers added to all response paths: - route_general_request: StreamingResponse with full debug headers - route_disaggregated_prefill_request: X-Backend-Server-Prefill/Decode - route_sleep_wakeup_request: JSONResponse with backend info - proxy_multipart_request: JSONResponse with full debug headers Includes _build_debug_headers() helper function and unit tests.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Pull request overview
Adds debug response headers to help operators identify which backend handled a request and what routing logic was applied, improving observability for testing/benchmarking in the vLLM router.
Changes:
- Added
_build_debug_headers()helper and injected backend/routing headers into general and multipart proxy responses. - Added debug headers for disaggregated prefill responses and sleep/wakeup responses.
- Added unit tests covering
_build_debug_headers()behavior across common/edge cases.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/vllm_router/services/request_service/request.py |
Introduces debug header helper and applies it (or equivalent inline logic) across several request/response paths. |
src/tests/test_debug_headers.py |
Adds tests validating the debug header helper output under multiple scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| response_headers = { | ||
| "X-Request-Id": request_id, | ||
| "X-Backend-Server": server_url, | ||
| "X-Backend-Id": endpoints[0].Id, |
There was a problem hiding this comment.
PR description indicates X-Backend-Server is only returned for the General and Multipart paths, but this sleep/wakeup response also includes it. Either update the PR description/header table to match the implementation, or drop this header from the sleep/wakeup path to keep the documented contract accurate.
| router = MagicMock() | ||
| router.__class__.__name__ = "RoundRobinRouter" |
There was a problem hiding this comment.
This test changes router.__class__.__name__ on a MagicMock, which mutates the MagicMock class name globally and can create confusing cross-test side effects. Prefer using a small dummy router class/instance whose type name is already the desired value (or type('RoundRobinRouter', (), {})()) so the test remains isolated.
| router = MagicMock() | |
| router.__class__.__name__ = "RoundRobinRouter" | |
| router = type("RoundRobinRouter", (), {})() |
| headers = { | ||
| "X-Backend-Server": server_url, | ||
| } | ||
|
|
||
| # Find the endpoint that was used and add its metadata | ||
| for ep in endpoints: | ||
| if ep.url == server_url: | ||
| headers["X-Backend-Id"] = ep.Id | ||
| if ep.pod_name: | ||
| headers["X-Backend-Pod"] = ep.pod_name | ||
| break | ||
|
|
||
| # Add routing logic type | ||
| if router is not None: | ||
| headers["X-Routing-Logic"] = type(router).__name__ | ||
|
|
There was a problem hiding this comment.
These debug headers expose internal backend URLs and (optionally) pod names to every client. That can leak infrastructure details and potentially credentials if a backend URL ever contains userinfo. Consider gating this behind an explicit opt-in (e.g., a feature gate like DebugHeaders, an env var, or a request header restricted to trusted callers) and/or redacting sensitive URL components before returning them.
| request.app.state.decode_client._base_url | ||
| ), | ||
| "X-Backend-Type": "disaggregated", | ||
| "X-Routing-Logic": "DisaggregatedPrefillRouter", |
There was a problem hiding this comment.
X-Routing-Logic is hardcoded here, while other paths derive it from the router instance (type(router).__name__). This risks drifting if the class is renamed or the routing logic changes. Prefer deriving it dynamically (or reusing _build_debug_headers / a shared helper) for consistency.
| "X-Routing-Logic": "DisaggregatedPrefillRouter", | |
| "X-Routing-Logic": DisaggregatedPrefillRouter.__name__, |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the vLLM router by introducing debug response headers across all request paths. This feature provides critical operational insights, allowing users to quickly identify the specific backend server, its unique ID, and the routing logic that handled a request. This information is invaluable for debugging, performance analysis, and understanding the flow of requests within the system, particularly in complex or distributed environments. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces debug response headers to various routing paths, a valuable feature for debugging and monitoring the vLLM router. However, these headers disclose sensitive internal infrastructure details such as backend URLs and pod names to all clients unconditionally, constituting an information disclosure vulnerability. It is recommended to make these headers optional, disabled by default, and restricted to authorized requests or specific debugging environments. Additionally, the implementation could be improved for consistency and maintainability by fully leveraging the new _build_debug_headers helper function across all routing paths, as some currently duplicate logic. There are also minor style issues regarding naming conventions and type hints.
| def _build_debug_headers( | ||
| server_url: str, | ||
| endpoints: list, | ||
| router=None, | ||
| ) -> dict: | ||
| """Build debug response headers with backend information. | ||
|
|
||
| These headers help operators identify which backend processed a request, | ||
| the routing logic used, and other useful debugging information. | ||
|
|
||
| Args: | ||
| server_url: The URL of the backend that handled the request. | ||
| endpoints: The list of EndpointInfo objects considered for routing. | ||
| router: The router instance (optional), used to extract routing logic name. | ||
|
|
||
| Returns: | ||
| A dict of debug headers to merge into the response headers. | ||
| """ | ||
| headers = { | ||
| "X-Backend-Server": server_url, | ||
| } | ||
|
|
||
| # Find the endpoint that was used and add its metadata | ||
| for ep in endpoints: | ||
| if ep.url == server_url: | ||
| headers["X-Backend-Id"] = ep.Id | ||
| if ep.pod_name: | ||
| headers["X-Backend-Pod"] = ep.pod_name | ||
| break | ||
|
|
||
| # Add routing logic type | ||
| if router is not None: | ||
| headers["X-Routing-Logic"] = type(router).__name__ | ||
|
|
||
| return headers |
There was a problem hiding this comment.
The _build_debug_headers function and its usage introduce several new HTTP response headers (X-Backend-Server, X-Backend-Id, X-Backend-Pod, X-Routing-Logic) that disclose internal infrastructure details, such as backend URLs and pod names. These headers are added unconditionally to all responses, which constitutes an information disclosure vulnerability. This information should be restricted to authorized users or controlled by a configuration flag (e.g., --enable-debug-headers) and disabled by default in production environments. Additionally, for better static analysis, the type hint list for endpoints on line 102 should be more precise, e.g., List[EndpointInfo].
| "X-Backend-Server-Prefill": str( | ||
| request.app.state.prefill_client._base_url | ||
| ), | ||
| "X-Backend-Server-Decode": str( | ||
| request.app.state.decode_client._base_url | ||
| ), |
There was a problem hiding this comment.
In the route_disaggregated_prefill_request function, internal URLs for prefill and decode backends are directly exposed in the X-Backend-Server-Prefill and X-Backend-Server-Decode response headers. This reveals internal network topology to the client, constituting an information disclosure vulnerability. This information should be restricted to authorized users or controlled by a configuration flag. Additionally, these debug headers are manually constructed here, bypassing the _build_debug_headers helper function, which leads to code duplication and potential inconsistencies. It's recommended to reuse _build_debug_headers to maintain a single source of truth for debug header generation, and avoid direct access to internal implementation details like _base_url.
| class MockEndpointInfo: | ||
| url: str | ||
| model_names: List[str] | ||
| Id: str |
There was a problem hiding this comment.
The attribute Id in MockEndpointInfo is capitalized. According to PEP 8, variable and attribute names should be in snake_case (e.g., id). While this is a mock object, it's good practice to maintain consistency with Python's naming conventions, especially if EndpointInfo (the real class) also uses Id.
| Id: str | |
| id: str |
| # Find the endpoint that was used and add its metadata | ||
| for ep in endpoints: | ||
| if ep.url == server_url: | ||
| headers["X-Backend-Id"] = ep.Id |
There was a problem hiding this comment.
| response_headers = { | ||
| "X-Request-Id": request_id, | ||
| "X-Backend-Server": server_url, | ||
| "X-Backend-Id": endpoints[0].Id, | ||
| } | ||
| if endpoints[0].pod_name: | ||
| response_headers["X-Backend-Pod"] = endpoints[0].pod_name |
There was a problem hiding this comment.
The debug headers for route_sleep_wakeup_request are manually constructed here, duplicating logic that is already encapsulated in the _build_debug_headers helper function. To improve consistency and reduce redundancy, please use the _build_debug_headers function.
For example, you can call _build_debug_headers(server_url, endpoints) and then merge the result into response_headers.
response_headers = {
"X-Request-Id": request_id,
**_build_debug_headers(server_url, endpoints)
}
Summary
Closes #683
Adds debug response headers to all response paths in the vLLM router, enabling operators to identify which backend processed a request, the routing logic used, and other useful debugging information for testing and benchmarking.
Headers Added
Changes
oute_general_request(),
oute_disaggregated_prefill_request(),
oute_sleep_wakeup_request(), and \proxy_multipart_request().
Testing