From 3190f42abf65e25053e59c2e8b5c9a96dd21c220 Mon Sep 17 00:00:00 2001 From: mateo Date: Thu, 3 Sep 2026 08:09:51 +0000 Subject: [PATCH 1/6] refactor: clear fresh tech debt from the last 24 hours (2026-09-03) Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .../model_armor/model_armor.py | 5 +--- litellm/responses/streaming_iterator.py | 19 +++++------- litellm/rust_bridge/runtime.py | 30 ------------------- type-discipline-budget.json | 4 +-- 4 files changed, 10 insertions(+), 48 deletions(-) diff --git a/litellm/proxy/guardrails/guardrail_hooks/model_armor/model_armor.py b/litellm/proxy/guardrails/guardrail_hooks/model_armor/model_armor.py index 7d88a037f4f..f0de6ee0ac7 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/model_armor/model_armor.py +++ b/litellm/proxy/guardrails/guardrail_hooks/model_armor/model_armor.py @@ -1095,10 +1095,7 @@ class ModelArmorGuardrail(CustomGuardrail, VertexBase): add_guardrail_to_applied_guardrails_header, ) - # Collect all chunks - all_chunks: Final[list[Any]] = [] - async for chunk in response: - all_chunks.append(chunk) + all_chunks: Final[Sequence[Any]] = tuple([chunk async for chunk in response]) if not all_chunks or self._is_terminal_error_stream(all_chunks): for chunk in all_chunks: diff --git a/litellm/responses/streaming_iterator.py b/litellm/responses/streaming_iterator.py index f271655f5e3..9f9016c5a7f 100644 --- a/litellm/responses/streaming_iterator.py +++ b/litellm/responses/streaming_iterator.py @@ -496,10 +496,9 @@ class BaseResponsesAPIStreamingIterator: if logging_response is self.completed_response: return target: Final[object] = getattr(logging_response, "response", None) - existing_hidden: Final[object] = getattr(target, "_hidden_params", None) - if not isinstance(existing_hidden, Mapping): + if not isinstance(target, ResponsesAPIResponse): return - existing: Final[Mapping[str, object]] = existing_hidden + existing: Final[Mapping[str, object]] = target._hidden_params source_hidden: Final[object] = getattr( getattr(self.completed_response, "response", None), "_hidden_params", None ) @@ -510,15 +509,11 @@ class BaseResponsesAPIStreamingIterator: raw_headers: Final[Mapping[str, object]] = raw if isinstance(raw, Mapping) else EMPTY_MAPPING # rebuild by value and let existing keys win: sharing the source dicts would alias what the proxy # splats into the client's HTTP headers, and copying non-header keys would carry response_cost - setattr( # noqa: B010 # target is typed object here, so a plain attribute store does not type check - target, - "_hidden_params", - { # mutable-ok: the cost calculator writes optional_params into _hidden_params - "additional_headers": {**headers}, # mutable-ok: fresh copy, logging callbacks may mutate it - "headers": {**raw_headers}, # mutable-ok: fresh copy, logging callbacks may mutate it - **existing, - }, - ) + target._hidden_params = { # mutable-ok: the cost calculator writes optional_params into _hidden_params + "additional_headers": {**headers}, # mutable-ok: fresh copy, logging callbacks may mutate it + "headers": {**raw_headers}, # mutable-ok: fresh copy, logging callbacks may mutate it + **existing, + } def _handle_logging_completed_response(self): """Base implementation - should be overridden by subclasses""" diff --git a/litellm/rust_bridge/runtime.py b/litellm/rust_bridge/runtime.py index 00f06c046a2..d411673439f 100644 --- a/litellm/rust_bridge/runtime.py +++ b/litellm/rust_bridge/runtime.py @@ -116,28 +116,6 @@ async def aattempt( return RustHandled(adapt(value)) -def call(operation: Callable[[], ResultT], context: BridgeErrorContext) -> ResultT: - exceptions: Final = native_exception_types() - if exceptions is None: - return operation() - upstream: Final = exceptions[1] - try: - return operation() - except upstream as error: - _raise_upstream(error, context) - - -async def acall(operation: Callable[[], Awaitable[ResultT]], context: BridgeErrorContext) -> ResultT: - exceptions: Final = native_exception_types() - if exceptions is None: - return await operation() - upstream: Final = exceptions[1] - try: - return await operation() - except upstream as error: - _raise_upstream(error, context) - - def _decline_reason(error: BaseException) -> str: reason: Final[object] = error.args[0] if error.args else str(error) return reason if isinstance(reason, str) else str(reason) @@ -170,11 +148,3 @@ def _raise_upstream(error: BaseException, context: BridgeErrorContext) -> NoRetu llm_provider=context.provider, model=context.model, ) from error - - -def identity(value: ResultT) -> ResultT: - return value - - -async def async_none() -> None: - return None diff --git a/type-discipline-budget.json b/type-discipline-budget.json index d5bf3883be4..704d7e8a596 100644 --- a/type-discipline-budget.json +++ b/type-discipline-budget.json @@ -1,9 +1,9 @@ { "LIT001": { - "limit": 22330 + "limit": 22329 }, "LIT002": { - "limit": 26763 + "limit": 26762 }, "LIT003": { "limit": 261 From 4e9c6b5dd436680b7c39b3df427c3f6651668f4c Mon Sep 17 00:00:00 2001 From: mateo Date: Thu, 3 Sep 2026 08:26:43 +0000 Subject: [PATCH 2/6] refactor(model_armor): type the buffered stream chunks as object Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- basedpyright-code-budget.json | 2 +- .../guardrails/guardrail_hooks/model_armor/model_armor.py | 2 +- type-discipline-budget.json | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/basedpyright-code-budget.json b/basedpyright-code-budget.json index 2967fc2a505..45a3856d246 100644 --- a/basedpyright-code-budget.json +++ b/basedpyright-code-budget.json @@ -24,7 +24,7 @@ "limit": 19 }, "reportExplicitAny": { - "limit": 4124 + "limit": 4123 }, "reportFunctionMemberAccess": { "limit": 7 diff --git a/litellm/proxy/guardrails/guardrail_hooks/model_armor/model_armor.py b/litellm/proxy/guardrails/guardrail_hooks/model_armor/model_armor.py index f0de6ee0ac7..4a60f092bfb 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/model_armor/model_armor.py +++ b/litellm/proxy/guardrails/guardrail_hooks/model_armor/model_armor.py @@ -1095,7 +1095,7 @@ class ModelArmorGuardrail(CustomGuardrail, VertexBase): add_guardrail_to_applied_guardrails_header, ) - all_chunks: Final[Sequence[Any]] = tuple([chunk async for chunk in response]) + all_chunks: Final[Sequence[object]] = tuple([chunk async for chunk in response]) if not all_chunks or self._is_terminal_error_stream(all_chunks): for chunk in all_chunks: diff --git a/type-discipline-budget.json b/type-discipline-budget.json index 704d7e8a596..972bc3315f2 100644 --- a/type-discipline-budget.json +++ b/type-discipline-budget.json @@ -1,9 +1,9 @@ { "LIT001": { - "limit": 22329 + "limit": 22328 }, "LIT002": { - "limit": 26762 + "limit": 26761 }, "LIT003": { "limit": 261 From 8b37de14b1e9921b60535108b07fa7b0166a6bc7 Mon Sep 17 00:00:00 2001 From: mateo Date: Fri, 4 Sep 2026 08:05:04 +0000 Subject: [PATCH 3/6] refactor: drop fresh Any annotations and suppressions from admission control, spend summary, and dual cache Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- basedpyright-code-budget.json | 6 ++--- litellm/caching/dual_cache.py | 2 +- litellm/litellm_core_utils/litellm_logging.py | 2 +- .../admission_control_middleware.py | 10 ++------ .../spend_management_endpoints.py | 25 ++++++++++--------- ruff-strict-budget.json | 2 +- type-discipline-budget.json | 4 +-- 7 files changed, 23 insertions(+), 28 deletions(-) diff --git a/basedpyright-code-budget.json b/basedpyright-code-budget.json index 0a29e7eae7e..91e32bc1789 100644 --- a/basedpyright-code-budget.json +++ b/basedpyright-code-budget.json @@ -1,6 +1,6 @@ { "reportAny": { - "limit": 14074 + "limit": 14070 }, "reportArgumentType": { "limit": 2206 @@ -24,7 +24,7 @@ "limit": 19 }, "reportExplicitAny": { - "limit": 4123 + "limit": 4117 }, "reportFunctionMemberAccess": { "limit": 7 @@ -108,7 +108,7 @@ "limit": 38311 }, "reportUnknownParameterType": { - "limit": 19624 + "limit": 19623 }, "reportUnknownVariableType": { "limit": 29847 diff --git a/litellm/caching/dual_cache.py b/litellm/caching/dual_cache.py index df67ba08416..ec17cc1d809 100644 --- a/litellm/caching/dual_cache.py +++ b/litellm/caching/dual_cache.py @@ -257,7 +257,7 @@ class DualCache(BaseCache): self, current_time: float, keys: list[str], - result: Sequence[Any], + result: Sequence[object], ) -> tuple[list[str], dict[str, float | None]]: """ Atomically choose keys to fetch from Redis and reserve their access time. diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.py index 17a19f05fa3..925c7416b19 100644 --- a/litellm/litellm_core_utils/litellm_logging.py +++ b/litellm/litellm_core_utils/litellm_logging.py @@ -3815,7 +3815,7 @@ class Logging(LiteLLMLoggingBaseClass): def record_streamed_anthropic_message_id(self, message_id: str) -> None: self.streamed_anthropic_message_id = message_id - def _anthropic_messages_logged_response(self, result: Any) -> ModelResponse: + def _anthropic_messages_logged_response(self, result: object) -> ModelResponse: """ The ModelResponse a /v1/messages spend_logs row is built from. diff --git a/litellm/proxy/middleware/admission_control_middleware.py b/litellm/proxy/middleware/admission_control_middleware.py index aa62ef9e3bf..e347428be83 100644 --- a/litellm/proxy/middleware/admission_control_middleware.py +++ b/litellm/proxy/middleware/admission_control_middleware.py @@ -32,9 +32,6 @@ class AdmissionControlSettings: queue_timeout_seconds: float -AdmissionControlSettingsGetter: TypeAlias = Callable[[], AdmissionControlSettings | None] # mutable-ok: Callable params - - @dataclass(frozen=True, slots=True) class AdmissionControlStats: admitted: int @@ -66,13 +63,10 @@ class AdmissionControlMetrics: rejected_counter: _Counter -AdmissionControlMetricsFactory: TypeAlias = Callable[[], AdmissionControlMetrics | None] # mutable-ok: Callable params - - class AdmissionControlState: """Per-process admission counters and the in-flight semaphore shared by one worker's requests.""" - def __init__(self, metrics_factory: AdmissionControlMetricsFactory) -> None: + def __init__(self, metrics_factory: Callable[[], AdmissionControlMetrics | None]) -> None: self._metrics_factory = metrics_factory self._metrics: AdmissionControlMetrics | None = None self._metrics_init_attempted = False @@ -140,7 +134,7 @@ class AdmissionControlMiddleware: def __init__( self, app: ASGIApp, - get_settings: AdmissionControlSettingsGetter, + get_settings: Callable[[], AdmissionControlSettings | None], state: AdmissionControlState, ) -> None: self.app = app diff --git a/litellm/proxy/spend_tracking/spend_management_endpoints.py b/litellm/proxy/spend_tracking/spend_management_endpoints.py index dff100bdea7..f8831ca4152 100644 --- a/litellm/proxy/spend_tracking/spend_management_endpoints.py +++ b/litellm/proxy/spend_tracking/spend_management_endpoints.py @@ -3365,23 +3365,24 @@ async def view_spend_logs( ) sql_query, params = summary_sql_and_params rows: Final[Sequence[_SpendDailySummaryRow]] = await _query_raw(prisma_client, sql_query, *params) - if len(rows) == 0: - return [] # pyright: ignore[reportUnknownVariableType] # empty summary has no element type - summary_items: Final = tuple( _daily_summary_item(date.fromisoformat(day), tuple(day_rows)) for day, day_rows in groupby(rows, key=lambda row: row["day"]) ) - final_date: Final = date.fromisoformat(rows[-1]["day"]) + final_date: Final = date.fromisoformat(rows[-1]["day"]) if len(rows) > 0 else None end_date_date: Final = end_date_obj.date() - padding: Final[tuple[Mapping[str, object], ...]] = tuple( - { - "startTime": final_date + timedelta(days=offset), - "spend": 0, - "users": {}, - "models": {}, - } - for offset in range(1, (end_date_date - final_date).days + 1) + padding: Final[tuple[Mapping[str, object], ...]] = ( + () + if final_date is None + else tuple( + { + "startTime": final_date + timedelta(days=offset), + "spend": 0, + "users": {}, + "models": {}, + } + for offset in range(1, (end_date_date - final_date).days + 1) + ) ) return [*summary_items, *padding] diff --git a/ruff-strict-budget.json b/ruff-strict-budget.json index 8763318b4eb..f54f31d182d 100644 --- a/ruff-strict-budget.json +++ b/ruff-strict-budget.json @@ -78,7 +78,7 @@ "limit": 1 }, "C901": { - "limit": 311 + "limit": 309 }, "D419": { "limit": 6 diff --git a/type-discipline-budget.json b/type-discipline-budget.json index ab1a793e09d..3b56aa11d02 100644 --- a/type-discipline-budget.json +++ b/type-discipline-budget.json @@ -1,9 +1,9 @@ { "LIT001": { - "limit": 22328 + "limit": 22326 }, "LIT002": { - "limit": 26750 + "limit": 26746 }, "LIT003": { "limit": 261 From e7c29351e8b2e912ad42140938d7d4a77cc6e4d5 Mon Sep 17 00:00:00 2001 From: mateo Date: Fri, 4 Sep 2026 16:35:26 +0000 Subject: [PATCH 4/6] chore: ratchet lint budgets after merging litellm_internal_staging Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- basedpyright-code-budget.json | 6 +++--- ruff-strict-budget.json | 2 +- type-discipline-budget.json | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/basedpyright-code-budget.json b/basedpyright-code-budget.json index 1b0650c70d8..ca288a2a644 100644 --- a/basedpyright-code-budget.json +++ b/basedpyright-code-budget.json @@ -1,6 +1,6 @@ { "reportAny": { - "limit": 14074 + "limit": 14072 }, "reportArgumentType": { "limit": 2206 @@ -24,7 +24,7 @@ "limit": 19 }, "reportExplicitAny": { - "limit": 4124 + "limit": 4121 }, "reportFunctionMemberAccess": { "limit": 7 @@ -108,7 +108,7 @@ "limit": 38309 }, "reportUnknownParameterType": { - "limit": 19622 + "limit": 19621 }, "reportUnknownVariableType": { "limit": 29846 diff --git a/ruff-strict-budget.json b/ruff-strict-budget.json index 0252e85efa6..7a1e709bb22 100644 --- a/ruff-strict-budget.json +++ b/ruff-strict-budget.json @@ -78,7 +78,7 @@ "limit": 1 }, "C901": { - "limit": 309 + "limit": 308 }, "D419": { "limit": 6 diff --git a/type-discipline-budget.json b/type-discipline-budget.json index 589d5249b2d..78405a9a9db 100644 --- a/type-discipline-budget.json +++ b/type-discipline-budget.json @@ -1,9 +1,9 @@ { "LIT001": { - "limit": 22326 + "limit": 22325 }, "LIT002": { - "limit": 26746 + "limit": 26744 }, "LIT003": { "limit": 261 From 966ab10fd659d3d7febc5515757c021a816dccae Mon Sep 17 00:00:00 2001 From: mateo Date: Fri, 4 Sep 2026 22:33:15 +0000 Subject: [PATCH 5/6] chore: ratchet lint budgets after merging litellm_internal_staging Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- basedpyright-code-budget.json | 6 +++--- ruff-strict-budget.json | 2 +- type-discipline-budget.json | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/basedpyright-code-budget.json b/basedpyright-code-budget.json index 4cea4a4804a..9c32cc84ee9 100644 --- a/basedpyright-code-budget.json +++ b/basedpyright-code-budget.json @@ -1,6 +1,6 @@ { "reportAny": { - "limit": 14072 + "limit": 14070 }, "reportArgumentType": { "limit": 2206 @@ -24,7 +24,7 @@ "limit": 19 }, "reportExplicitAny": { - "limit": 4121 + "limit": 4118 }, "reportFunctionMemberAccess": { "limit": 7 @@ -108,7 +108,7 @@ "limit": 38309 }, "reportUnknownParameterType": { - "limit": 19621 + "limit": 19620 }, "reportUnknownVariableType": { "limit": 29846 diff --git a/ruff-strict-budget.json b/ruff-strict-budget.json index 7a1e709bb22..fe5dad5731b 100644 --- a/ruff-strict-budget.json +++ b/ruff-strict-budget.json @@ -78,7 +78,7 @@ "limit": 1 }, "C901": { - "limit": 308 + "limit": 307 }, "D419": { "limit": 6 diff --git a/type-discipline-budget.json b/type-discipline-budget.json index 8589a9451cf..71571317d9b 100644 --- a/type-discipline-budget.json +++ b/type-discipline-budget.json @@ -1,9 +1,9 @@ { "LIT001": { - "limit": 22328 + "limit": 22327 }, "LIT002": { - "limit": 26748 + "limit": 26746 }, "LIT003": { "limit": 261 From aedaf0d5a7e32a2608ef81d194a2de7bc83b6f99 Mon Sep 17 00:00:00 2001 From: mateo Date: Sat, 5 Sep 2026 00:45:00 +0000 Subject: [PATCH 6/6] chore: ratchet lint budgets after merging litellm_internal_staging Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- basedpyright-code-budget.json | 6 +++--- ruff-strict-budget.json | 2 +- type-discipline-budget.json | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/basedpyright-code-budget.json b/basedpyright-code-budget.json index 669107bb5b1..9aadf0f974f 100644 --- a/basedpyright-code-budget.json +++ b/basedpyright-code-budget.json @@ -1,6 +1,6 @@ { "reportAny": { - "limit": 14074 + "limit": 14072 }, "reportArgumentType": { "limit": 2206 @@ -24,7 +24,7 @@ "limit": 19 }, "reportExplicitAny": { - "limit": 4124 + "limit": 4121 }, "reportFunctionMemberAccess": { "limit": 7 @@ -108,7 +108,7 @@ "limit": 38309 }, "reportUnknownParameterType": { - "limit": 19621 + "limit": 19620 }, "reportUnknownVariableType": { "limit": 29844 diff --git a/ruff-strict-budget.json b/ruff-strict-budget.json index 5eaecd27d63..b485eb76f4b 100644 --- a/ruff-strict-budget.json +++ b/ruff-strict-budget.json @@ -78,7 +78,7 @@ "limit": 1 }, "C901": { - "limit": 307 + "limit": 306 }, "D419": { "limit": 6 diff --git a/type-discipline-budget.json b/type-discipline-budget.json index 3d01c08e8eb..ad7d7327b7e 100644 --- a/type-discipline-budget.json +++ b/type-discipline-budget.json @@ -1,9 +1,9 @@ { "LIT001": { - "limit": 22326 + "limit": 22325 }, "LIT002": { - "limit": 26748 + "limit": 26746 }, "LIT003": { "limit": 261