Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(update): 采用已在进行的重启前也经过最后一道检查;通知按身份移除
Dash20298893241c
diff --git a/apps/desktop/src/main/__tests__/updateService.test.ts b/apps/desktop/src/main/__tests__/updateService.test.tsindex 8d47e8c291..6f161c06c1 100644--- a/apps/desktop/src/main/__tests__/updateService.test.ts+++ b/apps/desktop/src/main/__tests__/updateService.test.ts@@ -594,10 +594,17 @@ describe('agent-facing managed app update check', () => {expect(await service.checkForUpdate()).toBe('ready');await vi.waitFor(() => { expect(spawnProcess).toHaveBeenCalledOnce(); });const beforeRelaunch = vi.fn(async () => true);- await expect(service.applyConfirmedAppUpdateForAgent({ expectedVersion: '0.0.66', beforeRelaunch }))+ const beforeSpawn = vi.fn(() => true);+ await expect(service.applyConfirmedAppUpdateForAgent({ expectedVersion: '0.0.66', beforeRelaunch, beforeSpawn })).resolves.toMatchObject({ status: 'failed', errorCode: 'version_changed', stagedVersion: '0.0.65' });- await expect(service.applyConfirmedAppUpdateForAgent({ expectedVersion: '0.0.65', beforeRelaunch }))+ expect(beforeSpawn).not.toHaveBeenCalled();+ // Adopting it still passes the last gate, where the caller records its restart.+ await expect(service.applyConfirmedAppUpdateForAgent({ expectedVersion: '0.0.65', beforeRelaunch, beforeSpawn })).resolves.toEqual({ status: 'relaunching', targetVersion: '0.0.65' });+ expect(beforeSpawn).toHaveBeenCalledOnce();+ await expect(service.applyConfirmedAppUpdateForAgent({+ expectedVersion: '0.0.65', beforeRelaunch, beforeSpawn: () => false,+ })).resolves.toMatchObject({ status: 'failed', errorCode: 'relaunch_cancelled' });expect(beforeRelaunch).not.toHaveBeenCalled();expect(spawnProcess).toHaveBeenCalledOnce();} finally {diff --git a/apps/desktop/src/main/agent-app-update/__tests__/agentAppUpdateService.test.ts b/apps/desktop/src/main/agent-app-update/__tests__/agentAppUpdateService.test.tsindex 65385a54eb..6f9470cf82 100644--- a/apps/desktop/src/main/agent-app-update/__tests__/agentAppUpdateService.test.ts+++ b/apps/desktop/src/main/agent-app-update/__tests__/agentAppUpdateService.test.ts@@ -328,6 +328,35 @@ describe('Agent app update install', () => {expect(harness.deps.requestHostPermission).toHaveBeenCalledTimes(2);});+ it('never drops an unrelated notice when flushes overlap', async () => {+ const harness = setup({+ apply: vi.fn(async ({ beforeRelaunch }) => {+ harness.switchOwner({ ownerId: 'owner-b' });+ await beforeRelaunch();+ return { status: 'failed' as const, reason: 'x', errorCode: 'relaunch_cancelled' };+ }),+ });+ // Two failed installs from two tasks, both queued while their account is away.+ await harness.service.install(caller);+ await flush();+ harness.switchOwner(ownerA);+ // The second request's opportunistic retry hits a busy database, so task-1 stays queued.+ vi.mocked(harness.deps.notify).mockRejectedValueOnce(new Error('database busy'));+ await harness.service.install({ sessionId: 'task-2', sessionInstanceId: 'instance-2' });+ await flush();+ harness.switchOwner(ownerA);+ vi.mocked(harness.deps.notify).mockClear();+ await Promise.all([+ harness.service.deliverPendingResult(),+ harness.service.deliverPendingResult(),+ ]);+ const delivered = new Set(vi.mocked(harness.deps.notify).mock.calls.map((call) => call[1]));+ expect(delivered).toEqual(new Set(['task-1', 'task-2']));+ vi.mocked(harness.deps.notify).mockClear();+ await harness.service.deliverPendingResult();+ expect(harness.deps.notify).not.toHaveBeenCalled();+ });+it('writes the restart record only at the last gate, and clears it if the spawn then fails', async () => {const harness = setup({apply: vi.fn(async ({ beforeRelaunch, beforeSpawn }) => {diff --git a/apps/desktop/src/main/agent-app-update/agentAppUpdateService.ts b/apps/desktop/src/main/agent-app-update/agentAppUpdateService.tsindex d1e1a3f5a1..1a6b96821c 100644--- a/apps/desktop/src/main/agent-app-update/agentAppUpdateService.ts+++ b/apps/desktop/src/main/agent-app-update/agentAppUpdateService.ts@@ -276,6 +276,8 @@ export function createAgentAppUpdateService(deps: AgentAppUpdateDeps) {};const flushNotices = async () => {for (const notice of [...pendingNotices]) {+ // A concurrent flush may already have delivered it.+ if (!pendingNotices.includes(notice)) continue;// Never write into whichever account replaced the one that confirmed.if (!deps.isOwnerCurrent(notice.owner)) continue;try {@@ -284,7 +286,9 @@ export function createAgentAppUpdateService(deps: AgentAppUpdateDeps) {deps.logger?.warn?.('agent app update notice failed; will retry', { error: String(error) });continue;}- pendingNotices.splice(pendingNotices.indexOf(notice), 1);+ // Identity-based removal: overlapping flushes never remove another notice.+ const index = pendingNotices.indexOf(notice);+ if (index >= 0) pendingNotices.splice(index, 1);}};diff --git a/apps/desktop/src/main/updateService.ts b/apps/desktop/src/main/updateService.tsindex 806fcfe858..1f7673ad13 100644--- a/apps/desktop/src/main/updateService.ts+++ b/apps/desktop/src/main/updateService.ts@@ -2209,13 +2209,20 @@ export async function applyConfirmedAppUpdateForAgent(options: {...(current ? { stagedVersion: current } : {}),};};+ const relaunchCancelled: AgentConfirmedAppUpdateResult = {+ status: 'failed', reason: '更新已下载,但本次没有重启。', errorCode: 'relaunch_cancelled',+ };+ // A relaunch already under way (Settings banner or idle auto-install) counts+ // as this install only for the confirmed version, and only after the same+ // last gate a spawn of our own would pass (the caller records its restart there).+ const adoptRelaunchUnderWay = (): AgentConfirmedAppUpdateResult =>+ versionChanged()+ ?? (options.beforeSpawn?.() === false+ ? relaunchCancelled+ : { status: 'relaunching', targetVersion: readyVersion });const unsupported = agentUpdateUnsupportedReason();if (unsupported) return { status: 'failed', reason: unsupported, errorCode: 'unsupported' };- // A relaunch already under way (Settings banner or idle auto-install) only- // counts as this install when it applies the confirmed version.- if (isRelaunching || autoRelaunchInProgress) {- return versionChanged() ?? { status: 'relaunching', targetVersion: readyVersion };- }+ if (isRelaunching || autoRelaunchInProgress) return adoptRelaunchUnderWay();if (currentStatus !== 'ready') {const result = await checkForUpdate();if (result !== 'ready') {@@ -2224,13 +2231,8 @@ export async function applyConfirmedAppUpdateForAgent(options: {}const changedAfterDownload = versionChanged();if (changedAfterDownload) return changedAfterDownload;- if (!await options.beforeRelaunch()) {- return { status: 'failed', reason: '更新已下载,但本次没有重启。', errorCode: 'relaunch_cancelled' };- }- // Same rule for a relaunch that started during the wait.- if (isRelaunching || autoRelaunchInProgress) {- return versionChanged() ?? { status: 'relaunching', targetVersion: readyVersion };- }+ if (!await options.beforeRelaunch()) return relaunchCancelled;+ if (isRelaunching || autoRelaunchInProgress) return adoptRelaunchUnderWay();// A background check may have superseded the staged patch during the wait.const changedBeforeRelaunch = versionChanged();if (changedBeforeRelaunch) return changedBeforeRelaunch;@@ -2243,9 +2245,8 @@ export async function applyConfirmedAppUpdateForAgent(options: {let cancelledBeforeSpawn: AgentConfirmedAppUpdateResult | null = null;await executeRelaunch(resolvedRelaunchTheme, {shouldProceed: () => {- cancelledBeforeSpawn = versionChanged() ?? (options.beforeSpawn?.() === false- ? { status: 'failed', reason: '更新已下载,但本次没有重启。', errorCode: 'relaunch_cancelled' }- : null);+ cancelledBeforeSpawn = versionChanged()+ ?? (options.beforeSpawn?.() === false ? relaunchCancelled : null);return cancelledBeforeSpawn === null;},});