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.
fix(backend/executor): skip scheduled runs for paywalled users quietly (#14325)
Bentlyfb68a6e66ece
diff --git a/autogpt_platform/backend/backend/executor/scheduler.py b/autogpt_platform/backend/backend/executor/scheduler.pyindex 83f50020fc..a3a160ff7b 100644--- a/autogpt_platform/backend/backend/executor/scheduler.py+++ b/autogpt_platform/backend/backend/executor/scheduler.py@@ -66,6 +66,7 @@ from backend.util.exceptions import (GraphValidationError,NotAuthorizedError,NotFoundError,+ UserPaywalledError,)from backend.util.feature_flag import initialize_launchdarkly, shutdown_launchdarklyfrom backend.util.logging import PrefixFilter@@ -234,6 +235,11 @@ async def _execute_graph(**kwargs):# Expected while an expert is paused (budget/archive): skip quietly;# the schedule stays registered for one-click resume.logger.info(f"Skipping scheduled run for graph #{args.graph_id}: {e}")+ except UserPaywalledError as e:+ # Expected while the owner has no subscription: skip quietly. The+ # schedule stays registered so it resumes on its own once they+ # subscribe, and a recurring tick is not an error worth paging on.+ logger.info(f"Skipping scheduled run for graph #{args.graph_id}: {e}")except ExpertPrivateTenancyNotFoundError:# Graph schedules are recurring, so the next cron tick is the retry.logger.warning(diff --git a/autogpt_platform/backend/backend/executor/scheduler_unit_test.py b/autogpt_platform/backend/backend/executor/scheduler_unit_test.pyindex 135b90ca1a..6563fab4a7 100644--- a/autogpt_platform/backend/backend/executor/scheduler_unit_test.py+++ b/autogpt_platform/backend/backend/executor/scheduler_unit_test.py@@ -39,6 +39,7 @@ from backend.executor.scheduler import (from backend.util.exceptions import (ExpertNotFoundError,ExpertPrivateTenancyNotFoundError,+ UserPaywalledError,)_SCHEDULER_PATH = "backend.executor.scheduler"@@ -1089,6 +1090,42 @@ async def test_execute_graph_forwards_expert_id():assert mock_add.call_args.kwargs["expert_id"] == "expert-1"+async def test_execute_graph_quietly_skips_paywalled_user(caplog):+ args = GraphExecutionJobArgs(+ schedule_id="sched-1",+ user_id="user-1",+ graph_id="graph-1",+ graph_version=3,+ cron="* * * * *",+ input_data={},+ input_credentials={},+ )+ mock_add = AsyncMock(+ side_effect=UserPaywalledError("A subscription is required to run agents.")+ )+ mock_db = MagicMock()+ mock_db.increment_onboarding_runs = AsyncMock()++ with (+ patch(f"{_SCHEDULER_PATH}.execution_utils.add_graph_execution", new=mock_add),+ patch(+ f"{_SCHEDULER_PATH}.get_database_manager_async_client",+ return_value=mock_db,+ ),+ caplog.at_level(logging.INFO, logger=_SCHEDULER_PATH),+ ):+ await _execute_graph(**args.model_dump(mode="json"))++ mock_db.increment_onboarding_runs.assert_not_awaited()+ assert any(+ record.levelno == logging.INFO+ and "Skipping scheduled run for graph #graph-1" in record.getMessage()+ for record in caplog.records+ )+ assert not any(record.levelno >= logging.ERROR for record in caplog.records)++@pytest.mark.asyncioasync def test_execute_graph_quietly_skips_unavailable_expert(caplog):args = GraphExecutionJobArgs(