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

Record a backup refused by the running latch as a skipped slot

[._.]/ Adam Eivy1327de634b1f
diff --git a/server/services/backupScheduler.js b/server/services/backupScheduler.js
index 224f511f48..fdd674742f 100644
--- a/server/services/backupScheduler.js
+++ b/server/services/backupScheduler.js
@@ -58,6 +58,8 @@ function registrationInputs(settings) {
* Re-read settings and run a backup if it is still wanted — the cron handler
* body, shared with the missed-slot catch-up (#8456) so both paths respect a
* disable/destPath-clear that happened after registration/detection.
+ * Returns `{ skipped: true, reason }` when no snapshot was taken, so the
+ * scheduler records the slot as skipped instead of as a successful run (#12023).
* @param {string} logReason - what triggered this run, for the log line
*/
async function runScheduledBackup(logReason) {
@@ -67,17 +69,21 @@ async function runScheduledBackup(logReason) {
if (corrupt) throw new Error('Backup settings unreadable — scheduled run was not started');
const effective = resolveBackupConfig(fresh.backup);
if (!effective.enabled) {
- console.log('💾 Backup scheduler: disabled since registration — skipping run');
- return;
+ console.warn('💾 Backup scheduler: disabled since registration — skipping run');
+ return { skipped: true, reason: 'disabled since registration' };
}
if (!effective.destPath) {
- console.log('💾 Backup scheduler: destPath cleared since registration — skipping run');
- return;
+ console.warn('💾 Backup scheduler: destPath cleared since registration — skipping run');
+ return { skipped: true, reason: 'destination cleared since registration' };
}
const excludePaths = fresh.backup?.excludePaths || [];
const disabledDefaultExcludes = fresh.backup?.disabledDefaultExcludes || [];
console.log(`💾 Backup scheduler: running ${logReason} backup`);
- await runBackup(effective.destPath, null, { excludePaths, disabledDefaultExcludes, retentionCount: effective.retentionCount });
+ const result = await runBackup(effective.destPath, null, { excludePaths, disabledDefaultExcludes, retentionCount: effective.retentionCount });
+ if (result?.skipped) {
+ console.warn(`⚠️ Backup scheduler: ${logReason} backup skipped — a backup is already running`);
+ return { skipped: true, reason: 'already running' };
+ }
}
/**
diff --git a/server/services/backupScheduler.test.js b/server/services/backupScheduler.test.js
index 6f632760f9..a42e020133 100644
--- a/server/services/backupScheduler.test.js
+++ b/server/services/backupScheduler.test.js
@@ -168,6 +168,27 @@ describe('startBackupScheduler', () => {
expect(schedule).toHaveBeenCalledTimes(1);
});
+ it('reports a backup refused by the already-running latch as a skipped slot, not a success (#12023)', async () => {
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
+ try {
+ const settings = { backup: { enabled: true, destPath: '/example-backups' } };
+ getSettings.mockResolvedValueOnce(settings);
+ await startBackupScheduler();
+ const handler = schedule.mock.calls[0][0].handler;
+ getSettings.mockResolvedValueOnce(settings);
+ runBackup.mockResolvedValueOnce({ skipped: true });
+
+ await expect(handler()).resolves.toEqual({ skipped: true, reason: 'already running' });
+ expect(warn).toHaveBeenCalledWith(expect.stringContaining('already running'));
+
+ getSettings.mockResolvedValueOnce(settings);
+ runBackup.mockResolvedValueOnce({ success: true });
+ await expect(handler()).resolves.toBeUndefined();
+ } finally {
+ warn.mockRestore();
+ }
+ });
+
it('handler skips the run if backup was disabled since registration', async () => {
getSettings.mockResolvedValueOnce({
backup: { enabled: true, destPath: '/dest', excludePaths: [], disabledDefaultExcludes: [] }
diff --git a/server/services/eventScheduler.js b/server/services/eventScheduler.js
index d11e640fc4..5e2df9436e 100644
--- a/server/services/eventScheduler.js
+++ b/server/services/eventScheduler.js
@@ -393,6 +393,8 @@ function schedule(config) {
runCount: 0,
active: true,
lastRunSucceeded: null,
+ lastRunSkipped: null,
+ lastSkipReason: null,
lastError: null,
consecutiveFailures: 0,
// The promise of the run in progress, or null. One run per event at a
@@ -540,7 +542,7 @@ function rearm(event) {
* @param {boolean} result.success - Whether the handler completed
* @param {string|null} result.error - Handler failure message, if any
*/
-function recordEventHistory(event, { startTime, success, error }) {
+function recordEventHistory(event, { startTime, success, error, skipped, skipReason }) {
// push + truncate is faster than unshift + pop for large arrays
eventHistory.push({
eventId: event.id,
@@ -548,7 +550,9 @@ function recordEventHistory(event, { startTime, success, error }) {
runAt: startTime,
duration: Date.now() - startTime,
success,
- error
+ error,
+ skipped,
+ skipReason
})
if (eventHistory.length > MAX_HISTORY) {
@@ -584,9 +588,17 @@ async function executeEvent(event) {
let success = true
let error = null
+ let skipped = false
+ let skipReason = null
try {
- await event.handler(event)
+ const result = await event.handler(event)
+ // A handler that did no work reports `{ skipped: true, reason }` so the
+ // slot is recorded as skipped rather than as a successful run (#12023).
+ if (result?.skipped === true) {
+ skipped = true
+ skipReason = typeof result.reason === 'string' ? result.reason : null
+ }
} catch (err) {
success = false
error = err.message
@@ -599,14 +611,16 @@ async function executeEvent(event) {
})
} finally {
event.lastRunSucceeded = success
+ event.lastRunSkipped = skipped
+ event.lastSkipReason = skipReason
event.lastError = error
event.consecutiveFailures = success ? 0 : event.consecutiveFailures + 1
- recordEventHistory(event, { startTime, success, error })
+ recordEventHistory(event, { startTime, success, error, skipped, skipReason })
// A synchronous listener that throws must not cost the schedule its re-arm
try {
- cosEvents.emit('scheduler:ran', { id: event.id, success, runCount: event.runCount })
+ cosEvents.emit('scheduler:ran', { id: event.id, success, skipped, runCount: event.runCount })
} catch (err) {
console.error(`⚠️ Event ${event.id} scheduler:ran listener threw: ${err.message}`)
}
@@ -731,6 +745,8 @@ function getEvent(id) {
lastRunAt: event.lastRunAt,
runCount: event.runCount,
lastRunSucceeded: event.lastRunSucceeded,
+ lastRunSkipped: event.lastRunSkipped,
+ lastSkipReason: event.lastSkipReason,
lastError: event.lastError,
consecutiveFailures: event.consecutiveFailures,
metadata: event.metadata
@@ -764,7 +780,8 @@ function getHistory(options = {}) {
*/
function getStats() {
const events = Array.from(scheduledEvents.values())
- const recent = eventHistory.slice(-100).reverse()
+ // A skipped slot did no work, so it counts toward neither side of the rate.
+ const recent = eventHistory.slice(-100).reverse().filter(h => !h.skipped)
return {
totalEvents: events.length,
diff --git a/server/services/eventScheduler.test.js b/server/services/eventScheduler.test.js
index 42724d8743..95e4df01cf 100644
--- a/server/services/eventScheduler.test.js
+++ b/server/services/eventScheduler.test.js
@@ -435,6 +435,31 @@ describe('schedule() lifecycle with fake timers', () => {
expect(handler).toHaveBeenCalledTimes(2);
});
+ it('records a handler that reports { skipped } as a skipped slot, not a successful run (#12023)', async () => {
+ const ran = vi.fn();
+ cosEvents.on('scheduler:ran', ran);
+ const handler = vi.fn()
+ .mockResolvedValueOnce({ skipped: true, reason: 'already running' })
+ .mockRejectedValueOnce(new Error('boom'));
+ schedule({ id: 'skip-1', type: 'interval', intervalMs: 5000, handler });
+ const rateBefore = getStats().recentSuccessRate;
+
+ await vi.advanceTimersByTimeAsync(5000);
+
+ const [entry] = getHistory({ eventId: 'skip-1' });
+ expect(entry).toMatchObject({ success: true, skipped: true, skipReason: 'already running', error: null });
+ expect(getEvent('skip-1')).toMatchObject({ lastRunSucceeded: true, lastRunSkipped: true, lastSkipReason: 'already running', runCount: 1 });
+ expect(ran).toHaveBeenCalledWith(expect.objectContaining({ id: 'skip-1', success: true, skipped: true }));
+
+ // The skipped slot counts toward neither side of the success rate; the
+ // failure that follows does.
+ expect(getStats().recentSuccessRate).toBe(rateBefore);
+ await vi.advanceTimersByTimeAsync(5000);
+ expect(getStats().recentSuccessRate).not.toBe(rateBefore);
+ expect(getEvent('skip-1')).toMatchObject({ lastRunSucceeded: false, lastRunSkipped: false, lastSkipReason: null });
+ cosEvents.off('scheduler:ran', ran);
+ });
+
it('records a failed handler in history without deactivating a recurring event', async () => {
const handler = vi.fn().mockRejectedValue(new Error('boom'));
schedule({ id: 'fail-1', type: 'interval', intervalMs: 5000, handler });