Repository navigation
[Bugfix][Router] Key request stats by dispatch, not by X-Request-Id - #1115
Conversation
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]>
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
@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]>
|
@chrikrah thanks, good point. Added in 3b77f1f: |
chrikrah
left a comment
There was a problem hiding this comment.
@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?
…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]>
* [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]>
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]>
process_requestandproxy_multipart_requestkeyRequestStatsMonitorby the request id, which is the client'sX-Request-Idwhen 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:on_new_requestoverwrites the first request's start time;on_request_completepops the entry;on_request_completefinds no entry and returns early (it is idempotent since [Bugfix][Router] Fix leaked in-flight counters in RequestStatsMonitor #1072), so its in-flight slot is never released.The engine then keeps one request counted in
in_decoding_requests(orin_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. TheX-Request-Idsent to the engine and returned to the client is unchanged.Tests:
test_process_request_counts_overlapping_requests_sharing_an_idinsrc/tests/test_request_stats.pyruns two overlappingprocess_requestcalls with the same id against a realRequestStatsMonitor. Onmainone request stays in flight after both finish (in_decoding_requests == 1,finished_requests == 1); with this change both are released (0and2).pytest src/tests: 241 passed, Python 3.12,pip install -e .plus pytest, pytest-asyncio and httpx.pre-commit runon 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.
-swhen doinggit commit[Bugfix],[Feat], and[CI].🤖 Generated with Claude Code