Skip to content

fix: process cron job system events during heartbeat execution#7109

Closed
ArsalanShakil wants to merge 6 commits intoopenclaw:mainfrom
ArsalanShakil:fix/cron-job-system-events-ignored
Closed

fix: process cron job system events during heartbeat execution#7109
ArsalanShakil wants to merge 6 commits intoopenclaw:mainfrom
ArsalanShakil:fix/cron-job-system-events-ignored

Conversation

@ArsalanShakil
Copy link

@ArsalanShakil ArsalanShakil commented Feb 2, 2026

Fixes #7065

This commit addresses several issues with cron job system events being ignored during heartbeat execution:

  1. Exempt cron events from empty HEARTBEAT.md skip - cron events (like exec events) have pending system events to process and should not be skipped when the heartbeat file is empty.

  2. Read system events for cron triggers - the heartbeat runner now reads pending system events for cron events (reason starts with "cron:"), not just exec events.

  3. Add CRON_EVENT_PROMPT - when a cron event triggers with pending system events, the AI receives a specialized prompt instructing it to relay the reminder instead of the standard heartbeat prompt.

  4. Default enabled to true in createJob - cron jobs now default to enabled when not explicitly set.

  5. Default wakeMode to "now" for one-shot jobs - one-shot jobs (schedule.kind: "at") now default to wakeMode: "now" for immediate delivery instead of "next-heartbeat".

Greptile Overview

Greptile Summary

This PR improves cron-triggered reminder delivery by ensuring heartbeat runs don’t skip when HEARTBEAT.md is effectively empty for cron-triggered runs, and by checking pending system events for cron triggers (not just exec-event triggers). It also introduces a dedicated CRON_EVENT_PROMPT so cron-triggered reminders are relayed to the user rather than producing a generic heartbeat ack, and updates cron job defaults (enabled defaults to true; one-shot schedule.kind: "at" defaults to wakeMode: "now").

These changes fit into the existing infra by extending runHeartbeatOnce’s event-aware prompting (previously only exec completions) to include cron reasons, and by updating cron normalization/job creation defaults to align runtime behavior with the intended delivery semantics.

Confidence Score: 4/5

  • This PR is generally safe to merge, but there are a couple of edge cases where cron prompting/delivery can behave incorrectly.
  • Changes are small and localized, and defaults look consistent with the PR’s intent. Main concern is prompt selection/delivery logic for cron events: any queued system event can trigger the cron prompt, and cron reminders can still be suppressed if the model outputs HEARTBEAT_OK (unlike exec completion handling).
  • src/infra/heartbeat-runner.ts

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

Context used:

  • Context from dashboard - CLAUDE.md (source)
  • Context from dashboard - AGENTS.md (source)

@openclaw-barnacle openclaw-barnacle bot added the agents Agent runtime and tooling label Feb 2, 2026
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 2, 2026

Additional Comments (1)

src/infra/heartbeat-runner.ts
[P1] Cron reminders can still be suppressed as HEARTBEAT_OK tokens

There’s special handling to avoid suppressing exec completions (shouldSkipMain ignores normalized.shouldSkip when hasExecCompletion), but cron reminders don’t get the same exemption. If the model responds with HEARTBEAT_OK (or text that strips to empty), shouldSkipMain will be true and the reminder may never be delivered.

If cron reminders are intended to always deliver the reminder text, consider exempting hasCronEvents from shouldSkipMain (and possibly adding a cron fallback similar to execFallbackText).

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/infra/heartbeat-runner.ts
Line: 646:659

Comment:
[P1] Cron reminders can still be suppressed as HEARTBEAT_OK tokens

There’s special handling to avoid suppressing exec completions (`shouldSkipMain` ignores `normalized.shouldSkip` when `hasExecCompletion`), but cron reminders don’t get the same exemption. If the model responds with `HEARTBEAT_OK` (or text that strips to empty), `shouldSkipMain` will be true and the reminder may never be delivered.

If cron reminders are intended to always deliver the reminder text, consider exempting `hasCronEvents` from `shouldSkipMain` (and possibly adding a cron fallback similar to `execFallbackText`).

How can I resolve this? If you propose a fix, please make it concise.

@ArsalanShakil ArsalanShakil force-pushed the fix/cron-job-system-events-ignored branch from c0c1c32 to 2abf902 Compare February 2, 2026 12:16
@openclaw-barnacle openclaw-barnacle bot added the channel: slack Channel integration: slack label Feb 2, 2026
Arsalan Shakil and others added 3 commits February 2, 2026 14:53
Fixes openclaw#7065

This commit addresses several issues with cron job system events being
ignored during heartbeat execution:

1. Exempt cron events from empty HEARTBEAT.md skip - cron events (like
   exec events) have pending system events to process and should not be
   skipped when the heartbeat file is empty.

2. Read system events for cron triggers - the heartbeat runner now reads
   pending system events for cron events (reason starts with "cron:"),
   not just exec events.

3. Add CRON_EVENT_PROMPT - when a cron event triggers with pending
   system events, the AI receives a specialized prompt instructing it to
   relay the reminder instead of the standard heartbeat prompt.

4. Default enabled to true in createJob - cron jobs now default to
   enabled when not explicitly set.

5. Default wakeMode to "now" for one-shot jobs - one-shot jobs
   (schedule.kind: "at") now default to wakeMode: "now" for immediate
   delivery instead of "next-heartbeat".

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Address PR review feedback: hasCronEvents now checks for "Cron reminder:"
marker instead of just any pending system event, preventing unrelated
events from triggering CRON_EVENT_PROMPT.
Simplify the function since Request always has a url property,
fixing the no-base-to-string lint error.
@ArsalanShakil ArsalanShakil force-pushed the fix/cron-job-system-events-ignored branch from e322707 to b13dd53 Compare February 2, 2026 12:57
@openclaw-barnacle openclaw-barnacle bot removed the channel: slack Channel integration: slack label Feb 2, 2026
@NoelisTired
Copy link

I really need this to merge; LGTM!

@adam91holt
Copy link
Contributor

🔍 Overlapping PRs Detected

This PR appears to overlap with 6 other open PRs addressing agents, cron, infra:

Similarity PR Author Title
92.5% #6822 @radling005 fix: bypass empty-heartbeat-file check for cron jobs
91.5% #3335 @hkirat Fixes cron jobs
91.5% #5415 @betterthanhajin fix: don't skip heartbeat for cron systemEvent jobs with empty HEARTB…
91.3% #4256 @radling005 fix: bypass empty-heartbeat-file check for cron jobs
87.7% #4465 @spiceoogway fix: Make cron systemEvents trigger autonomous agent action
87.7% #666 @roshanasingh4 [AI-assisted] fix(cron): wait for heartbeat to complete when wakeMode is "now"

🔍 Detected by OpenClaw PR Tracker — AI-powered duplicate detection for open source

@DmitriyAlergant
Copy link

Would you consider expanding the PR to also cover the situation where:

A system event (not originated from openclaw's cron... just an explicitly sent system event via CLI) was sent with "next-heartbeat" mode, but HEARTBEAT.md is empty.

I think this should trigger the next HEARTBEAT run (at its next normal schedule) not being skipped. Currently it is skipped. And i don't think your PR changes that currently?

Or advise if you believe this should be a standalone change.

@ArsalanShakil
Copy link
Author

@DmitriyAlergant

I think a standalone PR would be better here. This PR specifically addresses cron-originated events (identified by the "Cron reminder:" prefix). Generic system events sent via CLI with "next-heartbeat" mode are a slightly different use case - they shouldn't require the cron marker logic.

@tyler6204
Copy link
Member

Superseded by #11641 (merge commit: 8fae55e). Closing to reduce duplicate PR noise. Please open a new PR only if there is additional scope beyond this fix.

@tyler6204 tyler6204 closed this Feb 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Cron job system events are ignored during heartbeat execution

5 participants

Comments