Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(update): 旁移损坏的重启记录时连同残留备份一起保留

Dashcc71585f215a
diff --git a/apps/desktop/src/main/agent-app-update/__tests__/restartRecords.test.ts b/apps/desktop/src/main/agent-app-update/__tests__/restartRecords.test.ts
index ad2854731d..2a5f9516e8 100644
--- a/apps/desktop/src/main/agent-app-update/__tests__/restartRecords.test.ts
+++ b/apps/desktop/src/main/agent-app-update/__tests__/restartRecords.test.ts
@@ -51,6 +51,17 @@ describe('restart records file', () => {
expect(fs.readFileSync(path.join(dir, aside[0]!), 'utf8')).toBe('{"records": [ broken');
});
+ it('keeps a leftover backup next to the moved-aside file instead of overwriting it', () => {
+ fs.writeFileSync(file, '{"records": [ broken');
+ const backup = JSON.stringify({ records: [record('in-backup')] });
+ fs.writeFileSync(`${file}.bak`, backup);
+ addRestartRecord(file, record('new'));
+ expect(listRestartRecords(file).map((entry) => entry.requestId)).toEqual(['new']);
+ const asideBackup = fs.readdirSync(dir).filter((name) => /\.corrupt-\d+\.bak$/.test(name));
+ expect(asideBackup).toHaveLength(1);
+ expect(fs.readFileSync(path.join(dir, asideBackup[0]!), 'utf8')).toBe(backup);
+ });
+
it('leaves a corrupt file untouched when only reading or removing', () => {
fs.writeFileSync(file, 'not json');
expect(listRestartRecords(file)).toEqual([]);
diff --git a/apps/desktop/src/main/agent-app-update/restartRecords.ts b/apps/desktop/src/main/agent-app-update/restartRecords.ts
index 4eb8262292..eb04529359 100644
--- a/apps/desktop/src/main/agent-app-update/restartRecords.ts
+++ b/apps/desktop/src/main/agent-app-update/restartRecords.ts
@@ -60,6 +60,9 @@ function readRecords(file: string, mode: 'lenient' | 'before-write'): AgentAppUp
// destroyed, and a damaged file cannot block every later update either.
// A failed move throws, which cancels the restart.
const aside = `${file}.corrupt-${Date.now()}`;
+ // A leftover `.bak` goes with it: the next atomic write would otherwise restore
+ // and then replace it, losing whatever records that backup still holds.
+ if (fs.existsSync(`${file}.bak`)) fs.renameSync(`${file}.bak`, `${aside}.bak`);
fs.renameSync(file, aside);
log.warn('agent app update marker was corrupt; moved aside', { path: maskPath(aside) });
} else {