fix(cron): avoid busy-wait drift for recurring main jobs#58872
Conversation
Greptile SummaryThis PR fixes a busy-wait drift issue for recurring main-session cron jobs using
Confidence Score: 5/5Safe to merge — the fix is well-scoped, correctly targets only recurring main-session jobs, and is guarded by a dedicated regression test. All findings are P2 or lower. The logic change is minimal and correct: the isRecurringJob predicate covers all recurring schedule kinds (cron and every), one-shot at jobs are unaffected, and requestHeartbeatNow is a required dependency so no null-safety gap is introduced. The regression test adequately locks in the intended behavior. No files require special attention. Reviews (1): Last reviewed commit: "Cron: avoid busy-wait drift for recurrin..." | Re-trigger Greptile |
Summary
--wake nowstay inside the cron run whilerunHeartbeatOncekeeps returningrequests-in-flight, which inflateslastDurationMsand lets schedule drift accumulate.*/3 * * * *can appear to run for minutes and miss later slots even with--exact.requestHeartbeatNow()immediately after the first busyrunHeartbeatOnceresult instead of busy-waiting in the cron lane.--atjobs still keep the existing synchronous wait-for-heartbeat behavior.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause / Regression History (if applicable)
executeMainSessionCronJob()retriedrunHeartbeatOnce()for up to the busy-wait window even for recurring jobs, so the cron run duration included main-lane contention instead of just cron scheduling work.wakeMode=nowbehavior, but no regression test for recurring main-session jobs underrequests-in-flightpressure.git blame, prior PR, issue, or refactor if known): Unknown.Regression Test Plan (if applicable)
src/cron/service.issue-regressions.test.tswakeMode="now"andrunHeartbeatOnce()returningrequests-in-flightshould request a queued heartbeat immediately and complete with a short recorded duration.src/cron/service.runs-one-shot-main-job-disables-it.test.tscovers one-shotwakeMode nowbehavior, but not recurring jobs.User-visible / Behavior Changes
Recurring main-session cron jobs using
--wake nowno longer sit in a long busy-wait loop when the main lane is already busy. Their cron run finishes quickly after queueing the immediate heartbeat, which keepslastDurationMscloser to scheduler overhead and reduces drift from blocked cron slots.Diagram (if applicable)
Security Impact (required)
Yes/No) NoYes/No) NoYes/No) NoYes/No) NoYes/No) NoYes, explain risk + mitigation:Repro + Verification
Environment
wakeMode=nowSteps
wakeMode=now.runHeartbeatOnce()return{ status: "skipped", reason: "requests-in-flight" }.Expected
Actual
Evidence
Human Verification (required)
pnpm test -- src/cron/service.issue-regressions.test.ts -t "#58833|busy-recurring-main|main lane is busy"andpnpm test -- src/cron/service.runs-one-shot-main-job-disables-it.test.ts -t "wakeMode now".wakeMode nowtests still pass, so the synchronous one-shot behavior remains intact.pnpm checkis currently failing due to unrelated existingtsgoerrors outside the cron surface.Review Conversations
Compatibility / Migration
Yes/No) YesYes/No) NoYes/No) NoRisks and Mitigations