Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

bugfix(cron): 定时任务默认不提前启动

kdgmpwb698f77f127a
diff --git a/docs/en/ScheduledTasks.md b/docs/en/ScheduledTasks.md
index dc4537d17f..8bee69a983 100644
--- a/docs/en/ScheduledTasks.md
+++ b/docs/en/ScheduledTasks.md
@@ -98,7 +98,7 @@ JiuwenSwarm provides two automation mechanisms: **Scheduled Tasks (Cron)** and *
| **Cron Expression** | Cron expression | `0 9 * * *` (every day at 9am) |
| **Status** | Task status | Enable/Disable |
| **Description** | Task content description | Generate today's work reminder |
-| **Wake Offset Seconds** | Wake-up advance seconds | `300` (5 minutes advance) |
+| **Wake Offset Seconds** | Wake-up advance seconds | `0` (default, no advance wake-up) |
| **Delivery Channel** | Result delivery channel | `web`, `feishu`, `wechat`, `wecom`, `whatsapp`, `telegram`, etc. |
| **Project Directory** | Project working directory (absolute path) for task归属 | `/home/user/my-project`; defaults to current session's project |
@@ -278,7 +278,7 @@ Scheduled task execution results are:
### Q4: What does wake_offset_seconds do?
-`wake_offset_seconds` defines how early to wake up the Agent. For example:
+`wake_offset_seconds` defines how early to wake up the Agent (default `0`, i.e. no advance wake-up). For example, when set to `300` (5 minutes):
- Task scheduled for 9:00 AM
- `wake_offset_seconds: 300` (5 minutes)
- Agent starts preparing at 8:55 AM to ensure execution at 9:00 AM sharp
diff --git a/docs/en/SlashCommands.md b/docs/en/SlashCommands.md
index 211d091b56..c2b8e5a8f3 100644
--- a/docs/en/SlashCommands.md
+++ b/docs/en/SlashCommands.md
@@ -450,7 +450,7 @@ Manage cron jobs via RPC calls to the backend `CronController`, sharing the same
| `timezone` | No | IANA timezone, default `Asia/Shanghai` |
| `mode` | No | Execution mode, default `agent.fast`. Options: `agent`, `agent.fast`, `agent.plan`, `plan`, `team`, `team.plan`, `code.team`. Team modes use streaming multi-agent execution; see [Scheduled tasks — Team mode](ScheduledTasks.md#6-team-mode-and-swarmflow-multi-agent-scheduled-jobs) |
| `timeout_seconds` | No | Per-run timeout in seconds (60–259200). Default 600 for normal modes, 1200 for team modes |
-| `wake_offset_seconds` | No | Wake-up offset in seconds, default 300 |
+| `wake_offset_seconds` | No | Wake-up offset in seconds, default 0 |
| `delete_after_run` | No | Auto-delete after one run, default false |
- `add` examples:
diff --git "a/docs/zh/Slash\345\221\275\344\273\244\350\241\250.md" "b/docs/zh/Slash\345\221\275\344\273\244\350\241\250.md"
index 7d676ad9e6..6a1d2f4074 100644
--- "a/docs/zh/Slash\345\221\275\344\273\244\350\241\250.md"
+++ "b/docs/zh/Slash\345\221\275\344\273\244\350\241\250.md"
@@ -467,7 +467,7 @@
| `timezone` | 否 | IANA 时区,默认 `Asia/Shanghai` |
| `mode` | 否 | 执行模式,默认 `agent.fast`。可选:`agent`、`agent.fast`、`agent.plan`、`plan`、`team`、`team.plan`、`code.team`。`team` 系列走多 Agent 流式执行,详见 [定时任务 — Team 模式](定时任务.md#6-team-模式与-swarmflow多智能体定时任务) |
| `timeout_seconds` | 否 | 单次执行超时(秒),范围 60~259200。未设置时普通模式默认 600,Team 模式默认 1200 |
-| `wake_offset_seconds` | 否 | 提前唤醒秒数,默认 300 |
+| `wake_offset_seconds` | 否 | 提前唤醒秒数,默认 0 |
| `delete_after_run` | 否 | 执行一次后自动删除,默认 false |
- `add` 示例:
diff --git "a/docs/zh/\345\256\232\346\227\266\344\273\273\345\212\241.md" "b/docs/zh/\345\256\232\346\227\266\344\273\273\345\212\241.md"
index 02a8819a77..e9148613ea 100644
--- "a/docs/zh/\345\256\232\346\227\266\344\273\273\345\212\241.md"
+++ "b/docs/zh/\345\256\232\346\227\266\344\273\273\345\212\241.md"
@@ -99,7 +99,7 @@ JiuwenSwarm 提供了两种自动化机制:**定时任务**和**心跳**。详
| **时区** | 任务执行时区 | `Asia/Shanghai`(默认) |
| **状态** | 任务状态 | 启用/停用 |
| **描述** | 任务内容描述 | 生成今日工作提醒 |
-| **唤醒偏移秒数** | 提前唤醒秒数 | `300`(提前5分钟) |
+| **唤醒偏移秒数** | 提前唤醒秒数 | `0`(默认,不提前唤醒) |
| **推送频道** | 结果推送频道 | `web`、`feishu`、`wechat`、`wecom`、`whatsapp`、`telegram` 等 |
| **执行模式** | Agent 执行模式 | `agent.plan`(默认) |
| **项目目录** | 任务归属的项目工作目录(绝对路径) | `/home/user/my-project`;不填则默认取当前会话所在项目 |
@@ -281,7 +281,7 @@ Agent 会自动:
### Q4: wake_offset_seconds 是什么作用?
-`wake_offset_seconds` 定义了提前唤醒 Agent 的时间。例如:
+`wake_offset_seconds` 定义了提前唤醒 Agent 的时间(默认 `0`,即不提前唤醒)。例如设置为 `300`(5分钟)时:
- 任务设定 9:00 执行
- `wake_offset_seconds: 300`(5分钟)
- Agent 会在 8:55 开始准备,确保 9:00 准时执行
diff --git a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/cron.ts b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/cron.ts
index a5873cfaec..da488da840 100644
--- a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/cron.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/cron.ts
@@ -454,7 +454,7 @@ async function _handleShow(ctx: CommandContext, parts: string[]): Promise<void>
{ label: "targets", value: job.targets },
{ label: "mode", value: job.mode || cronMeta.default_mode },
{ label: "timeout_seconds", value: formatTimeoutLabel(job, cronMeta) },
- { label: "wake_offset_seconds", value: String(job.wake_offset_seconds ?? 300) },
+ { label: "wake_offset_seconds", value: String(job.wake_offset_seconds ?? 0) },
{ label: "delete_after_run", value: String(isOneShot) },
],
}),
@@ -577,7 +577,7 @@ async function _handleAdd(ctx: CommandContext, raw: string): Promise<void> {
targets: kvPairs.targets,
timezone: kvPairs.timezone,
mode: kvPairs.mode,
- wake_offset_seconds: parseInt(kvPairs.wake_offset_seconds || "300", 10),
+ wake_offset_seconds: parseInt(kvPairs.wake_offset_seconds || "0", 10),
delete_after_run: kvPairs.delete_after_run === "true",
...(kvPairs.timeout_seconds
? { timeout_seconds: parseInt(kvPairs.timeout_seconds, 10) }
diff --git a/jiuwenswarm/gateway/cron/controller.py b/jiuwenswarm/gateway/cron/controller.py
index e9c35c775c..3bc41c3f46 100644
--- a/jiuwenswarm/gateway/cron/controller.py
+++ b/jiuwenswarm/gateway/cron/controller.py
@@ -470,8 +470,8 @@ class CronController:
},
"wake_offset_seconds": {
"type": "integer",
- "description": "Seconds to wake before push. Default 300",
- "default": 300,
+ "description": "Seconds to wake before push. Default 0",
+ "default": 0,
},
"mode": {
"type": "string",
diff --git a/jiuwenswarm/gateway/cron/cron_json_convert.py b/jiuwenswarm/gateway/cron/cron_json_convert.py
index adbd793535..c719b7bd30 100644
--- a/jiuwenswarm/gateway/cron/cron_json_convert.py
+++ b/jiuwenswarm/gateway/cron/cron_json_convert.py
@@ -12,7 +12,7 @@ CLI 工具:把 cron JSON 在「扁平结构」与「OpenClaw 嵌套结构」
"enabled": true,
"cron_expr": "0 9 * * *",
"timezone": "Asia/Shanghai",
- "wake_offset_seconds": 300,
+ "wake_offset_seconds": 0,
"description": "...",
"targets": "web"
}
@@ -117,8 +117,8 @@ def convert_cron_job_dict_to_flat(data: dict[str, Any]) -> dict[str, Any]:
else:
return data
- # 你的偏好:不管 OpenClaw 里 wakeMode 是什么,转换到 jiuwenswarm 时都统一写成 60s
- wake_offset_seconds = 300
+ # 你的偏好:不管 OpenClaw 里 wakeMode 是什么,转换到 jiuwenswarm 时都统一写成 0(不提前唤醒)
+ wake_offset_seconds = 0
desc = str(data.get("description") or data.get("name") or "")
payload = data.get("payload")
diff --git a/jiuwenswarm/gateway/cron/models.py b/jiuwenswarm/gateway/cron/models.py
index e56a256ee1..80434ad29e 100644
--- a/jiuwenswarm/gateway/cron/models.py
+++ b/jiuwenswarm/gateway/cron/models.py
@@ -236,7 +236,7 @@ class CronJob:
enabled: bool
cron_expr: str
timezone: str
- wake_offset_seconds: int = 300
+ wake_offset_seconds: int = 0
description: str = ""
# For one-shot schedules where croniter has no "next" after the run.
expired: bool = False
@@ -315,7 +315,7 @@ class CronJob:
enabled = bool(data.get("enabled", False))
expired = bool(data.get("expired", False))
- wake_offset_seconds_raw = data.get("wake_offset_seconds", 300)
+ wake_offset_seconds_raw = data.get("wake_offset_seconds", 0)
try:
wake_offset_seconds = int(wake_offset_seconds_raw)
except Exception as exc: # noqa: BLE001
diff --git a/jiuwenswarm/gateway/cron/store.py b/jiuwenswarm/gateway/cron/store.py
index 5a948aeac5..03c4f12e2f 100644
--- a/jiuwenswarm/gateway/cron/store.py
+++ b/jiuwenswarm/gateway/cron/store.py
@@ -231,7 +231,7 @@ class CronJobStore:
enabled=bool(enabled),
cron_expr=str(cron_expr or "").strip(),
timezone=str(timezone or "").strip(),
- wake_offset_seconds=int(wake_offset_seconds) if wake_offset_seconds is not None else 300,
+ wake_offset_seconds=int(wake_offset_seconds) if wake_offset_seconds is not None else 0,
description=str(description or ""),
targets=str(targets or "").strip(),
session_id=sid,