fix(proxy): take the write-slot advisory lock before member name checks

Bugbot flagged that the member create path ran its name-collision check without any lock, so two concurrent creates of the same name could both pass. Take the same pg_advisory_xact_lock main takes at the top of the write transaction so member writes serialize before the checks run.
This commit is contained in:
devin-ai-integration[bot] 2026-09-23 06:40:40 +00:00
parent 77915d43b8
commit e39e1c8dea

View file

@ -321,6 +321,10 @@ def _member_auto_router_marker_for_update(
return incoming_params.model is None or incoming_params.model == _effective_model(None, existing.litellm_params)
AUTO_ROUTER_WRITE_SLOT_LOCK_KEY: Final = 5_872_301
_WRITE_SLOT_LOCK_SQL: Final = "SELECT 1 AS locked FROM pg_advisory_xact_lock($1)"
@asynccontextmanager
async def _member_auto_router_write_slot(
prisma_client: PrismaClient,
@ -345,6 +349,7 @@ async def _member_auto_router_write_slot(
transaction_client: Final = _ModelTransactionClient.model_validate(prisma_client.db)
async with transaction_client.tx(timeout=datetime.timedelta(seconds=30)) as tx_ctx:
tables: Final[_TxModelTables] = tx_ctx
await tx_ctx.query_raw(_WRITE_SLOT_LOCK_SQL, AUTO_ROUTER_WRITE_SLOT_LOCK_KEY)
config_rows: Final = () if llm_router is None else tuple(llm_router.config_deployments())
if member_write.model_id is not None:
await tx_ctx.query_raw(