From 5ab2db20751c0f8609fffbb2108d1d376c1a5af8 Mon Sep 17 00:00:00 2001 From: Theodore Li Date: Mon, 31 Aug 2026 19:24:40 -0700 Subject: [PATCH] fix(cron): derive async job retention cutoffs from one clock read --- apps/sim/app/api/cron/cleanup-stale-executions/route.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/sim/app/api/cron/cleanup-stale-executions/route.ts b/apps/sim/app/api/cron/cleanup-stale-executions/route.ts index 3578a3f958f..c920c86826d 100644 --- a/apps/sim/app/api/cron/cleanup-stale-executions/route.ts +++ b/apps/sim/app/api/cron/cleanup-stale-executions/route.ts @@ -504,9 +504,10 @@ export const GET = withRouteHandler(async (request: NextRequest) => { }) } - const retentionThreshold = new Date(Date.now() - JOB_RETENTION_HOURS * 60 * 60 * 1000) + const retentionNow = Date.now() + const retentionThreshold = new Date(retentionNow - JOB_RETENTION_HOURS * 60 * 60 * 1000) const irrecoverableCarrierRetentionThreshold = new Date( - Date.now() - SCHEDULE_CARRIER_IRRECOVERABLE_RETENTION_HOURS * 60 * 60 * 1000 + retentionNow - SCHEDULE_CARRIER_IRRECOVERABLE_RETENTION_HOURS * 60 * 60 * 1000 ) let asyncJobsDeleted = 0