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
fix: retry backup cron registration after a rejected cron expression (#3910)
[._.]/ Adam Eivyaebef7e24183
diff --git a/server/services/backupScheduler.js b/server/services/backupScheduler.jsindex bddeb730e5..e00e1712b2 100644--- a/server/services/backupScheduler.js+++ b/server/services/backupScheduler.js@@ -49,9 +49,9 @@ export async function syncBackupSchedule(settings) {// destPath and the exclude lists are re-read by the handler on every run.const signature = JSON.stringify({ active: Boolean(inputs), cron: inputs?.cron ?? null, tz: timezone });if (signature === lastSignature) return registered;- lastSignature = signature;if (!inputs) {+ lastSignature = signature;if (registered) {cancel(EVENT_ID);registered = false;@@ -66,31 +66,46 @@ export async function syncBackupSchedule(settings) {// expression cleanly re-registers. destPath, excludePaths and// disabledDefaultExcludes are re-read inside the handler so toggles saved in// the Settings UI take effect on the next scheduled run.- schedule({- id: EVENT_ID,- type: 'cron',- cron: inputs.cron,- timezone,- handler: async () => {- const fresh = await getSettings();- if (fresh.backup?.enabled === false) {- console.log('💾 Backup scheduler: disabled since registration — skipping run');- return;- }- const destPath = fresh.backup?.destPath;- if (!destPath) {- console.log('💾 Backup scheduler: destPath cleared since registration — skipping run');- return;- }- const excludePaths = fresh.backup?.excludePaths || [];- const disabledDefaultExcludes = fresh.backup?.disabledDefaultExcludes || [];- console.log('💾 Backup scheduler: running scheduled backup');- await runBackup(destPath, null, { excludePaths, disabledDefaultExcludes });- },- metadata: { source: 'backupScheduler' }- });- registered = true;+ //+ // try/catch (allowed here — this runs on the settings event bus / at boot,+ // outside the request lifecycle): schedule() CANCELS the existing event+ // before it validates the new cron, so a malformed expression tears down a+ // working timer and throws. Leave `lastSignature` unset in that case so the+ // next save — even one that re-submits the same value — retries instead of+ // short-circuiting on a registration that never happened.+ try {+ schedule({+ id: EVENT_ID,+ type: 'cron',+ cron: inputs.cron,+ timezone,+ handler: async () => {+ const fresh = await getSettings();+ if (fresh.backup?.enabled === false) {+ console.log('💾 Backup scheduler: disabled since registration — skipping run');+ return;+ }+ const destPath = fresh.backup?.destPath;+ if (!destPath) {+ console.log('💾 Backup scheduler: destPath cleared since registration — skipping run');+ return;+ }+ const excludePaths = fresh.backup?.excludePaths || [];+ const disabledDefaultExcludes = fresh.backup?.disabledDefaultExcludes || [];+ console.log('💾 Backup scheduler: running scheduled backup');+ await runBackup(destPath, null, { excludePaths, disabledDefaultExcludes });+ },+ metadata: { source: 'backupScheduler' }+ });+ } catch (err) {+ registered = false;+ lastSignature = null;+ console.error(`❌ Backup scheduler: cron "${inputs.cron}" rejected — no backup scheduled: ${err.message}`);+ return false;+ }+ registered = true;+ lastSignature = signature;console.log(`💾 Backup scheduler: registered daily backup at cron "${inputs.cron}"`);return true;}diff --git a/server/services/backupScheduler.test.js b/server/services/backupScheduler.test.jsindex a089554589..08fa3b77ea 100644--- a/server/services/backupScheduler.test.js+++ b/server/services/backupScheduler.test.js@@ -203,6 +203,20 @@ describe('settings:updated re-sync', () => {expect(cancel).toHaveBeenCalledWith('backup-daily');});+ it('retries after a rejected cron instead of short-circuiting on it', async () => {+ // eventScheduler.schedule() cancels the existing event BEFORE validating the+ // replacement, so a bad cron leaves nothing registered — the next save must+ // re-attempt even when it submits the identical (now-fixed) settings.+ getSettings.mockResolvedValue({ backup: { enabled: true, destPath: '/dest', cronExpression: 'nonsense' } });+ schedule.mockImplementationOnce(() => { throw new Error('Cron type requires cron expression'); });+ await startBackupScheduler();+ expect(schedule).toHaveBeenCalledTimes(1);++ // Same inputs again: the failed attempt must not be remembered as applied.+ await emitSettings({ backup: { enabled: true, destPath: '/dest', cronExpression: 'nonsense' } });+ expect(schedule).toHaveBeenCalledTimes(2);+ });+it('is a no-op for a save that does not touch backup registration', async () => {getSettings.mockResolvedValue({ backup: { enabled: true, destPath: '/dest' } });await startBackupScheduler();