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] |
||
|---|---|---|
| .. | ||
| cron-protocol-conformance.test.ts | ||
| isolated-agent.test.ts | ||
| isolated-agent.ts | ||
| normalize.test.ts | ||
| normalize.ts | ||
| payload-migration.ts | ||
| run-log.test.ts | ||
| run-log.ts | ||
| schedule.test.ts | ||
| schedule.ts | ||
| service.test.ts | ||
| service.ts | ||
| store.ts | ||
| types.ts | ||