Skip to content

[Bugfix][Router] Key request stats by dispatch, not by X-Request-Id - #1115

Merged
ruizhang0101 merged 3 commits into
vllm-project:mainfrom
David-Wu1119:fix/stats-key-per-dispatch
Oct 14, 2026
Merged

ruizhang0101 merged 3 commits into
vllm-project:mainfrom
David-Wu1119:fix/stats-key-per-dispatch

Conversation

@David-Wu1119

Copy link
Copy Markdown
Contributor

process_request and proxy_multipart_request key RequestStatsMonitor by the request id, which is the client's X-Request-Id when one is sent. If two in-flight requests to the same engine carry the same id (a client that sets one id per session or trace, or a retry that reuses the id while the first attempt is still running), they share one entry:

The engine then keeps one request counted in in_decoding_requests (or in_prefill_requests) permanently, and load-aware and priority routing treat it as busier than it is. Before #1072 the same sequence did not leak, because the second completion still decremented the counters.

This change keys the stats by an id made for each dispatch (stats_id = str(uuid.uuid4())) in both functions. The X-Request-Id sent to the engine and returned to the client is unchanged.

Tests:

  • New test_process_request_counts_overlapping_requests_sharing_an_id in src/tests/test_request_stats.py runs two overlapping process_request calls with the same id against a real RequestStatsMonitor. On main one request stays in flight after both finish (in_decoding_requests == 1, finished_requests == 1); with this change both are released (0 and 2).
  • pytest src/tests: 241 passed, Python 3.12, pip install -e . plus pytest, pytest-asyncio and httpx.
  • pre-commit run on both files passes.

No open issue or PR covers this (#1080, #1040 and #1001 touch the same code for other reasons).

Found while auditing the router's request statistics with AI assistance; the fix and test were written with Claude Code.


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

🤖 Generated with Claude Code

process_request and proxy_multipart_request keyed RequestStatsMonitor by
the client's X-Request-Id. When two in-flight requests to one engine
share that id, the second on_new_request overwrites the first's start
time, and the second on_request_complete finds no entry (it returns
early since vllm-project#1072), so the engine keeps one request counted as in flight
permanently. Load-aware and priority routing then treat that engine as
busier than it is. Key the stats by an id made for each dispatch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: David-Wu1119 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 2, 2026 19:47

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@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 request statistics tracking to use a newly generated UUID (stats_id) instead of the client-provided request_id. This prevents issues where concurrent requests reusing the same X-Request-Id would incorrectly share a single tracking slot. The changes are applied to both process_request and proxy_multipart_request flows, and a corresponding integration test has been added to verify overlapping requests sharing an ID are counted correctly. There are no review comments, so I have no feedback to provide.

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

@David-Wu1119 approving at 532e8b6. The leak reproduces here at 532e8b6, and it is the decoding counter that sticks, which is what load-aware and priority routing read.

$ cd <tree at 532e8b6> && PYTHONPATH=src pytest src/tests/ -q --ignore=src/tests/perftest --ignore=src/tests/external_providers
183 passed in 18.86s

# src/vllm_router/services/request_service/request.py from c8c1719 (merge base), your test kept
1 failed, 182 passed in 18.68s
FAILED src/tests/test_request_stats.py::test_process_request_counts_overlapping_requests_sharing_an_id
E assert 1 == 0  where 1 = RequestStats(..., in_decoding_requests=1, finished_requests=1, ...)
# not run: a real engine, so the duplicate X-Request-Id itself rests on your report

request_stats.py:153 keys request_start_time by (engine_url, request_id) and nothing else reads that key, so moving it off the client header costs no correlation. All nine call sites now pass stats_id.

non-blocking: the proxy_multipart_request half is unpinned. Reverting only those six hunks to request_id, keeping the rest and your test, still gives 183 passed. src/tests/test_multipart_proxy.py does not assert on the monitor. The same two-overlapping-dispatch case against proxy_multipart_request would close it.

@Shaoting-Feng #1072 is what makes the second on_request_complete return early here, so this sits directly on it. Would you merge it now, or wait for the multipart test?

Drive proxy_multipart_request twice with the same X-Request-Id in streaming
mode and check both dispatches release their slots, so the multipart half
of the fix is pinned like process_request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: David-Wu1119 <[email protected]>
@David-Wu1119

Copy link
Copy Markdown
Contributor Author

@chrikrah thanks, good point. Added in 3b77f1f: test_multipart_request_counts_overlapping_requests_sharing_an_id drives proxy_multipart_request twice with the same X-Request-Id (streaming, both past their first chunk before either finishes) and checks prefill/decoding are back to 0 with 2 finished. It passes on this branch and fails when only the six proxy_multipart_request hunks are reverted to request_id; src/tests passes locally (242 passed).

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

@David-Wu1119 the multipart test closes the gap I flagged at 532e8b6, so I'd merge 3b77f1f as it stands. It fails the way it should when the multipart half goes back to the header id.

$ cd <tree at 3b77f1f> && PYTHONPATH=src pytest src/tests/ -q --ignore=src/tests/perftest --ignore=src/tests/external_providers
184 passed, 1 warning in 16.64s

# the six proxy_multipart_request calls switched back to request_id, everything else at 3b77f1f
1 failed, 183 passed, 1 warning in 15.03s
FAILED src/tests/test_request_stats.py::test_multipart_request_counts_overlapping_requests_sharing_an_id
E  assert 1 == 0  where 1 = RequestStats(..., in_decoding_requests=1, finished_requests=1, ...)

# 3b77f1f merged onto main at 4e076e8, which brings in #1104's request.py change
208 passed, 1 warning in 16.38s

@ruizhang0101 the merge with main is conflict-free, and both halves of the fix are now pinned by a test. Could you take this one in?

@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

@ruizhang0101
ruizhang0101 enabled auto-merge (squash) October 14, 2026 01:32
@ruizhang0101
ruizhang0101 merged commit bebd72c into vllm-project:main Oct 14, 2026
16 checks passed
punitvara added a commit to punitvara/production-stack that referenced this pull request Nov 10, 2026
…m-project#939

- Add related work (vllm-project#939, vllm-project#984, vllm-project#1164, vllm-project#1115, vllm-project#876)
- Drop --retry-on-backend-5xx and request_retries_total; reuse vllm-project#939
- Re-scope Phase 1a to stall detection and passive ejection
- Require new settings in the dynamic config
- Replace line-number reference with function names

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: Punit Vara <[email protected]>
bcdonadio added a commit to powerhome/vllm-production-stack that referenced this pull request Nov 12, 2026
* [Bugfix][Router] Read vllm:kv_cache_usage_perc for KV cache usage (vllm-project#1118)

Signed-off-by: Muhammad Ibrahim <[email protected]>

* [Doc] Add Simplified Chinese translation (README.zh.md) (vllm-project#1136)

Signed-off-by: YE <[email protected]>

* [CI/Build] Run helm unittest in CI and fix two broken tests (vllm-project#1131)

Signed-off-by: zjjkee <[email protected]>

* [Bugfix][Router] Key request stats by dispatch, not by X-Request-Id (vllm-project#1115)

Signed-off-by: David-Wu1119 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Rui Zhang <[email protected]>

* [Bugfix][Router] Use least-inflight for PrefixAware below-threshold fallback (vllm-project#1089)

Signed-off-by: Dundy Pasupuleti <[email protected]>

* [Bugfix][Router] Keep P/D model labels when dynamic config reloads the router (vllm-project#1129)

Signed-off-by: MinJun Choi <[email protected]>

* [Bugfix] Match KEDA scalers to enabled model deployments (vllm-project#1142)

Signed-off-by: bojiang-li <[email protected]>

* [Router] added pooling route (vllm-project#1112)

Signed-off-by: [email protected] <[email protected]>
Co-authored-by: [email protected] <[email protected]>
Co-authored-by: Rui Zhang <[email protected]>

* [CI] Drop host docker prune from runner-cleanup workflow (vllm-project#1174)

Signed-off-by: Rui Zhang <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>

* [Feat][Router] Add /v1/systemone and /v1/decisions routes (vllm-project#1173)

Signed-off-by: Shern Shiou Tan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>

* [CI/Build] Stop k8s routing tests when the engine pods never become ready (vllm-project#1134)

Signed-off-by: MinJun Choi <[email protected]>

* [Bugfix][Router] Upgrade aiohttp and vllm (0.33.0) to resolve router image CVEs (vllm-project#1185)

Signed-off-by: Shern Shiou Tan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>

* Bump chart version to 0.1.14 (vllm-project#1190)

Signed-off-by: Rui Zhang <[email protected]>

---------

Signed-off-by: Muhammad Ibrahim <[email protected]>
Signed-off-by: YE <[email protected]>
Signed-off-by: zjjkee <[email protected]>
Signed-off-by: David-Wu1119 <[email protected]>
Signed-off-by: Dundy Pasupuleti <[email protected]>
Signed-off-by: MinJun Choi <[email protected]>
Signed-off-by: bojiang-li <[email protected]>
Signed-off-by: [email protected] <[email protected]>
Signed-off-by: Rui Zhang <[email protected]>
Signed-off-by: Shern Shiou Tan <[email protected]>
Signed-off-by: MinJun Choi <[email protected]>
Signed-off-by: Rui Zhang <[email protected]>
Signed-off-by: Bernardo Donadio <[email protected]>
Co-authored-by: Muhammad Ibrahim <[email protected]>
Co-authored-by: YE <[email protected]>
Co-authored-by: Jingke zou <[email protected]>
Co-authored-by: Yanze (David) Wu <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Rui Zhang <[email protected]>
Co-authored-by: Dundy Pasupuleti <[email protected]>
Co-authored-by: MinJun Choi <[email protected]>
Co-authored-by: Bojiang Li <[email protected]>
Co-authored-by: MaelvanDijk <[email protected]>
Co-authored-by: [email protected] <[email protected]>
Co-authored-by: Shern Shiou Tan <[email protected]>
unsorted-otter added a commit to unsorted-otter/production-stack that referenced this pull request Nov 30, 2026
Resolve the conflict in process_request's finally block by keeping
main's side: vllm-project#1072 already moved on_request_complete into finally, and
vllm-project#1115 keys request stats by the per-dispatch stats_id instead of
request_id.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: unsorted-otter <[email protected]>
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.

4 participants