From d642ada2f7cf37e2d9901fb3c4eb7827202833e6 Mon Sep 17 00:00:00 2001 From: "devin-ai-integration[bot]" <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 23 Oct 2026 20:58:17 +0000 Subject: [PATCH] fix(proxy): satisfy LIT010 and LIT014 in the tool discovery buffer Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- litellm/proxy/db/db_transaction_queue/redis_update_buffer.py | 3 ++- litellm/proxy/db/db_transaction_queue/tool_discovery_queue.py | 3 +-- litellm/proxy/db/tool_registry_writer.py | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/litellm/proxy/db/db_transaction_queue/redis_update_buffer.py b/litellm/proxy/db/db_transaction_queue/redis_update_buffer.py index 4c18591a6f5..734ac961fc1 100644 --- a/litellm/proxy/db/db_transaction_queue/redis_update_buffer.py +++ b/litellm/proxy/db/db_transaction_queue/redis_update_buffer.py @@ -9,6 +9,7 @@ import json from collections.abc import Mapping, Sequence from datetime import datetime from functools import reduce +from itertools import chain from typing import TYPE_CHECKING, Any, Final, Literal, TypeAlias, TypeVar, cast from pydantic import TypeAdapter @@ -604,7 +605,7 @@ class RedisUpdateBuffer: if not entries: return () batches: Final = tuple(_TOOL_DISCOVERY_ITEMS.validate_json(entry) for entry in entries) - return aggregate_tool_discoveries(item for batch in batches for item in batch) + return aggregate_tool_discoveries(chain.from_iterable(batches)) @with_service_target(SPEND_QUEUE_TARGET) async def store_spend_logs_in_redis( diff --git a/litellm/proxy/db/db_transaction_queue/tool_discovery_queue.py b/litellm/proxy/db/db_transaction_queue/tool_discovery_queue.py index 0a60ff77b27..b53850e0327 100644 --- a/litellm/proxy/db/db_transaction_queue/tool_discovery_queue.py +++ b/litellm/proxy/db/db_transaction_queue/tool_discovery_queue.py @@ -26,8 +26,7 @@ def aggregate_tool_discoveries(items: Iterable[ToolDiscoveryQueueItem]) -> tuple """Collapse items to one per tool_name, summing call_count, in first-seen order.""" by_name: dict[str, ToolDiscoveryQueueItem] = {} # mutable-ok: single pass fold keyed by tool_name for item in items: - tool_name = item.get("tool_name", "") - if not tool_name: + if not (tool_name := item.get("tool_name", "")): continue by_name[tool_name] = _merged(by_name.get(tool_name), item) return tuple(by_name.values()) diff --git a/litellm/proxy/db/tool_registry_writer.py b/litellm/proxy/db/tool_registry_writer.py index 3cc4aa4a044..513313b2d34 100644 --- a/litellm/proxy/db/tool_registry_writer.py +++ b/litellm/proxy/db/tool_registry_writer.py @@ -8,6 +8,7 @@ Admins use the management endpoints to read and update input_policy / output_pol import uuid from collections.abc import Mapping, Sequence from datetime import datetime, timezone +from itertools import chain from types import MappingProxyType from typing import TYPE_CHECKING, Final, Protocol @@ -159,7 +160,7 @@ def build_tool_bulk_upsert(items: Sequence[ToolDiscoveryQueueItem]) -> tuple[str ' "last_used_at" = EXCLUDED."last_used_at",\n' ' "updated_at" = EXCLUDED."updated_at"' ) - return sql, tuple(value for item in items for value in _tool_row_params(item)) + return sql, tuple(chain.from_iterable(map(_tool_row_params, items))) async def batch_upsert_tools(