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): 有更新版本正在覆盖下载时不按确认版本重启

Dashb8a8736fa19b
diff --git a/apps/desktop/src/main/__tests__/updateService.test.ts b/apps/desktop/src/main/__tests__/updateService.test.ts
index 04fbc6974f..8d47e8c291 100644
--- a/apps/desktop/src/main/__tests__/updateService.test.ts
+++ b/apps/desktop/src/main/__tests__/updateService.test.ts
@@ -606,6 +606,39 @@ describe('agent-facing managed app update check', () => {
}
});
+ it('never restarts into the confirmed version while a newer one is superseding it', async () => {
+ let finishSecond: (() => void) | undefined;
+ download.mockImplementation(({ targetPath }: { targetPath: string }) => {
+ const write = () => {
+ fs.mkdirSync(path.dirname(targetPath), { recursive: true });
+ fs.writeFileSync(targetPath, 'update');
+ return { path: targetPath, size: 123 };
+ };
+ if (download.mock.calls.length === 1) return Promise.resolve(write());
+ return new Promise((resolve) => { finishSecond = () => resolve(write()); });
+ });
+ const exitSpy = vi.spyOn(process, 'exit').mockImplementation((() => undefined) as never);
+ const service = await freshUpdateService('darwin');
+ try {
+ const result = await service.applyConfirmedAppUpdateForAgent({
+ expectedVersion: '0.0.65',
+ beforeRelaunch: async () => {
+ // A background poll starts downloading 0.0.66 over the staged 0.0.65.
+ void service.checkForUpdate(updateManifest('0.0.66'));
+ await vi.waitFor(() => { expect(download).toHaveBeenCalledTimes(2); });
+ return true;
+ },
+ });
+ expect(result).toMatchObject({ status: 'failed', errorCode: 'version_changed', stagedVersion: '0.0.66' });
+ expect(spawnProcess).not.toHaveBeenCalled();
+ expect(exitSpy).not.toHaveBeenCalled();
+ finishSecond?.();
+ } finally {
+ service.stopUpdateService();
+ exitSpy.mockRestore();
+ }
+ });
+
it('does not relaunch when the download fails or the build is unsupported', async () => {
download.mockRejectedValue(new Error('network'));
const service = await freshUpdateService('darwin');
diff --git a/apps/desktop/src/main/updateService.ts b/apps/desktop/src/main/updateService.ts
index a32be49f5d..806fcfe858 100644
--- a/apps/desktop/src/main/updateService.ts
+++ b/apps/desktop/src/main/updateService.ts
@@ -2195,15 +2195,20 @@ export async function applyConfirmedAppUpdateForAgent(options: {
/** Re-checked inside the relaunch, after Subagent reclaim and right before the updater spawns. */
beforeSpawn?: () => boolean;
}): Promise<AgentConfirmedAppUpdateResult> {
- const versionChanged = (): AgentConfirmedAppUpdateResult | null =>
- options.expectedVersion && readyVersion !== options.expectedVersion
- ? {
- status: 'failed',
- reason: `当前渠道的新版本是 ${readyVersion ?? '未知版本'},与确认的 ${options.expectedVersion} 不同,本次没有安装;请重新发起更新。`,
- errorCode: 'version_changed',
- ...(readyVersion ? { stagedVersion: readyVersion } : {}),
- }
- : null;
+ // The single version rule for every checkpoint: the staged patch is the
+ // confirmed version and no newer one is being downloaded over it. Like the
+ // built-in banner, never restart while superseding.
+ const versionChanged = (): AgentConfirmedAppUpdateResult | null => {
+ if (!options.expectedVersion) return null;
+ const current = currentStatus === 'superseding' ? downloadingVersion : readyVersion;
+ if (current === options.expectedVersion && currentStatus !== 'superseding') return null;
+ return {
+ status: 'failed',
+ reason: `当前渠道的新版本是 ${current ?? '未知版本'},与确认的 ${options.expectedVersion} 不同,本次没有安装;请重新发起更新。`,
+ errorCode: 'version_changed',
+ ...(current ? { stagedVersion: current } : {}),
+ };
+ };
const unsupported = agentUpdateUnsupportedReason();
if (unsupported) return { status: 'failed', reason: unsupported, errorCode: 'unsupported' };
// A relaunch already under way (Settings banner or idle auto-install) only
@@ -2226,12 +2231,12 @@ export async function applyConfirmedAppUpdateForAgent(options: {
if (isRelaunching || autoRelaunchInProgress) {
return versionChanged() ?? { status: 'relaunching', targetVersion: readyVersion };
}
- if (currentStatus !== 'ready' || !readyVersion) {
- return { status: 'failed', reason: '已下载的更新不再可用,请重新检查更新。', errorCode: 'not_ready' };
- }
// A background check may have superseded the staged patch during the wait.
const changedBeforeRelaunch = versionChanged();
if (changedBeforeRelaunch) return changedBeforeRelaunch;
+ if (currentStatus !== 'ready' || !readyVersion) {
+ return { status: 'failed', reason: '已下载的更新不再可用,请重新检查更新。', errorCode: 'not_ready' };
+ }
const targetVersion = readyVersion;
// Both bindings are re-checked once more inside the relaunch, after its
// Subagent reclaim wait: the confirmed version and the caller's condition.
diff --git a/docs/product-rules/agent-app-update.md b/docs/product-rules/agent-app-update.md
index 7e4bb2edc9..ab39672d33 100644
--- a/docs/product-rules/agent-app-update.md
+++ b/docs/product-rules/agent-app-update.md
@@ -17,7 +17,7 @@ Agent 只能反复引导用户去点「检查更新」;那次收紧的起因
- 确认后走「设置 → 关于」同一条更新状态机:`checkForUpdate()` 下载(单飞,重复调用不重复下载),
等调用任务这轮回复结束(最多 2 分钟)后 `executeRelaunch()` 重启;Windows / Linux 会等更新器真正启动
(5 秒内成功即退出、失败即写回原因)再收尾。确认卡总是写明具体目标版本(后台正在下载时用实际下载的版本;读不到就不弹卡),安装只认卡片上确认的版本:
- 渠道期间换了新版本时不安装,提示重新发起。安装绑定确认时的账号:退出或切换账号会取消重启,
+ 渠道期间换了新版本、或有更新的版本正在下载覆盖时(与内置横幅一致,不在 superseding 时重启)不安装,提示重新发起。安装绑定确认时的账号:退出或切换账号会取消重启,
标记与结果消息只写回该账号,绝不写进后来的账号。拒绝、超时或卡片未送达都不下载、
不重启。同一时刻只有一个安装请求;确认卡等待中或已开始安装时再次调用直接返回当前状态。
- 重启前在账号私有目录写一份标记;新版本启动、该账号数据库就绪后,把结果(新版本号或「仍是旧版本」)