From 7d2ce5fcac067f590026f8bb237480cb157cc90c Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 16 Nov 2026 03:19:58 +0000 Subject: [PATCH 1/7] test(desktop): an update download picks up a release published since the last check Fails on main: downloadAvailableUpdate calls electronUpdater.downloadUpdate without checking first, so it downloads whatever the last background check found (#37462). Co-Authored-By: Claude Opus 5.5 --- .../src/updates/DesktopUpdates.test.ts | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/apps/desktop/src/updates/DesktopUpdates.test.ts b/apps/desktop/src/updates/DesktopUpdates.test.ts index 53bd956ca6da7..f5467bde45246 100644 --- a/apps/desktop/src/updates/DesktopUpdates.test.ts +++ b/apps/desktop/src/updates/DesktopUpdates.test.ts @@ -494,6 +494,37 @@ describe("DesktopUpdates", () => { ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer))); }); + it.effect("downloads the newest release published since the last check", () => { + // electron-updater downloads the release its last checkForUpdates found. + let published = "1.2.4"; + let lastChecked: string | undefined; + const harness = makeHarness({ + checkForUpdates: Effect.sync(() => { + lastChecked = published; + harness.emit("update-available", { version: published }); + }), + downloadUpdate: Effect.sync(() => { + harness.emit("update-downloaded", { version: lastChecked }); + }), + }); + + return Effect.scoped( + Effect.gen(function* () { + const updates = yield* DesktopUpdates.DesktopUpdates; + yield* updates.configure; + yield* updates.check("poll"); + yield* flushCallbacks; + assert.equal((yield* updates.getState).availableVersion, "1.2.4"); + + published = "1.2.5"; + const result = yield* updates.download; + yield* flushCallbacks; + assert.isTrue(result.completed); + assert.equal((yield* updates.getState).downloadedVersion, "1.2.5"); + }), + ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer))); + }); + it.effect("restores download state and permits retry after interruption", () => Effect.gen(function* () { const actionStarted = yield* Deferred.make(); From 5b6faa333e5b6650bd354c0813c2c50b14f91164 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 16 Nov 2026 03:27:50 +0000 Subject: [PATCH 2/7] fix(desktop): an update download fetches the newest release, not the last check's downloadAvailableUpdate called electronUpdater.downloadUpdate straight away, so it downloaded whatever the last background check (startup, then every 4 hours) had found. If a newer nightly came out since, the app restarted into an outdated build and offered another update within seconds. Run a check under the held download reservation first. A newer release replaces the offer before downloading; a failed check falls back to the known offer, which electron-updater still holds; an offer that no longer stands is not downloaded. Fixes #37462 Co-Authored-By: Claude Opus 5.5 --- .../src/updates/DesktopRemoteUpdates.test.ts | 12 +++---- .../src/updates/DesktopUpdates.test.ts | 36 +++++++++++++++++++ apps/desktop/src/updates/DesktopUpdates.ts | 16 ++++++++- 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/apps/desktop/src/updates/DesktopRemoteUpdates.test.ts b/apps/desktop/src/updates/DesktopRemoteUpdates.test.ts index fdac65f86a595..5cdf2ba1b56dc 100644 --- a/apps/desktop/src/updates/DesktopRemoteUpdates.test.ts +++ b/apps/desktop/src/updates/DesktopRemoteUpdates.test.ts @@ -733,16 +733,15 @@ describe("DesktopRemoteUpdates", () => { it.effect("waits for a background check before installing a prepared update", () => { const backgroundCheckStarted = Deferred.makeUnsafe(); const releaseBackgroundCheck = Deferred.makeUnsafe(); - let checks = 0; + let blockCheck = false; const harness = makeHarness({ - checkForUpdates: Effect.suspend(() => { - checks += 1; - return checks === 2 + checkForUpdates: Effect.suspend(() => + blockCheck ? Deferred.succeed(backgroundCheckStarted, undefined).pipe( Effect.andThen(Deferred.await(releaseBackgroundCheck)), ) - : Effect.void; - }), + : Effect.void, + ), }); return runRemoteUpdatesTest(harness, ({ requests, commits }) => @@ -755,6 +754,7 @@ describe("DesktopRemoteUpdates", () => { harness.emit("update-downloaded", { version: "1.2.4" }); yield* settle; + blockCheck = true; const backgroundCheck = yield* updates.check("poll").pipe(Effect.forkChild); yield* Deferred.await(backgroundCheckStarted); assert.isTrue(yield* updates.isActionActive); diff --git a/apps/desktop/src/updates/DesktopUpdates.test.ts b/apps/desktop/src/updates/DesktopUpdates.test.ts index f5467bde45246..225b283d36e64 100644 --- a/apps/desktop/src/updates/DesktopUpdates.test.ts +++ b/apps/desktop/src/updates/DesktopUpdates.test.ts @@ -525,6 +525,42 @@ describe("DesktopUpdates", () => { ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer))); }); + it.effect("downloads the known offer when the check before downloading fails", () => { + let checks = 0; + const harness = makeHarness({ + checkForUpdates: Effect.suspend(() => { + checks += 1; + if (checks > 1) { + return Effect.fail( + new ElectronUpdater.ElectronUpdaterCheckForUpdatesError({ + channel: null, + cause: new Error("offline"), + }), + ); + } + harness.emit("update-available", { version: "1.2.4" }); + return Effect.void; + }), + downloadUpdate: Effect.sync(() => { + harness.emit("update-downloaded", { version: "1.2.4" }); + }), + }); + + return Effect.scoped( + Effect.gen(function* () { + const updates = yield* DesktopUpdates.DesktopUpdates; + yield* updates.configure; + yield* updates.check("poll"); + yield* flushCallbacks; + + const result = yield* updates.download; + yield* flushCallbacks; + assert.isTrue(result.completed); + assert.equal((yield* updates.getState).downloadedVersion, "1.2.4"); + }), + ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer))); + }); + it.effect("restores download state and permits retry after interruption", () => Effect.gen(function* () { const actionStarted = yield* Deferred.make(); diff --git a/apps/desktop/src/updates/DesktopUpdates.ts b/apps/desktop/src/updates/DesktopUpdates.ts index 055c6574391a6..4b2e28111c4aa 100644 --- a/apps/desktop/src/updates/DesktopUpdates.ts +++ b/apps/desktop/src/updates/DesktopUpdates.ts @@ -643,8 +643,22 @@ export const make = Effect.gen(function* () { return { accepted: false, completed: false }; } - const state = yield* Ref.get(updateStateRef); + const offered = yield* Ref.get(updateStateRef); + let state = offered; return yield* Effect.gen(function* () { + // electron-updater downloads what its last check found, which can be hours old. + yield* checkForUpdates( + "download", + "held", + offered.channel !== desktopUpdateChannelOf(environment.appVersion), + ); + state = yield* Ref.get(updateStateRef); + if (state.status === "error") { + // A failed check keeps electron-updater's earlier result, so the known offer still downloads. + state = offered; + } else if (state.status !== "available") { + return { accepted: true, completed: false }; + } yield* setState(reduceDesktopUpdateStateOnDownloadStart(state)); yield* electronUpdater.setDisableDifferentialDownload( isArm64HostRunningIntelBuild(environment.runtimeInfo), From 013c6fd2c84f59bbc0d09e9d8419f3383cc279d9 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 16 Nov 2026 03:39:11 +0000 Subject: [PATCH 3/7] fix(desktop): startup recovery installs the build its update action downloaded The update download now re-checks first, so it can fetch a newer build than the one the recovery window offered. Recovery passed the offered version to installPrepared, which then refused the newer download and never restarted. Install the version the download reports instead. Co-Authored-By: Claude Opus 5.5 --- .../src/app/DesktopStartupRecovery.test.ts | 72 +++++++++++++++++++ .../desktop/src/app/DesktopStartupRecovery.ts | 9 ++- 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src/app/DesktopStartupRecovery.test.ts b/apps/desktop/src/app/DesktopStartupRecovery.test.ts index 029bcaac2b487..5d407feff79d1 100644 --- a/apps/desktop/src/app/DesktopStartupRecovery.test.ts +++ b/apps/desktop/src/app/DesktopStartupRecovery.test.ts @@ -211,3 +211,75 @@ it.effect.each([ }), ).pipe(Effect.provide(DesktopState.layer)), ); + +it.effect("installs the build the update action downloaded, not the one it offered", () => + Effect.scoped( + Effect.gen(function* () { + const installed = yield* Deferred.make(); + const shown = yield* Deferred.make(); + let navigate: ((event: { preventDefault: () => void }, url: string) => void) | undefined; + const recovery = { + isDestroyed: () => false, + loadURL: () => Promise.resolve(), + once: () => {}, + webContents: { + setWindowOpenHandler: () => {}, + on: (_event: string, listener: typeof navigate) => { + navigate = listener; + Deferred.doneUnsafe(shown, Effect.void); + }, + }, + } as unknown as Electron.BrowserWindow; + const offered = updateState({ status: "available", availableVersion: "0.1.4" }); + const state = yield* DesktopState.DesktopState; + yield* listen.pipe( + Effect.provide( + Layer.mergeAll( + FileSystem.layerNoop({ readFileString: () => Effect.succeed("0.1.3") }), + Layer.succeed(DesktopEnvironment.DesktopEnvironment, { + appVersion: "0.1.3", + stateDir: "/task/state", + logDir: "/task/logs", + path: { join: (...parts: string[]) => parts.join("/") }, + } as unknown as DesktopEnvironment.DesktopEnvironment["Service"]), + Layer.succeed(ElectronApp.ElectronApp, { + on: () => Effect.void, + } as unknown as ElectronApp.ElectronApp["Service"]), + Layer.succeed( + ElectronShell.ElectronShell, + {} as ElectronShell.ElectronShell["Service"], + ), + Layer.succeed(ElectronTheme.ElectronTheme, { + shouldUseDarkColors: Effect.succeed(false), + } as ElectronTheme.ElectronTheme["Service"]), + Layer.succeed(ElectronWindow.ElectronWindow, { + main: Effect.succeedNone, + create: () => Effect.succeed(recovery), + } as unknown as ElectronWindow.ElectronWindow["Service"]), + Layer.succeed(DesktopUpdates.DesktopUpdates, { + subscribe: Effect.succeed({ latest: offered, changes: Stream.empty }), + check: () => Effect.void, + getState: Effect.succeed(offered), + // A release published since the offer: the download fetches it instead. + download: Effect.succeed({ + accepted: true, + completed: true, + state: updateState({ status: "downloaded", downloadedVersion: "0.1.5" }), + }), + installPrepared: (version: string) => Deferred.succeed(installed, version), + } as unknown as DesktopUpdates.DesktopUpdates["Service"]), + ), + ), + ); + yield* SubscriptionRef.set(state.primaryBackendStartup, { + _tag: "Failing", + reason: "Server failed before readiness", + managedPolicy: false, + output: "Failure details", + }); + yield* Deferred.await(shown); + navigate!({ preventDefault: () => {} }, "https://startup-recovery.invalid/update"); + expect(yield* Deferred.await(installed)).toBe("0.1.5"); + }), + ).pipe(Effect.provide(DesktopState.layer)), +); diff --git a/apps/desktop/src/app/DesktopStartupRecovery.ts b/apps/desktop/src/app/DesktopStartupRecovery.ts index e6c210043cf26..769a30cf7680b 100644 --- a/apps/desktop/src/app/DesktopStartupRecovery.ts +++ b/apps/desktop/src/app/DesktopStartupRecovery.ts @@ -212,12 +212,15 @@ export const listen: Effect.Effect< switch (action) { case "update": { if (current._tag !== "Update") return; - const state = yield* updates.getState; - if (state.downloadedVersion === null) { + let { downloadedVersion } = yield* updates.getState; + if (downloadedVersion === null) { + // The download re-checks first, so it can fetch a newer build than the one offered. const download = yield* updates.download; if (!download.completed) return; + downloadedVersion = download.state.downloadedVersion; } - yield* updates.installPrepared(current.version); + if (downloadedVersion === null) return; + yield* updates.installPrepared(downloadedVersion); return; } case "reinstall": From 3b8ae7274b1db95e0a2691aa882bd195c29274c5 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 16 Nov 2026 03:49:16 +0000 Subject: [PATCH 4/7] fix(desktop): restarting to update installs a release published since the download installDownloadedUpdate handed the retained download to quitAndInstall without checking the feed, so a build downloaded hours ago installed as-is and the next startup check offered a newer one. The install entry point now checks first, before taking the install reservation (an updater error during the install reservation would start install recovery). When that check replaces the retained download with a newer offer, it downloads that build and installs it; a failed download reports its error instead of restarting. A failed check keeps the retained download, which installs as before. Co-Authored-By: Claude Opus 5.5 --- .../src/updates/DesktopUpdates.test.ts | 43 ++++++++++++++++++- apps/desktop/src/updates/DesktopUpdates.ts | 28 +++++++++++- 2 files changed, 68 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src/updates/DesktopUpdates.test.ts b/apps/desktop/src/updates/DesktopUpdates.test.ts index 225b283d36e64..aefb95c0dbb87 100644 --- a/apps/desktop/src/updates/DesktopUpdates.test.ts +++ b/apps/desktop/src/updates/DesktopUpdates.test.ts @@ -344,10 +344,11 @@ describe("DesktopUpdates", () => { const installFiber = yield* updates.install.pipe(Effect.forkScoped); yield* Deferred.await(installStarted); + const checksBefore = harness.checkCount(); const checkResult = yield* updates.check("manual"); assert.isFalse(checkResult.checked); - assert.equal(harness.checkCount(), 0); + assert.equal(harness.checkCount(), checksBefore); yield* Deferred.succeed(releaseInstall, undefined); const installResult = yield* Fiber.join(installFiber); @@ -358,7 +359,9 @@ describe("DesktopUpdates", () => { ); it.effect("preserves a queued installer after a background updater error", () => { - const harness = makeHarness(); + const harness = makeHarness({ + checkForUpdates: Effect.sync(() => harness.emit("update-not-available")), + }); return Effect.scoped( Effect.gen(function* () { @@ -525,6 +528,42 @@ describe("DesktopUpdates", () => { ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer))); }); + it.effect("installs a release published after the retained download", () => { + let published = "1.2.4"; + let lastChecked: string | undefined; + let installedVersion: string | null | undefined; + const harness = makeHarness({ + checkForUpdates: Effect.sync(() => { + lastChecked = published; + harness.emit("update-available", { version: published }); + }), + downloadUpdate: Effect.sync(() => { + harness.emit("update-downloaded", { version: lastChecked }); + }), + quitAndInstall: Effect.sync(() => { + installedVersion = harness.sentStates.at(-1)?.downloadedVersion; + }), + }); + + return Effect.scoped( + Effect.gen(function* () { + const updates = yield* DesktopUpdates.DesktopUpdates; + yield* updates.configure; + yield* updates.check("poll"); + yield* flushCallbacks; + yield* updates.download; + yield* flushCallbacks; + assert.equal((yield* updates.getState).downloadedVersion, "1.2.4"); + + published = "1.2.5"; + const result = yield* updates.installPrepared("1.2.4"); + assert.isTrue(result.accepted); + assert.equal(harness.quitAndInstalls(), 1); + assert.equal(installedVersion, "1.2.5"); + }), + ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer))); + }); + it.effect("downloads the known offer when the check before downloading fails", () => { let checks = 0; const harness = makeHarness({ diff --git a/apps/desktop/src/updates/DesktopUpdates.ts b/apps/desktop/src/updates/DesktopUpdates.ts index 4b2e28111c4aa..fda6056ad86aa 100644 --- a/apps/desktop/src/updates/DesktopUpdates.ts +++ b/apps/desktop/src/updates/DesktopUpdates.ts @@ -962,7 +962,33 @@ export const make = Effect.gen(function* () { state: yield* Ref.get(updateStateRef), }; } - const result = yield* installDownloadedUpdate(expectedVersion); + let installVersion = expectedVersion; + // A download can be hours old: a release published since replaces it before restarting. + const retained = yield* Ref.get(updateStateRef); + if ( + retained.downloadedVersion !== null && + (expectedVersion === undefined || retained.downloadedVersion === expectedVersion) && + (yield* checkForUpdates( + "install", + "acquire", + retained.channel !== desktopUpdateChannelOf(environment.appVersion), + )) && + (yield* Ref.get(updateStateRef)).status === "available" + ) { + const download = yield* downloadAvailableUpdate; + if (!download.completed) { + return { + accepted: download.accepted, + completed: false, + failed: download.accepted, + state: yield* Ref.get(updateStateRef), + }; + } + if (expectedVersion !== undefined) { + installVersion = (yield* Ref.get(updateStateRef)).downloadedVersion ?? expectedVersion; + } + } + const result = yield* installDownloadedUpdate(installVersion); return { accepted: result.accepted, completed: result.completed, From dd5d3c7b3a487b8ffc17760afcca78b0bc4ad6f1 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 16 Nov 2026 04:08:10 +0000 Subject: [PATCH 5/7] fix(desktop): update refreshes keep a failed check quiet and never install an older build A failed check before downloading published an error state before the known-offer fallback ran, and the remote update flow treats that state as final after its own check. The download's refresh now calls the updater directly and only logs a failure, so the offer stays on screen while it downloads. electron-updater compares a check with the running build, so a stale feed could replace a newer retained download with an older offer. Install now restores the retained download unless the refreshed offer is newer. Co-Authored-By: Claude Opus 5.5 --- .../src/updates/DesktopUpdates.test.ts | 33 ++++++++++ apps/desktop/src/updates/DesktopUpdates.ts | 65 ++++++++++++------- 2 files changed, 75 insertions(+), 23 deletions(-) diff --git a/apps/desktop/src/updates/DesktopUpdates.test.ts b/apps/desktop/src/updates/DesktopUpdates.test.ts index aefb95c0dbb87..9b814fcb9ed36 100644 --- a/apps/desktop/src/updates/DesktopUpdates.test.ts +++ b/apps/desktop/src/updates/DesktopUpdates.test.ts @@ -596,6 +596,39 @@ describe("DesktopUpdates", () => { yield* flushCallbacks; assert.isTrue(result.completed); assert.equal((yield* updates.getState).downloadedVersion, "1.2.4"); + // Remote requests treat a published error after their own check as final. + assert.notInclude( + harness.sentStates.map((state) => state.status), + "error", + ); + }), + ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer))); + }); + + it.effect("installs the retained download when a stale feed offers an older release", () => { + let published = "1.2.5"; + let installedVersion: string | null | undefined; + const harness = makeHarness({ + checkForUpdates: Effect.sync(() => harness.emit("update-available", { version: published })), + downloadUpdate: Effect.sync(() => harness.emit("update-downloaded", { version: "1.2.5" })), + quitAndInstall: Effect.sync(() => { + installedVersion = harness.sentStates.at(-1)?.downloadedVersion; + }), + }); + + return Effect.scoped( + Effect.gen(function* () { + const updates = yield* DesktopUpdates.DesktopUpdates; + yield* updates.configure; + yield* updates.check("poll"); + yield* updates.download; + yield* flushCallbacks; + + published = "1.2.4"; + const result = yield* updates.installPrepared("1.2.5"); + assert.isTrue(result.accepted); + assert.equal(harness.downloadCount(), 1); + assert.equal(installedVersion, "1.2.5"); }), ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer))); }); diff --git a/apps/desktop/src/updates/DesktopUpdates.ts b/apps/desktop/src/updates/DesktopUpdates.ts index fda6056ad86aa..b4e736e310f18 100644 --- a/apps/desktop/src/updates/DesktopUpdates.ts +++ b/apps/desktop/src/updates/DesktopUpdates.ts @@ -557,6 +557,15 @@ export const make = Effect.gen(function* () { }); }); + // The flag is shared updater state, so callers flip it only while holding a reservation. + const runUpdaterCheck = Effect.fnUntraced(function* (allowDowngrade: boolean) { + const restoreDowngrade = yield* electronUpdater.allowDowngrade; + if (allowDowngrade) yield* electronUpdater.setAllowDowngrade(true); + return yield* electronUpdater.checkForUpdates.pipe( + Effect.ensuring(electronUpdater.setAllowDowngrade(restoreDowngrade).pipe(Effect.ignore)), + ); + }); + const checkForUpdates = Effect.fn("desktop.updates.checkForUpdates")(function* ( reason: string, actionReservation: "acquire" | "held" = "acquire", @@ -586,11 +595,7 @@ export const make = Effect.gen(function* () { } yield* logUpdaterInfo("checking for updates", { reason }); - // The flag is shared updater state, so it flips only while this check holds the reservation. - const restoreDowngrade = yield* electronUpdater.allowDowngrade; - if (allowDowngrade) yield* electronUpdater.setAllowDowngrade(true); - return yield* electronUpdater.checkForUpdates.pipe( - Effect.ensuring(electronUpdater.setAllowDowngrade(restoreDowngrade).pipe(Effect.ignore)), + return yield* runUpdaterCheck(allowDowngrade).pipe( Effect.as(true), Effect.catchTags({ ElectronUpdaterCheckForUpdatesError: Effect.fn( @@ -647,16 +652,21 @@ export const make = Effect.gen(function* () { let state = offered; return yield* Effect.gen(function* () { // electron-updater downloads what its last check found, which can be hours old. - yield* checkForUpdates( - "download", - "held", + yield* logUpdaterInfo("checking for updates", { reason: "download" }); + yield* runUpdaterCheck( offered.channel !== desktopUpdateChannelOf(environment.appVersion), + ).pipe( + // A failed check keeps electron-updater's earlier result, so the known offer still downloads. + Effect.catchTags({ + ElectronUpdaterCheckForUpdatesError: (error) => + logUpdaterWarning(error.message, { + errorTag: error._tag, + cause: describeUpdateErrorCause(error.cause), + }), + }), ); state = yield* Ref.get(updateStateRef); - if (state.status === "error") { - // A failed check keeps electron-updater's earlier result, so the known offer still downloads. - state = offered; - } else if (state.status !== "available") { + if (state.status !== "available") { return { accepted: true, completed: false }; } yield* setState(reduceDesktopUpdateStateOnDownloadStart(state)); @@ -975,17 +985,26 @@ export const make = Effect.gen(function* () { )) && (yield* Ref.get(updateStateRef)).status === "available" ) { - const download = yield* downloadAvailableUpdate; - if (!download.completed) { - return { - accepted: download.accepted, - completed: false, - failed: download.accepted, - state: yield* Ref.get(updateStateRef), - }; - } - if (expectedVersion !== undefined) { - installVersion = (yield* Ref.get(updateStateRef)).downloadedVersion ?? expectedVersion; + const refreshed = yield* Ref.get(updateStateRef); + // electron-updater compares a stale feed with the running build, not the retained download. + if ( + refreshed.availableVersion === null || + compareSemverVersions(refreshed.availableVersion, retained.downloadedVersion) <= 0 + ) { + yield* setState(retained); + } else { + const download = yield* downloadAvailableUpdate; + if (!download.completed) { + return { + accepted: download.accepted, + completed: false, + failed: download.accepted, + state: yield* Ref.get(updateStateRef), + }; + } + if (expectedVersion !== undefined) { + installVersion = (yield* Ref.get(updateStateRef)).downloadedVersion ?? expectedVersion; + } } } const result = yield* installDownloadedUpdate(installVersion); From 4371af19c19794b038cacf43a11983f069c7aa06 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 16 Nov 2026 04:11:35 +0000 Subject: [PATCH 6/7] refactor(desktop): trace the shared updater check helper Co-Authored-By: Claude Opus 5.5 --- apps/desktop/src/updates/DesktopUpdates.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/desktop/src/updates/DesktopUpdates.ts b/apps/desktop/src/updates/DesktopUpdates.ts index b4e736e310f18..4a43b52057b8f 100644 --- a/apps/desktop/src/updates/DesktopUpdates.ts +++ b/apps/desktop/src/updates/DesktopUpdates.ts @@ -558,7 +558,9 @@ export const make = Effect.gen(function* () { }); // The flag is shared updater state, so callers flip it only while holding a reservation. - const runUpdaterCheck = Effect.fnUntraced(function* (allowDowngrade: boolean) { + const runUpdaterCheck = Effect.fn("desktop.updates.runUpdaterCheck")(function* ( + allowDowngrade: boolean, + ) { const restoreDowngrade = yield* electronUpdater.allowDowngrade; if (allowDowngrade) yield* electronUpdater.setAllowDowngrade(true); return yield* electronUpdater.checkForUpdates.pipe( From d3a2d04e97dca893defaa5bb13dd019ef913a944 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 16 Nov 2026 04:14:04 +0000 Subject: [PATCH 7/7] fix(desktop): install downloads the release its own check found When install's check found a newer release, the download it started ran a second check, and a stale feed answering that one could replace the newer offer with an older build. The download now skips its refresh when install has just checked. Co-Authored-By: Claude Opus 5.5 --- .../src/updates/DesktopUpdates.test.ts | 3 ++ apps/desktop/src/updates/DesktopUpdates.ts | 41 +++++++++++-------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/apps/desktop/src/updates/DesktopUpdates.test.ts b/apps/desktop/src/updates/DesktopUpdates.test.ts index 9b814fcb9ed36..33ed00a764738 100644 --- a/apps/desktop/src/updates/DesktopUpdates.test.ts +++ b/apps/desktop/src/updates/DesktopUpdates.test.ts @@ -556,8 +556,11 @@ describe("DesktopUpdates", () => { assert.equal((yield* updates.getState).downloadedVersion, "1.2.4"); published = "1.2.5"; + const checksBefore = harness.checkCount(); const result = yield* updates.installPrepared("1.2.4"); assert.isTrue(result.accepted); + // A second check before downloading could find a stale feed's older release. + assert.equal(harness.checkCount(), checksBefore + 1); assert.equal(harness.quitAndInstalls(), 1); assert.equal(installedVersion, "1.2.5"); }), diff --git a/apps/desktop/src/updates/DesktopUpdates.ts b/apps/desktop/src/updates/DesktopUpdates.ts index 4a43b52057b8f..775a9ff6b04ff 100644 --- a/apps/desktop/src/updates/DesktopUpdates.ts +++ b/apps/desktop/src/updates/DesktopUpdates.ts @@ -626,7 +626,10 @@ export const make = Effect.gen(function* () { ); }); - const downloadAvailableUpdate = Effect.gen(function* () { + // Install refreshes before downloading, and a second check could pick a stale, older release. + const downloadAvailableUpdate = Effect.fn("desktop.updates.downloadAvailableUpdate")(function* ( + refresh: boolean, + ) { const admission = yield* Effect.scoped( admitAfterCheck( Effect.gen(function* () { @@ -653,20 +656,22 @@ export const make = Effect.gen(function* () { const offered = yield* Ref.get(updateStateRef); let state = offered; return yield* Effect.gen(function* () { - // electron-updater downloads what its last check found, which can be hours old. - yield* logUpdaterInfo("checking for updates", { reason: "download" }); - yield* runUpdaterCheck( - offered.channel !== desktopUpdateChannelOf(environment.appVersion), - ).pipe( - // A failed check keeps electron-updater's earlier result, so the known offer still downloads. - Effect.catchTags({ - ElectronUpdaterCheckForUpdatesError: (error) => - logUpdaterWarning(error.message, { - errorTag: error._tag, - cause: describeUpdateErrorCause(error.cause), - }), - }), - ); + if (refresh) { + // electron-updater downloads what its last check found, which can be hours old. + yield* logUpdaterInfo("checking for updates", { reason: "download" }); + yield* runUpdaterCheck( + offered.channel !== desktopUpdateChannelOf(environment.appVersion), + ).pipe( + // A failed check keeps electron-updater's earlier result, so the known offer still downloads. + Effect.catchTags({ + ElectronUpdaterCheckForUpdatesError: (error) => + logUpdaterWarning(error.message, { + errorTag: error._tag, + cause: describeUpdateErrorCause(error.cause), + }), + }), + ); + } state = yield* Ref.get(updateStateRef); if (state.status !== "available") { return { accepted: true, completed: false }; @@ -719,7 +724,7 @@ export const make = Effect.gen(function* () { }), Effect.ensuring(finishUpdateAction("download")), ); - }).pipe(Effect.withSpan("desktop.updates.downloadAvailableUpdate")); + }); const updateRestartMarkerDir = environment.path.join(environment.baseDir, "runtime"); const updateRestartMarkerPath = environment.path.join( @@ -995,7 +1000,7 @@ export const make = Effect.gen(function* () { ) { yield* setState(retained); } else { - const download = yield* downloadAvailableUpdate; + const download = yield* downloadAvailableUpdate(false); if (!download.completed) { return { accepted: download.accepted, @@ -1418,7 +1423,7 @@ export const make = Effect.gen(function* () { }; }), download: Effect.gen(function* () { - const result = yield* downloadAvailableUpdate; + const result = yield* downloadAvailableUpdate(true); return { accepted: result.accepted, completed: result.completed,