SKILL: smart-wake
Objective
Ensure long-running tasks do not lose progress when subagent timeout occurs.
Standard mechanism:
- 1. Auto-save state before timeout / reaching timeout threshold.
- Cron wake to re-invoke agent at scheduled time.
- Resume task from latest checkpoint using
sessions_spawn (or session_spawn depending on runtime) with appropriate wakeMode.
Activation Triggers
Use
smart-wake when any of the following conditions are met:
- - Task duration exceeds default subagent timeout.
- Requires periodic polling (by minute/hour) to continue processing.
- Multi-step workflow that may pause mid-execution but must resume accurately.
- Running overnight / off-hours but still needs to auto-continue.
Available Tools (Built-in)
- -
sessions_spawn / session_spawn (spawn new work session) - Gateway cron jobs (schedule wake events)
- Memory/slot for state persistence (state checkpoint)
Do not create new tools. Only use existing mechanisms.
State Contract (MANDATORY)
Each task must implement checkpointing with minimum schema:
CODEBLOCK0
Requirements:
- - Update checkpoint after each completed step.
- Final checkpoint before timeout.
- Resume always reads latest checkpoint; never re-run blindly.
Standard Workflow
Step 1 — Preflight (Estimate Timeout)
- - Determine subagent timeout and total task duration.
- If
estimated_duration > 70% timeout: enable smart-wake immediately. - Create
task_id and initial checkpoint.
Step 2 — Execute by Small Chunks
- - Divide task into 5–15 minute chunks.
- After each chunk:
- Write progress to checkpoint,
- Record artifact/path,
- Update
next_actions.
Step 3 — Pre-timeout Auto-save
- - When ~10–20% timeout remains:
- Flush final checkpoint,
- Set
status = waiting,
- Prepare resume payload (task
id + nextactions).
Step 4 — Schedule Cron Wake
- - Register Gateway cron job to wake after appropriate interval (e.g., 2–10 minutes depending on load).
- Cron payload MUST contain:
-
task_id
-
resume_from=latest_checkpoint
- INLINECODE13
Step 5 — Spawn Resume Session
- - At wake time, call
sessions_spawn (or session_spawn) with wakeMode enabling auto-resume via cron. - Pass concise context:
- objective,
- latest checkpoint,
- next step,
- completion criteria.
Step 6 — Resume + Idempotency Guard
1. Read checkpoint,
2. Verify artifacts exist,
3. Skip completed steps,
4. Continue exact
next_actions.
- - When entire task completes: set
status = done, cancel remaining cron wakes.
Sample Resume Packet (Reference)
CODEBLOCK1
Note: Field names may vary by Gateway/OpenClaw version, but checkpoint + wakeMode + resume context principles are mandatory.
Operational Rules
- 1. Never resume without valid checkpoint.
- Never overwrite artifacts without checksum/timestamp verification.
- No infinite wake loops: limit
retry_count (e.g., max 5). - Every wake must have clear reason (
timeout_recovery, dependency_ready, scheduled_progress). - Clean up on done: completed task must clear related cron jobs.
Output Format After Each Wake Cycle
CODEBLOCK2
Anti-patterns (FORBIDDEN)
- - Running long tasks without periodic checkpointing.
- Waking without passing
task_id/resume context. - Re-running entire pipeline from start when only 1 step is missing.
- Not canceling cron after
done.
Expected Outcomes
- - No state loss on subagent timeout.
- Long tasks progress steadily via cron wake.
- Full system auditability: checkpoint → wake → resume → done.
技能:smart-wake
目标
确保长时间运行的任务在子代理超时时不会丢失进度。
标准机制:
- 1. 自动保存状态 在超时前/达到超时阈值时。
- 定时唤醒 在预定时间重新调用代理。
- 恢复任务 从最新检查点使用 sessionsspawn(或根据运行环境使用 sessionspawn)并配合适当的 wakeMode。
触发条件
当满足以下任一条件时使用 smart-wake:
- - 任务持续时间超过默认子代理超时时间。
- 需要定期轮询(按分钟/小时)以继续处理。
- 多步骤工作流可能在中途暂停但必须准确恢复。
- 在夜间/非工作时间运行但仍需自动继续。
可用工具(内置)
- - sessionsspawn / sessionspawn(生成新的工作会话)
- 网关定时任务(调度唤醒事件)
- 用于状态持久化的内存/槽位(状态检查点)
不要创建新工具。仅使用现有机制。
状态契约(必选)
每个任务必须实现具有最小模式的检查点:
json
{
taskid: smartwake_,
goal: 最终目标,
status: running|waiting|blocked|done|failed,
current_step: 步骤名称,
progress_pct: 0,
lastcompleted: [步骤a, 步骤_b],
nextactions: [操作1, 操作_2],
artifacts: [路径/文件1, 路径/文件2],
errors: [],
retry_count: 0,
updatedat: ISOTIMESTAMP
}
要求:
- - 在完成每个步骤后更新检查点。
- 在超时前进行最终检查点保存。
- 恢复时始终读取最新检查点;绝不盲目重新运行。
标准工作流程
步骤 1 — 预检(估算超时时间)
- - 确定子代理超时时间和总任务持续时间。
- 如果 estimatedduration > 70% timeout:立即启用 smart-wake。
- 创建 taskid 和初始检查点。
步骤 2 — 分小块执行
- - 将任务划分为 5–15 分钟的小块。
- 每个小块完成后:
- 将进度写入检查点,
- 记录工件/路径,
- 更新 next_actions。
步骤 3 — 超时前自动保存
- 刷新最终检查点,
- 设置 status = waiting,
- 准备恢复负载(task
id + nextactions)。
步骤 4 — 调度定时唤醒
- - 注册网关定时任务,在适当间隔后唤醒(例如,根据负载情况 2–10 分钟)。
- 定时负载必须包含:
- task_id
- resume
from=latestcheckpoint
- reason=timeout_recovery
步骤 5 — 生成恢复会话
- - 在唤醒时,调用 sessionsspawn(或 sessionspawn)并设置 wakeMode 以通过定时任务启用自动恢复。
- 传递简洁上下文:
- 目标,
- 最新检查点,
- 下一步,
- 完成标准。
步骤 6 — 恢复 + 幂等性保护
1. 读取检查点,
2. 验证工件是否存在,
3. 跳过已完成的步骤,
4. 继续执行确切的 next_actions。
- - 当整个任务完成时:设置 status = done,取消剩余的定时唤醒。
示例恢复数据包(参考)
json
{
task: 恢复长时间运行的任务,
taskid: smartwakereposcan20260301T120000Z,
wakeMode: cron,
resume: {
from: latest_checkpoint,
currentstep: collectphase_2,
next_actions: [获取第6-10页, 去重, 导出报告]
},
done_criteria: [
输出文件已生成,
验证通过,
状态标记为完成
]
}
注意:字段名称可能因 Gateway/OpenClaw 版本而异,但检查点 + wakeMode + 恢复上下文原则是强制性的。
操作规则
- 1. 没有有效检查点绝不恢复。
- 未经校验和/时间戳验证绝不覆盖工件。
- 无无限唤醒循环:限制 retrycount(例如,最多 5 次)。
- 每次唤醒必须有明确原因(timeoutrecovery、dependencyready、scheduledprogress)。
- 完成后清理:已完成的任务必须清除相关的定时任务。
每次唤醒周期后的输出格式
json
{
taskid: smartwake<...>,
status: running|waiting|done|failed,
progress_pct: 65,
current_step: ...,
resumedfromcheckpoint: true,
nextwakescheduled: true,
nextwakeat: ISO_TIMESTAMP|null,
notes: 简洁、可审计
}
反模式(禁止)
- - 运行长时间任务而不进行定期检查点保存。
- 未传递 task_id/恢复上下文就唤醒。
- 仅缺少 1 个步骤时从头重新运行整个流程。
- 完成后未取消定时任务。
预期结果
- - 子代理超时时无状态丢失。
- 长时间任务通过定时唤醒稳步推进。
- 完整系统可审计性:检查点 → 唤醒 → 恢复 → 完成。