openclaw-vainplex/src/cron
Roshan Singh 91c870a0c4 fix(cron): wait for heartbeat to complete when wakeMode is "now"
Fixes #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]
2026-01-10 18:31:35 +01:00
..
cron-protocol-conformance.test.ts feat: multi-agent routing + multi-account providers 2026-01-06 18:33:37 +00:00
isolated-agent.test.ts fix: harden Gmail hook model defaults (#472) (thanks @koala73) 2026-01-09 19:59:45 +01:00
isolated-agent.ts refactor: centralize WhatsApp target normalization 2026-01-10 02:39:52 +01:00
normalize.test.ts refactor: cron payload migration cleanup (#621) 2026-01-09 22:56:55 +00:00
normalize.ts refactor: cron payload migration cleanup (#621) 2026-01-09 22:56:55 +00:00
payload-migration.ts refactor: cron payload migration cleanup (#621) 2026-01-09 22:56:55 +00:00
run-log.test.ts chore: rename project to clawdbot 2026-01-04 14:38:51 +00:00
run-log.ts refactor(cron): move store into ~/.clawdis/cron 2025-12-13 12:38:08 +00:00
schedule.test.ts test: cover every schedule anchor boundary 2026-01-02 11:33:49 +01:00
schedule.ts fix(cron): prevent every schedule from firing in infinite loop 2026-01-01 17:30:05 -07:00
service.test.ts refactor: cron payload migration cleanup (#621) 2026-01-09 22:56:55 +00:00
service.ts fix(cron): wait for heartbeat to complete when wakeMode is "now" 2026-01-10 18:31:35 +01:00
store.ts refactor(cron): drop auto-migration 2025-12-13 12:45:02 +00:00
types.ts feat(msteams): add MS Teams provider skeleton 2026-01-09 11:05:34 +01:00