From 63a7258dca008af64b21c6fc604e8d04c3534c50 Mon Sep 17 00:00:00 2001 From: krishung5 Date: Mon, 27 Jul 2026 09:52:16 -0700 Subject: [PATCH 1/4] fix(kv-router): return terminal prefill responses directly Signed-off-by: krishung5 --- .../src/kv_router/prefill_router/admission.rs | 82 ++++++++++++++++++- lib/llm/src/kv_router/prefill_router/mod.rs | 67 +++++++++++---- 2 files changed, 132 insertions(+), 17 deletions(-) diff --git a/lib/llm/src/kv_router/prefill_router/admission.rs b/lib/llm/src/kv_router/prefill_router/admission.rs index ac178274df2e..9b838701dd2a 100644 --- a/lib/llm/src/kv_router/prefill_router/admission.rs +++ b/lib/llm/src/kv_router/prefill_router/admission.rs @@ -17,7 +17,7 @@ use super::{PrefillCompletion, PrefillError, PrefillRouter}; use crate::{ kv_router::KvPushRouter, protocols::common::{ - llm_backend::{LLMEngineOutput, PreprocessedRequest}, + llm_backend::{FinishReason, LLMEngineOutput, PreprocessedRequest}, timing::RequestTracker, }, session_affinity::{AffinityTarget, SessionAffinityPushRouter}, @@ -110,6 +110,21 @@ impl PrefillRouter { tokio::spawn(async move { while prefill_response.next().await.is_some() {} }); } + // A CTX request that reaches EOS/stop during its one-token prefill step + // is already complete and does not establish a KV-cache handoff. A + // missing finish reason is equivalent to TRT-LLM's "not_finished"; + // Length also requires the normal GEN handoff. + let is_terminal = first_output + .data + .as_ref() + .and_then(|output| output.finish_reason.as_ref()) + .is_some_and(|reason| !matches!(reason, FinishReason::Length)); + if is_terminal { + return Ok(PrefillCompletion::Terminal { + output: first_output, + }); + } + let Some(output) = &first_output.data else { return Err(PrefillError::NoDisaggregatedParams( "Prefill router output has no data field".to_string(), @@ -121,7 +136,7 @@ impl PrefillRouter { )); }; - Ok(PrefillCompletion { + Ok(PrefillCompletion::Handoff { result: crate::protocols::common::preprocessor::PrefillResult { disaggregated_params, prompt_tokens_details, @@ -203,4 +218,67 @@ mod tests { assert!(result.is_err()); assert!(!tracker.record_prefill_complete()); } + + #[tokio::test] + async fn terminal_prefill_without_handoff_is_returned_to_caller() { + let output = LLMEngineOutput { + token_ids: vec![2], + finish_reason: Some(FinishReason::EoS), + ..Default::default() + }; + let result = PrefillRouter::consume_prefill_stream( + prefill_stream(vec![Annotated::from_data(output)]), + None, + ) + .await + .unwrap(); + + let PrefillCompletion::Terminal { output } = result else { + panic!("expected terminal prefill completion"); + }; + assert_eq!( + output.data.and_then(|data| data.finish_reason), + Some(FinishReason::EoS) + ); + } + + #[tokio::test] + async fn length_limited_prefill_still_requires_handoff() { + let output = LLMEngineOutput { + finish_reason: Some(FinishReason::Length), + disaggregated_params: Some(json!({"ctx_request_id": 42})), + ..Default::default() + }; + let result = PrefillRouter::consume_prefill_stream( + prefill_stream(vec![Annotated::from_data(output)]), + None, + ) + .await + .unwrap(); + + let PrefillCompletion::Handoff { result, .. } = result else { + panic!("expected prefill handoff"); + }; + assert_eq!(result.disaggregated_params, json!({"ctx_request_id": 42})); + } + + #[tokio::test] + async fn unfinished_prefill_still_requires_handoff() { + let output = LLMEngineOutput { + finish_reason: None, + disaggregated_params: Some(json!({"ctx_request_id": 42})), + ..Default::default() + }; + let result = PrefillRouter::consume_prefill_stream( + prefill_stream(vec![Annotated::from_data(output)]), + None, + ) + .await + .unwrap(); + + let PrefillCompletion::Handoff { result, .. } = result else { + panic!("expected prefill handoff"); + }; + assert_eq!(result.disaggregated_params, json!({"ctx_request_id": 42})); + } } diff --git a/lib/llm/src/kv_router/prefill_router/mod.rs b/lib/llm/src/kv_router/prefill_router/mod.rs index f30c7b101b67..cea0bc859190 100644 --- a/lib/llm/src/kv_router/prefill_router/mod.rs +++ b/lib/llm/src/kv_router/prefill_router/mod.rs @@ -5,6 +5,7 @@ use std::sync::atomic::AtomicU8; use std::sync::{Arc, OnceLock}; use anyhow::Result; +use futures::stream; use tokio_util::sync::CancellationToken; use uuid::Uuid; @@ -90,6 +91,9 @@ enum PrefillOutcome { worker_id: u64, worker_link: Option, }, + Terminal { + output: Annotated, + }, } fn extract_bootstrap_info(params: &serde_json::Value) -> Option { @@ -121,9 +125,14 @@ pub enum PrefillQueryOutcome { }, } -struct PrefillCompletion { - result: PrefillResult, - worker_link: Option, +enum PrefillCompletion { + Handoff { + result: PrefillResult, + worker_link: Option, + }, + Terminal { + output: Annotated, + }, } /// PrefillRouter is a forward-only operator that sits between Migration and the decode router. @@ -248,19 +257,27 @@ impl drop(prefill_phase_barrier); let completion = Self::consume_prefill_stream(prefill_stream, tracker).await?; - if let Some(bootstrap_info) = - extract_bootstrap_info(&completion.result.disaggregated_params) - { - PrefillOutcome::Bootstrap { - bootstrap_info, - worker_id: prepared.worker_id, - } - } else { - PrefillOutcome::Completed { - result: completion.result, - worker_id: prepared.worker_id, - worker_link: completion.worker_link, + match completion { + PrefillCompletion::Handoff { + result, + worker_link, + } => { + if let Some(bootstrap_info) = + extract_bootstrap_info(&result.disaggregated_params) + { + PrefillOutcome::Bootstrap { + bootstrap_info, + worker_id: prepared.worker_id, + } + } else { + PrefillOutcome::Completed { + result, + worker_id: prepared.worker_id, + worker_link, + } + } } + PrefillCompletion::Terminal { output } => PrefillOutcome::Terminal { output }, } }; Ok((outcome, topology_constraints)) @@ -282,6 +299,23 @@ impl } }; + // A prefill request can terminate before the backend establishes a KV + // handoff (for example, EOS on the one-token context step). Native + // disaggregated backends return that context response directly instead + // of launching a generation-only request with missing handoff IDs. + let outcome = match outcome { + PrefillOutcome::Terminal { mut output } => { + if let Some(data) = output.data.as_mut() { + data.disaggregated_params = None; + } + return Ok(dynamo_runtime::pipeline::ResponseStream::new( + Box::pin(stream::once(async move { output })), + engine_ctx, + )); + } + outcome => outcome, + }; + // NVBugs 5969206: Do NOT abort decode routing when context is killed. // In disaggregated serving, the prefill may have completed and KV transfer // is in flight. Blocking decode here orphans the transfer (no receiver) @@ -322,6 +356,9 @@ impl decode_req.migration_link = worker_link; decode_req.routing_mut().prefill_worker_id = Some(worker_id); } + PrefillOutcome::Terminal { .. } => { + unreachable!("terminal prefill outcomes return before decode routing") + } }; if let Some(topology_constraints) = topology_constraints { From 2e1537dc591125c7d5512988d7ea0581274e6fa9 Mon Sep 17 00:00:00 2001 From: krishung5 Date: Mon, 27 Jul 2026 09:45:40 -0700 Subject: [PATCH 2/4] fix(trtllm): adapt disagg request IDs across API versions Signed-off-by: krishung5 --- .../trtllm/request_handlers/handler_base.py | 8 +-- .../tests/test_trtllm_disagg_request_id.py | 63 +++++++++++++++++++ .../src/dynamo/trtllm/utils/disagg_utils.py | 37 +++++++++++ 3 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 components/src/dynamo/trtllm/tests/test_trtllm_disagg_request_id.py diff --git a/components/src/dynamo/trtllm/request_handlers/handler_base.py b/components/src/dynamo/trtllm/request_handlers/handler_base.py index dd645a100e83..594499452daf 100644 --- a/components/src/dynamo/trtllm/request_handlers/handler_base.py +++ b/components/src/dynamo/trtllm/request_handlers/handler_base.py @@ -28,7 +28,6 @@ from tensorrt_llm.executor.result import GenerationResult from tensorrt_llm.executor.utils import RequestError from tensorrt_llm.llmapi import DisaggregatedParams as LlmDisaggregatedParams -from tensorrt_llm.llmapi.disagg_utils import get_global_disagg_request_id from tensorrt_llm.llmapi.llm import SamplingParams from tensorrt_llm.sampling_params import GuidedDecodingParams from tensorrt_llm.scheduling_params import SchedulingParams @@ -61,6 +60,7 @@ from dynamo.trtllm.utils.disagg_utils import ( DisaggregatedParams, DisaggregatedParamsCodec, + get_compatible_global_disagg_request_id, ) from dynamo.trtllm.utils.request_utils import ( apply_stop_conditions_to_sampling_params, @@ -728,7 +728,7 @@ def _setup_disaggregated_params_for_mode( else: disaggregated_params = LlmDisaggregatedParams( request_type="context_only", - disagg_request_id=get_global_disagg_request_id( + disagg_request_id=get_compatible_global_disagg_request_id( self.disagg_machine_id ), ) @@ -737,8 +737,8 @@ def _setup_disaggregated_params_for_mode( # ep_disaggregated_params, so the PYTHON transceiver can track # requests across prefill/decode workers. if disaggregated_params.disagg_request_id is None: - disaggregated_params.disagg_request_id = get_global_disagg_request_id( - self.disagg_machine_id + disaggregated_params.disagg_request_id = ( + get_compatible_global_disagg_request_id(self.disagg_machine_id) ) # AGGREGATED (prefill_and_decode) mode with encoder disaggregation: diff --git a/components/src/dynamo/trtllm/tests/test_trtllm_disagg_request_id.py b/components/src/dynamo/trtllm/tests/test_trtllm_disagg_request_id.py new file mode 100644 index 000000000000..7453d3201ebf --- /dev/null +++ b/components/src/dynamo/trtllm/tests/test_trtllm_disagg_request_id.py @@ -0,0 +1,63 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +from unittest.mock import patch + +import pytest + +from dynamo.trtllm.utils import disagg_utils + +pytestmark = [ + pytest.mark.unit, + pytest.mark.trtllm, + pytest.mark.core, + pytest.mark.pre_merge, + pytest.mark.gpu_1, +] + + +def test_rc22_machine_id_is_split_losslessly(): + with ( + patch.object(disagg_utils, "_TRTLLM_DISAGG_ID_HAS_PROCESS_ID", True), + patch.object( + disagg_utils, + "_trtllm_get_global_disagg_request_id", + return_value=123, + ) as generate, + ): + result = disagg_utils.get_compatible_global_disagg_request_id(1020) + + assert result == 123 + generate.assert_called_once_with(15, 60) + + +def test_rc22_all_dynamo_machine_ids_are_in_range_and_unique(): + pairs = { + divmod(machine_id, disagg_utils._TRTLLM_PROCESS_ID_SPACE) + for machine_id in range(disagg_utils._DYNAMO_DISAGG_MACHINE_ID_SPACE) + } + + assert len(pairs) == disagg_utils._DYNAMO_DISAGG_MACHINE_ID_SPACE + assert all(0 <= node_id < 256 for node_id, _ in pairs) + assert all(0 <= process_id < 64 for _, process_id in pairs) + + +def test_rc21_keeps_legacy_machine_id(): + with ( + patch.object(disagg_utils, "_TRTLLM_DISAGG_ID_HAS_PROCESS_ID", False), + patch.object( + disagg_utils, + "_trtllm_get_global_disagg_request_id", + return_value=456, + ) as generate, + ): + result = disagg_utils.get_compatible_global_disagg_request_id(1020) + + assert result == 456 + generate.assert_called_once_with(1020) + + +@pytest.mark.parametrize("machine_id", [-1, 1021]) +def test_invalid_dynamo_machine_id_fails_fast(machine_id): + with pytest.raises(ValueError, match="machine_id must be in range"): + disagg_utils.get_compatible_global_disagg_request_id(machine_id) diff --git a/components/src/dynamo/trtllm/utils/disagg_utils.py b/components/src/dynamo/trtllm/utils/disagg_utils.py index 375d46f19628..461fc463e9ec 100644 --- a/components/src/dynamo/trtllm/utils/disagg_utils.py +++ b/components/src/dynamo/trtllm/utils/disagg_utils.py @@ -15,9 +15,46 @@ import base64 import dataclasses +import inspect from tensorrt_llm.executor.result import Logprob from tensorrt_llm.llmapi import DisaggregatedParams +from tensorrt_llm.llmapi.disagg_utils import ( + get_global_disagg_request_id as _trtllm_get_global_disagg_request_id, +) + +# Dynamo maps its distributed-runtime connection ID into TRT-LLM's historical +# 10-bit machine-ID space with ``connection_id % 1021``. TRT-LLM rc22 split +# that field into an 8-bit node ID and a 6-bit process ID. Preserve Dynamo's +# existing 10-bit worker slot and encode it losslessly into the new pair. +_TRTLLM_DISAGG_ID_HAS_PROCESS_ID = ( + "process_id" in inspect.signature(_trtllm_get_global_disagg_request_id).parameters +) +_TRTLLM_PROCESS_ID_SPACE = 1 << 6 +_DYNAMO_DISAGG_MACHINE_ID_SPACE = 1021 + + +def get_compatible_global_disagg_request_id(machine_id: int) -> int: + """Generate a global TRT-LLM disaggregation request ID across API versions. + + TRT-LLM <= rc21 accepts a 10-bit ``machine_id``. TRT-LLM >= rc22 accepts + an 8-bit ``node_id`` plus a 6-bit ``process_id``. Dynamo's existing + machine ID is in ``[0, 1021)``; splitting that value with ``divmod(64)`` + produces a unique, in-range pair without changing Dynamo's collision + characteristics. + """ + + if not 0 <= machine_id < _DYNAMO_DISAGG_MACHINE_ID_SPACE: + raise ValueError( + "Dynamo disagg machine_id must be in range " + f"[0, {_DYNAMO_DISAGG_MACHINE_ID_SPACE}), got {machine_id}" + ) + + if _TRTLLM_DISAGG_ID_HAS_PROCESS_ID: + node_id, process_id = divmod(machine_id, _TRTLLM_PROCESS_ID_SPACE) + return _trtllm_get_global_disagg_request_id(node_id, process_id) + + return _trtllm_get_global_disagg_request_id(machine_id) class DisaggregatedParamsCodec: From fc8b649530a666cbc8f76558bd8ec5e0ebf6a5f3 Mon Sep 17 00:00:00 2001 From: krishung5 Date: Mon, 27 Jul 2026 10:29:07 -0700 Subject: [PATCH 3/4] fix(trtllm): harden rc22 disagg compatibility Signed-off-by: krishung5 --- .../tests/test_trtllm_disagg_request_id.py | 9 +- .../src/dynamo/trtllm/utils/disagg_utils.py | 9 ++ .../src/kv_router/prefill_router/admission.rs | 104 ++++++++++++++---- lib/llm/src/kv_router/prefill_router/mod.rs | 45 ++++++-- 4 files changed, 135 insertions(+), 32 deletions(-) diff --git a/components/src/dynamo/trtllm/tests/test_trtllm_disagg_request_id.py b/components/src/dynamo/trtllm/tests/test_trtllm_disagg_request_id.py index 7453d3201ebf..4aa486969106 100644 --- a/components/src/dynamo/trtllm/tests/test_trtllm_disagg_request_id.py +++ b/components/src/dynamo/trtllm/tests/test_trtllm_disagg_request_id.py @@ -38,8 +38,13 @@ def test_rc22_all_dynamo_machine_ids_are_in_range_and_unique(): } assert len(pairs) == disagg_utils._DYNAMO_DISAGG_MACHINE_ID_SPACE - assert all(0 <= node_id < 256 for node_id, _ in pairs) - assert all(0 <= process_id < 64 for _, process_id in pairs) + assert all( + 0 <= node_id < disagg_utils._TRTLLM_NODE_ID_SPACE for node_id, _ in pairs + ) + assert all( + 0 <= process_id < disagg_utils._TRTLLM_PROCESS_ID_SPACE + for _, process_id in pairs + ) def test_rc21_keeps_legacy_machine_id(): diff --git a/components/src/dynamo/trtllm/utils/disagg_utils.py b/components/src/dynamo/trtllm/utils/disagg_utils.py index 461fc463e9ec..3c2a021d0521 100644 --- a/components/src/dynamo/trtllm/utils/disagg_utils.py +++ b/components/src/dynamo/trtllm/utils/disagg_utils.py @@ -23,6 +23,9 @@ get_global_disagg_request_id as _trtllm_get_global_disagg_request_id, ) +# This compatibility shim intentionally relies on the public helper retaining +# its name while TRT-LLM distinguishes the two known APIs by the ``process_id`` +# parameter added in rc22. # Dynamo maps its distributed-runtime connection ID into TRT-LLM's historical # 10-bit machine-ID space with ``connection_id % 1021``. TRT-LLM rc22 split # that field into an 8-bit node ID and a 6-bit process ID. Preserve Dynamo's @@ -31,6 +34,7 @@ "process_id" in inspect.signature(_trtllm_get_global_disagg_request_id).parameters ) _TRTLLM_PROCESS_ID_SPACE = 1 << 6 +_TRTLLM_NODE_ID_SPACE = 1 << 8 _DYNAMO_DISAGG_MACHINE_ID_SPACE = 1021 @@ -52,6 +56,11 @@ def get_compatible_global_disagg_request_id(machine_id: int) -> int: if _TRTLLM_DISAGG_ID_HAS_PROCESS_ID: node_id, process_id = divmod(machine_id, _TRTLLM_PROCESS_ID_SPACE) + if node_id >= _TRTLLM_NODE_ID_SPACE: + raise ValueError( + "Dynamo disagg machine_id maps outside TRT-LLM's 8-bit " + f"node_id space: machine_id={machine_id}, node_id={node_id}" + ) return _trtllm_get_global_disagg_request_id(node_id, process_id) return _trtllm_get_global_disagg_request_id(machine_id) diff --git a/lib/llm/src/kv_router/prefill_router/admission.rs b/lib/llm/src/kv_router/prefill_router/admission.rs index 9b838701dd2a..15a63440aa56 100644 --- a/lib/llm/src/kv_router/prefill_router/admission.rs +++ b/lib/llm/src/kv_router/prefill_router/admission.rs @@ -111,9 +111,11 @@ impl PrefillRouter { } // A CTX request that reaches EOS/stop during its one-token prefill step - // is already complete and does not establish a KV-cache handoff. A - // missing finish reason is equivalent to TRT-LLM's "not_finished"; - // Length also requires the normal GEN handoff. + // is already complete and does not establish a KV-cache handoff. The + // prefill protocol carries this classification on the first output's + // data; a data-less first output is rejected below. A missing finish + // reason is equivalent to TRT-LLM's "not_finished", while Length still + // requires the normal GEN handoff. let is_terminal = first_output .data .as_ref() @@ -121,7 +123,7 @@ impl PrefillRouter { .is_some_and(|reason| !matches!(reason, FinishReason::Length)); if is_terminal { return Ok(PrefillCompletion::Terminal { - output: first_output, + output: Box::new(first_output), }); } @@ -135,6 +137,25 @@ impl PrefillRouter { "Prefill router output missing disaggregated_params".to_string(), )); }; + // TRT-LLM serializes ctx_request_id as null for a terminal context + // response. Terminal responses returned above do not need a handoff; + // any non-terminal response that explicitly carries a null ID cannot + // be decoded safely. Refuse it here instead of dispatching GEN and + // failing later inside the backend. Other backends do not expose this + // TRT-LLM-specific field and are unaffected. + let ctx_request_id = disaggregated_params.get("ctx_request_id"); + let is_trtllm_context_handoff = disaggregated_params + .get("request_type") + .and_then(serde_json::Value::as_str) + == Some("context_only"); + if ctx_request_id.is_some_and(serde_json::Value::is_null) + || (is_trtllm_context_handoff && ctx_request_id.is_none()) + { + return Err(PrefillError::NoDisaggregatedParams( + "Prefill router output has no usable ctx_request_id for a non-terminal handoff" + .to_string(), + )); + } Ok(PrefillCompletion::Handoff { result: crate::protocols::common::preprocessor::PrefillResult { @@ -220,26 +241,35 @@ mod tests { } #[tokio::test] - async fn terminal_prefill_without_handoff_is_returned_to_caller() { - let output = LLMEngineOutput { - token_ids: vec![2], - finish_reason: Some(FinishReason::EoS), - ..Default::default() - }; - let result = PrefillRouter::consume_prefill_stream( - prefill_stream(vec![Annotated::from_data(output)]), - None, - ) - .await - .unwrap(); + async fn terminal_finish_reasons_without_handoff_are_returned_to_caller() { + for finish_reason in [ + FinishReason::EoS, + FinishReason::Stop, + FinishReason::Cancelled, + FinishReason::Error("prefill failed".to_string()), + FinishReason::ContentFilter, + ] { + let output = LLMEngineOutput { + token_ids: vec![2], + finish_reason: Some(finish_reason.clone()), + ..Default::default() + }; + let result = PrefillRouter::consume_prefill_stream( + prefill_stream(vec![Annotated::from_data(output)]), + None, + ) + .await + .unwrap(); - let PrefillCompletion::Terminal { output } = result else { - panic!("expected terminal prefill completion"); - }; - assert_eq!( - output.data.and_then(|data| data.finish_reason), - Some(FinishReason::EoS) - ); + let PrefillCompletion::Terminal { output } = result else { + panic!("expected terminal prefill completion for {finish_reason:?}"); + }; + let output = *output; + assert_eq!( + output.data.and_then(|data| data.finish_reason), + Some(finish_reason) + ); + } } #[tokio::test] @@ -281,4 +311,32 @@ mod tests { }; assert_eq!(result.disaggregated_params, json!({"ctx_request_id": 42})); } + + #[tokio::test] + async fn non_terminal_prefill_without_usable_ctx_request_id_fails_before_decode() { + for disaggregated_params in [ + json!({"ctx_request_id": null}), + json!({"request_type": "context_only"}), + ] { + let output = LLMEngineOutput { + finish_reason: None, + disaggregated_params: Some(disaggregated_params), + ..Default::default() + }; + let result = PrefillRouter::consume_prefill_stream( + prefill_stream(vec![Annotated::from_data(output)]), + None, + ) + .await; + let Err(error) = result else { + panic!("expected a missing ctx_request_id to reject the handoff"); + }; + + assert!(matches!( + error, + PrefillError::NoDisaggregatedParams(message) + if message.contains("no usable ctx_request_id") + )); + } + } } diff --git a/lib/llm/src/kv_router/prefill_router/mod.rs b/lib/llm/src/kv_router/prefill_router/mod.rs index cea0bc859190..fafe800310fb 100644 --- a/lib/llm/src/kv_router/prefill_router/mod.rs +++ b/lib/llm/src/kv_router/prefill_router/mod.rs @@ -92,7 +92,7 @@ enum PrefillOutcome { worker_link: Option, }, Terminal { - output: Annotated, + output: Box>, }, } @@ -131,10 +131,19 @@ enum PrefillCompletion { worker_link: Option, }, Terminal { - output: Annotated, + output: Box>, }, } +fn strip_terminal_disaggregated_params( + mut output: Annotated, +) -> Annotated { + if let Some(data) = output.data.as_mut() { + data.disaggregated_params = None; + } + output +} + /// PrefillRouter is a forward-only operator that sits between Migration and the decode router. /// It optionally calls a prefill worker before routing to decode, extracting disaggregated_params /// from the prefill response and injecting them into the decode request. @@ -304,10 +313,8 @@ impl // disaggregated backends return that context response directly instead // of launching a generation-only request with missing handoff IDs. let outcome = match outcome { - PrefillOutcome::Terminal { mut output } => { - if let Some(data) = output.data.as_mut() { - data.disaggregated_params = None; - } + PrefillOutcome::Terminal { output } => { + let output = strip_terminal_disaggregated_params(*output); return Ok(dynamo_runtime::pipeline::ResponseStream::new( Box::pin(stream::once(async move { output })), engine_ctx, @@ -485,7 +492,10 @@ mod tests { use dynamo_kv_router::config::RouterConfigOverride; use std::collections::{HashMap, HashSet}; - use crate::protocols::common::preprocessor::{PreprocessedRequest, RoutingHints}; + use crate::protocols::common::{ + FinishReason, + preprocessor::{PreprocessedRequest, RoutingHints}, + }; const MAX_ROOM: u64 = i64::MAX as u64; @@ -502,6 +512,27 @@ mod tests { assert_eq!(override_config.router_temperature, Some(0.7)); } + #[test] + fn terminal_response_strips_disaggregated_params() { + let output = Annotated::from_data(LLMEngineOutput { + token_ids: vec![2], + finish_reason: Some(FinishReason::EoS), + disaggregated_params: Some(serde_json::json!({ + "ctx_request_id": null, + "request_type": "context_only", + })), + ..Default::default() + }); + + let output = strip_terminal_disaggregated_params(output); + let data = output + .data + .expect("terminal response should retain its data"); + assert_eq!(data.token_ids, vec![2]); + assert_eq!(data.finish_reason, Some(FinishReason::EoS)); + assert!(data.disaggregated_params.is_none()); + } + #[test] fn bootstrap_room_falls_back_when_dp_unavailable() { assert_eq!(compute_bootstrap_room(None, None, 12345), 12345); From 1eaf08035daf0c88fa1be18a442798080794d7e6 Mon Sep 17 00:00:00 2001 From: krishung5 Date: Mon, 27 Jul 2026 11:35:02 -0700 Subject: [PATCH 4/4] test(trtllm): skip request ID tests without CUDA Signed-off-by: krishung5 --- .../trtllm/tests/test_trtllm_disagg_request_id.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/components/src/dynamo/trtllm/tests/test_trtllm_disagg_request_id.py b/components/src/dynamo/trtllm/tests/test_trtllm_disagg_request_id.py index 4aa486969106..89537159f7b1 100644 --- a/components/src/dynamo/trtllm/tests/test_trtllm_disagg_request_id.py +++ b/components/src/dynamo/trtllm/tests/test_trtllm_disagg_request_id.py @@ -4,6 +4,16 @@ from unittest.mock import patch import pytest +import torch + +# Pytest applies marker selection after importing test modules. Importing +# disagg_utils loads TensorRT-LLM bindings, which require libcuda even though +# these tests do not execute CUDA kernels, so skip collection on CPU runners. +if not torch.cuda.is_available(): + pytest.skip( + "CUDA/GPU not available, but tensorrt_llm import requires CUDA.", + allow_module_level=True, + ) from dynamo.trtllm.utils import disagg_utils