AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
feat(backend): Make execution limit per user per graph and reduce to 25 (#11169)
Zamil Majdy934cb3a9c7fc
diff --git a/autogpt_platform/backend/backend/data/execution.py b/autogpt_platform/backend/backend/data/execution.pyindex e03b5f7386..a097737706 100644--- a/autogpt_platform/backend/backend/data/execution.py+++ b/autogpt_platform/backend/backend/data/execution.py@@ -479,16 +479,18 @@ async def get_graph_executions(async def get_graph_executions_count(- user_id: str,+ user_id: Optional[str] = None,+ graph_id: Optional[str] = None,statuses: Optional[list[ExecutionStatus]] = None,created_time_gte: Optional[datetime] = None,created_time_lte: Optional[datetime] = None,) -> int:"""- Get count of graph executions for a user with optional filters.+ Get count of graph executions with optional filters.Args:- user_id: The user ID to filter by+ user_id: Optional user ID to filter by+ graph_id: Optional graph ID to filter bystatuses: Optional list of execution statuses to filter bycreated_time_gte: Optional minimum creation timecreated_time_lte: Optional maximum creation time@@ -498,9 +500,14 @@ async def get_graph_executions_count("""where_filter: AgentGraphExecutionWhereInput = {"isDeleted": False,- "userId": user_id,}+ if user_id:+ where_filter["userId"] = user_id++ if graph_id:+ where_filter["agentGraphId"] = graph_id+if created_time_gte or created_time_lte:where_filter["createdAt"] = {"gte": created_time_gte or datetime.min.replace(tzinfo=timezone.utc),diff --git a/autogpt_platform/backend/backend/executor/manager.py b/autogpt_platform/backend/backend/executor/manager.pyindex dea8cffd30..7c97378bbe 100644--- a/autogpt_platform/backend/backend/executor/manager.py+++ b/autogpt_platform/backend/backend/executor/manager.py@@ -1467,6 +1467,7 @@ class ExecutionManager(AppProcess):graph_exec_id = graph_exec_entry.graph_exec_iduser_id = graph_exec_entry.user_id+ graph_id = graph_exec_entry.graph_idlogger.info(f"[{self.service_name}] Received RUN for graph_exec_id={graph_exec_id}, user_id={user_id}")@@ -1476,6 +1477,7 @@ class ExecutionManager(AppProcess):# Only check executions from the last 24 hours for performancecurrent_running_count = get_db_client().get_graph_executions_count(user_id=user_id,+ graph_id=graph_id,statuses=[ExecutionStatus.RUNNING],created_time_gte=datetime.now(timezone.utc) - timedelta(hours=24),)@@ -1485,7 +1487,7 @@ class ExecutionManager(AppProcess):>= settings.config.max_concurrent_graph_executions_per_user):logger.warning(- f"[{self.service_name}] Rate limit exceeded for user {user_id}: "+ f"[{self.service_name}] Rate limit exceeded for user {user_id} on graph {graph_id}: "f"{current_running_count}/{settings.config.max_concurrent_graph_executions_per_user} running executions")_ack_message(reject=True, requeue=True)diff --git a/autogpt_platform/backend/backend/util/settings.py b/autogpt_platform/backend/backend/util/settings.pyindex 68dabceccd..6ee5ff3134 100644--- a/autogpt_platform/backend/backend/util/settings.py+++ b/autogpt_platform/backend/backend/util/settings.py@@ -149,10 +149,10 @@ class Config(UpdateTrackingModel["Config"], BaseSettings):description="Time in seconds for how far back to check for the late executions.",)max_concurrent_graph_executions_per_user: int = Field(- default=50,+ default=25,ge=1,le=1000,- description="Maximum number of concurrent graph executions allowed per user.",+ description="Maximum number of concurrent graph executions allowed per user per graph.",)block_error_rate_threshold: float = Field(