Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(update): abort stale-channel apply and refresh the beta switch
guyong0c2a49d2f192
diff --git a/apps/desktop/src/main/__tests__/updateService.test.ts b/apps/desktop/src/main/__tests__/updateService.test.tsindex 0382c848f2..766e50cfa0 100644--- a/apps/desktop/src/main/__tests__/updateService.test.ts+++ b/apps/desktop/src/main/__tests__/updateService.test.ts@@ -546,6 +546,32 @@ describe('startup update relaunch safety', () => {service.stopUpdateService();}});++ it('aborts auto-relaunch when the channel changes during eligibility', async () => {+ 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;+ }),+ );+ });+ try {+ await probeStarted;+ expect(service.enableUncustomizedBetaChannel()).toBe(true);+ expect(service.getUpdateStatus()).toBe('ready');+ releaseProbe?.(false);+ await vi.waitFor(() => {+ expect(service.getUpdateStatus()).toBe('idle');+ });+ expect(service.isUpdateRelaunchImminent()).toBe(false);+ } finally {+ service.stopUpdateService();+ }+ });});describe('splash 启动下载 0% 显式广播', () => {diff --git a/apps/desktop/src/main/updateService.ts b/apps/desktop/src/main/updateService.tsindex 1a536ddd0b..dbcfa67348 100644--- a/apps/desktop/src/main/updateService.ts+++ b/apps/desktop/src/main/updateService.ts@@ -180,6 +180,22 @@ function broadcastStatus(payload: UpdateStatusPayload): void {}}+function channelSettingsWire() {+ return {+ enableBeta: readUpdateChannelSettings().enableBeta,+ isCustomized: isEnableBetaUserCustomized(),+ };+}++function broadcastChannelSettings(): void {+ const payload = channelSettingsWire();+ for (const win of BrowserWindow.getAllWindows()) {+ if (!win.isDestroyed()) {+ win.webContents.send('update-channel-settings', payload);+ }+ }+}+function setStatus(status: UpdateStatus, extra?: Partial<UpdateStatusPayload>): void {currentStatus = status;lastErrorCode = extra?.errorCode;@@ -332,6 +348,11 @@ async function requestAutoRelaunch(return { accepted: false, blockReason };}+ if (stagedPatchClearDeferred) {+ log.info('auto relaunch aborted — update channel changed during eligibility check');+ return { accepted: false, blockReason: 'not-ready' };+ }+if (!readyFilePath || !fs.existsSync(readyFilePath)) {log.info('auto relaunch aborted — staged patch disappeared during eligibility check');return { accepted: false, blockReason: 'not-ready' };@@ -582,6 +603,11 @@ function isUpdateApplyCommitted(): boolean {return isRelaunching || autoRelaunchInProgress;}+function invalidateInFlightChannelDownloads(): void {+ updateChannelEpoch += 1;+ clearCachedManifest();+}+function flushDeferredStagedPatchClear(): void {if (!stagedPatchClearDeferred) return;if (isUpdateApplyCommitted() || autoRelaunchDecisionDepth > 0) return;@@ -603,6 +629,8 @@ function clearStagedPatch(): void {}if (autoRelaunchDecisionDepth > 0) {stagedPatchClearDeferred = true;+ // 立刻作废旧渠道 in-flight 下载,避免下载完成后又把旧补丁写成 ready。+ invalidateInFlightChannelDownloads();log.info('deferring staged patch clear until auto-relaunch eligibility settles');return;}@@ -612,12 +640,7 @@ function clearStagedPatch(): void {readyVersion = undefined;readyFilePath = undefined;removePatchInfo();- // 递增代际:任何 in-flight 的 checkForUpdate 在写回 patch 前都会看到代际变化,- // 从而放弃本次(基于旧渠道的)下载产物,不把 beta patch 重新落盘。- updateChannelEpoch += 1;- // 切渠道后旧渠道的 manifest 缓存作废:否则 agent 二进制 prepare 先- // getCachedManifest() 会继续按旧渠道的版本号/下载地址安装资产。- clearCachedManifest();+ invalidateInFlightChannelDownloads();// downloading 也要重置:opt-out 若发生在「首次 beta 下载进行中」,status 仍是// downloading;不 reset 的话,in-flight 下载完成后 discard 分支只是 `return 'idle'`// 而不 setStatus,update-get-status / update-check-now 会永远卡在 downloading。@@ -1296,10 +1319,7 @@ export function initUpdateService(): void {// 更新设置或重启应用(旧 update-auto-settings 没断言是历史债,不构成豁免)。ipcMain.handle('update-channel-settings-get', (event) => {assertTrustedAppRendererEvent(event);- return {- enableBeta: readUpdateChannelSettings().enableBeta,- isCustomized: isEnableBetaUserCustomized(),- };+ return channelSettingsWire();});ipcMain.handle('update-channel-settings-set', (event, payload: unknown) => {@@ -1321,10 +1341,7 @@ export function initUpdateService(): void {if (wasBeta !== next) {clearStagedPatch();}- return {- enableBeta: readUpdateChannelSettings().enableBeta,- isCustomized: isEnableBetaUserCustomized(),- };+ return channelSettingsWire();});ipcMain.handle('update-channel-settings-reset', (event) => {@@ -1335,10 +1352,7 @@ export function initUpdateService(): void {if (wasBeta) {clearStagedPatch();}- return {- enableBeta: readUpdateChannelSettings().enableBeta,- isCustomized: isEnableBetaUserCustomized(),- };+ return channelSettingsWire();});// 打开 beta 前的预检:探测 manifest-{platform}-beta.json 是否可达。@@ -1529,6 +1543,7 @@ export function enableUncustomizedBetaChannel(): boolean {if (wrote && !wasBeta) {// 真正开始应用时 clearStagedPatch 会跳过;资格检查中会记下,结束后再补清。clearStagedPatch();+ broadcastChannelSettings();}return wrote;}diff --git a/apps/desktop/src/preload/preload.ts b/apps/desktop/src/preload/preload.tsindex 11590fed55..770a69ac5b 100644--- a/apps/desktop/src/preload/preload.ts+++ b/apps/desktop/src/preload/preload.ts@@ -385,6 +385,7 @@ function createIpcFanOut(channel: string): FanOut {// Stage 2 C1: cc-agent:* push channel fanout 全部退役 (renderer 已切到 maker:event 等),// 老 7 个 fanOut + fanOutUserMessagePersisted 一起拿掉。const fanOutUpdateStatus = createIpcFanOut('update-status');+const fanOutUpdateChannelSettings = createIpcFanOut('update-channel-settings');const fanOutOrcaWorkerChanged = createIpcFanOut('maker:orca:worker-changed');// 右侧栏独立子窗口(RSB window)状态 / 上下文 / 命令推送const fanOutRsbWindowStateChanged = createIpcFanOut('maker:rsb-window:state-changed');@@ -3725,6 +3726,7 @@ contextBridge.exposeInMainWorld('electronAPI', {// ── App Update (F2/F4) ──onUpdateStatus: fanOutUpdateStatus,+ onUpdateChannelSettings: fanOutUpdateChannelSettings,checkForUpdate: (): Promise<{result:diff --git a/apps/desktop/src/renderer/hooks/useBetaChannelSettings.ts b/apps/desktop/src/renderer/hooks/useBetaChannelSettings.tsindex d18eb46ee5..2626cccd64 100644--- a/apps/desktop/src/renderer/hooks/useBetaChannelSettings.ts+++ b/apps/desktop/src/renderer/hooks/useBetaChannelSettings.ts@@ -46,8 +46,12 @@ export function useBetaChannelSettings(): {.catch(() => {if (!cancelled) setState((current) => ({ ...current, loading: false }));});+ const unsubscribe = window.electronAPI.onUpdateChannelSettings((payload) => {+ if (!cancelled) setState(normalize(payload));+ });return () => {cancelled = true;+ unsubscribe();};}, []);diff --git a/apps/desktop/src/renderer/vite-env.d.ts b/apps/desktop/src/renderer/vite-env.d.tsindex dff29509a2..b2dcd91dd8 100644--- a/apps/desktop/src/renderer/vite-env.d.ts+++ b/apps/desktop/src/renderer/vite-env.d.ts@@ -3435,6 +3435,9 @@ interface ElectronAPI {relaunchForChannelChange: () => Promise<void>;/** 打开 beta 前预检:探测 beta manifest 是否可达(HTTP 200)。 */probeBetaChannel: () => Promise<{ available: boolean }>;+ onUpdateChannelSettings: (+ callback: (payload: { enableBeta: boolean; isCustomized?: boolean }) => void,+ ) => () => void;setUpdateRelaunchTheme: (theme: 'light' | 'dark') => void;// E4D 毛玻璃:family 切换/启动通知 main 开关 vibrancy(仅 CINDY 透壁纸)theme: { applyVibrancy: (familyId: string, isDark: boolean) => void };