From 7b828e30d5e56d78a6be1bc61dc0e44f9c8b4ce6 Mon Sep 17 00:00:00 2001 From: Wentao Ye <44945378+yewentao256@users.noreply.github.com> Date: Fri, 11 Jul 2025 21:57:24 -0400 Subject: [PATCH] [CI Bug] Fix Async Engine, Inputs, Utils, Worker Test: 'State' object has no attribute 'enable_server_load_tracking' (#20845) Signed-off-by: yewentao256 --- vllm/entrypoints/utils.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/vllm/entrypoints/utils.py b/vllm/entrypoints/utils.py index 423b99dbe565c..6c37ce818e6d0 100644 --- a/vllm/entrypoints/utils.py +++ b/vllm/entrypoints/utils.py @@ -33,10 +33,12 @@ async def listen_for_disconnect(request: Request) -> None: while True: message = await request.receive() if message["type"] == "http.disconnect": - if request.app.state.enable_server_load_tracking: - # on timeout/cancellation the BackgroundTask in load_aware_call - # cannot decrement the server load metrics. - # Must be decremented by with_cancellation instead. + # If load tracking is enabled *and* the counter exists, decrement + # it. Combines the previous nested checks into a single condition + # to satisfy the linter rule. + if (getattr(request.app.state, "enable_server_load_tracking", + False) + and hasattr(request.app.state, "server_load_metrics")): request.app.state.server_load_metrics -= 1 break @@ -101,9 +103,14 @@ def load_aware_call(func): raise ValueError( "raw_request required when server load tracking is enabled") - if not raw_request.app.state.enable_server_load_tracking: + if not getattr(raw_request.app.state, "enable_server_load_tracking", + False): return await func(*args, **kwargs) + # ensure the counter exists + if not hasattr(raw_request.app.state, "server_load_metrics"): + raw_request.app.state.server_load_metrics = 0 + raw_request.app.state.server_load_metrics += 1 try: response = await func(*args, **kwargs)