fix(cron): reject non-positive every_seconds intervals
A negative every_seconds created a job with no next run and still reported 'Created job', so it silently never fired. every_seconds=0 passed the exactly-one-schedule check but then fell through the truthiness test to the misleading 'either every_seconds, cron_expr, or at is required' error. Declare minimum=1 in the tool schema, check every_seconds explicitly, and have CronService refuse every schedules without a positive every_ms, matching the WebUI parser.
This commit is contained in:
1 parent
e2cd6908c7
commit
b5f539292d
4 files changed
+46
-2
No files matched your search
@@ -31,7 +31,9 @@ _CRON_PARAMETERS = tool_parameters_schema(
|
||||
"(e.g., 'Send a reminder to WeChat: xxx' or 'Check system status and report'). "
|
||||
"Not used for action='list' or action='remove'."
|
||||
),
|
||||
every_seconds=IntegerSchema(description="Interval in seconds (for recurring tasks)"),
|
||||
every_seconds=IntegerSchema(
|
||||
description="Interval in seconds (for recurring tasks)", minimum=1
|
||||
),
|
||||
cron_expr=StringSchema("Cron expression like '0 9 * * *' (for scheduled tasks)"),
|
||||
tz=StringSchema(
|
||||
"Optional IANA timezone for cron expressions (e.g. 'America/Vancouver'). "
|
||||
@@ -183,7 +185,9 @@ class CronTool(Tool):
|
||||
|
||||
# Build schedule
|
||||
delete_after = False
|
||||
if every_seconds:
|
||||
if every_seconds is not None:
|
||||
if every_seconds <= 0:
|
||||
return ToolResult.error("Error: every_seconds must be a positive integer")
|
||||
schedule = CronSchedule(kind="every", every_ms=every_seconds * 1000)
|
||||
elif cron_expr:
|
||||
effective_tz = tz or self._default_timezone
|
||||
|
||||
@@ -73,6 +73,8 @@ def _validate_schedule_for_add(schedule: CronSchedule) -> None:
|
||||
"""Validate schedule fields that would otherwise create non-runnable jobs."""
|
||||
if schedule.tz and schedule.kind != "cron":
|
||||
raise ValueError("tz can only be used with cron schedules")
|
||||
if schedule.kind == "every" and (schedule.every_ms is None or schedule.every_ms <= 0):
|
||||
raise ValueError("every schedule requires a positive 'every_ms'")
|
||||
|
||||
if schedule.kind == "cron":
|
||||
if not schedule.expr or not schedule.expr.strip():
|
||||
|
||||
Reference in new issue
Block a user