Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix(bot): normalize cron one-shot datetimes (#4064)
wutongyuonce492235de8617
diff --git a/bot/tests/test_cron_datetime_parsing.py b/bot/tests/test_cron_datetime_parsing.pynew file mode 100644index 000000000..823f22038--- /dev/null+++ b/bot/tests/test_cron_datetime_parsing.py@@ -0,0 +1,88 @@+# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd.+# SPDX-License-Identifier: AGPL-3.0+"""Regression tests for cron ISO datetime parsing."""++import sys+from pathlib import Path+from types import SimpleNamespace++import pytest+import typer++sys.path.insert(0, str(Path(__file__).resolve().parents[1]))++from vikingbot.agent.tools.cron import CronTool # noqa: E402+from vikingbot.cli.commands import cron_add # noqa: E402+from vikingbot.config.schema import SessionKey # noqa: E402+from vikingbot.cron.service import CronService # noqa: E402+++def test_cron_cli_accepts_z_datetime(tmp_path, monkeypatch):+ monkeypatch.setattr("vikingbot.config.loader.get_data_dir", lambda: tmp_path)++ cron_add(+ name="release",+ message="ship it",+ every=None,+ cron_expr=None,+ at="2099-08-17T10:00:00Z",+ deliver=False,+ )++ jobs = CronService(tmp_path / "cron" / "jobs.json").list_jobs()+ assert len(jobs) == 1+ assert jobs[0].schedule.at_ms == 4090644000000+++def test_cron_cli_reports_invalid_datetime(tmp_path, monkeypatch):+ monkeypatch.setattr("vikingbot.config.loader.get_data_dir", lambda: tmp_path)++ with pytest.raises(typer.Exit):+ cron_add(+ name="release",+ message="ship it",+ every=None,+ cron_expr=None,+ at="not-a-date",+ deliver=False,+ )+++async def test_cron_tool_accepts_z_datetime(tmp_path):+ service = CronService(tmp_path / "jobs.json")+ tool = CronTool(service)+ context = SimpleNamespace(+ session_key=SessionKey(type="cli", channel_id="default", chat_id="default"),+ channel_metadata=None,+ )++ result = await tool.execute(+ context,+ action="add",+ name="release",+ message="ship it",+ at="2099-08-17T10:00:00Z",+ )++ assert result.startswith("Created job")+ assert service.list_jobs()[0].schedule.at_ms == 4090644000000+++async def test_cron_tool_reports_invalid_datetime(tmp_path):+ tool = CronTool(CronService(tmp_path / "jobs.json"))+ context = SimpleNamespace(+ session_key=SessionKey(type="cli", channel_id="default", chat_id="default"),+ channel_metadata=None,+ )++ result = await tool.execute(+ context,+ action="add",+ name="release",+ message="ship it",+ at="not-a-date",+ )++ assert result.startswith("Error: invalid at datetime:")diff --git a/bot/vikingbot/agent/tools/cron.py b/bot/vikingbot/agent/tools/cron.pyindex b74c97421..70f09546f 100644--- a/bot/vikingbot/agent/tools/cron.py+++ b/bot/vikingbot/agent/tools/cron.py@@ -2,6 +2,7 @@from typing import TYPE_CHECKING, Any+from openviking.utils.time_utils import parse_iso_datetimefrom vikingbot.agent.tools.base import Toolfrom vikingbot.cron.service import CronServicefrom vikingbot.cron.types import CronSchedule@@ -104,9 +105,10 @@ class CronTool(Tool):elif cron_expr:schedule = CronSchedule(kind="cron", expr=cron_expr)elif at:- from datetime import datetime-- dt = datetime.fromisoformat(at)+ try:+ dt = parse_iso_datetime(at)+ except ValueError as e:+ return f"Error: invalid at datetime: {e}"at_ms = int(dt.timestamp() * 1000)schedule = CronSchedule(kind="at", at_ms=at_ms)delete_after = Truediff --git a/bot/vikingbot/cli/commands.py b/bot/vikingbot/cli/commands.pyindex 6fb52df55..a80807442 100644--- a/bot/vikingbot/cli/commands.py+++ b/bot/vikingbot/cli/commands.py@@ -21,6 +21,7 @@ from prompt_toolkit.styles import Style as PromptStylefrom rich.console import Consolefrom rich.table import Table+from openviking.utils.time_utils import parse_iso_datetimefrom vikingbot import __logo__, __version__from vikingbot.agent.loop import AgentLoopfrom vikingbot.bus.queue import MessageBus@@ -1134,9 +1135,11 @@ def cron_add(elif cron_expr:schedule = CronSchedule(kind="cron", expr=cron_expr)elif at:- import datetime-- dt = datetime.datetime.fromisoformat(at)+ try:+ dt = parse_iso_datetime(at)+ except ValueError as e:+ console.print(f"[red]Error: invalid --at datetime: {e}[/red]")+ raise typer.Exit(1) from eschedule = CronSchedule(kind="at", at_ms=int(dt.timestamp() * 1000))else:console.print("[red]Error: Must specify --every, --cron, or --at[/red]")