refactor: daily fresh tech debt cleanup, rolling PR (2026-09-25) (#43151)

* refactor: clean up fresh tech debt from 2026-09-24 (stacked comprehensions, getattr, bare dict)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* chore: drop the budget ratchet from the PR branch, the default-branch automation owns it

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
devin-ai-integration[bot] 2026-09-26 01:32:55 -07:00 • committed by GitHub
parent 90873c46de
commit 1e6c98334c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 28 additions and 15 deletions

View file

@ -43,7 +43,7 @@ def _uses_native_vertex_output(
) -> bool:
if custom_llm_provider != "vertex_ai":
return False
if model_name and getattr(litellm, "disable_vertex_batch_output_transformation", False):
if model_name and litellm.disable_vertex_batch_output_transformation:
return True
return first_row is not None and is_native_vertex_batch_output_row(first_row)

View file

@ -684,7 +684,7 @@ class LangfuseSpanExporter(SpanExporter):
def _round(self, halving: _Halving) -> _Halving:
sent: Final = tuple((batch, self._send_batch(batch)) for batch in halving.pending)
return _Halving(
pending=tuple(part for batch, outcome in sent if outcome == "too_large" for part in _smaller(batch)),
pending=tuple(chain.from_iterable(_smaller(batch) for batch, outcome in sent if outcome == "too_large")),
settled=halving.settled
+ tuple(
SpanExportResult.SUCCESS if outcome == "delivered" else SpanExportResult.FAILURE

View file

@ -3,6 +3,7 @@
from collections.abc import Awaitable, Callable, Mapping, Sequence
from dataclasses import dataclass
from datetime import date, datetime, timedelta, timezone
from itertools import chain
from types import MappingProxyType
from typing import Final, Literal, TypeAlias
@ -126,7 +127,8 @@ async def fetch_openai_daily_costs(
return MappingProxyType(
{
day: sum(
result.amount.value for bucket in buckets if _bucket_day(bucket) == day for result in bucket.results
result.amount.value
for result in chain.from_iterable(bucket.results for bucket in buckets if _bucket_day(bucket) == day)
)
for day in days
}

View file

@ -6855,12 +6855,13 @@ class MCPServerManager:
if not tool_permissions:
return {}
expanded: Final = tuple(
(server_id, tuple(tools or ()))
for key, tools in tool_permissions.items()
for server_id in self.expand_permission_list([key])
chain.from_iterable(
((server_id, tuple(tools or ())) for server_id in self.expand_permission_list([key]))
for key, tools in tool_permissions.items()
)
)
return {
server_id: list(dict.fromkeys(tool for _, tools in group for tool in tools))
server_id: list(dict.fromkeys(chain.from_iterable(tools for _, tools in group)))
for server_id, group in groupby(sorted(expanded, key=itemgetter(0)), key=itemgetter(0))
}

View file

@ -14,6 +14,7 @@ import re
from collections.abc import Container, Mapping, Sequence
from dataclasses import dataclass
from functools import reduce
from itertools import chain
from types import MappingProxyType
from typing import TYPE_CHECKING, Final, cast
@ -191,7 +192,7 @@ def alias_map(aliases: object) -> Mapping[str, str]:
def _alias_names(alias_maps: Sequence[Mapping[str, str]]) -> tuple[str, ...]:
return tuple(dict.fromkeys(alias for aliases in alias_maps for alias in aliases))
return tuple(dict.fromkeys(chain.from_iterable(alias_maps)))
def _rewrite(model_id: str, alias_maps: Sequence[Mapping[str, str]]) -> str | None:

View file

@ -474,7 +474,9 @@ class _ProxyDBLogger(CustomLogger):
spend_log_error("Error in tracking cost callback - %s", str(e), exc=e)
@staticmethod
async def _enrich_failure_metadata_unless_db_stalled(metadata: dict, original_exception: Exception) -> dict:
async def _enrich_failure_metadata_unless_db_stalled(
metadata: dict[str, object], original_exception: Exception
) -> dict[str, object]:
if isinstance(original_exception, DBLookupDeadlineExceeded):
return metadata
return await _ProxyDBLogger._enrich_failure_metadata_with_key_info(metadata=metadata)

View file

@ -215,17 +215,23 @@ def _meta_with_user_details(
return updated
def _user_id_needing_details(api_key: str, meta: KeyMetadataDict) -> str | None:
user_id: Final = meta.get("user_id")
if not isinstance(user_id, str) or not user_id:
return None
if meta.get("user_email") and not (_is_cli_session_key(api_key) and not meta.get("team_id")):
return None
return user_id
async def attach_user_details(
prisma_client: PrismaClient,
recovered: Mapping[str, KeyMetadataDict],
) -> Mapping[str, KeyMetadataDict]:
needing_details: Final = frozenset(
user_id
for api_key, meta in recovered.items()
for user_id in (meta.get("user_id"),)
if isinstance(user_id, str)
and user_id
and (not meta.get("user_email") or (_is_cli_session_key(api_key) and not meta.get("team_id")))
for user_id in (_user_id_needing_details(api_key, meta) for api_key, meta in recovered.items())
if user_id is not None
)
details: Final = await _details_for_user_ids(prisma_client, needing_details)
if not details:

View file

@ -3,6 +3,7 @@ models and KWARG_ARTIFACTS into all_litellm_params."""
from collections.abc import Callable, Iterator, Mapping, MutableMapping, Sequence
from dataclasses import dataclass, field, fields, is_dataclass
from itertools import chain
from types import MappingProxyType
from typing import TYPE_CHECKING, Final, Literal, TypeAlias
@ -359,6 +360,6 @@ def owned_wire_names(root: type) -> tuple[str, ...]:
return tuple(names())
OWNED_KWARG_NAMES: Final = tuple(name for root in LITELLM_OWNED_ROOTS for name in owned_wire_names(root))
OWNED_KWARG_NAMES: Final = tuple(chain.from_iterable(owned_wire_names(root) for root in LITELLM_OWNED_ROOTS))
AGENTIC_LOOP_KWARG_NAMES: Final = (*wire_names(AgenticLoopState), *wire_names(AgenticLoopOptions))
BEDROCK_BATCH_KWARG_NAMES: Final = wire_names(BedrockBatchConnection)