fix(cron): use effectiveStatus for recurring job backoff scheduling

Missed substitution on line 420: the recurring-job backoff branch still
checked result.status instead of effectiveStatus, so a job that delivered
successfully (delivered=true) could still have its nextRunAtMs pushed out
by error backoff even though all status fields showed ok.

Also adds a nextRunAtMs assertion for the delivered=true override case.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Barry 2026-03-19 07:35:38 -04:00
parent defdbe9110
commit 4742ca7c4a
2 changed files with 28 additions and 1 deletions

View File

@ -137,4 +137,31 @@ describe("applyJobResult delivered=true overrides error status (#50170)", ()
expect(job.state.lastRunStatus).toBe("ok");
expect(job.state.consecutiveErrors).toBe(0);
});
it("does not apply error backoff to nextRunAtMs for recurring job when delivered=true overrides error", () => {
// Use a high-frequency schedule so the backoff (30 s minimum) would
// exceed the natural interval and push nextRunAtMs out if applied.
const schedule = { kind: "every" as const, intervalMs: 5_000 };
const jobError = createJob({ schedule });
const jobOk = createJob({ id: "test-job-2", schedule });
const stateError = createMockState([jobError]);
const stateOk = createMockState([jobOk]);
applyJobResult(stateError, jobError, {
...BASE_RESULT,
status: "error",
error: "Warning: Canvas failed",
delivered: true,
});
applyJobResult(stateOk, jobOk, {
...BASE_RESULT,
status: "ok",
delivered: true,
});
// Both should schedule the same natural next run — no backoff on delivered=true.
expect(jobError.state.nextRunAtMs).toBe(jobOk.state.nextRunAtMs);
});
});

View File

@ -417,7 +417,7 @@ export function applyJobResult(
);
}
}
} else if (result.status === "error" && job.enabled) {
} else if (effectiveStatus === "error" && job.enabled) {
// Apply exponential backoff for errored jobs to prevent retry storms.
const backoff = errorBackoffMs(job.state.consecutiveErrors ?? 1);
let normalNext: number | undefined;