fix(cron): reject past one-time schedules in the cron tool

The webui automation path already rejects one-time schedules that are
not in the future, but the agent cron tool silently accepted them: a
past ISO datetime produced an enabled job with next_run_at_ms=None
that never fires and never honors delete_after_run, while the tool
reported success. Reject the request at the tool boundary with an
actionable error instead.

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
FanouZeng-TTandClaude Code authored and Xubin Ren committed 2026-09-17 20:57:51 +08:00
1 parent 2fb1659398
commit b1d54b2ca2
2 files changed
+49 -5

No files matched your search

+6
View File
@@ -4,6 +4,7 @@
from __future__ import annotations
import time
from contextvars import ContextVar, Token
from datetime import datetime
from typing import Any
@@ -201,6 +202,11 @@ class CronTool(Tool):
return err
dt = dt.replace(tzinfo=ZoneInfo(self._default_timezone))
at_ms = int(dt.timestamp() * 1000)
if at_ms <= int(time.time() * 1000):
return ToolResult.error(
f"Error: one-time job time '{at}' is not in the future. "
"Retry with a future ISO datetime computed from the current time."
)
schedule = CronSchedule(kind="at", at_ms=at_ms)
delete_after = True
else: