From 835cac0ae79fd37b9bc9c61814b259f484097e3a Mon Sep 17 00:00:00 2001 From: FanouZeng-TT <18280587072@163.com> Date: Mon, 14 Sep 2026 21:12:40 +0800 Subject: [PATCH] fix(cron): reject conflicting schedule fields Co-Authored-By: Claude Code --- nanobot/agent/tools/cron.py | 8 ++++++++ tests/cron/test_cron_tool_list.py | 11 +++++++++++ 2 files changed, 19 insertions(+) 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(