[AI-assisted] fix(cron): wait for heartbeat to complete when wakeMode is "now"#666
Merged
steipete merged 5 commits intoopenclaw:mainfrom Jan 10, 2026
Conversation
8c94346 to
309ed00
Compare
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]
5a0ae72 to
7dd0899
Compare
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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #652
Cron jobs with wakeMode: "now" were completing immediately without waiting for agent.
See commit for full details.