Skip to content

[AI-assisted] fix(cron): wait for heartbeat to complete when wakeMode is "now"#666

Merged
steipete merged 5 commits intoopenclaw:mainfrom
roshanasingh4:fix/652-cron-wakeMode-now-waits-for-agent
Jan 10, 2026
Merged

[AI-assisted] fix(cron): wait for heartbeat to complete when wakeMode is "now"#666
steipete merged 5 commits intoopenclaw:mainfrom
roshanasingh4:fix/652-cron-wakeMode-now-waits-for-agent

Conversation

@roshanasingh4
Copy link
Contributor

Fixes #652

Cron jobs with wakeMode: "now" were completing immediately without waiting for agent.

See commit for full details.

roshanasingh4 and others added 5 commits January 10, 2026 18:31
Fixes openclaw#652

When cron jobs with sessionTarget:"main" have wakeMode:"now",
they were being marked as completed immediately without waiting for the
agent to actually process the system event.

The issue was that requestHeartbeatNow() is fire-and-forget and
doesn't wait for the heartbeat to complete. The job would finish
with durationMs: 0 before the agent had a chance to run.

This fix:
- Adds runHeartbeatOnce to CronServiceDeps
- Wires it up in gateway/server.ts to load config and pass runtime
- Modifies executeJob() to call runHeartbeatOnce when wakeMode:"now"
- Waits for heartbeat to complete and maps status to cron result:
  * "ran" → "ok"
  * "skipped" → "skipped"
  * "failed" → "error"
- Falls back to old behavior for wakeMode:"next-heartbeat" or if
  runHeartbeatOnce is not available (backward compatibility)

Benefits:
- Jobs now have accurate durationMs reflecting actual processing time
- Jobs are correctly marked with "error" status if heartbeat fails
- Prevents race condition where job completes before agent runs

[AI-assisted] - Generated with z.ai GLM-4.7
[Tested: Lightly tested - Logic validated with test scenarios, code quality checks passed, integration testing requires live Clawdbot instance]
@steipete steipete force-pushed the fix/652-cron-wakeMode-now-waits-for-agent branch from 5a0ae72 to 7dd0899 Compare January 10, 2026 17:33
@steipete steipete merged commit 7ac628a into openclaw:main Jan 10, 2026
20 checks passed
@steipete
Copy link
Contributor

Landed via temp rebase onto main.\n\n- Gate: pnpm lint && pnpm build && pnpm test\n- Land head: 7dd0899\n- Merge commit: 7ac628a\n\nThanks @roshanasingh4!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cron jobs with wakeMode: "now" mark complete without invoking agent session

2 participants

Comments