From 159021e95e598f25d7d8e187cdabead074c2afbb Mon Sep 17 00:00:00 2001 From: Theo Browne Date: Thu, 13 Aug 2026 17:28:50 -0700 Subject: [PATCH] review: detect install failure by state transition, not lingering errorContext Co-Authored-By: Claude Fable 5 --- .../src/updates/DesktopRemoteUpdates.test.ts | 44 +++++++++++++++++++ .../src/updates/DesktopRemoteUpdates.ts | 13 +++--- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/apps/desktop/src/updates/DesktopRemoteUpdates.test.ts b/apps/desktop/src/updates/DesktopRemoteUpdates.test.ts index 39049b5aa0..5965c2cf2c 100644 --- a/apps/desktop/src/updates/DesktopRemoteUpdates.test.ts +++ b/apps/desktop/src/updates/DesktopRemoteUpdates.test.ts @@ -136,6 +136,50 @@ describe("DesktopRemoteUpdates", () => { ); }); + it.effect("does not misread a lingering install error as a failed retry", () => { + let installAttempts = 0; + const harness = makeHarness({ + quitAndInstall: Effect.suspend(() => { + installAttempts += 1; + return installAttempts === 1 + ? Effect.fail( + new ElectronUpdater.ElectronUpdaterQuitAndInstallError({ + channel: "latest", + isSilent: true, + isForceRunAfter: true, + cause: new Error("first attempt failed"), + }), + ) + : Effect.void; + }), + }); + + return runRemoteUpdatesTest(harness, ({ reports, requests }) => + Effect.gen(function* () { + yield* Queue.offer(requests, request("req-5")); + yield* settle; + harness.emit("update-available", { version: "1.2.4" }); + yield* settle; + harness.emit("update-downloaded", { version: "1.2.4" }); + yield* settle; + // First run failed; state is "downloaded" with a lingering + // errorContext "install". The retry succeeds and must not report + // that leftover as a fresh failure. + yield* Queue.offer(requests, request("req-6")); + yield* settle; + + const retryTerminals = terminalReports(reports).filter( + (report) => report.requestId === "req-6", + ); + assert.deepEqual( + retryTerminals.map((report) => report.outcome), + ["installing"], + ); + assert.equal(harness.quitAndInstalls(), 2); + }), + ); + }); + it.effect("reports up-to-date without installing when there is no update", () => { const harness = makeHarness(); diff --git a/apps/desktop/src/updates/DesktopRemoteUpdates.ts b/apps/desktop/src/updates/DesktopRemoteUpdates.ts index dc6d78e29c..4378498405 100644 --- a/apps/desktop/src/updates/DesktopRemoteUpdates.ts +++ b/apps/desktop/src/updates/DesktopRemoteUpdates.ts @@ -91,18 +91,19 @@ export const listen: Effect.Effect< // published after this point never reaches the requester. yield* publishReport(state, { outcome: "installing" }); yield* logInfo("remote update installing", { requestId: request.requestId }); + const before = yield* updates.getState; const result = yield* updates.install; if (!result.accepted) { yield* publishReport(result.state, { outcome: "failed", reason: "The desktop app could not start the install.", }); - } else if ( - result.state.status === "error" || - result.state.errorContext === "install" - ) { - // Install failures reduce to status "downloaded" with - // errorContext "install", not to "error". + } else if (result.state !== before) { + // During an accepted install the only state writes are the + // failure reducers, so a transition means this attempt + // failed. Field checks cannot tell a fresh failure from a + // lingering errorContext left by a previous attempt, which + // success does not clear. yield* publishReport(result.state, { outcome: "failed", reason: result.state.message ?? "The desktop app failed to install the update.",