From 4c1c2cb90c9767642f77dd1f27436022bed1a0c9 Mon Sep 17 00:00:00 2001 From: -LAN- Date: Wed, 23 Jul 2025 18:18:17 +0800 Subject: [PATCH] fix: improve max active requests calculation logic - Use app model's max_active_requests or fall back to global config - When global APP_MAX_ACTIVE_REQUESTS is non-zero, enforce it as a hard limit - Add comprehensive docstring explaining the behavior Signed-off-by: -LAN- --- api/services/app_generate_service.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/api/services/app_generate_service.py b/api/services/app_generate_service.py index 245c123a04..07bd960753 100644 --- a/api/services/app_generate_service.py +++ b/api/services/app_generate_service.py @@ -130,9 +130,22 @@ class AppGenerateService: @staticmethod def _get_max_active_requests(app_model: App) -> int: - max_active_requests = app_model.max_active_requests - if max_active_requests is None: - max_active_requests = int(dify_config.APP_MAX_ACTIVE_REQUESTS) + """ + Get the maximum number of active requests allowed for an app. + + If the app has a custom max_active_requests setting, it will be used + unless the global APP_MAX_ACTIVE_REQUESTS config is non-zero, in which + case the minimum of the two values is returned to enforce the global limit. + + Args: + app_model: The App model instance + + Returns: + The maximum number of active requests allowed + """ + max_active_requests = app_model.max_active_requests or dify_config.APP_MAX_ACTIVE_REQUESTS + if dify_config.APP_MAX_ACTIVE_REQUESTS != 0: + return min(max_active_requests, dify_config.APP_MAX_ACTIVE_REQUESTS) return max_active_requests @classmethod