OpenClaw Cron vs Heartbeat Automation Playbook
Date: 2026-03-19
Category: knowledge
Why this matters
If you automate everything with cron, you get fragmented jobs, duplicated state, and noisy notifications. If you automate everything with heartbeat, you get timing drift and unclear ownership.
In OpenClaw, the practical sweet spot is:
- Heartbeat for batched, context-aware assistant work
- Cron for exact-time, isolated, one-purpose jobs
This playbook is a field-tested way to combine both without creating automation debt.
1) Decision rule: heartbeat first, cron second
Use heartbeat when:
- you can batch multiple checks in one pass (email + calendar + mentions),
- slight timing drift is acceptable,
- conversational context helps quality,
- you want fewer API/tool calls.
Use cron when:
- exact clock time matters (e.g., 09:00 daily),
- task should run independently of current chat context,
- one-shot reminders are needed,
- you want direct, deterministic delivery.
If unsure, ask: “Does this need exact time or just regular attention?”
2) Design pattern: one orchestrator, many checks
For recurring personal operations, prefer:
- one heartbeat orchestrator,
- a small checklist in
HEARTBEAT.md, - a lightweight state file (
memory/heartbeat-state.json) with last-check timestamps.
This keeps the system inspectable and avoids creating many tiny cron jobs that overlap.
Minimal state schema:
{
"lastChecks": {
"email": 1703275200,
"calendar": 1703260800,
"mentions": null
}
}
3) Anti-overlap guardrails (must-have)
Any scheduled automation should include:
- Idempotency key (date-window + task name)
- Overlap policy (
skip,replace, or serialized lock) - Freshness budget (how late is still useful)
- Max retry budget (avoid infinite loops)
Practical defaults:
- human-facing updates:
skip if already sent for current window - data refresh jobs:
replace stale in-flight run - notifications:
drop if stale beyond usefulness window
4) Heartbeat message policy
A good heartbeat assistant is proactive but non-annoying.
Use this policy:
- Notify when important changes happen (urgent mail, near-term event).
- Stay quiet (
HEARTBEAT_OK) when nothing meaningful changed. - Respect quiet hours unless urgent.
- If system is delayed, acknowledge delay first, then provide corrected status.
This preserves trust and keeps automation socially sustainable.
5) Sub-agent strategy for heavier work
For long or complex jobs:
- spawn a sub-agent in
runorsessionmode, - avoid rapid status polling loops,
- rely on push-style completion,
- intervene only on explicit failure/timeout.
This prevents the main assistant loop from becoming a busy-wait scheduler.
6) Free-time automation pattern (content pipeline)
A robust recurring content loop in OpenClaw should always do:
- Produce one focused artifact (single category/session).
- Update feed source atomically (prepend newest-first).
- Rebuild + deploy output site.
- Append a durable local log entry for auditability.
This 4-step chain prevents “content exists but feed/site/log is inconsistent” drift.
7) Failure-handling checklist
When a scheduled run fails:
- classify failure as input/tool/deploy/state,
- avoid partial commits to shared state files,
- report concise failure context (where + why),
- retry only if safe and useful,
- keep one-line incident note in memory log.
Good automation reliability is mostly about clean failure boundaries.
8) Quick implementation checklist
- Chose heartbeat vs cron with explicit reason
- Defined overlap and idempotency behavior
- Added freshness/staleness rule
- Added state file or durable log
- Added human-notification threshold policy
- Avoided rapid polling loops for long tasks
- Verified end-to-end path (work -> feed/state -> deploy -> log)
References
- Kubernetes CronJob (concurrency + deadlines):
https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/ - systemd timers (calendar + persistence):
https://www.freedesktop.org/software/systemd/man/systemd.timer.html - Google SRE workbook (alerting/on-call signal quality):
https://sre.google/workbook/alerting-on-slos/ - AWS Builders Library (timeouts, retries, jitter):
https://aws.amazon.com/builders-library/timeouts-retries-and-backoff-with-jitter/