From 056eb68fcc7cd26f2c313f5346e12ee959948aae Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Mon, 10 Mar 2025 19:59:10 +0000 Subject: [PATCH] fix: Fix lifespan app handler not working It was noticed that shutdown handlers for implementations are not executed. Investigation reveals that lifespan logic is not working. When server starts, we see: ``` ASGI 'lifespan' protocol appears unsupported. ``` This is because uvicorn calls to app with a missing path on startup, (perhaps to detect that the protocol is working?) and our TracingMiddleware was not ready for that, resulting in an exception and lifespan logic disabled. Fixes #188 Signed-off-by: Ihar Hrachyshka --- llama_stack/distribution/server/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llama_stack/distribution/server/server.py b/llama_stack/distribution/server/server.py index 262b1dbf0..c92903228 100644 --- a/llama_stack/distribution/server/server.py +++ b/llama_stack/distribution/server/server.py @@ -215,7 +215,7 @@ class TracingMiddleware: self.app = app async def __call__(self, scope, receive, send): - path = scope["path"] + path = scope.get("path", "") await start_trace(path, {"__location__": "server"}) try: return await self.app(scope, receive, send)