Date: October 18, 2025
Status: โ FIXED
Branch:fix/backups-fail-on-vercelCommit:ee9a0302
๐ด Problem Summary
After deploying to Vercel Production environment (following the resolution of the Preview vs Production cron job issue), scheduled backup cron jobs were executing successfully but creating empty directories instead of copying files.
Observed Behavior
โ Vercel cron jobs triggering on schedule (every 5 minutes).
โ /api/cron/execute-backups endpoint being called.
โ Backup jobs marked as "running" in database.
โ Backup directories created in destination service.
โ Backup directories were empty - no files copied.
โ Jobs marked as "failed" with error: Unexpected token '<', "<!DOCTYPE "... is not valid JSON.
๐ Root Cause Analysis
Investigation Steps
Ran investigation script:
node scripts/investigate-failed-backup.mjs
Result: Found failed jobs with error Unexpected token '<', "<!DOCTYPE "... is not valid JSON
Analyzed error pattern:
This error occurs when code expects JSON but receives HTML.
Typically happens when fetching a non-existent endpoint (404 page).
Examined backup execution code:
File: src/app/api/jobs/[id]/execute/route.ts.
Line 157: const batchRes = await fetch(\${process.env.NEXT_PUBLIC_SITE_URL}${batchCopyPath}`, ...)`.
Line 114: Similar pattern for create-folder endpoint.
Identified the issue:
process.env.NEXT_PUBLIC_SITE_URL is undefined in server-side code.
The NEXT_PUBLIC_ prefix means the variable is for client-side code only.
In server-side code, NEXT_PUBLIC_* variables are not available via process.env.
This caused the fetch URL to be undefined/api/rclone/batch-copy (invalid URL).
Invalid URL resulted in a 404 HTML error page instead of JSON response.
Why This Wasn't Caught Earlier
One-time backups worked because they were triggered from the client-side UI.
Client-side code has access to NEXT_PUBLIC_SITE_URL.