Repository navigation
[serve][llm] Serve only inference routes under direct streaming - #68528
jeffreywang88 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request restricts the routes served by the direct-streaming application to a predefined set of client-facing inference routes, dropping unauthenticated operational routes (such as /pause and /sleep) by default. It also introduces the RAY_SERVE_LLM_DIRECT_STREAMING_EXTRA_ROUTES environment variable to allow users to expose additional routes. The feedback suggests normalizing these extra routes to ensure they always start with a leading slash / to prevent configuration mismatches, and defensively accessing the path attribute on Starlette routes to avoid potential AttributeErrors.
| dropped = sorted({r.path for r in app.routes if r.path not in allowed}) | ||
| app.routes[:] = [r for r in app.routes if r.path in allowed] |
There was a problem hiding this comment.
In Starlette/FastAPI, not all route classes are guaranteed to have a path attribute (for example, custom route types or Starlette's Host routing class). Accessing r.path directly can raise an AttributeError. We should use getattr or check hasattr to defensively handle such routes.
| dropped = sorted({r.path for r in app.routes if r.path not in allowed}) | |
| app.routes[:] = [r for r in app.routes if r.path in allowed] | |
| dropped = sorted({r.path for r in app.routes if hasattr(r, "path") and r.path not in allowed}) | |
| app.routes[:] = [r for r in app.routes if getattr(r, "path", None) in allowed] |
da2ac51 to
913c284
Compare
Signed-off-by: Jeffrey Wang <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
913c284 to
ef4faea
Compare
|
Heads-up from #68623, which adds The allowlist in this PR has
If it's easier, I can add it in a follow-up after whichever PR lands second. |
Description
With direct streaming, the vLLM replica now serves only inference routes. Operational routes such as
/pause,/collective_rpcand/scale_elastic_epreturn 404.RAY_SERVE_LLM_DIRECT_STREAMING_EXTRA_ROUTESserves extra routes when needed.Why
OpenAiIngressexposes a fixed set of routes. Direct streaming serves vLLM's whole app instead, so clients can call every route vLLM mounts. That includes routes that control the engine and have no auth:/scale_elastic_epis always mounted, andVLLM_SERVER_DEV_MODE=1adds/pause,/sleep,/collective_rpc,/update_weightsand more.Why an allowlist in Ray:
/scale_elastic_epand clients must not. Ray can call it throughLLMServermethods, as it already does forpauseandsleep./%73cale_elastic_ep.VLLM_SERVER_DEV_MODEisn't enough. It removes only the dev-mode routes./scale_elastic_epand 24 other routes are mounted without it, and enabling a feature such as elastic EP or fault tolerance mounts its control routes.Changes
constants.py: addDIRECT_STREAMING_VLLM_ROUTESandRAY_SERVE_LLM_DIRECT_STREAMING_EXTRA_ROUTES.vllm_engine.py:build_asgi_appkeeps only those routes.test_direct_streaming_drops_operational_routes: the same checks end to end, through HAProxy and a real replica.test_kv_events.py: calls/reset_prefix_cache, so it now lists that route in the env var.Routes
Direct streaming on vLLM 0.34.0:
/v1/chat/completions,/v1/completions,/v1/responses(+ retrieve, cancel),/v1/embeddings,/v1/audio/transcriptions,/v1/audio/translations,/v1/score,/v1/rerank,/v1/models/v1/messages,/v1/messages/count_tokens/tokenize,/detokenize,/pooling,/classify,/score,/rerank/scale_elastic_ep,/is_scaling_elastic_ep/health,/ping,/metrics,/load,/version,/kv_event_sources/docs,/redoc,/openapi.json/invocations,/generative_scoring,/inference/v1/*,/v1/chat/completions/batch,/v1/decisions,/v1/systemone,*/render,*/derender/pause,/resume,/sleep,/wake_up,/collective_rpc,/abort_requests,/reset_prefix_cache,/update_weights,/server_infoand 14 more/v1/load_lora_adapter,/v1/fault_tolerance/*,/start_profile,/tokenizer_info,/checkpoint/*,/v1/realtime, Cohere routes, endpoint plugin routesRAY_SERVE_LLM_DIRECT_STREAMING_EXTRA_ROUTEScan serve any 404 route again. Ray's/-/healthzhealth checks are unaffected.Validation
Live: direct streaming with HAProxy,
Qwen/Qwen3-0.6B, vLLM 0.34.0,VLLM_SERVER_DEV_MODE=1./scale_elastic_ep,/%73cale_elastic_ep/server_info,/is_paused,/reset_prefix_cache,/collective_rpc,/metrics,/healthWith
RAY_SERVE_LLM_DIRECT_STREAMING_EXTRA_ROUTES=/reset_prefix_cache, that route returns 200.Tests:
/scale_elastic_epreaches the handler) and passes with this PR.LLMServerunit tests give the same results before and after.test_kv_events.py::TestKvEventsfails locally on both master and this PR, before it reaches/reset_prefix_cache, so I couldn't run that change end to end.Related issues
Related: vllm-project/vllm#59094, which puts
/scale_elastic_epbehind vLLM's--api-key.AI assistance (🤖 Claude Code) was used to prepare this PR.