Cron Worker Guardrails (POSIX)
A reliability-first checklist for OpenClaw cron workers and any unattended automation.
Scope (important)
- - This skill is POSIX-focused (bash/sh examples).
- The principles are portable, but if you're on Windows/PowerShell you'll need equivalent patterns.
The NO_REPLY convention
Many OpenClaw setups treat emitting exactly NO_REPLY as "silent success" (no human notification).
- - If your runtime does not support
NO_REPLY, interpret it as: print nothing on success.
Quick Start
1) Scripts-first: move logic into a repo script (recommended: tools/<job>.py or tools/<job>.sh).
2) One command in cron: cron should run one short command (no multi-line bash -lc '...').
3) Deterministic cwd/env: cd to the repo (or have the script do it), and document required env vars.
4) Silent on success: print nothing (or exactly NO_REPLY) when OK; only emit a short alert when broken.
Also see:
Why this skill exists
Cron failures are rarely "logic bugs". In practice they're often:
- - brittle shell quoting (
bash -lc '...' nested quotes) - command substitution surprises (
$(...)) - one-liners that hide escaping bugs (
python -c "...") - cwd/env drift ("works locally, fails in cron")
- pipelines that fail for the wrong reason (
pipefail + head / SIGPIPE)
The fix is boring but effective: scripts-first + deterministic execution + silent-on-success.
Portability rules (still apply)
Even on POSIX, do not hardcode deployment-specific absolute paths tied to one machine.
Prefer:
- - repo-relative paths
- environment variables you document
- minimal wrappers that
cd into the repo
Common failure patterns -> fixes
1) unexpected EOF while looking for matching ')'
Likely causes:
- - unclosed
$(...) from command substitution - broken nested quotes in INLINECODE18
Fix pattern:
- - Replace the whole multi-line shell block with a script.
- Cron calls exactly one short command, for example:
- INLINECODE19
2) False failure from pipefail + head (SIGPIPE)
Symptom:
- - command exits non-zero even though the output you wanted is fine
Fix pattern:
- - avoid
pipefail when piping into INLINECODE23 - or better: do the filtering in a script (read only what you need)
3) "Works locally, fails in cron"
Common causes:
- - wrong working directory
- missing env vars
- different PATH
Fix pattern:
- -
cd into the repo (or have the script do it) - keep dependencies explicit and documented
Git footgun: git push rejected (non-fast-forward)
Symptom:
- -
! [rejected] ... (non-fast-forward) when automation pushes to a long-lived PR/feature branch.
Conservative fix (no force-push):
- - On rejection, fetch the remote branch, transplant your new local commits onto it (cherry-pick), then retry push once.
Copy/paste hardening header (portable)
Use this near the top of a cron prompt (2 lines, low-noise):
- - Hardening (MUST): follow
references/cron-agent-contract.md (scripts-first, deterministic cwd, silent-on-success). - Also apply the
cron-worker-guardrails skill. If parsing/multi-step logic is needed, write/run a small tools/*.py script.
Cron Worker 防护栏 (POSIX)
面向 OpenClaw cron 工作进程及任何无人值守自动化任务的可靠性优先检查清单。
适用范围(重要)
- - 本技能 聚焦 POSIX 系统(bash/sh 示例)。
- 相关原则具有可移植性,但若使用 Windows/PowerShell 系统,需采用等效模式。
NO_REPLY 约定
许多 OpenClaw 配置将精确输出 NO_REPLY 视为静默成功(不触发人工通知)。
- - 若运行环境不支持 NO_REPLY,请将其理解为:成功时不输出任何内容。
快速入门
1) 脚本优先: 将逻辑移至仓库脚本(推荐:tools/<任务>.py 或 tools/<任务>.sh)。
2) cron 单命令: cron 应运行一条简短命令(避免多行 bash -lc ...)。
3) 确定性工作目录/环境: cd 到仓库目录(或让脚本自行处理),并记录所需环境变量。
4) 成功静默: 正常时无输出(或精确输出 NO_REPLY);仅在异常时发出简短告警。
另请参阅:
- - references/cron-agent-contract.md
- references/pitfalls.md
为何需要此技能
cron 故障很少是逻辑错误。实践中常见问题包括:
- - 脆弱的 shell 引号(bash -lc ... 嵌套引号)
- 命令替换意外结果($(...))
- 隐藏转义错误的一行命令(python -c ...)
- 工作目录/环境漂移(本地正常,cron 失败)
- 因错误原因失败的管道(pipefail + head / SIGPIPE)
解决方案虽显单调但行之有效:脚本优先 + 确定性执行 + 成功静默。
可移植性规则(仍然适用)
即使在 POSIX 系统上,也不要硬编码与单台机器绑定的部署特定绝对路径。
推荐做法:
- - 使用仓库相对路径
- 使用已记录的环境变量
- 使用能 cd 进入仓库的最小包装脚本
常见失败模式 -> 修复方案
1) unexpected EOF while looking for matching )
可能原因:
- - 命令替换中未闭合的 $(...)
- bash -lc ... 中嵌套引号断裂
修复模式:
- - 将整个多行 shell 块替换为脚本。
- cron 仅调用一条简短命令,例如:
- python3 tools/<任务>.py
2) pipefail + head 导致的假性失败(SIGPIPE)
症状:
修复模式:
- - 向 head 传递管道时避免使用 pipefail
- 或更优方案:在脚本中完成过滤(仅读取所需内容)
3) 本地正常,cron 失败
常见原因:
修复模式:
- - cd 进入仓库目录(或让脚本自行处理)
- 保持依赖关系明确且已记录
Git 陷阱:git push 被拒绝(非快进)
症状:
- - 自动化向长期存在的 PR/功能分支推送时出现 ! [rejected] ... (non-fast-forward)
保守修复方案(无强制推送):
- - 拒绝时,获取远程分支,将本地新提交移植到其上(cherry-pick),然后重试推送一次。
复制/粘贴加固头(可移植)
在 cron 提示顶部附近使用(2 行,低噪音):
- - 加固(必须): 遵循 references/cron-agent-contract.md(脚本优先、确定性工作目录、成功静默)。
- 同时应用 cron-worker-guardrails 技能。如需解析/多步骤逻辑,请编写/运行小型 tools/*.py 脚本。