fix(cron): share isolated announce flow + harden cron scheduling/delivery (#11641)

* fix(cron): comprehensive cron scheduling and delivery fixes

- Fix delivery target resolution for isolated agent cron jobs
- Improve schedule parsing and validation
- Add job retry logic and error handling
- Enhance cron ops with better state management
- Add timer improvements for more reliable cron execution
- Add cron event type to protocol schema
- Support cron events in heartbeat runner (skip empty-heartbeat check,
  use dedicated CRON_EVENT_PROMPT for relay)

* fix: remove cron debug test and add changelog/docs notes (#11641) (thanks @tyler6204)
This commit is contained in:
Tyler Yust
2026-02-07 19:46:01 -08:00
committed by GitHub
parent ebe5730401
commit 8fae55e8e0
19 changed files with 488 additions and 150 deletions

View File

@@ -49,17 +49,13 @@ export function computeNextRunAtMs(schedule: CronSchedule, nowMs: number): numbe
timezone: resolveCronTimezone(schedule.tz),
catch: false,
});
let cursor = nowMs;
for (let attempt = 0; attempt < 3; attempt++) {
const next = cron.nextRun(new Date(cursor));
if (!next) {
return undefined;
}
const nextMs = next.getTime();
if (Number.isFinite(nextMs) && nextMs > nowMs) {
return nextMs;
}
cursor += 1_000;
// Use a tiny lookback (1ms) so croner doesn't skip the current second
// boundary. Without this, a job updated at exactly its cron time would
// be scheduled for the *next* matching time (e.g. 24h later for daily).
const next = cron.nextRun(new Date(nowMs - 1));
if (!next) {
return undefined;
}
return undefined;
const nextMs = next.getTime();
return Number.isFinite(nextMs) && nextMs >= nowMs ? nextMs : undefined;
}