Skip to content

feat: add debug response headers with backend information#864

Open
NJX-njx wants to merge 1 commit intovllm-project:mainfrom
NJX-njx:feat/683-debug-response-headers
Open

feat: add debug response headers with backend information#864
NJX-njx wants to merge 1 commit intovllm-project:mainfrom
NJX-njx:feat/683-debug-response-headers

Conversation

@NJX-njx
Copy link

@NJX-njx NJX-njx commented Mar 4, 2026

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

Header Description Response Paths
\X-Backend-Server\ URL of the backend that handled the request General, Multipart
\X-Backend-Id\ Endpoint ID of the chosen backend General, Multipart, Sleep/Wakeup
\X-Backend-Pod\ Pod name (when available, e.g. K8s) General, Multipart, Sleep/Wakeup
\X-Routing-Logic\ Router class name (e.g. RoundRobinRouter) General, Multipart
\X-Backend-Server-Prefill\ Prefill backend URL Disaggregated Prefill
\X-Backend-Server-Decode\ Decode backend URL Disaggregated Prefill
\X-Backend-Type\ \disaggregated\ for disagg prefill Disaggregated Prefill

Changes

  • **\src/vllm_router/services/request_service/request.py**: Added _build_debug_headers()\ helper function and injected debug headers in
    oute_general_request(),
    oute_disaggregated_prefill_request(),
    oute_sleep_wakeup_request(), and \proxy_multipart_request().
  • **\src/tests/test_debug_headers.py**: Unit tests for the _build_debug_headers()\ function covering all edge cases.

Testing

  • Unit tests for the helper function
  • All existing tests pass

…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.
Copilot AI review requested due to automatic review settings March 4, 2026 10:33
@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +783 to +786
response_headers = {
"X-Request-Id": request_id,
"X-Backend-Server": server_url,
"X-Backend-Id": endpoints[0].Id,
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +75 to +76
router = MagicMock()
router.__class__.__name__ = "RoundRobinRouter"
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
router = MagicMock()
router.__class__.__name__ = "RoundRobinRouter"
router = type("RoundRobinRouter", (), {})()

Copilot uses AI. Check for mistakes.
Comment on lines +118 to +133
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__

Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
request.app.state.decode_client._base_url
),
"X-Backend-Type": "disaggregated",
"X-Routing-Logic": "DisaggregatedPrefillRouter",
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
"X-Routing-Logic": "DisaggregatedPrefillRouter",
"X-Routing-Logic": DisaggregatedPrefillRouter.__name__,

Copilot uses AI. Check for mistakes.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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

  • Debug Response Headers: Added new debug response headers to all response paths in the vLLM router to provide backend and routing information.
  • Backend Identification: Enabled identification of the backend server URL, endpoint ID, and pod name (if available) that processed a request.
  • Routing Logic Visibility: Included the name of the router class (e.g., RoundRobinRouter) in debug headers to show the routing logic used.
  • Disaggregated Prefill Support: Introduced specific debug headers for disaggregated prefill requests, detailing prefill and decode backend URLs and type.
  • New Helper Function: Implemented a _build_debug_headers helper function to centralize the logic for constructing debug headers.
  • Unit Tests: Added comprehensive unit tests for the _build_debug_headers function to ensure correct behavior across various scenarios.

🧠 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
  • src/tests/test_debug_headers.py
    • Added a new test file to validate the functionality of the _build_debug_headers helper function.
    • Included test cases for basic header generation, router integration, handling of missing pod names, and behavior with unknown backend servers.
  • src/vllm_router/services/request_service/request.py
    • Implemented the _build_debug_headers helper function to dynamically generate debug headers based on the backend server URL, endpoint information, and router instance.
    • Integrated the _build_debug_headers function into route_general_request to append backend and routing details to general API responses.
    • Modified route_disaggregated_prefill_request to include specific debug headers such as X-Backend-Server-Prefill, X-Backend-Server-Decode, X-Backend-Type, and X-Routing-Logic.
    • Updated route_sleep_wakeup_request to add X-Backend-Server, X-Backend-Id, and X-Backend-Pod headers to its responses.
    • Incorporated the _build_debug_headers function into proxy_multipart_request to ensure multipart responses also carry relevant debug information.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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 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.

Comment on lines +100 to +134
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
Copy link
Contributor

Choose a reason for hiding this comment

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

security-medium medium

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].

Comment on lines +699 to +704
"X-Backend-Server-Prefill": str(
request.app.state.prefill_client._base_url
),
"X-Backend-Server-Decode": str(
request.app.state.decode_client._base_url
),
Copy link
Contributor

Choose a reason for hiding this comment

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

security-medium medium

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
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
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
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The attribute ep.Id is capitalized. In Python, attribute names typically follow snake_case (e.g., ep.id) as per PEP 8. Please ensure consistency with the EndpointInfo class definition.

Suggested change
headers["X-Backend-Id"] = ep.Id
headers["X-Backend-Id"] = ep.id

Comment on lines +783 to +789
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
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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)
            }

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.

vllm_router : add debug headers in the response

2 participants