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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review: normalize DOW 7=Sunday, validate timezone, relax cron validation
Adam Eivy109cd8a3f21d
diff --git a/client/src/components/cos/tabs/JobsTab.jsx b/client/src/components/cos/tabs/JobsTab.jsxindex bbc9ca6494..4ad5dcb5eb 100644--- a/client/src/components/cos/tabs/JobsTab.jsx+++ b/client/src/components/cos/tabs/JobsTab.jsx@@ -489,6 +489,10 @@ export default function JobsTab() {toast.error('Prompt template is required for AI jobs');return;}+ if (newJob.scheduleMode === 'cron' && (!newJob.cronExpression?.trim() || newJob.cronExpression.trim().split(/\s+/).length !== 5)) {+ toast.error('A valid 5-field cron expression is required for cron scheduling');+ return;+ }const created = await api.createCosJob(normalizeJobPayload(newJob)).catch(err => {toast.error(err.message);diff --git a/server/lib/timezone.js b/server/lib/timezone.jsindex 18d2ae545b..9820785469 100644--- a/server/lib/timezone.js+++ b/server/lib/timezone.js@@ -38,7 +38,17 @@ function getFormatter(timezone) {*/export async function getUserTimezone() {const settings = await getSettings()- return settings.timezone || Intl.DateTimeFormat().resolvedOptions().timeZone+ const tz = settings.timezone+ if (tz) {+ // Validate the configured timezone; fall back to system timezone if invalid+ try {+ new Intl.DateTimeFormat('en-US', { timeZone: tz })+ return tz+ } catch {+ console.error(`❌ Invalid configured timezone "${tz}", falling back to system default`)+ }+ }+ return Intl.DateTimeFormat().resolvedOptions().timeZone}/**diff --git a/server/routes/apps.js b/server/routes/apps.jsindex c912cd4750..d34b956c0f 100644--- a/server/routes/apps.js+++ b/server/routes/apps.js@@ -357,10 +357,9 @@ router.put('/:id/task-types/:taskType', asyncHandler(async (req, res) => {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' });- }+ // Validate syntax and field ranges (parseCronToNextRun throws on invalid expressions)+ // Note: null return means no match within search window (e.g. leap day) -- not invalid+ parseCronToNextRun(interval, new Date(), 'UTC');}} 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.jsindex 231e95456e..11312b2f78 100644--- a/server/routes/cos.js+++ b/server/routes/cos.js@@ -966,11 +966,9 @@ 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 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' });- }+ // Validate syntax and field ranges (parseCronToNextRun throws on invalid expressions)+ // Note: null return means no match within search window (e.g. leap day) -- not invalid+ parseCronToNextRun(cronExpression, new Date(), 'UTC');}const job = await autonomousJobs.createJob({@@ -989,10 +987,8 @@ router.put('/jobs/:id', asyncHandler(async (req, res) => {if (parts.length !== 5) {throw new ServerError('cronExpression must be a 5-field cron expression', { status: 400, code: 'VALIDATION_ERROR' });}- 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' });- }+ // Validate syntax and field ranges (parseCronToNextRun throws on invalid expressions)+ parseCronToNextRun(cronExpression, new Date(), 'UTC');}const job = await autonomousJobs.updateJob(req.params.id, {name, description, category, type, interval, intervalMs, scheduledTime, cronExpression,diff --git a/server/services/eventScheduler.js b/server/services/eventScheduler.jsindex ad41fa3b4b..0b78509bce 100644--- a/server/services/eventScheduler.js+++ b/server/services/eventScheduler.js@@ -117,9 +117,14 @@ function parseCronToNextRun(cronExpr, from = new Date(), timezone = 'UTC') {hour = next.getHours(); minute = next.getMinutes()}+ // Normalize DOW: cron allows 7 for Sunday, but JS getDay() returns 0+ // Match both 0 and 7 representations for Sunday+ const dowMatches = matchesCronField(dow, dayOfWeekExpr, 0) ||+ (dow === 0 && matchesCronField(7, dayOfWeekExpr, 0))+if (matchesCronField(month, monthExpr, 1) &&matchesCronField(day, dayOfMonthExpr, 1) &&- matchesCronField(dow, dayOfWeekExpr, 0) &&+ dowMatches &&matchesCronField(hour, hourExpr, 0) &&matchesCronField(minute, minuteExpr, 0)) {return nextdiff --git a/server/services/taskSchedule.js b/server/services/taskSchedule.jsindex 7351dfddde..d78aa75a88 100644--- a/server/services/taskSchedule.js+++ b/server/services/taskSchedule.js@@ -1350,7 +1350,8 @@ export async function shouldRunTask(taskType, appId = null) {result = { shouldRun: false, reason: 'invalid-cron' };break;}- const fromDate = lastRun ? new Date(lastRun) : new Date(now);+ // For never-run tasks, use 1 minute ago so the first scheduled occurrence can match+ const fromDate = lastRun ? new Date(lastRun) : new Date(now - 60_000);const nextRun = parseCronToNextRun(cronExpr, fromDate, timezone);if (!nextRun) {result = { shouldRun: false, reason: 'invalid-cron', cronExpression: cronExpr };