NOTICE: Failed to sync: directory not found: 1TDpy53fMpSeNj8iBiI7227Vu_4Sb27c8
Google Drive API Response:
{"error":{"code":404,"message":"File not found: 1TDpy53fMpSeNj8iBiI7227Vu_4Sb27c8"}}
Root Cause
Path Resolution Failure:
Sync job attempts to resolve folder ID 1TDpy53fMpSeNj8iBiI7227Vu_4Sb27c8 to a path
Google Drive API returns 404 (folder deleted/moved/no access)
Path resolver catches error and returns wasResolved: false
Sync job logs a warning but proceeds anyway with the raw folder ID
Rclone receives invalid folder ID and fails
Error was already caught in previous fix, but path validation was missing
Why 404 Happens:
Folder was deleted from Google Drive.
Folder was moved to trash.
OAuth token doesn't have permission to access the folder.
Folder is in a shared drive requiring different API calls.
Solution
Added early validation to fail sync jobs when folder IDs cannot be resolved:
Updated:src/lib/sync/execute-sync-job.ts
// Validate path resolution - fail early if folders don't existconst sourceResolutionFailed =!resolvedSource?.resolvedPath && item.sourceId!=="root"&& item.sourceId!=="";const destResolutionFailed =!resolvedDestination?.resolvedPath && item.destinationFolderId!=="root"&& item.destinationFolderId!=="";if(sourceResolutionFailed || destResolutionFailed){const errors:string[]=[];if(sourceResolutionFailed){ errors.push(`Source folder not found or inaccessible: ${item.sourceService} folder ID "${item.sourceId}". `+`The folder may have been deleted, moved, or you may no longer have access to it.`); logger.error(`[executeSyncJob] Source path resolution failed for item ${item.id}`,{ jobId, userId, service: item.sourceService, accountId: item.sourceAccountId, folderId: item.sourceId,});}if(destResolutionFailed){ errors.push(`Destination folder not found or inaccessible: ${item.destinationService} folder ID "${item.destinationFolderId}". `+`The folder may have been deleted, moved, or you may no longer have access to it.`); logger.error(`[executeSyncJob] Destination path resolution failed for item ${item.id}`,{ jobId, userId, service: item.destinationService, accountId: item.destinationAccountId, folderId: item.destinationFolderId,});}// Throw error to skip this item and mark it as failedthrownewError(`Path resolution failed: ${errors.join(" ")}`+`Please update the sync job configuration with valid folder IDs.`);}
Impact
Before:
❌ Sync jobs proceeded with invalid folder IDs.
❌ Rclone failed with cryptic "directory not found" errors.
❌ Activity logs showed success when operations actually failed.
❌ Users had no idea what went wrong.
After:
✅ Sync jobs fail early with clear error messages.
✅ Activity logs show detailed failure reasons.
✅ Users know exactly what's wrong: "folder may have been deleted, moved, or you may no longer have access".
✅ Users get actionable guidance: "Please update the sync job configuration with valid folder IDs".
✅ Enhanced error logging with full context for debugging.
Testing
Test Case 1: Rclone Binary Path
Development (Windows):
# Should use rclone.exenode fly-rclone/server.js
# ✅ Uses rclone.exe from local directory or PATH
Production (Fly.io/Linux):
# Should use /usr/local/bin/rclone or the system PATH entry for rclonenode server.js
# ✅ Uses the rclone binary installed by Dockerfile
Test Case 2: Folder ID Validation
Valid Folder IDs:
// Should succeedsourceId:"1ABC123xyz"(exists inGoogleDrive)destinationId:"root"(always valid)// ✅ Sync proceeds normally
Invalid Folder IDs:
// Should fail with clear errorsourceId:"1TDpy53fMpSeNj8iBiI7227Vu_4Sb27c8"(404fromGoogleDrive)// ❌ Sync fails with: "Source folder not found or inaccessible..."
Deployment
Rclone Service (Fly.io)
The rclone service needs to be redeployed to pick up the new path resolution logic:
cd fly-rclone
./deploy.sh --env prod
Verification:
# Check logs for successful startupflyctl logs --app stratofusion-rclone-prod
# Should see:# ✅ "Rclone path resolved to: rclone" (not rclone.exe)
Next.js Application
The Next.js application needs to be redeployed for the sync job validation changes:
# Deploy to Vercel or your hosting platformvercel --prod
Monitoring
Key Metrics to Watch
Sync Job Success Rate
Monitor syncJobs table for status = 'failed'.
Check syncJobItems for failure patterns.
Rclone Operation Status
Monitor Fly.io logs for "rclone.exe: not found" errors (should be zero).
Check operation completion rates.
Path Resolution Failures
Monitor activity logs for "Path resolution failed" messages.
Track which folder IDs are failing most often.
Alerts to Set Up
-- Alert on high sync job failure rateSELECTCOUNT(*)FROM sync_jobs
WHEREstatus='failed'AND created_at >NOW()-INTERVAL'1 hour'HAVINGCOUNT(*)>5;-- Alert on path resolution failuresSELECT*FROM activity_logs
WHERE message LIKE'%Path resolution failed%'AND created_at >NOW()-INTERVAL'1 hour';
Future Improvements
1. Folder ID Validation UI
Add a validation step in the sync job creation UI:
Check if folder IDs exist before saving the job.
Show warning if folders are inaccessible.
Suggest alternative folders.
2. Automatic Folder ID Updates
Implement a background job to:
Detect when folder IDs become invalid.
Attempt to find the folder by name in the new location.
Update sync job configuration automatically.
Notify users of changes.
3. Better Error Recovery
Add retry logic for transient errors:
Distinguish between permanent (404) and temporary (503) errors.