From cd5790f92bd4890b43570a70b04ccdd307f7561c Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 27 Oct 2026 12:28:16 +0000 Subject: [PATCH 1/3] test(desktop): reproduce Windows update failing when the signature check times out Reproduces #20345: when the first Windows signature checks of a freshly written installer time out, downloadUpdate fails instead of retrying until the check finishes. Co-Authored-By: Claude Opus 5.5 --- .../src/electron/ElectronUpdater.test.ts | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 apps/desktop/src/electron/ElectronUpdater.test.ts diff --git a/apps/desktop/src/electron/ElectronUpdater.test.ts b/apps/desktop/src/electron/ElectronUpdater.test.ts new file mode 100644 index 0000000000000..896d1848fb235 --- /dev/null +++ b/apps/desktop/src/electron/ElectronUpdater.test.ts @@ -0,0 +1,54 @@ +import { assert, describe, it } from "@effect/vitest"; +import * as Effect from "effect/Effect"; +import type { VerifyUpdateCodeSignature } from "electron-updater"; +import { vi } from "vite-plus/test"; + +const { autoUpdaterMock } = vi.hoisted(() => ({ + autoUpdaterMock: { + channel: "latest", + downloadUpdate: vi.fn(() => Promise.resolve([])), + verifyUpdateCodeSignature: undefined as VerifyUpdateCodeSignature | undefined, + }, +})); + +vi.mock("electron-updater", () => ({ + autoUpdater: autoUpdaterMock, +})); + +import * as ElectronUpdater from "./ElectronUpdater.ts"; + +describe("ElectronUpdater", () => { + it.effect("downloads the update when the first Windows signature checks time out", () => + Effect.gen(function* () { + const publisherNames = ["T3 Tools Inc"]; + const installerPath = "C:\\updater\\pending\\temp-T3-Code-x64.exe"; + // execFile marks the error killed when the verifier exceeds its 20-second timeout. + const timedOut = () => + Object.assign(new Error("Command failed: powershell.exe"), { killed: true }); + const verify = vi + .fn() + .mockRejectedValueOnce(timedOut()) + .mockRejectedValueOnce(timedOut()) + .mockRejectedValueOnce(timedOut()) + .mockResolvedValueOnce(null); + autoUpdaterMock.verifyUpdateCodeSignature = verify; + autoUpdaterMock.downloadUpdate.mockImplementationOnce(async () => { + // NsisUpdater reads the current verifier and accepts only null as a valid signature. + const rejection = await autoUpdaterMock.verifyUpdateCodeSignature!( + publisherNames, + installerPath, + ); + if (rejection !== null) throw new Error(`Invalid signature: ${rejection}`); + return []; + }); + const updater = yield* ElectronUpdater.ElectronUpdater; + + yield* updater.downloadUpdate; + + assert.deepEqual( + verify.mock.calls, + Array.from({ length: 4 }, () => [publisherNames, installerPath]), + ); + }).pipe(Effect.provide(ElectronUpdater.layer)), + ); +}); From 2d79f4472543089b3739b511ef6af52ea5192462 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 27 Oct 2026 12:32:56 +0000 Subject: [PATCH 2/3] fix(desktop): Windows updates survive a slow first signature check On machines with on-access antivirus, electron-updater's PowerShell signature check of a freshly written installer can take ~55 s, but it is killed after 20 s, so the update download fails. Wrap the updater's own verifier and rerun it after a timed-out check, up to five attempts. Invalid signatures and other errors still fail at once. A retry that electron-updater ends by skipping verification after a failed PowerShell capability probe is rejected instead of accepted. Fixes pingdotgg/t3code#20345 Co-Authored-By: Claude Opus 5.5 --- .../src/electron/ElectronUpdater.test.ts | 82 +++++++++++++++---- apps/desktop/src/electron/ElectronUpdater.ts | 53 ++++++++++++ 2 files changed, 118 insertions(+), 17 deletions(-) diff --git a/apps/desktop/src/electron/ElectronUpdater.test.ts b/apps/desktop/src/electron/ElectronUpdater.test.ts index 896d1848fb235..b8bde313030c2 100644 --- a/apps/desktop/src/electron/ElectronUpdater.test.ts +++ b/apps/desktop/src/electron/ElectronUpdater.test.ts @@ -7,6 +7,7 @@ const { autoUpdaterMock } = vi.hoisted(() => ({ autoUpdaterMock: { channel: "latest", downloadUpdate: vi.fn(() => Promise.resolve([])), + logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn() }, verifyUpdateCodeSignature: undefined as VerifyUpdateCodeSignature | undefined, }, })); @@ -17,14 +18,27 @@ vi.mock("electron-updater", () => ({ import * as ElectronUpdater from "./ElectronUpdater.ts"; +const publisherNames = ["T3 Tools Inc"]; +const installerPath = "C:\\updater\\pending\\temp-T3-Code-x64.exe"; +// execFile marks the error killed when the verifier exceeds its 20-second timeout. +const timedOut = () => Object.assign(new Error("Command failed: powershell.exe"), { killed: true }); + +const downloadVerifyingSignature = () => { + autoUpdaterMock.downloadUpdate.mockImplementationOnce(async () => { + // NsisUpdater reads the current verifier and accepts only null as a valid signature. + const rejection = await autoUpdaterMock.verifyUpdateCodeSignature!( + publisherNames, + installerPath, + ); + if (rejection !== null) throw new Error(`Invalid signature: ${rejection}`); + return []; + }); + return Effect.flatMap(ElectronUpdater.ElectronUpdater, (updater) => updater.downloadUpdate); +}; + describe("ElectronUpdater", () => { it.effect("downloads the update when the first Windows signature checks time out", () => Effect.gen(function* () { - const publisherNames = ["T3 Tools Inc"]; - const installerPath = "C:\\updater\\pending\\temp-T3-Code-x64.exe"; - // execFile marks the error killed when the verifier exceeds its 20-second timeout. - const timedOut = () => - Object.assign(new Error("Command failed: powershell.exe"), { killed: true }); const verify = vi .fn() .mockRejectedValueOnce(timedOut()) @@ -32,18 +46,8 @@ describe("ElectronUpdater", () => { .mockRejectedValueOnce(timedOut()) .mockResolvedValueOnce(null); autoUpdaterMock.verifyUpdateCodeSignature = verify; - autoUpdaterMock.downloadUpdate.mockImplementationOnce(async () => { - // NsisUpdater reads the current verifier and accepts only null as a valid signature. - const rejection = await autoUpdaterMock.verifyUpdateCodeSignature!( - publisherNames, - installerPath, - ); - if (rejection !== null) throw new Error(`Invalid signature: ${rejection}`); - return []; - }); - const updater = yield* ElectronUpdater.ElectronUpdater; - - yield* updater.downloadUpdate; + + yield* downloadVerifyingSignature(); assert.deepEqual( verify.mock.calls, @@ -51,4 +55,48 @@ describe("ElectronUpdater", () => { ); }).pipe(Effect.provide(ElectronUpdater.layer)), ); + + it.effect( + "fails on invalid signatures, other errors and repeated timeouts on each download", + () => + Effect.gen(function* () { + const cases = [ + { outcome: () => Promise.resolve("Invalid publisher"), calls: 1 }, + { outcome: () => Promise.reject(new Error("Cannot execute PowerShell")), calls: 1 }, + { outcome: () => Promise.reject(timedOut()), calls: 5 }, + ]; + for (const { outcome, calls } of cases) { + const verify = vi.fn(outcome); + autoUpdaterMock.verifyUpdateCodeSignature = verify; + + // A second download must neither stack retries nor start with a spent budget. + for (let download = 1; download <= 2; download++) { + const error = yield* downloadVerifyingSignature().pipe(Effect.flip); + assert.instanceOf(error, ElectronUpdater.ElectronUpdaterDownloadUpdateError); + assert.equal(verify.mock.calls.length, calls * download); + } + } + }).pipe(Effect.provide(ElectronUpdater.layer)), + ); + + it.effect("rejects a retry when the upstream capability probe skips verification", () => + Effect.gen(function* () { + const verify = vi + .fn() + .mockRejectedValueOnce(timedOut()) + .mockImplementationOnce(async () => { + // electron-updater warns through the updater's logger, then resolves null unchecked. + autoUpdaterMock.logger.warn( + "Cannot execute ConvertTo-Json: spawnSync powershell.exe ETIMEDOUT. Ignoring signature validation due to unsupported powershell version. Please upgrade to powershell 3 or higher.", + ); + return null; + }); + autoUpdaterMock.verifyUpdateCodeSignature = verify; + + const error = yield* downloadVerifyingSignature().pipe(Effect.flip); + + assert.instanceOf(error, ElectronUpdater.ElectronUpdaterDownloadUpdateError); + assert.equal(verify.mock.calls.length, 2); + }).pipe(Effect.provide(ElectronUpdater.layer)), + ); }); diff --git a/apps/desktop/src/electron/ElectronUpdater.ts b/apps/desktop/src/electron/ElectronUpdater.ts index c71b42040db29..23e34a72f6c08 100644 --- a/apps/desktop/src/electron/ElectronUpdater.ts +++ b/apps/desktop/src/electron/ElectronUpdater.ts @@ -5,6 +5,7 @@ import * as Schema from "effect/Schema"; import * as Scope from "effect/Scope"; import { autoUpdater } from "electron-updater"; +import type { NsisUpdater, VerifyUpdateCodeSignature } from "electron-updater"; type AutoUpdater = typeof autoUpdater; @@ -80,6 +81,57 @@ export class ElectronUpdater extends Context.Service< } >()("@t3tools/desktop/electron/ElectronUpdater") {} +// Each timed-out check costs at least 20 s; five outlast the ~55 s first check seen behind on-access antivirus. +const SIGNATURE_CHECK_ATTEMPTS = 5; + +const signatureChecksWithRetry = new WeakSet(); + +const isTimedOut = (error: unknown) => + typeof error === "object" && error !== null && "killed" in error && error.killed === true; + +const retrySignatureCheckOnTimeout = () => { + // Only the Windows NSIS updater has this hook; its PowerShell check is killed after 20 s. + const updater = autoUpdater as AutoUpdater & + Partial>; + const verify = updater.verifyUpdateCodeSignature; + if (verify === undefined || signatureChecksWithRetry.has(verify)) return; + + const verifyRejectingSkip: VerifyUpdateCodeSignature = async (publisherNames, path) => { + const logger = updater.logger; + let skipped = false; + updater.logger = { + info: (message) => logger?.info(message), + warn: (message) => { + // After a timeout, a failed capability probe makes electron-updater warn and resolve null unchecked. + skipped ||= String(message).includes("Ignoring signature validation"); + logger?.warn(message); + }, + error: (message) => logger?.error(message), + debug: (message) => logger?.debug?.(message), + }; + try { + const result = await verify(publisherNames, path); + return skipped ? "Signature validation was skipped after a timed-out check." : result; + } finally { + updater.logger = logger; + } + }; + + const verifyWithRetry: VerifyUpdateCodeSignature = async (publisherNames, path) => { + for (let attempt = 1; ; attempt++) { + try { + return attempt === 1 + ? await verify(publisherNames, path) + : await verifyRejectingSkip(publisherNames, path); + } catch (error) { + if (!isTimedOut(error) || attempt === SIGNATURE_CHECK_ATTEMPTS) throw error; + } + } + }; + signatureChecksWithRetry.add(verifyWithRetry); + updater.verifyUpdateCodeSignature = verifyWithRetry; +}; + /** @public */ export const make = ElectronUpdater.of({ setFeedURL: Effect.fn("ElectronUpdater.setFeedURL")(function (options) { @@ -141,6 +193,7 @@ export const make = ElectronUpdater.of({ }).pipe(Effect.asVoid); }), downloadUpdate: Effect.suspend(() => { + retrySignatureCheckOnTimeout(); const channel = autoUpdater.channel; return Effect.tryPromise({ try: () => autoUpdater.downloadUpdate(), From 718cd67ba9d741a076040f3654e47bafe052929c Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 27 Oct 2026 12:45:39 +0000 Subject: [PATCH 3/3] fix(desktop): retry a signature check the capability probe skipped instead of failing Co-Authored-By: Claude Opus 5.5 --- .../src/electron/ElectronUpdater.test.ts | 32 ++++++++++++------- apps/desktop/src/electron/ElectronUpdater.ts | 14 ++++---- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/apps/desktop/src/electron/ElectronUpdater.test.ts b/apps/desktop/src/electron/ElectronUpdater.test.ts index b8bde313030c2..027db1a7b3e19 100644 --- a/apps/desktop/src/electron/ElectronUpdater.test.ts +++ b/apps/desktop/src/electron/ElectronUpdater.test.ts @@ -79,24 +79,32 @@ describe("ElectronUpdater", () => { }).pipe(Effect.provide(ElectronUpdater.layer)), ); - it.effect("rejects a retry when the upstream capability probe skips verification", () => + it.effect("retries a check the upstream capability probe skipped, and never accepts one", () => Effect.gen(function* () { - const verify = vi + const skipped = async () => { + // electron-updater warns through the updater's logger, then resolves null unchecked. + autoUpdaterMock.logger.warn( + "Cannot execute ConvertTo-Json: spawnSync powershell.exe ETIMEDOUT. Ignoring signature validation due to unsupported powershell version. Please upgrade to powershell 3 or higher.", + ); + return null; + }; + + const recovers = vi .fn() .mockRejectedValueOnce(timedOut()) - .mockImplementationOnce(async () => { - // electron-updater warns through the updater's logger, then resolves null unchecked. - autoUpdaterMock.logger.warn( - "Cannot execute ConvertTo-Json: spawnSync powershell.exe ETIMEDOUT. Ignoring signature validation due to unsupported powershell version. Please upgrade to powershell 3 or higher.", - ); - return null; - }); - autoUpdaterMock.verifyUpdateCodeSignature = verify; + .mockImplementationOnce(skipped) + .mockResolvedValueOnce(null); + autoUpdaterMock.verifyUpdateCodeSignature = recovers; + yield* downloadVerifyingSignature(); + assert.equal(recovers.mock.calls.length, 3); + const alwaysSkipped = vi + .fn(skipped) + .mockRejectedValueOnce(timedOut()); + autoUpdaterMock.verifyUpdateCodeSignature = alwaysSkipped; const error = yield* downloadVerifyingSignature().pipe(Effect.flip); - assert.instanceOf(error, ElectronUpdater.ElectronUpdaterDownloadUpdateError); - assert.equal(verify.mock.calls.length, 2); + assert.equal(alwaysSkipped.mock.calls.length, 5); }).pipe(Effect.provide(ElectronUpdater.layer)), ); }); diff --git a/apps/desktop/src/electron/ElectronUpdater.ts b/apps/desktop/src/electron/ElectronUpdater.ts index 23e34a72f6c08..bb5b8283981f6 100644 --- a/apps/desktop/src/electron/ElectronUpdater.ts +++ b/apps/desktop/src/electron/ElectronUpdater.ts @@ -96,7 +96,7 @@ const retrySignatureCheckOnTimeout = () => { const verify = updater.verifyUpdateCodeSignature; if (verify === undefined || signatureChecksWithRetry.has(verify)) return; - const verifyRejectingSkip: VerifyUpdateCodeSignature = async (publisherNames, path) => { + const verifyDetectingSkip = async (publisherNames: Array, path: string) => { const logger = updater.logger; let skipped = false; updater.logger = { @@ -111,7 +111,7 @@ const retrySignatureCheckOnTimeout = () => { }; try { const result = await verify(publisherNames, path); - return skipped ? "Signature validation was skipped after a timed-out check." : result; + return { result, skipped }; } finally { updater.logger = logger; } @@ -119,12 +119,14 @@ const retrySignatureCheckOnTimeout = () => { const verifyWithRetry: VerifyUpdateCodeSignature = async (publisherNames, path) => { for (let attempt = 1; ; attempt++) { + const lastAttempt = attempt === SIGNATURE_CHECK_ATTEMPTS; try { - return attempt === 1 - ? await verify(publisherNames, path) - : await verifyRejectingSkip(publisherNames, path); + if (attempt === 1) return await verify(publisherNames, path); + const { result, skipped } = await verifyDetectingSkip(publisherNames, path); + if (!skipped) return result; + if (lastAttempt) return "Signature validation was skipped after a timed-out check."; } catch (error) { - if (!isTimedOut(error) || attempt === SIGNATURE_CHECK_ATTEMPTS) throw error; + if (!isTimedOut(error) || lastAttempt) throw error; } } };