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: restore cron null rejection, fix nextLocalTime exact-match

Adam Eivya499a3d9f340
diff --git a/server/lib/timezone.js b/server/lib/timezone.js
index 9820785469..3025398539 100644
--- a/server/lib/timezone.js
+++ b/server/lib/timezone.js
@@ -104,7 +104,7 @@ export function nextLocalTime(afterMs, hours, minutes, timezone) {
// How many minutes until the target time?
let deltaMin = desiredMin - currentMin
- if (deltaMin <= 0) deltaMin += 1440 // wrap to next day
+ if (deltaMin < 0) deltaMin += 1440 // wrap to next day
const candidate = afterMs + deltaMin * 60_000
// DST transitions can shift the result by up to ±60 min — verify and nudge if needed.
diff --git a/server/lib/timezone.test.js b/server/lib/timezone.test.js
index f7e057f52b..d0d646f439 100644
--- a/server/lib/timezone.test.js
+++ b/server/lib/timezone.test.js
@@ -71,6 +71,12 @@ describe('timezone', () => {
expect(resultDate.getUTCDate()).toBe(24)
})
+ it('returns same timestamp when afterMs exactly matches target time', () => {
+ const after = new Date('2026-03-24T14:00:00Z').getTime()
+ const result = nextLocalTime(after, 14, 0, 'UTC')
+ expect(result).toBe(after)
+ })
+
it('wraps to next day if time has passed', () => {
const after = new Date('2026-03-24T15:00:00Z').getTime()
const result = nextLocalTime(after, 14, 0, 'UTC')
diff --git a/server/routes/cos.js b/server/routes/cos.js
index 11312b2f78..f198f86b82 100644
--- a/server/routes/cos.js
+++ b/server/routes/cos.js
@@ -966,9 +966,11 @@ 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 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');
+ // Validate syntax, field ranges, and reachability
+ const nextRun = parseCronToNextRun(cronExpression, new Date(), 'UTC');
+ if (!nextRun) {
+ throw new ServerError('Invalid cronExpression: no matching time found (check field ranges)', { status: 400, code: 'VALIDATION_ERROR' });
+ }
}
const job = await autonomousJobs.createJob({
@@ -987,8 +989,11 @@ 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' });
}
- // Validate syntax and field ranges (parseCronToNextRun throws on invalid expressions)
- parseCronToNextRun(cronExpression, new Date(), 'UTC');
+ // Validate syntax, field ranges, and reachability
+ const nextRun = parseCronToNextRun(cronExpression, new Date(), 'UTC');
+ if (!nextRun) {
+ throw new ServerError('Invalid cronExpression: no matching time found (check field ranges)', { status: 400, code: 'VALIDATION_ERROR' });
+ }
}
const job = await autonomousJobs.updateJob(req.params.id, {
name, description, category, type, interval, intervalMs, scheduledTime, cronExpression,