gmail sync: don't retry on overquota, import what we have

- OVERQUOTA from Gmail now continues to import step instead of retrying
- partial sync completion email tells user to try again in a few hours
- engine syncs handler meta to job on completion for richer notifications

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-02 20:00:45 +00:00
co-authored by Claude Opus 4.6
parent 583580eb10
commit de1baa1588
3 changed files with 48 additions and 17 deletions
+1
View File
@@ -218,6 +218,7 @@ async function runJob(job: Job) {
if (final && final.status === 'running') {
final.status = 'completed';
final.completedAt = Date.now();
final.meta = { ...final.meta, ...sharedMeta };
await writeJob(final);
console.log(`[queue] Job ${final.id} completed`);
if (final.notify !== false) await notifyCompletion(final);
+20 -10
View File
@@ -268,19 +268,29 @@ const gmailSyncHandler: JobHandler = {
await readLoop;
if (exitCode !== 0) {
console.error(`[gmail-sync] mbsync failed`);
const isOverquota = stderrBuf.includes('OVERQUOTA');
const isAuthFail = stderrBuf.includes('AUTHENTICATIONFAILED') || stderrBuf.includes('Invalid credentials');
if (isOverquota || isAuthFail) {
const emailCount = await countMaildirFiles(maildirPath);
ctx.meta.gmailSyncRecoverable = true;
ctx.meta.gmailSyncEmailCount = emailCount;
ctx.meta.gmailSyncIsAuthFail = isAuthFail;
}
throw new Error(`mbsync exited with code ${exitCode}: ${stderrBuf.slice(-500)}`);
}
console.log('[gmail-sync] mbsync completed successfully');
if (isOverquota) {
// Gmail throttled us — don't retry, just import what we have
const emailCount = await countMaildirFiles(maildirPath);
console.log(`[gmail-sync] Gmail OVERQUOTA — proceeding to import ${emailCount} downloaded emails`);
ctx.meta.gmailSyncPartial = true;
ctx.meta.gmailSyncEmailCount = emailCount;
// Fall through to import step
} else {
console.error(`[gmail-sync] mbsync failed`);
if (isAuthFail) {
const emailCount = await countMaildirFiles(maildirPath);
ctx.meta.gmailSyncRecoverable = true;
ctx.meta.gmailSyncEmailCount = emailCount;
ctx.meta.gmailSyncIsAuthFail = true;
}
throw new Error(`mbsync exited with code ${exitCode}: ${stderrBuf.slice(-500)}`);
}
} else {
console.log('[gmail-sync] mbsync completed successfully');
}
} finally {
// Always clean up config (contains password)
await unlink(configPath).catch(() => {});