fix(proxy): declare the redis family on the tool discovery buffer and drop the blind except and cast

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
devin-ai-integration[bot] 2026-10-23 20:43:59 +00:00
parent e7848a7d4a
commit e78eab9d69
2 changed files with 10 additions and 4 deletions

View file

@ -581,7 +581,7 @@ class RedisUpdateBuffer:
RedisPipelineRpushOperation(key=REDIS_TOOL_DISCOVERY_BUFFER_KEY, values=[safe_dumps(items)])
]
)
except Exception as e:
except (RedisError, OSError, asyncio.TimeoutError) as e:
verbose_proxy_logger.error(
"Tool discovery - failed to push %d tool rows to Redis, restoring them for the next tick. Error: %s",
len(items),
@ -590,6 +590,7 @@ class RedisUpdateBuffer:
for item in items:
tool_discovery_queue.add_update(item)
@with_service_target(SPEND_QUEUE_TARGET)
async def get_all_tool_discoveries_from_redis_buffer(self) -> tuple[ToolDiscoveryQueueItem, ...]:
"""Drain every worker's tool rows and fold them to one row per tool_name."""
if self.redis_cache is None:
@ -605,6 +606,7 @@ class RedisUpdateBuffer:
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)
@with_service_target(SPEND_QUEUE_TARGET)
async def store_spend_logs_in_redis(
self,
rows: Sequence[SpendLogRow],

View file

@ -4,18 +4,22 @@ tool with the number of times it was invoked since the previous flush.
"""
from collections.abc import Iterable
from typing import Final, cast
from typing import Final
from pydantic import TypeAdapter
from litellm._logging import verbose_proxy_logger
from litellm.proxy._types import ToolDiscoveryQueueItem
_ITEM: Final = TypeAdapter(ToolDiscoveryQueueItem)
def _merged(existing: ToolDiscoveryQueueItem | None, item: ToolDiscoveryQueueItem) -> ToolDiscoveryQueueItem:
"""The first sighting keeps its origin and caller fields, later sightings only add to call_count."""
increment: Final = item.get("call_count", 1)
if existing is None:
return cast(ToolDiscoveryQueueItem, {**item, "call_count": increment})
return cast(ToolDiscoveryQueueItem, {**existing, "call_count": existing.get("call_count", 1) + increment})
return _ITEM.validate_python({**item, "call_count": increment})
return _ITEM.validate_python({**existing, "call_count": existing.get("call_count", 1) + increment})
def aggregate_tool_discoveries(items: Iterable[ToolDiscoveryQueueItem]) -> tuple[ToolDiscoveryQueueItem, ...]: