Prevent queue loss during app updates

- Increase quit timeout from 900ms to 5000ms to ensure pending saves complete
- Add persistNowSync() called before update install to flush queue to disk
- Remove blockAllPersistence from shutdown save condition — shutdown must
  always persist to prevent data loss across restarts
- Add temp file recovery as last resort when both primary and backup
  session files are corrupted

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Sucukdeluxe
2026-03-26 19:34:48 +01:00
co-authored by Claude Opus 4.6
parent ffb48a8883
commit 5aeab9ecad
4 changed files with 606 additions and 570 deletions
+19 -1
View File
@@ -881,7 +881,25 @@ export function loadSession(paths: StoragePaths): SessionState {
return backup;
}
logger.error("Session konnte nicht geladen werden (auch Backup fehlgeschlagen)");
// Last resort: try to recover from temp files left by interrupted writes
for (const kind of ["sync", "async"] as const) {
const tmpPath = sessionTempPath(paths.sessionFile, kind);
if (fs.existsSync(tmpPath)) {
const tmpSession = readSessionFile(tmpPath);
if (tmpSession && Object.keys(tmpSession.packages).length > 0) {
logger.warn(`Session aus temporaerer Datei wiederhergestellt: ${tmpPath} (${Object.keys(tmpSession.packages).length} Pakete)`);
try {
const payload = JSON.stringify({ ...tmpSession, updatedAt: Date.now() });
fs.writeFileSync(paths.sessionFile, payload, "utf8");
} catch {
// ignore restore write failure
}
return tmpSession;
}
}
}
logger.error("Session konnte nicht geladen werden (Primary, Backup und Temp-Dateien fehlgeschlagen)");
return emptySession();
}