Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review: align cron iteration limits, hoist timezone, validate overrides

Adam Eivy16889ba6e9ec
diff --git a/server/routes/apps.js b/server/routes/apps.js
index 410625784b..c912cd4750 100644
--- a/server/routes/apps.js
+++ b/server/routes/apps.js
@@ -12,6 +12,7 @@ import { logAction } from '../services/history.js';
import { z } from 'zod';
import { validateRequest, appSchema, appUpdateSchema, sanitizeTaskMetadata } from '../lib/validation.js';
import * as git from '../services/git.js';
+import { parseCronToNextRun } from '../services/eventScheduler.js';
import { asyncHandler, ServerError } from '../lib/errorHandler.js';
import { safeJSONParse } from '../lib/fileUtils.js';
import { parseEcosystemFromPath, usesPm2 } from '../services/streamingDetect.js';
@@ -355,6 +356,12 @@ router.put('/:id/task-types/:taskType', asyncHandler(async (req, res) => {
if (!isCron && !allowedIntervals.includes(interval)) {
throw new ServerError('interval must be one of rotation|daily|weekly|once|on-demand, a cron expression, or null', { status: 400, code: 'VALIDATION_ERROR' });
}
+ if (isCron) {
+ const nextRun = parseCronToNextRun(interval, new Date(), 'UTC');
+ if (!nextRun) {
+ throw new ServerError('Invalid cron expression: unable to compute next run time', { status: 400, code: 'VALIDATION_ERROR' });
+ }
+ }
} else if (interval !== null) {
throw new ServerError('interval must be a string or null', { status: 400, code: 'VALIDATION_ERROR' });
}
diff --git a/server/routes/cos.js b/server/routes/cos.js
index 49e6c427f3..231e95456e 100644
--- a/server/routes/cos.js
+++ b/server/routes/cos.js
@@ -966,7 +966,7 @@ router.post('/jobs', asyncHandler(async (req, res) => {
if (parts.length !== 5) {
throw new ServerError('cronExpression must be a 5-field cron expression (minute hour dayOfMonth month dayOfWeek)', { status: 400, code: 'VALIDATION_ERROR' });
}
- // Validate by computing next run within a 90-day window to avoid expensive searches
+ // Validate by attempting to compute the next run time
const nextRun = parseCronToNextRun(cronExpression, new Date(), 'UTC');
if (!nextRun) {
throw new ServerError('Invalid cronExpression: unable to compute next run time', { status: 400, code: 'VALIDATION_ERROR' });
diff --git a/server/services/eventScheduler.js b/server/services/eventScheduler.js
index da1a17a180..ad41fa3b4b 100644
--- a/server/services/eventScheduler.js
+++ b/server/services/eventScheduler.js
@@ -50,8 +50,8 @@ function validateCronFieldRange(expr, min, max) {
return true
}
-// Maximum iterations for cron search loop (1 year in minutes)
-const MAX_CRON_ITERATIONS = 525960
+// Maximum iterations for cron search loop (2 years in minutes, matches maxDate window)
+const MAX_CRON_ITERATIONS = 1051920
/**
* Parse cron expression to next execution time
diff --git a/server/services/meatspacePostDrillCache.js b/server/services/meatspacePostDrillCache.js
index 1979c08a2a..f5b14a582a 100644
--- a/server/services/meatspacePostDrillCache.js
+++ b/server/services/meatspacePostDrillCache.js
@@ -136,6 +136,6 @@ export async function initDrillCache(providerId, model) {
for (const type of lowTypes) {
await replenishType(type, providerId, model);
}
- })();
+ })().catch(err => console.error(`❌ POST drill cache startup fill failed: ${err.message}`));
}
}
diff --git a/server/services/taskSchedule.js b/server/services/taskSchedule.js
index abeb2f4e2f..7351dfddde 100644
--- a/server/services/taskSchedule.js
+++ b/server/services/taskSchedule.js
@@ -1233,9 +1233,11 @@ export async function shouldRunTask(taskType, appId = null) {
return { shouldRun: false, reason: 'disabled' };
}
+ // Fetch timezone once for reuse across weekday and cron checks
+ const timezone = await getUserTimezone();
+
// Weekday-only tasks skip weekends (timezone-aware)
if (interval.weekdaysOnly) {
- const timezone = await getUserTimezone();
const { dayOfWeek } = getLocalParts(new Date(), timezone);
if (dayOfWeek === 0 || dayOfWeek === 6) {
return { shouldRun: false, reason: 'weekday-only' };
@@ -1348,8 +1350,7 @@ export async function shouldRunTask(taskType, appId = null) {
result = { shouldRun: false, reason: 'invalid-cron' };
break;
}
- const timezone = await getUserTimezone();
- const fromDate = lastRun ? new Date(lastRun) : new Date(now - DAY);
+ const fromDate = lastRun ? new Date(lastRun) : new Date(now);
const nextRun = parseCronToNextRun(cronExpr, fromDate, timezone);
if (!nextRun) {
result = { shouldRun: false, reason: 'invalid-cron', cronExpression: cronExpr };