Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(update): do not restore a stale patch after channel change
guyonga4fb92e35187
diff --git a/apps/desktop/src/main/__tests__/updateService.test.ts b/apps/desktop/src/main/__tests__/updateService.test.tsindex f1f3545626..d9df9c9aef 100644--- a/apps/desktop/src/main/__tests__/updateService.test.ts+++ b/apps/desktop/src/main/__tests__/updateService.test.ts@@ -734,6 +734,49 @@ describe('startup update relaunch safety', () => {service.stopUpdateService();}});++ it('does not restore a superseded patch after a channel change', async () => {+ const { DownloadError } = await import('../downloader/index');+ const service = await bootWithStagedPatch({ enabled: true });+ let releaseProbe: ((busy: boolean) => void) | undefined;+ const probeStarted = new Promise<void>((resolveStarted) => {+ service.setUpdateAutoRelaunchBusyProbe(+ () =>+ new Promise<boolean>((resolveProbe) => {+ resolveStarted();+ releaseProbe = resolveProbe;+ }),+ );+ });+ let failDownload: ((error: Error) => void) | undefined;+ download.mockImplementation(() => new Promise((_, reject) => {+ failDownload = reject;+ }));+ try {+ await probeStarted;+ await expect(service.enableUncustomizedBetaChannel()).resolves.toBe(true);+ service.setUpdateAutoRelaunchBusyProbe(() => true);+ readUpdateChannelSettings.mockReturnValue({+ enableBeta: true,+ orgDefaultEnableBeta: true,+ });+ fetchManifest.mockResolvedValue(updateManifest('0.0.66'));+ const checkPromise = service.checkForUpdate();+ await vi.waitFor(() => {+ expect(failDownload).toBeTypeOf('function');+ });+ releaseProbe?.(true);+ await vi.waitFor(() => {+ expect(service.getUpdateStatus()).toBe('superseding');+ });+ failDownload?.(new DownloadError('NETWORK', 'boom'));+ await expect(checkPromise).resolves.toBe('idle');+ expect(service.getUpdateStatus()).toBe('idle');+ expect(fs.existsSync(path.join(TEST_USER_DATA, 'updates', 'patch-info.json'))).toBe(false);+ } finally {+ service.stopUpdateService();+ }+ });});describe('splash 启动下载 0% 显式广播', () => {diff --git a/apps/desktop/src/main/updateService.ts b/apps/desktop/src/main/updateService.tsindex 7c87b248d3..9e0fb7a36d 100644--- a/apps/desktop/src/main/updateService.ts+++ b/apps/desktop/src/main/updateService.ts@@ -668,16 +668,9 @@ function flushDeferredStagedPatchClear(): void {if (!deferredStagedPatch) return;if (isUpdateApplyCommitted() || autoRelaunchDecisionDepth > 0) return;const stale = deferredStagedPatch;- deferredStagedPatch = undefined;- if (isCurrentPatchNewerThanDeferred(stale)) {- log.info('keeping newer staged patch after deferred channel-change clear');- if (stale.path && stale.path !== readyFilePath) {- try { fs.unlinkSync(stale.path); } catch { /* ignore */ }- }- return;- }if (currentStatus === 'downloading' || currentStatus === 'superseding') {// 新渠道下载还在飞:不要再推进代际,也不要删同路径 dest。+ // 标记先留着——下载失败若把旧补丁快照写回来,后续还能再清。if (readyChannelEpoch === stale.epoch) {readyVersion = undefined;readyFilePath = undefined;@@ -685,6 +678,14 @@ function flushDeferredStagedPatchClear(): void {}return;}+ deferredStagedPatch = undefined;+ if (isCurrentPatchNewerThanDeferred(stale)) {+ log.info('keeping newer staged patch after deferred channel-change clear');+ if (stale.path && stale.path !== readyFilePath) {+ try { fs.unlinkSync(stale.path); } catch { /* ignore */ }+ }+ return;+ }discardStagedPatchFiles();}@@ -1077,9 +1078,20 @@ async function doCheckForUpdate(manifestOverride?: Manifest | null): Promise<Che// readyFilePath 全都没动过,直接重新广播 ready 让 banner 按钮从 loading 恢复成可点。// 下一次 30min 轮询会再次尝试 b。if (wasReady) {- // 下载期间用户切渠道:旧 patch 已被 clearStagedPatch 清掉,不能恢复。- if (channelEpochAtStart !== updateChannelEpoch) {+ // 下载期间用户切渠道:旧 patch 已被作废,不能从局部快照恢复。+ // 代际在下载开始前就可能已经推进过,所以还要看旧补丁自己的代际。+ const staleChannelPatch =+ channelEpochAtStart !== updateChannelEpoch ||+ (previousReadyChannelEpoch != null && previousReadyChannelEpoch !== updateChannelEpoch);+ if (staleChannelPatch) {log.info('update channel changed during superseding download — not restoring stale patch');+ if (previousReadyFilePath) {+ try { fs.unlinkSync(previousReadyFilePath); } catch { /* ignore */ }+ }+ readyVersion = undefined;+ readyFilePath = undefined;+ readyChannelEpoch = undefined;+ removePatchInfo();setStatus('idle');return 'idle';}