Skip to content

Your lightweight open-source personal agent.

fix(cron): reject conflicting schedule fields

FanouZeng-TT835cac0ae79f
diff --git a/nanobot/agent/tools/cron.py b/nanobot/agent/tools/cron.py
index 72f15a441..5be8e9712 100644
--- a/nanobot/agent/tools/cron.py
+++ b/nanobot/agent/tools/cron.py
@@ -181,6 +181,14 @@ class CronTool(Tool):
if err := self._validate_timezone(tz):
return err
+ schedule_count = sum(
+ value is not None for value in (every_seconds, cron_expr, at)
+ )
+ if schedule_count != 1:
+ return ToolResult.error(
+ "Error: exactly one of every_seconds, cron_expr, or at is required"
+ )
+
# Build schedule
delete_after = False
if every_seconds:
diff --git a/tests/cron/test_cron_tool_list.py b/tests/cron/test_cron_tool_list.py
index ce2b94991..51ee92c13 100644
--- a/tests/cron/test_cron_tool_list.py
+++ b/tests/cron/test_cron_tool_list.py
@@ -384,6 +384,17 @@ def test_add_at_job_accepts_future_datetime(tmp_path) -> None:
assert job.state.next_run_at_ms is not None
+def test_add_job_rejects_multiple_schedule_fields(tmp_path) -> None:
+ tool = _make_tool(tmp_path)
+ with request_context(
+ RequestContext(channel="telegram", chat_id="chat-1", session_key="telegram:chat-1")
+ ):
+ result = tool._add_job(None, "Morning standup", 60, "0 8 * * *", None, None)
+
+ assert result == "Error: exactly one of every_seconds, cron_expr, or at is required"
+ assert tool._cron.list_jobs() == []
+
+
def test_add_job_binds_current_session_key(tmp_path) -> None:
tool = _make_tool(tmp_path)
with request_context(