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(desktop): roll back migration marker when receipt commit fails

Yuewei-LLdc8c6c05d1a6
diff --git a/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts b/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts
index 2c027c42e2..ffc7908501 100644
--- a/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts
+++ b/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts
@@ -257,8 +257,13 @@ export class GhostInstallReceiptStore {
// 代之以 per-id 迁移标记:receipt 初次落账时同步写 `.migrated-<id>` 哨兵文件。
// coordinator 扫描时见到”无 receipt + 有哨兵”就跳过 —— 这是新模型装的插件、
// 不是 legacy,删掉 receipt 不能骗到一次从可变目录重铸批准。
+ //
+ // 标记写入在 receipt 之前,receipt 写失败必须回滚标记,避免留一个
+ // 无 receipt 的哨兵把合法 legacy 插件永久挡在迁移之外。
+ let markerWritten = false;
if (!this.hasMigrationLedger()) {
await this.ensureMigrationMarker(receipt.id);
+ markerWritten = true;
}
const target = this.receiptPath(receipt.id);
const temp = path.join(
@@ -272,6 +277,11 @@ export class GhostInstallReceiptStore {
mode: 0o600,
});
await fs.promises.rename(temp, target);
+ } catch (error) {
+ if (markerWritten) {
+ await this.removeMigrationMarker(receipt.id).catch(() => undefined);
+ }
+ throw error;
} finally {
await fs.promises.rm(temp, { force: true }).catch(() => undefined);
}
@@ -541,6 +551,11 @@ export class GhostInstallReceiptStore {
}
}
+ /** 回滚 per-id 迁移标记(receipt 写入失败时调用)。 */
+ async removeMigrationMarker(id: string): Promise<void> {
+ await fs.promises.rm(this.migrationMarkerPath(id), { force: true });
+ }
+
async writeMigrationLedger(ledger: GhostLegacyMigrationLedger): Promise<void> {
const root = this.rootDir();
await fs.promises.mkdir(root, { recursive: true });