From 03231f3b266c8b67799c6fa6785aefd36a767bbe Mon Sep 17 00:00:00 2001 From: yuneng-jiang Date: Sat, 14 Mar 2026 12:43:03 -0700 Subject: [PATCH] [Fix] CI failures: mypy type error, ruff lint, and flaky router test - Fix mypy arg-type error in background_streaming.py by adding proper type annotation and cast for terminal_status - Fix ruff F401 false positive for httpx import in vantage_destination.py caused by from __future__ import annotations - Fix flaky test_arouter_responses_api_bridge by providing a properly structured mock response to prevent exception mapping errors Co-Authored-By: Claude Opus 4.6 --- .../focus/destinations/vantage_destination.py | 2 +- .../proxy/response_polling/background_streaming.py | 14 +++++++++----- tests/test_litellm/test_router.py | 8 +++++++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/litellm/integrations/focus/destinations/vantage_destination.py b/litellm/integrations/focus/destinations/vantage_destination.py index 9e6028900f..4b9d270d2f 100644 --- a/litellm/integrations/focus/destinations/vantage_destination.py +++ b/litellm/integrations/focus/destinations/vantage_destination.py @@ -6,7 +6,7 @@ import csv import io from typing import Any, Optional -import httpx +import httpx # noqa: F401 - used at runtime (AsyncClient, HTTPStatusError) from litellm._logging import verbose_logger diff --git a/litellm/proxy/response_polling/background_streaming.py b/litellm/proxy/response_polling/background_streaming.py index 682ad4943b..5ec0aac8e2 100644 --- a/litellm/proxy/response_polling/background_streaming.py +++ b/litellm/proxy/response_polling/background_streaming.py @@ -9,7 +9,7 @@ https://platform.openai.com/docs/api-reference/responses-streaming """ import asyncio import json -from typing import Any +from typing import Any, Optional, cast from fastapi import Request, Response @@ -17,6 +17,7 @@ from litellm._logging import verbose_proxy_logger from litellm.proxy.auth.user_api_key_auth import UserAPIKeyAuth from litellm.proxy.common_request_processing import ProxyBaseLLMRequestProcessing from litellm.proxy.response_polling.polling_handler import ResponsePollingHandler +from litellm.types.llms.openai import ResponsesAPIStatus async def background_streaming_task( # noqa: PLR0915 @@ -114,7 +115,7 @@ async def background_streaming_task( # noqa: PLR0915 UPDATE_INTERVAL = 0.150 # 150ms batching interval # Track the terminal event from the stream (may not be "completed") - terminal_status = None # Will be set by response.completed/failed/incomplete/cancelled + terminal_status: Optional[ResponsesAPIStatus] = None # Will be set by response.completed/failed/incomplete/cancelled terminal_error = None _event_to_status = { "response.completed": "completed", @@ -249,9 +250,12 @@ async def background_streaming_task( # noqa: PLR0915 # Terminal event - extract all ResponsesAPIResponse fields # https://platform.openai.com/docs/api-reference/responses-streaming response_data = event.get("response", {}) - terminal_status = response_data.get( - "status", - _event_to_status.get(event_type, "completed"), + terminal_status = cast( + ResponsesAPIStatus, + response_data.get( + "status", + _event_to_status.get(event_type, "completed"), + ), ) # Extract error for failed responses diff --git a/tests/test_litellm/test_router.py b/tests/test_litellm/test_router.py index 8c37214e19..b563a2e3c5 100644 --- a/tests/test_litellm/test_router.py +++ b/tests/test_litellm/test_router.py @@ -643,7 +643,13 @@ def test_arouter_responses_api_bridge(): ## CONFIRM MODEL NAME IS STRIPPED client = HTTPHandler() - with patch.object(client, "post", return_value=MagicMock()) as mock_post: + mock_response = MagicMock() + mock_response.status_code = 200 + mock_response.headers = {"content-type": "application/json"} + mock_response.json.return_value = {"id": "resp_test", "object": "response", "status": "completed", "output": []} + mock_response.text = '{"id": "resp_test", "object": "response", "status": "completed", "output": []}' + + with patch.object(client, "post", return_value=mock_response) as mock_post: try: result = router.completion( model="[IP-approved] o3-pro",