fix(vllm): preserve per-choice KV handoffs in disaggregated serving #19706
All Vouch review confidence checks passed
Residual risk 0.30 = Change Risk (0.57) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.57 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #19706"
general
weight: 0.35
luckyq
Overview
When serving Kimi K3 with disaggregated vLLM and
n=4, we observed prefill KV-cache usage ballooning and high time to first token (TTFT). Each request created four prefill leases, but decode consumed only one; the other three held KV blocks for roughly 30 seconds until expiry, building up cache pressure and delaying new requests. This PR preserves each choice's KV handoff: the tested JSON and streaming requests consumed all four leases with zero expiries.Key Changes
The root cause is a mismatch between parallel sampling and the single-handoff protocol. Prefill retains
n=4, so vLLM creates four children and four leases. Dynamo selects the first output's token IDs and forwards onePrefillResultcontaining onekv_transfer_paramsrecord. Decode applies that record before vLLM creates its four children, so all four read the same producer lease. The API can still return four correct answers while the other three leases remain held.The parallel-sampling wrapper contains 333 lines of core code, excluding tests, comments, and blank lines, with readiness and response-metadata plumbing in the existing router and frontend:
parallel_sampling.rs: splitn > 1into indexedn=1requests before prefill. Each choice gets a unique request ID, independent routing state, and its own first token and KV transfer metadata. Explicit seeds follow vLLM'sseed + indexbehavior.pipeline.rs: install the wrapper in both Rust and Python chat-processor pipelines for vLLM decode deployments advertisingvllm_inference_v1_generate.Requests without a prefill target retain their original
nand go directly to decode. Pending prefill activation is rejected before fan-out. The wrapper then waits for the first child dispatch outcome: an error returns through the HTTP error path; success opens the stream while siblings continue dispatching. Later dispatch failures retain their typed errors in the stream. Each child preserves the encoder release and inline-fallback context and independently retains frontend-decoded media through its first response or dispatch cleanup. Parallel sampling and migration collect these storage handles through a shared request helper. Unexpected worker cancellation fails the response. Requested worker IDs follow each choice through Rust chat and completion response projection. Per-worker metrics also follow each choice through Rust and Python processing: TTFT measures its first token from the parent request start, and inter-token latency uses successive chunks from that choice. Tool-parser buffering and batched completion prompts preserve this attribution; request-level token totals cover the merged response. The request span records choice zero's prefill and decode worker IDs.Each choice passes through routing and admission independently. With multiple prefill workers, distributing choices across workers can reduce prefix-cache reuse.
Validation
Validation at
28c5122383(upstreammainate78fed08a4): 1,499 selected Rust tests passed, including per-choice handoffs, streaming and cancellation, real NIXL/UCX media lifetime, frontend response projection, hexadecimal worker metric labels, and the once-per-request first-token profiling hook. The frontend protocol suite has 10 existing ignored tests.Rebase validation at
9bb89f5a74: rebased onto upstreammainatb5e3bc6882. OnlyCargo.lockconflicted; both upstream runtime dependencies and the native test dependencies were retained. The PR's source patch is unchanged, and its lockfile diff still adds only three dependency entries with no package-version changes. 173 targeted Rust tests passed across router-host and discovery, including sampling, migration, pipeline gating, per-choice lease consumption, and real NIXL media lifetime. The build used--locked; formatting, router-host clippy, and local pre-commit passed. Full CI requires maintainer approval for9bb89f5a74c3e5576ecc9f2ec6d7cd1baf75f51d. Prior broader tests and performance measurements below retain their original revisions.Rebase validation at
7e06d7bf4f: rebased onto upstreammainatec27292a5a. Resolved the two conflicts with #19547 by retaining both coalesced thinking-opener accounting and per-choice metrics attribution. The range diff and scoped review found no dropped behavior; both previously restored regression tests remain present.1,449 selected Rust tests passed, with 10 existing protocol tests ignored. This includes both upstream coalesced-opener reasoning-usage tests, per-choice reasoning/worker-metrics/buffering tests, deployment gating, and the real NIXL/UCX media-lifetime regression. Formatting, preprocessor/router-host clippy, and local pre-commit checks passed. The Python frontend and test files changed by this PR are unchanged by this rebase; the two Python runtime passes below remain evidence for
653d715504, and benchmark measurements remain tied tod71a24c. GitHub pre-merge CI subsequently passed at this revision, including Rust tests, clippy, feature builds, and pre-commit.Rebase validation at
653d715504: rebased onto upstreammainat8ad30a3647, which includes the domain-folder move (#19857) and OpenCV build fix (#19945). The sole Git conflict was the new parallel-sampling file's location; its production contents were preserved atlib/router/host/src/prefill_router/parallel_sampling.rs. Restoredonly_vllm_decode_deployments_enable_fanoutand the feature-gateddecoded_media_survives_sibling_dispatch_timeout; the latter now uses the publicDecodedMediaDescriptorconversion introduced by the crate split.1,444 selected Rust tests passed across discovery, frontend protocols, LLM, metrics, preprocessor, and router-host; 10 existing protocol tests were ignored. This includes both restored regressions. The native media test passed using the real NIXL 1.5.0 C API and UCX over loopback TCP: media storage survives a sibling dispatch timeout until the outstanding worker responds. The initial NIXL stub-mode setup failure was resolved by loading the installed wheel's native libraries.
Both Python cases of
TestRoutedEnginePath::test_routed_choice_metrics_survive_visible_and_buffered_outputpassed (visible and buffered output), with the current frontend and native_corebuilt from this same commit. The run used Python 3.12.3 and vLLM0.1.dev24218+g78e9a0c28; module paths were verified before execution. These are targeted unit tests, not a full Python suite or GPU integration run. Formatting, router-host clippy (includingtestingandtesting-nixl), and local repository pre-commit checks passed.CI at
653d715504: all GitHub Rust tests, clippy checks, and feature builds passed. The pre-commit job printed all hooks passed, then hit its three-minute timeout, also seen on main. These are previous-head CI results, not results for the latest rebase.Validation at
38b5ffaa4d: 1,462 Rust tests pass on upstreammainat8ba07e2d85: 1196 frontend-protocol, 177 router/encoder, 6 preprocessor, 2 discovery pipeline, 28 LLM, 52 metrics, 1 HTTP. The protocol suite has 10 existing ignored parser qualification tests. The PR adds 25 Rust test cases and 2 Python cases covering per-choice handoffs, streaming and cleanup, encoder policy, worker attribution, and metrics.Validation at
540f97d64c: 1,470 Rust tests pass on upstreammainat34e51b5c86: 1196 frontend-protocol, 184 router-host, 7 preprocessor, 2 discovery pipeline, 28 LLM, 52 metrics, 1 HTTP. The router-host run includes encoder and prefill routing tests, the real NIXL/TCP media-lifetime regression, and regressions for required encoder handoffs, cancellation, and per-choice encoder policy. The protocol suite has 10 existing ignored parser qualification tests.Validation at
65f4958742: 1,431 Rust tests pass on upstreammainat0fd80f5d70: 1,191 frontend-protocol tests, 187 selected LLM tests, 52 metrics tests, and 1 HTTP test. The protocol suite has 10 existing ignored parser qualification tests. The LLM run includes the real NIXL/TCP media-lifetime regression.Validation at
d71a24c4a0: 241 selected Rust tests pass (188 LLM, 52 metrics, 1 HTTP). New regressions cover an early dispatch error before stream creation, cancellation/drop during startup, preserving an untargetedn=4request, and recording choice zero's workers after choice one arrives first. The ready-choice test still streams beyond the output buffer while a sibling is blocked in dispatch.Historical native validation at
540f97d64c:decoded_media_survives_sibling_dispatch_timeoutexercised real NIXL-registered storage and TCP dispatch: after one choice finishes and a sibling times out, storage remained alive until the slow worker responds. That test required--features dynamo-router-host/testing-nixland native NIXL/UCX libraries; default CI did not enable it. The local run used CPU UCX withUCX_TLS=tcp,self,UCX_MODULES='^ib,rdmacm', andUCX_NET_DEVICES=lo.Rust validation at
e76223d099: all 267 selected Rust tests pass, including the migration and pipeline tests, on upstreammainatdaada9d6df.Kimi K3 replica, November 30, 2026, commit
8318f1e. One prefill worker and one decode worker on 16 GPUs, using NIXL pull with Mooncake. The baseline used a Dynamo 1.7.0 frontend; the candidate used the Dynamo 1.8.0 Python frontend and native runtime built from this commit. Both runs used the same workers: Dynamo 1.7.0 and vLLM0.1.dev24218+g78e9a0c28.| Synthetic chat request | Baseline leases read / created | Candidate leases read / created | Expiries, baseline → candidate |
|---|---:|---:|---:|
|
n=1, JSON | 1/1 | 1/1 | 0 → 0 ||
n=4, JSON | 1/4 | 4/4 | 3 → 0 ||
n=4, streaming | 1/4 | 4/4 | 3 → 0 |Counts match each decode child's remote request ID to its prefill lease, deduplicated across GPU ranks. The baseline control with four concurrent
n=1requests also consumed all four leases.Both candidate multi-choice requests returned the expected answer at indexes 0–3 with a stop for every choice. The stream ended with
[DONE]. The JSON response counted the 889-token prompt once and reported 48 completion tokens, matching the baseline.At commit
99826b0d44, all 94 selected router, response-projection, and protocol tests passed, covering:real_prefill_router_delivers_one_lease_per_choice: distinct first-token/lease pairs through the router forn=1andn=4, with every lease consumed.choices_have_independent_handoffs_seeds_and_interleaved_outputs: independent child state, seeded sampling, interleaved responses, and merged usage.WorkerUnavailableerrors, and a ready choice streaming six tokens through a two-item buffer while sibling dispatch remains blocked.At commit
5c696ebcc9, all 206 selected Rust tests passed. Metrics regressions cover interleaved choices on different workers, separate token timing when choices share a worker, zero-token chunks, buffered tool output, batched prompt indexes, and propagation through the Rust HTTP metrics adapter withoutnvextopt-in. They also verify prompt and completion token accounting. Three source-isolated Python cases passed for visible output, buffered output, and ordinary single-choice output; full Python test collection requires the nativedynamo._coreextension, which is absent from the local test environment.Deploying this fix on Dynamo 1.7.0 requires a frontend upgrade or backport.
Performance results
Setup and workload
Kimi K3, measured December 1, 2026, on 1 prefill + 2 decode workers (1P2D), 24 NVIDIA GB300 GPUs total, with 8 GPUs per worker, TP=8/DCP=8, FP8 KV cache, prefix caching, NIXL KV transfer with Mooncake, and DSpark speculative decoding with 4 speculative tokens.
The baseline uses the Dynamo 1.7.0 frontend. The candidate uses the Python frontend and native runtime built from this PR at
d71a24c4a02f62ef893fbc6bbbbf8160057d523d(Dynamo 1.8.0). Both frontends use the same running GPU workers, model, and worker settings: Dynamo 1.7.0 and vLLM0.1.dev24218+g78e9a0c28. Only the frontend changes; this measures an upgrade to the PR revision, not an isolated backport onto 1.7.0.The client is AIPerf 0.14.0, using its native synthetic multi-turn dataset and concurrency scheduler through a small configuration wrapper. Requests use streaming OpenAI-compatible chat completions. A custom endpoint adapter handles
n>1: it consumes the full response and aggregate usage for all choices, but appends only choice 0 to the next turn's conversation history, avoiding mixing independent samples.ignore_eos=true; temperature 0.6, thinking disabled. Thus ann=4request generates 1,024 output tokens, while only one sample continues the history.vllm:request_queue_time_secondshistogram deltas, per engine sequence. KV occupancy is sampledvllm:kv_cache_usage_percon the prefill worker, not total GPU memory usage; its capture includes short boundary scrapes around the run.Baseline: equal generated-sequence concurrency exposes the problem
C16/n=4 and C64/n=1 both permit 64 concurrent generated sequences and produce 640 samples / 163,840 output tokens. They differ in HTTP request count (160 vs. 640) and independent conversation histories (16 vs. 64), so this is an equal-output-work comparison, not identical input work.
| Baseline workload | Mean TTFT | Mean prefill queue delay | Prefill KV occupancy, mean / peak | Output tokens/s | Mean request latency |
|---|---:|---:|---:|---:|---:|
| C16, n=4 | 16.78 s | 14.53 s | 94.90% / 100.00% | 819 | 19.35 s |
| C64, n=1 | 3.63 s | 2.63 s | 9.15% / 40.91% | 2,343 | 6.55 s |
Despite fewer independent contexts, n=4 has 4.63× higher TTFT, 5.51× longer prefill queue delay, and 10.37× mean prefill KV occupancy, delivering only 35% of the n=1 throughput. Prefill reaches 100% occupancy and incurs 9 engine preemptions, versus none for n=1. This is consistent with the lease evidence above: unconsumed leases retain KV blocks until expiry, creating cache pressure and delaying scheduling. The queue metric measures scheduler wait; we did not separately instrument time blocked specifically on KV allocation.
The same comparison at higher concurrency pairs C32/n=4 with C128/n=1: both permit 128 concurrent generated sequences and produce 1,280 samples / 327,680 output tokens. HTTP request counts are 320 vs. 1,280, with 32 vs. 128 independent histories.
| Baseline workload | Mean TTFT | Mean prefill queue delay | Prefill KV occupancy, mean / peak | Output tokens/s | Mean request latency |
|---|---:|---:|---:|---:|---:|
| C32, n=4 | 39.60 s | 33.99 s | 97.16% / 100.00% | 727 | 43.27 s |
| C128, n=1 | 6.01 s | 5.16 s | 12.36% / 87.93% | 2,984 | 10.32 s |
Before the fix, C32/n=4 has 6.59× higher TTFT, 6.59× longer prefill queue delay, and 7.86× mean prefill KV occupancy, delivering only 24.3% of C128/n=1 throughput. It incurs 4 prefill preemptions, versus zero for C128/n=1.
Baseline → this PR
| Workload | Output tokens/s (speedup) | Mean TTFT | Mean prefill queue delay | Prefill KV occupancy, mean / peak | Mean request latency |
|---|---:|---:|---:|---:|---:|
| C16, n=4 | 819 → 3,245 (3.96×) | 16.78 → 1.05 s | 14.53 → 0.73 s | 94.90% / 100.00% → 5.94% / 29.01% | 19.35 → 4.68 s |
| C32, n=4 | 727 → 4,396 (6.05×) | 39.60 → 1.94 s | 33.99 → 1.61 s | 97.16% / 100.00% → 9.80% / 48.68% | 43.27 → 6.98 s |
| C64, n=1 | 2,343 → 2,459 (1.05×) | 3.63 → 3.11 s | 2.63 → 2.39 s | 9.15% / 40.91% → 7.37% / 44.13% | 6.55 → 6.19 s |
| C128, n=1 | 2,984 → 2,982 (0.999×) | 6.01 → 5.98 s | 5.16 → 5.15 s | 12.36% / 87.93% → 11.84% / 83.64% | 10.32 → 10.28 s |
For n=4, throughput improves 3.96× at C16 and 6.05× at C32, while mean TTFT falls approximately 16× and 20×. Mean prefill occupancy falls from roughly 95–97% to 6–10%, and prefill preemptions drop from 9/4 to zero. The C64/n=1 control shows no observed regression: throughput is 4.9% higher, with lower mean TTFT and latency.
The C128/n=1 control is essentially unchanged: throughput changes by -0.09%, mean TTFT is 6.01 → 5.98 s, and mean queue delay is 5.16 → 5.15 s. Both C128/n=1 runs completed all 1,280 requests with exactly 327,680 output tokens and zero preemptions on all three workers. All eight runs completed without request errors.
With the fix, C32/n=4 delivers 1.47× C128/n=1 throughput, with lower TTFT (1.94 vs. 5.98 s), prefill queue delay (1.61 vs. 5.15 s), and mean prefill KV occupancy (9.80% vs. 11.84%). This reverses the baseline result at the same generated-sequence concurrency and total output work; the different numbers of independent contexts still apply.
Each point is a single run. Runs were sequential, used fresh different synthetic-data seeds, and did not reset cache state between runs. The large n=4 changes are consistent with removing the lease-induced bottleneck; small n=1 differences should not be treated as statistically established improvements. The C16/n=4 and C32/n=4 candidate results above use the latest four-point sweep.
Issues and Ongoing Work
Closes #14018.
n > 1. This PR supports multi-choice requests by splitting them inton=1requests before they reach those workers.<details>
<summary>Pull Request Checklist</summary>
/pr-checklistskill.</details>
Maintainer CI commands:
/ok to test <sha>starts full CI./rerun ciretries failed jobs for the current commit.<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
New Features
Eligible vLLM deployments can now process multi-choice requests in parallel, with each choice handled separately and results combined in the original response.
Explicit seeds are adjusted per choice, and usage totals are combined across results.
* Single-choice and query-only requests continue to use the existing path.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->