Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
fix(cron): fire deployed schedules at the times their settings say
trohitgd4caa64e90bb
diff --git a/docs-internal/node-logic-flows/workflow_triggers/cronScheduler.md b/docs-internal/node-logic-flows/workflow_triggers/cronScheduler.mdindex 3322abae..63e562f8 100644--- a/docs-internal/node-logic-flows/workflow_triggers/cronScheduler.md+++ b/docs-internal/node-logic-flows/workflow_triggers/cronScheduler.md@@ -4,7 +4,7 @@|------|-------|| **Category** | workflow / trigger / tool (dual-purpose) || **Backend handler** | Plugin [`server/nodes/scheduler/cron_scheduler/__init__.py`](../../../server/nodes/scheduler/cron_scheduler/__init__.py) (`CronSchedulerNode`); dispatch via `BaseNode.execute()` + the `@Operation("trigger")` method. Deployed-workflow cron lifecycle lives in `DeploymentManager` (Temporal Schedules canary via `CronTriggerWorkflow`); this op only runs on a manual / AI-tool invocation. |-| **Tests** | [`server/tests/nodes/test_workflow_triggers.py`](../../../server/tests/nodes/test_workflow_triggers.py) |+| **Tests** | [`server/tests/nodes/test_workflow_triggers.py`](../../../server/tests/nodes/test_workflow_triggers.py); the deployed Schedule in [`server/tests/test_cron_canary.py`](../../../server/tests/test_cron_canary.py) || **Skill (if any)** | [`server/skills/task_agent/cron-scheduler-skill/SKILL.md`](../../../server/skills/task_agent/cron-scheduler-skill/SKILL.md) || **Dual-purpose tool** | yes - exposed on the `tool` output handle |@@ -131,6 +131,14 @@ flowchart TDThe manual-run op does not use any of that - it only sleeps for a fixedinterval. `daily_time`, `weekday`, `weekly_time`, `month_day`,`monthly_time`, and `timezone` are **display-only** in this code path.+- **The deployed Schedule's cron string** comes from+ `TriggerManager.build_cron_expression` (`services/deployment/triggers.py`):+ five fields, or seven (second first, year last) for `seconds`. Temporal+ reads six fields as minute through year, so the builder never emits six.+ Two settings cannot become a Schedule yet: `once` builds no expression+ (the SDK rejects `None`), and `month_day` `L` is not a value Temporal's+ cron syntax accepts (integers and month or weekday names only). A+ deployment using either fails at Start.- `iteration` is always `1`. The op does not loop; repeated firingscome from the deployed Schedule firing per tick (deployment mode).- `interval`, `interval_minutes`, `interval_hours` are Pydantic-validateddiff --git a/server/services/deployment/triggers.py b/server/services/deployment/triggers.pyindex de90f9de..66de99aa 100644--- a/server/services/deployment/triggers.py+++ b/server/services/deployment/triggers.py@@ -257,7 +257,13 @@ class TriggerManager:@staticmethoddef build_cron_expression(parameters: Dict[str, Any]) -> Optional[str]:- """Build cron expression from user-friendly parameters."""+ """Build a Temporal Schedule cron string from user-friendly parameters.++ Temporal reads five fields as minute, hour, day, month, weekday and+ seven as second first and year last. Six fields are minute through+ year to Temporal, not seconds first, so a schedule with seconds gets+ all seven.+ """frequency = parameters.get("frequency", "minutes")second, minute, hour = "0", "*/5", "*"@@ -299,7 +305,8 @@ class TriggerManager:elif frequency == "once":return None- return f"{second} {minute} {hour} {day} {month} {weekday}"+ fields = f"{minute} {hour} {day} {month} {weekday}"+ return fields if second == "0" else f"{second} {fields} *"@staticmethoddef find_trigger_nodes(nodes: list, edges: list) -> tuple:diff --git a/server/services/temporal/schedules.py b/server/services/temporal/schedules.pyindex 6ef40cf9..2b26c888 100644--- a/server/services/temporal/schedules.py+++ b/server/services/temporal/schedules.py@@ -102,7 +102,8 @@ async def create_cron_schedule(trigger_label: Cron-trigger node's label (``cronScheduler`` bydefault, or F2-renamed). Forms the suffix of the Scheduleid and child workflow ids.- cron_expression: Crontab string (5 or 6 field).+ cron_expression: Cron string with 5 fields, or 7 with the second+ first and the year last (Temporal reads 6 as minute through year).timezone: IANA tz name (e.g. ``"America/New_York"``).listener_data: Frozen action args for the workflow run(deployment graph snapshot + cron metadata).diff --git a/server/tests/test_cron_canary.py b/server/tests/test_cron_canary.pyindex 3df23cea..e6f54339 100644--- a/server/tests/test_cron_canary.py+++ b/server/tests/test_cron_canary.py@@ -467,6 +467,98 @@ class TestDeleteCronSchedulesForDeployment:)+# ---------------------------------------------------------------------------+# cron expressions, read the way Temporal reads them+# ---------------------------------------------------------------------------++# Temporal's cron layout (ScheduleSpec.cron_string in temporalio's+# api/schedule/v1): five fields start at the minute, six add a year at the+# end, and only seven start at the second. A missing second is 0 and a+# missing year is *; values are decimal integers.+_TEMPORAL_CRON_FIELDS = {+ 5: ("minute", "hour", "day_of_month", "month", "day_of_week"),+ 6: ("minute", "hour", "day_of_month", "month", "day_of_week", "year"),+ 7: ("second", "minute", "hour", "day_of_month", "month", "day_of_week", "year"),+}+++def _as_temporal_reads(expression: str) -> Dict[str, str]:+ fields = expression.split()+ calendar = {"second": "0", "year": "*"}+ for name, value in zip(_TEMPORAL_CRON_FIELDS[len(fields)], fields):+ calendar[name] = str(int(value)) if value.isdigit() else value+ return calendar+++def _fires(**fields: str) -> Dict[str, str]:+ """A calendar that matches every time, except where a field narrows it."""+ calendar = {"second": "0", "minute": "*", "hour": "*", "day_of_month": "*", "month": "*", "day_of_week": "*", "year": "*"}+ calendar.update(fields)+ return calendar+++class TestCronExpression:+ """The deploy path's cron string fires when the node says it will."""++ @pytest.mark.parametrize(+ ("params", "fires"),+ [+ pytest.param({"frequency": "seconds", "interval": 30}, _fires(second="*/30"), id="every-30-seconds"),+ pytest.param({"frequency": "minutes", "interval_minutes": 5}, _fires(minute="*/5"), id="every-5-minutes"),+ pytest.param({"frequency": "minutes", "interval_minutes": 1}, _fires(), id="every-minute"),+ pytest.param({"frequency": "hours", "interval_hours": 1}, _fires(minute="0"), id="hourly"),+ pytest.param({"frequency": "hours", "interval_hours": 6}, _fires(minute="0", hour="*/6"), id="every-6-hours"),+ pytest.param({"frequency": "days", "daily_time": "09:00"}, _fires(minute="0", hour="9"), id="daily"),+ pytest.param(+ {"frequency": "weeks", "weekday": "1", "weekly_time": "22:00"},+ _fires(minute="0", hour="22", day_of_week="1"),+ id="weekly",+ ),+ pytest.param(+ {"frequency": "months", "month_day": "15", "monthly_time": "08:00"},+ _fires(minute="0", hour="8", day_of_month="15"),+ id="monthly",+ ),+ ],+ )+ def test_fires_when_the_node_says(self, params, fires):+ from services.deployment.triggers import TriggerManager++ assert _as_temporal_reads(TriggerManager.build_cron_expression(params)) == fires++ def test_node_defaults_fire_every_five_minutes(self):+ from nodes.scheduler.cron_scheduler import CronSchedulerParams+ from services.deployment.triggers import TriggerManager++ expression = TriggerManager.build_cron_expression(CronSchedulerParams().model_dump())++ assert _as_temporal_reads(expression) == _fires(minute="*/5")++ @pytest.mark.parametrize(+ ("trigger", "fires"),+ [+ pytest.param({"every": "hour"}, _fires(minute="0"), id="hour"),+ pytest.param({"every": "day", "at": "09:00"}, _fires(minute="0", hour="9"), id="day"),+ pytest.param({"every": "week", "day": "friday", "at": "18:00"}, _fires(minute="0", hour="18", day_of_week="5"), id="week"),+ pytest.param({"every": "month", "day": "15", "at": "08:00"}, _fires(minute="0", hour="8", day_of_month="15"), id="month"),+ ],+ )+ def test_home_schedule_hires_fire_when_asked(self, trigger, fires):+ from datetime import datetime, timezone++ from services.deployment.triggers import TriggerManager+ from services.employees.builder import schedule_params+ from services.employees.hire_request import HireTrigger++ params = schedule_params(+ HireTrigger(kind="schedule", **trigger),+ "UTC",+ datetime(2026, 9, 25, 12, 0, tzinfo=timezone.utc),+ )++ assert _as_temporal_reads(TriggerManager.build_cron_expression(params)) == fires++# ---------------------------------------------------------------------------# DeploymentManager cron canary integration# ---------------------------------------------------------------------------