From b25dd8b71699394b51f0757e6ff1447e44323549 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Wed, 6 May 2026 15:31:05 -0700 Subject: [PATCH] fix: type-narrow session_id in _terminate_and_mark (mypy) Defensive: if both `session_id` and `id` are missing, return early. The str-cast keeps mypy happy when the row uses a UUID-typed column. LIT-2878 --- litellm/proxy/agent_session_endpoints/sweepers.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/litellm/proxy/agent_session_endpoints/sweepers.py b/litellm/proxy/agent_session_endpoints/sweepers.py index 9369f48cd0d..98b17149874 100644 --- a/litellm/proxy/agent_session_endpoints/sweepers.py +++ b/litellm/proxy/agent_session_endpoints/sweepers.py @@ -101,7 +101,11 @@ async def _terminate_and_mark( prisma_client: Any, ) -> None: """Common path: terminate VM, update session row. Idempotent.""" - session_id = getattr(session, "session_id", None) or getattr(session, "id", None) + session_id_raw = getattr(session, "session_id", None) or getattr(session, "id", None) + if not session_id_raw: + # Defensive: row without an id cannot be updated. + return + session_id: str = str(session_id_raw) # Re-fetch the row to confirm status hasn't moved (cheap optimistic lock). fresh = None