#3335: Fixes cron jobs
Cluster:
Heartbeat Functionality Improvements
Fixes https://github.com/moltbot/moltbot/issues/2323
Cron jobs seems to have broken after https://github.com/clawdbot/clawdbot/pull/1535
The reason seems to be an early return that was added in the PR above, that would not the `system events` queue clear if `HEARTBEAT.md` is empty.
Cron jobs are pushed to system events when executed, and hence the change ensures that if there are pending system events they should be executed irrespective of the `heartbeat.md` file being empty.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adjusts the heartbeat runner’s “empty HEARTBEAT.md” early-return behavior so that pending system events (e.g., cron-triggered reminders queued into the per-session system-events queue) still cause a heartbeat run. It adds tests covering the new behavior (run when HEARTBEAT.md is effectively empty but system events exist; still skip when empty and no events).
The change integrates with existing heartbeat logic by checking the session’s system-events queue before applying the cost-saving skip, ensuring cron/system-event delivery isn’t blocked by an empty heartbeat file.
<h3>Confidence Score: 4/5</h3>
- This PR is likely safe to merge and addresses the reported cron/system-events regression with targeted tests.
- The functional change is small and well-scoped (only gating the empty-heartbeat skip on presence of queued system events) and is covered by new tests. Main remaining risk is around edge cases where `sessionKey` resolution could be invalid and `hasSystemEvents` may throw earlier than before.
- src/infra/heartbeat-runner.ts (sessionKey/system-events check edge cases)
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#12365: test(heartbeat): don't skip empty HEARTBEAT.md for cron wake events
by tyclaudius-ai · 2026-02-09
87.5%
#15422: fix(auto-reply): keep cron systemEvent payloads that start with 'Re...
by liuxiaopai-ai · 2026-02-13
82.8%
#6094: auto-reply: ignore HTML comments in heartbeat check
by rudrapanchal81 · 2026-02-01
81.7%
#8418: fix: notify user after consecutive heartbeat/cron failures
by liaosvcaf · 2026-02-04
80.8%
#6522: fix(cron): deliver original message when agent response is heartbea...
by sidmohan0 · 2026-02-01
80.5%
#8698: fix(cron): default enabled to true for new jobs
by emmick4 · 2026-02-04
79.9%
#12303: fix(cron): correct nextRunAtMs calculation and prevent timer stall
by colddonkey · 2026-02-09
79.4%
#21014: fix(cron): suppress main-session summary for HEARTBEAT_OK responses
by nickjlamb · 2026-02-19
79.4%
#5498: Cron: honor next-heartbeat
by sebslight · 2026-01-31
79.0%
#15852: fix: pass agentId when resolving IRC session paths
by MisterGuy420 · 2026-02-14
78.7%