A modern, self-hosted backup solution for secure, encrypted backups across local and cloud storage.
fix: correct off-by-one in job retry counting
towfiqi13b232516443
diff --git a/backend/__tests__/jobs/JobQueue.test.ts b/backend/__tests__/jobs/JobQueue.test.tsindex f3ef43e..d60f932 100644--- a/backend/__tests__/jobs/JobQueue.test.ts+++ b/backend/__tests__/jobs/JobQueue.test.ts@@ -341,6 +341,24 @@ describe('JobQueue', () => {expect(job.attempts).toBe(3);});+ it('fails permanently when the attempt count reaches maxAttempts (no off-by-one)', () => {+ const job: Job = {+ id: 'fail-boundary',+ name: 'FailJob',+ payload: {},+ attempts: 2,+ maxAttempts: 3,+ retryDelay: 60000,+ lastAttempt: 0,+ };++ // attempts 2 -> 3 == maxAttempts, so this is the final run, not a re-queue.+ const isPermanent = jobQueue.failJob(job);++ expect(job.attempts).toBe(3);+ expect(isPermanent).toBe(true);+ });+it('sets lastAttempt timestamp', () => {const job: Job = {id: 'fail-5',diff --git a/backend/src/jobs/JobQueue.ts b/backend/src/jobs/JobQueue.tsindex 72b1ac5..49d76f0 100644--- a/backend/src/jobs/JobQueue.ts+++ b/backend/src/jobs/JobQueue.ts@@ -96,12 +96,12 @@ class JobQueue {job.attempts++;job.lastAttempt = Date.now();- if (job.attempts <= job.maxAttempts) {+ if (job.attempts < job.maxAttempts) {this.reQueue(job);return false; // It was re-queued, not permanently failed.} else {cronLogger.error(- `Job '${job.name}' for plan '${job.payload?.planId}' failed after ${job.maxAttempts} retries.`+ `Job '${job.name}' for plan '${job.payload?.planId}' failed after ${job.attempts} attempts.`);// Clear the running jobthis.runningJob = null;diff --git a/backend/src/managers/handlers/BackupHandler.ts b/backend/src/managers/handlers/BackupHandler.tsindex 4b92b71..7b6e6af 100644--- a/backend/src/managers/handlers/BackupHandler.ts+++ b/backend/src/managers/handlers/BackupHandler.ts@@ -161,7 +161,7 @@ export class BackupHandler {const classification = classifyResticExitCode(resticExitCode);const isNonRetryable = resticExitCode !== undefined && !classification.retryable;- const attemptsExhausted = retryInfo.attempts + 1 > retryInfo.maxAttempts;+ const attemptsExhausted = retryInfo.attempts + 1 >= retryInfo.maxAttempts;const permanentlyFailed = attemptsExhausted || isNonRetryable;// Mark as failed