From 2bce178aa6ecdcc9e85fc011597ee74db2a44a1f Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 30 Oct 2026 09:41:29 +0000 Subject: [PATCH 1/8] test(desktop): reproduce #27486 Windows update without disk space These tests reproduce pingdotgg/t3code#27486. On Windows, installing a downloaded update when the install volume lacks the space the NSIS installer needs must not quit into the installer. It must keep the update downloaded and retryable, with a disk-space message. A guard test shows that an install still proceeds when the volume has room. The harness takes a new `diskSpace` option, which the implementation still has to wire to its free-space and size seam. Co-Authored-By: Claude Opus 5.5 --- .../src/updates/DesktopUpdates.test.ts | 65 +++++++++++++++++++ .../desktop/src/updates/updatesTestHarness.ts | 6 ++ 2 files changed, 71 insertions(+) diff --git a/apps/desktop/src/updates/DesktopUpdates.test.ts b/apps/desktop/src/updates/DesktopUpdates.test.ts index c6bcd46b8c20..c9da196b1bfd 100644 --- a/apps/desktop/src/updates/DesktopUpdates.test.ts +++ b/apps/desktop/src/updates/DesktopUpdates.test.ts @@ -558,6 +558,71 @@ describe("DesktopUpdates", () => { ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer))); }); + // regression: #27486 a silent NSIS update on a full volume left a half-written install that no longer launched + it.effect("keeps a Windows update retryable when the install volume lacks space", () => { + const megabyte = 1024 * 1024; + const harness = makeHarness({ + platform: "win32", + diskSpace: { + freeBytes: 200 * megabyte, + installerBytes: 150 * megabyte, + installDirectoryBytes: 400 * megabyte, + }, + }); + + return Effect.scoped( + Effect.gen(function* () { + const desktopState = yield* DesktopState.DesktopState; + const pool = yield* DesktopBackendPool.DesktopBackendPool; + const updates = yield* DesktopUpdates.DesktopUpdates; + yield* updates.configure; + harness.emit("update-downloaded", { + version: "1.2.4", + downloadedFile: "C:\\Users\\me\\AppData\\Local\\t3code-updater\\pending\\installer.exe", + }); + yield* flushCallbacks; + + const result = yield* updates.install; + assert.equal(harness.quitAndInstalls(), 0, "the installer ran without enough disk space"); + assert.isFalse(yield* Ref.get(desktopState.quitting)); + assert.isTrue((yield* (yield* pool.primary).snapshot).desiredRunning); + assert.isFalse(result.completed); + assert.equal(result.state.status, "downloaded"); + assert.equal(result.state.downloadedVersion, "1.2.4"); + assert.equal(result.state.errorContext, "install"); + assert.isTrue(result.state.canRetry); + assert.match(result.state.message ?? "", /space/i); + }), + ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer))); + }); + + it.effect("installs a Windows update when the install volume has room", () => { + const megabyte = 1024 * 1024; + const harness = makeHarness({ + platform: "win32", + diskSpace: { + freeBytes: 2000 * megabyte, + installerBytes: 150 * megabyte, + installDirectoryBytes: 400 * megabyte, + }, + }); + + return Effect.scoped( + Effect.gen(function* () { + const updates = yield* DesktopUpdates.DesktopUpdates; + yield* updates.configure; + harness.emit("update-downloaded", { + version: "1.2.4", + downloadedFile: "C:\\Users\\me\\AppData\\Local\\t3code-updater\\pending\\installer.exe", + }); + yield* flushCallbacks; + + assert.isTrue((yield* updates.install).accepted); + assert.equal(harness.quitAndInstalls(), 1); + }), + ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer))); + }); + it.effect("restores only desired-running instances after an installer error event", () => { const starts: string[] = []; const stops: string[] = []; diff --git a/apps/desktop/src/updates/updatesTestHarness.ts b/apps/desktop/src/updates/updatesTestHarness.ts index d8d16b7dbfd6..7fd317bd2c66 100644 --- a/apps/desktop/src/updates/updatesTestHarness.ts +++ b/apps/desktop/src/updates/updatesTestHarness.ts @@ -40,6 +40,12 @@ export interface UpdatesHarnessOptions { readonly savedChannel?: DesktopAppSettings.DesktopSettings["updateChannel"]; /** Adds a WSL backend beside the primary, as on a Windows host with WSL enabled. */ readonly wslBackend?: boolean; + /** Sizes a Windows install preflight sees: free bytes on the install volume, the downloaded installer, and the install folder. */ + readonly diskSpace?: { + readonly freeBytes: number; + readonly installerBytes: number; + readonly installDirectoryBytes: number; + }; } export function makeHarness(options: UpdatesHarnessOptions = {}) { From 4933c121cee94a0cc0b34765019455c4eeda1aa4 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 30 Oct 2026 09:49:23 +0000 Subject: [PATCH 2/8] fix(desktop): Windows updates no longer quit into the installer on a full disk A silent NSIS update that ran out of space aborted partway and left an install that crashed on every launch. Before quitting into the installer on Windows, check the install volume has room for the downloaded installer plus two copies of the install folder (the staged package and the copy into it). If it does not, keep the update downloaded and retryable with a message giving the space needed and available. A failed measurement logs and installs as before. Fixes pingdotgg/t3code#27486 Co-Authored-By: Claude Opus 5.5 --- apps/desktop/src/main.ts | 3 +- .../src/updates/DesktopDiskSpace.test.ts | 35 +++++++++ apps/desktop/src/updates/DesktopDiskSpace.ts | 77 +++++++++++++++++++ apps/desktop/src/updates/DesktopUpdates.ts | 59 ++++++++++++++ .../desktop/src/updates/updatesTestHarness.ts | 23 ++++++ 5 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 apps/desktop/src/updates/DesktopDiskSpace.test.ts create mode 100644 apps/desktop/src/updates/DesktopDiskSpace.ts diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts index 9a3c327e6b86..be3cd16dc6d4 100644 --- a/apps/desktop/src/main.ts +++ b/apps/desktop/src/main.ts @@ -65,6 +65,7 @@ import * as DesktopState from "./app/DesktopState.ts"; import * as DesktopLegacyLocalStorage from "./app/DesktopLegacyLocalStorage.ts"; import * as DesktopTelemetryPublisher from "./telemetry/DesktopTelemetryPublisher.ts"; import * as DesktopRendererHistory from "./telemetry/DesktopRendererHistory.ts"; +import * as DesktopDiskSpace from "./updates/DesktopDiskSpace.ts"; import * as DesktopUpdates from "./updates/DesktopUpdates.ts"; import * as BrowserImport from "./preview/BrowserImport/BrowserImport.ts"; import * as LinuxBrowserSecret from "./preview/BrowserImport/LinuxBrowserSecret.ts"; @@ -211,7 +212,7 @@ const layerDesktopApplication = Layer.mergeAll( layerDesktopSsh, ).pipe( Layer.provideMerge(layerDesktopSnapShot), - Layer.provideMerge(DesktopUpdates.layer), + Layer.provideMerge(DesktopUpdates.layer.pipe(Layer.provide(DesktopDiskSpace.layer))), Layer.provideMerge(layerDesktopWslBackend), Layer.provideMerge(layerDesktopLocalEnvironmentAuth), ); diff --git a/apps/desktop/src/updates/DesktopDiskSpace.test.ts b/apps/desktop/src/updates/DesktopDiskSpace.test.ts new file mode 100644 index 000000000000..cf42a2c40a61 --- /dev/null +++ b/apps/desktop/src/updates/DesktopDiskSpace.test.ts @@ -0,0 +1,35 @@ +import * as NodeServices from "@effect/platform-node/NodeServices"; +import { assert, describe, it } from "@effect/vitest"; +import * as Effect from "effect/Effect"; +import * as Exit from "effect/Exit"; +import * as FileSystem from "effect/FileSystem"; +import * as Layer from "effect/Layer"; +import * as Path from "effect/Path"; + +import * as DesktopDiskSpace from "./DesktopDiskSpace.ts"; + +describe("DesktopDiskSpace", () => { + it.effect("sums nested files without following symlinks", () => + Effect.gen(function* () { + const fileSystem = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const diskSpace = yield* DesktopDiskSpace.DesktopDiskSpace; + const root = yield* fileSystem.makeTempDirectoryScoped(); + const outside = yield* fileSystem.makeTempDirectoryScoped(); + yield* fileSystem.makeDirectory(path.join(root, "resources", "app"), { recursive: true }); + yield* fileSystem.writeFileString(path.join(root, "app.exe"), "x".repeat(100)); + yield* fileSystem.writeFileString( + path.join(root, "resources", "app", "a.js"), + "x".repeat(20), + ); + yield* fileSystem.writeFileString(path.join(outside, "big.bin"), "x".repeat(5000)); + yield* fileSystem.symlink(path.join(outside, "big.bin"), path.join(root, "big-link")); + yield* fileSystem.symlink(outside, path.join(root, "outside-link")); + + assert.equal(yield* diskSpace.directoryBytes(root), 120); + assert.isTrue( + Exit.isFailure(yield* Effect.exit(diskSpace.directoryBytes(path.join(root, "missing")))), + ); + }).pipe(Effect.scoped, Effect.provide(Layer.merge(DesktopDiskSpace.layer, NodeServices.layer))), + ); +}); diff --git a/apps/desktop/src/updates/DesktopDiskSpace.ts b/apps/desktop/src/updates/DesktopDiskSpace.ts new file mode 100644 index 000000000000..4465fa09cd30 --- /dev/null +++ b/apps/desktop/src/updates/DesktopDiskSpace.ts @@ -0,0 +1,77 @@ +// @effect-diagnostics nodeBuiltinImport:off -- FileSystem has no statfs, and its stat follows symlinks. +import * as NodeFSP from "node:fs/promises"; +import * as NodePath from "node:path"; + +import * as Context from "effect/Context"; +import * as Effect from "effect/Effect"; +import * as Layer from "effect/Layer"; +import * as Schema from "effect/Schema"; + +const MAX_DIRECTORY_ENTRIES = 100_000; + +export class DesktopDiskSpaceError extends Schema.TaggedError()( + "DesktopDiskSpaceError", + { + operation: Schema.Literals(["freeBytes", "directoryBytes"]), + cause: Schema.Defect(), + }, +) { + override get message(): string { + return `Could not measure disk space (${this.operation}).`; + } +} + +export class DesktopDiskSpace extends Context.Service< + DesktopDiskSpace, + { + /** Bytes the current user can still write on the volume holding `path`. */ + readonly freeBytes: (path: string) => Effect.Effect; + /** Total size of the regular files below `path`, without following symlinks. */ + readonly directoryBytes: (path: string) => Effect.Effect; + } +>()("@t3tools/desktop/updates/DesktopDiskSpace") {} + +async function sumDirectoryBytes(root: string): Promise { + let total = 0; + let entries = 0; + const pending = [root]; + for (let directory = pending.pop(); directory !== undefined; directory = pending.pop()) { + const children = await NodeFSP.readdir(directory, { withFileTypes: true }).catch( + (cause: unknown) => { + if (directory === root) throw cause; + return []; + }, + ); + entries += children.length; + if (entries > MAX_DIRECTORY_ENTRIES) { + throw new Error(`More than ${MAX_DIRECTORY_ENTRIES} entries below the directory.`); + } + for (const child of children) { + const childPath = NodePath.join(directory, child.name); + if (child.isDirectory()) pending.push(childPath); + else if (child.isFile()) { + total += await NodeFSP.lstat(childPath).then( + (stats) => stats.size, + () => 0, + ); + } + } + } + return total; +} + +export const layer = Layer.succeed(DesktopDiskSpace, { + freeBytes: Effect.fn("DesktopDiskSpace.freeBytes")(function* (path: string) { + const stats = yield* Effect.tryPromise({ + try: () => NodeFSP.statfs(path), + catch: (cause) => new DesktopDiskSpaceError({ operation: "freeBytes", cause }), + }); + return stats.bavail * stats.bsize; + }), + directoryBytes: Effect.fn("DesktopDiskSpace.directoryBytes")(function* (path: string) { + return yield* Effect.tryPromise({ + try: () => sumDirectoryBytes(path), + catch: (cause) => new DesktopDiskSpaceError({ operation: "directoryBytes", cause }), + }); + }), +}); diff --git a/apps/desktop/src/updates/DesktopUpdates.ts b/apps/desktop/src/updates/DesktopUpdates.ts index 3a0b41cd9e36..377f8e48e3fc 100644 --- a/apps/desktop/src/updates/DesktopUpdates.ts +++ b/apps/desktop/src/updates/DesktopUpdates.ts @@ -34,6 +34,7 @@ import * as ElectronUpdater from "../electron/ElectronUpdater.ts"; import * as ElectronWindow from "../electron/ElectronWindow.ts"; import * as IpcChannels from "../ipc/channels.ts"; import * as DesktopAppSettings from "../settings/DesktopAppSettings.ts"; +import * as DesktopDiskSpace from "./DesktopDiskSpace.ts"; import { normalizeDesktopUpdateReleaseNotes } from "./releaseNotes.ts"; import { desktopUpdateChannelOf } from "@t3tools/shared/cliRelease"; import { compareSemverVersions } from "@t3tools/shared/semver"; @@ -71,6 +72,7 @@ const UpdateInfo = Schema.Struct({ // Malformed notes must not block update-state decoding; normalizeDesktopUpdateReleaseNotes validates separately. releaseNotes: Schema.optional(Schema.Unknown), releaseDate: Schema.optional(Schema.String), + downloadedFile: Schema.optional(Schema.String), }); const DownloadProgressInfo = Schema.Struct({ @@ -338,6 +340,8 @@ function getAutoUpdateDisabledReason(args: { return null; } +const MEGABYTE = 1024 * 1024; + function isArm64HostRunningIntelBuild(runtimeInfo: DesktopRuntimeInfo): boolean { return runtimeInfo.hostArch === "arm64" && runtimeInfo.appArch === "x64"; } @@ -352,6 +356,7 @@ export const make = Effect.gen(function* () { const environment = yield* DesktopEnvironment.DesktopEnvironment; const fileSystem = yield* FileSystem.FileSystem; const desktopSettings = yield* DesktopAppSettings.DesktopAppSettings; + const diskSpace = yield* DesktopDiskSpace.DesktopDiskSpace; const appUpdateYmlConfigRef = yield* Ref.make>(Option.none()); const activeUpdateActionRef = yield* Ref.make>(Option.none()); @@ -362,6 +367,7 @@ export const make = Effect.gen(function* () { const updaterConfiguredRef = yield* Ref.make(false); const lastLoggedDownloadMilestoneRef = yield* Ref.make(-1); const notAppliedVersionRef = yield* Ref.make(Option.none()); + const downloadedFileRef = yield* Ref.make(Option.none()); // The release a track switch's database check cleared. A build crosses to another track only // through such a switch, and never below that release: version order alone cannot tell whether // a Stable knows a Nightly's migrations. @@ -711,6 +717,47 @@ export const make = Effect.gen(function* () { ); }); + // A silent NSIS update that runs out of space leaves an install that no longer launches. It needs + // the installer, plus the package staged in $PLUGINSDIR and copied into the install folder. + const findInstallSpaceShortfall = Effect.fn("desktop.updates.findInstallSpaceShortfall")( + function* () { + if (environment.platform !== "win32") return Option.none(); + const installer = yield* Ref.get(downloadedFileRef); + if (Option.isNone(installer)) { + yield* logUpdaterWarning("skipping the install disk space check without an installer path"); + return Option.none(); + } + const installDirectory = environment.path.dirname(environment.resourcesPath); + return yield* Effect.all({ + freeBytes: diskSpace.freeBytes(installDirectory), + installerBytes: fileSystem + .stat(installer.value) + .pipe(Effect.map((info) => Number(info.size))), + installDirectoryBytes: diskSpace.directoryBytes(installDirectory), + }).pipe( + Effect.flatMap( + Effect.fnUntraced(function* ({ freeBytes, installerBytes, installDirectoryBytes }) { + const requiredBytes = installerBytes + 2 * installDirectoryBytes; + if (freeBytes >= requiredBytes) return Option.none(); + yield* logUpdaterWarning("not enough disk space to install the update", { + freeBytes, + requiredBytes, + }); + return Option.some( + `Not enough disk space to install the update: needs about ${Math.ceil(requiredBytes / MEGABYTE)} MB free on the install drive, ${Math.floor(freeBytes / MEGABYTE)} MB available.`, + ); + }), + ), + Effect.catch((error) => + logUpdaterWarning("could not check disk space before installing the update", { + errorTag: error._tag, + cause: describeUpdateErrorCause(error), + }).pipe(Effect.as(Option.none())), + ), + ); + }, + ); + const installDownloadedUpdate = (expectedVersion?: string) => Effect.scoped( Effect.gen(function* () { @@ -759,6 +806,17 @@ export const make = Effect.gen(function* () { return { accepted: false, completed: false, failed: false }; } + const spaceShortfall = yield* findInstallSpaceShortfall().pipe( + Effect.onInterrupt(() => finishUpdateAction("install")), + ); + if (Option.isSome(spaceShortfall)) { + yield* updateState((current) => + reduceDesktopUpdateStateOnInstallFailure(current, spaceShortfall.value), + ); + yield* finishUpdateAction("install"); + return { accepted: true, completed: false, failed: true }; + } + yield* Ref.set(desktopState.quitting, true); yield* Ref.set(installRunningBackendsRef, []); @@ -1032,6 +1090,7 @@ export const make = Effect.gen(function* () { } return; } + yield* Ref.set(downloadedFileRef, Option.fromNullishOr(info.downloadedFile)); yield* setState(reduceDesktopUpdateStateOnDownloadComplete(state, info.version)); yield* logUpdaterInfo("update downloaded", { version: info.version }); }), diff --git a/apps/desktop/src/updates/updatesTestHarness.ts b/apps/desktop/src/updates/updatesTestHarness.ts index 7fd317bd2c66..3d14e85d68af 100644 --- a/apps/desktop/src/updates/updatesTestHarness.ts +++ b/apps/desktop/src/updates/updatesTestHarness.ts @@ -1,5 +1,6 @@ import * as NodeServices from "@effect/platform-node/NodeServices"; import type { DesktopUpdateState } from "@t3tools/contracts"; +import * as ByteSize from "effect/ByteSize"; import * as Effect from "effect/Effect"; import * as FileSystem from "effect/FileSystem"; import * as PlatformError from "effect/PlatformError"; @@ -13,6 +14,7 @@ import * as ElectronUpdater from "../electron/ElectronUpdater.ts"; import * as ElectronWindow from "../electron/ElectronWindow.ts"; import * as DesktopAppSettings from "../settings/DesktopAppSettings.ts"; import * as DesktopState from "../app/DesktopState.ts"; +import * as DesktopDiskSpace from "./DesktopDiskSpace.ts"; import * as DesktopUpdates from "./DesktopUpdates.ts"; export const flushCallbacks = Effect.yieldNow; @@ -239,6 +241,7 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) { } satisfies DesktopAppSettings.DesktopAppSettings["Service"]) : DesktopAppSettings.layer; + const diskSpace = options.diskSpace; const updateRestartMarkers = new Set(); const installRecords = new Map(); let previousInstallRecord = options.installRecord; @@ -261,6 +264,14 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) { }), ); }, + ...(diskSpace === undefined + ? {} + : { + stat: () => + Effect.succeed({ + size: ByteSize.bytes(diskSpace.installerBytes), + } as FileSystem.File.Info), + }), makeDirectory: () => Effect.void, writeFileString: (path, data) => Effect.sync(() => { @@ -275,8 +286,20 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) { }), }); + const unmeasured = (operation: DesktopDiskSpace.DesktopDiskSpaceError["operation"]) => + Effect.fail(new DesktopDiskSpace.DesktopDiskSpaceError({ operation, cause: "unmeasured" })); + const layerDiskSpace = Layer.succeed(DesktopDiskSpace.DesktopDiskSpace, { + freeBytes: () => + diskSpace === undefined ? unmeasured("freeBytes") : Effect.succeed(diskSpace.freeBytes), + directoryBytes: () => + diskSpace === undefined + ? unmeasured("directoryBytes") + : Effect.succeed(diskSpace.installDirectoryBytes), + } satisfies DesktopDiskSpace.DesktopDiskSpace["Service"]); + const layer = DesktopUpdates.layer.pipe( Layer.provide(layerFileSystem), + Layer.provide(layerDiskSpace), Layer.provideMerge(layerUpdater), Layer.provideMerge(layerWindow), Layer.provideMerge(layerBackend), From e23bd9a991712243530a595fae862edbe0648572 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 30 Oct 2026 10:06:31 +0000 Subject: [PATCH 3/8] fix(desktop): measure Windows update space on %TEMP% and count ASAR archives The preflight required installer + two install folders on the install volume, but NSIS removes the old install before staging its package in %TEMP%, so the peak is installer + one install folder (plus a 128 MiB margin) on the temp volume. Inside Electron, fs reports app.asar and server.asar as empty directories, so measure through original-fs. Settings now toasts a refused install instead of dropping it. Co-Authored-By: Claude Opus 5.5 --- apps/desktop/src/updates/DesktopDiskSpace.ts | 27 ++++++----- .../src/updates/DesktopUpdates.test.ts | 45 +++++++++++++++++-- apps/desktop/src/updates/DesktopUpdates.ts | 41 +++++++++-------- .../desktop/src/updates/updatesTestHarness.ts | 10 +++-- .../components/settings/SettingsPanels.tsx | 13 ++++++ 5 files changed, 99 insertions(+), 37 deletions(-) diff --git a/apps/desktop/src/updates/DesktopDiskSpace.ts b/apps/desktop/src/updates/DesktopDiskSpace.ts index 4465fa09cd30..a6e27ff4c9e1 100644 --- a/apps/desktop/src/updates/DesktopDiskSpace.ts +++ b/apps/desktop/src/updates/DesktopDiskSpace.ts @@ -1,5 +1,6 @@ // @effect-diagnostics nodeBuiltinImport:off -- FileSystem has no statfs, and its stat follows symlinks. -import * as NodeFSP from "node:fs/promises"; +import * as NodeFS from "node:fs"; +import * as NodeOS from "node:os"; import * as NodePath from "node:path"; import * as Context from "effect/Context"; @@ -9,10 +10,14 @@ import * as Schema from "effect/Schema"; const MAX_DIRECTORY_ENTRIES = 100_000; +// Electron's fs reports .asar archives as empty directories; original-fs sees the real files. +const NodeFSP = ((process.getBuiltinModule("original-fs") as typeof NodeFS | undefined) ?? NodeFS) + .promises; + export class DesktopDiskSpaceError extends Schema.TaggedError()( "DesktopDiskSpaceError", { - operation: Schema.Literals(["freeBytes", "directoryBytes"]), + operation: Schema.Literals(["tempFreeBytes", "directoryBytes"]), cause: Schema.Defect(), }, ) { @@ -24,8 +29,8 @@ export class DesktopDiskSpaceError extends Schema.TaggedError Effect.Effect; + /** Bytes the current user can still write on the volume holding the temp directory. */ + readonly tempFreeBytes: Effect.Effect; /** Total size of the regular files below `path`, without following symlinks. */ readonly directoryBytes: (path: string) => Effect.Effect; } @@ -61,13 +66,13 @@ async function sumDirectoryBytes(root: string): Promise { } export const layer = Layer.succeed(DesktopDiskSpace, { - freeBytes: Effect.fn("DesktopDiskSpace.freeBytes")(function* (path: string) { - const stats = yield* Effect.tryPromise({ - try: () => NodeFSP.statfs(path), - catch: (cause) => new DesktopDiskSpaceError({ operation: "freeBytes", cause }), - }); - return stats.bavail * stats.bsize; - }), + tempFreeBytes: Effect.tryPromise({ + try: () => NodeFSP.statfs(NodeOS.tmpdir()), + catch: (cause) => new DesktopDiskSpaceError({ operation: "tempFreeBytes", cause }), + }).pipe( + Effect.map((stats) => stats.bavail * stats.bsize), + Effect.withSpan("DesktopDiskSpace.tempFreeBytes"), + ), directoryBytes: Effect.fn("DesktopDiskSpace.directoryBytes")(function* (path: string) { return yield* Effect.tryPromise({ try: () => sumDirectoryBytes(path), diff --git a/apps/desktop/src/updates/DesktopUpdates.test.ts b/apps/desktop/src/updates/DesktopUpdates.test.ts index c9da196b1bfd..78752871fdcf 100644 --- a/apps/desktop/src/updates/DesktopUpdates.test.ts +++ b/apps/desktop/src/updates/DesktopUpdates.test.ts @@ -559,12 +559,12 @@ describe("DesktopUpdates", () => { }); // regression: #27486 a silent NSIS update on a full volume left a half-written install that no longer launched - it.effect("keeps a Windows update retryable when the install volume lacks space", () => { + it.effect("keeps a Windows update retryable when the temp volume lacks space", () => { const megabyte = 1024 * 1024; const harness = makeHarness({ platform: "win32", diskSpace: { - freeBytes: 200 * megabyte, + tempFreeBytes: 200 * megabyte, installerBytes: 150 * megabyte, installDirectoryBytes: 400 * megabyte, }, @@ -596,12 +596,49 @@ describe("DesktopUpdates", () => { ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer))); }); - it.effect("installs a Windows update when the install volume has room", () => { + it.effect( + "installs a Windows update only with room for the installer, install folder and margin", + () => { + const megabyte = 1024 * 1024; + const requiredBytes = (150 + 400 + 128) * megabyte; + const installWithTempFreeBytes = (tempFreeBytes: number) => { + const harness = makeHarness({ + platform: "win32", + diskSpace: { + tempFreeBytes, + installerBytes: 150 * megabyte, + installDirectoryBytes: 400 * megabyte, + }, + }); + return Effect.scoped( + Effect.gen(function* () { + const updates = yield* DesktopUpdates.DesktopUpdates; + yield* updates.configure; + harness.emit("update-downloaded", { + version: "1.2.4", + downloadedFile: + "C:\\Users\\me\\AppData\\Local\\t3code-updater\\pending\\installer.exe", + }); + yield* flushCallbacks; + yield* updates.install; + return harness.quitAndInstalls(); + }), + ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer))); + }; + + return Effect.gen(function* () { + assert.equal(yield* installWithTempFreeBytes(requiredBytes - 1), 0); + assert.equal(yield* installWithTempFreeBytes(requiredBytes), 1); + }); + }, + ); + + it.effect("installs a Windows update when the temp volume has room", () => { const megabyte = 1024 * 1024; const harness = makeHarness({ platform: "win32", diskSpace: { - freeBytes: 2000 * megabyte, + tempFreeBytes: 2000 * megabyte, installerBytes: 150 * megabyte, installDirectoryBytes: 400 * megabyte, }, diff --git a/apps/desktop/src/updates/DesktopUpdates.ts b/apps/desktop/src/updates/DesktopUpdates.ts index 377f8e48e3fc..93ae031cb2f2 100644 --- a/apps/desktop/src/updates/DesktopUpdates.ts +++ b/apps/desktop/src/updates/DesktopUpdates.ts @@ -341,6 +341,8 @@ function getAutoUpdateDisabledReason(args: { } const MEGABYTE = 1024 * 1024; +// Covers cluster rounding and a release that grows; refusing is recoverable, a partial install is not. +const INSTALL_SPACE_MARGIN_BYTES = 128 * MEGABYTE; function isArm64HostRunningIntelBuild(runtimeInfo: DesktopRuntimeInfo): boolean { return runtimeInfo.hostArch === "arm64" && runtimeInfo.appArch === "x64"; @@ -717,8 +719,9 @@ export const make = Effect.gen(function* () { ); }); - // A silent NSIS update that runs out of space leaves an install that no longer launches. It needs - // the installer, plus the package staged in $PLUGINSDIR and copied into the install folder. + // NSIS deletes the old install before staging its package in %TEMP% and copying it in, so the + // %TEMP% volume peaks near installer + install folder. + // A separate install volume only needs about new - old, so it is not checked. const findInstallSpaceShortfall = Effect.fn("desktop.updates.findInstallSpaceShortfall")( function* () { if (environment.platform !== "win32") return Option.none(); @@ -727,27 +730,29 @@ export const make = Effect.gen(function* () { yield* logUpdaterWarning("skipping the install disk space check without an installer path"); return Option.none(); } - const installDirectory = environment.path.dirname(environment.resourcesPath); return yield* Effect.all({ - freeBytes: diskSpace.freeBytes(installDirectory), + freeBytes: diskSpace.tempFreeBytes, installerBytes: fileSystem .stat(installer.value) .pipe(Effect.map((info) => Number(info.size))), - installDirectoryBytes: diskSpace.directoryBytes(installDirectory), - }).pipe( - Effect.flatMap( - Effect.fnUntraced(function* ({ freeBytes, installerBytes, installDirectoryBytes }) { - const requiredBytes = installerBytes + 2 * installDirectoryBytes; - if (freeBytes >= requiredBytes) return Option.none(); - yield* logUpdaterWarning("not enough disk space to install the update", { - freeBytes, - requiredBytes, - }); - return Option.some( - `Not enough disk space to install the update: needs about ${Math.ceil(requiredBytes / MEGABYTE)} MB free on the install drive, ${Math.floor(freeBytes / MEGABYTE)} MB available.`, - ); - }), + installDirectoryBytes: diskSpace.directoryBytes( + environment.path.dirname(environment.resourcesPath), ), + }).pipe( + Effect.flatMap(({ freeBytes, installerBytes, installDirectoryBytes }) => { + const requiredBytes = installerBytes + installDirectoryBytes + INSTALL_SPACE_MARGIN_BYTES; + if (freeBytes >= requiredBytes) return Effect.succeed(Option.none()); + return logUpdaterWarning("not enough disk space to install the update", { + freeBytes, + requiredBytes, + }).pipe( + Effect.as( + Option.some( + `Not enough disk space to install the update: needs about ${Math.ceil(requiredBytes / MEGABYTE)} MB free, ${Math.floor(freeBytes / MEGABYTE)} MB available.`, + ), + ), + ); + }), Effect.catch((error) => logUpdaterWarning("could not check disk space before installing the update", { errorTag: error._tag, diff --git a/apps/desktop/src/updates/updatesTestHarness.ts b/apps/desktop/src/updates/updatesTestHarness.ts index 3d14e85d68af..9c2b97f2e7bb 100644 --- a/apps/desktop/src/updates/updatesTestHarness.ts +++ b/apps/desktop/src/updates/updatesTestHarness.ts @@ -42,9 +42,9 @@ export interface UpdatesHarnessOptions { readonly savedChannel?: DesktopAppSettings.DesktopSettings["updateChannel"]; /** Adds a WSL backend beside the primary, as on a Windows host with WSL enabled. */ readonly wslBackend?: boolean; - /** Sizes a Windows install preflight sees: free bytes on the install volume, the downloaded installer, and the install folder. */ + /** Sizes a Windows install preflight sees: free bytes on the temp volume, the downloaded installer, and the install folder. */ readonly diskSpace?: { - readonly freeBytes: number; + readonly tempFreeBytes: number; readonly installerBytes: number; readonly installDirectoryBytes: number; }; @@ -289,8 +289,10 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) { const unmeasured = (operation: DesktopDiskSpace.DesktopDiskSpaceError["operation"]) => Effect.fail(new DesktopDiskSpace.DesktopDiskSpaceError({ operation, cause: "unmeasured" })); const layerDiskSpace = Layer.succeed(DesktopDiskSpace.DesktopDiskSpace, { - freeBytes: () => - diskSpace === undefined ? unmeasured("freeBytes") : Effect.succeed(diskSpace.freeBytes), + tempFreeBytes: + diskSpace === undefined + ? unmeasured("tempFreeBytes") + : Effect.succeed(diskSpace.tempFreeBytes), directoryBytes: () => diskSpace === undefined ? unmeasured("directoryBytes") diff --git a/apps/web/src/components/settings/SettingsPanels.tsx b/apps/web/src/components/settings/SettingsPanels.tsx index c4e3d27a07fa..d3294e3d2a8b 100644 --- a/apps/web/src/components/settings/SettingsPanels.tsx +++ b/apps/web/src/components/settings/SettingsPanels.tsx @@ -31,6 +31,7 @@ import { MobileAppSettingsRow } from "./MobileAppSettingsRow"; import { canCheckForUpdate, getDesktopUpdateButtonTooltip, + getDesktopUpdateActionError, getDesktopUpdateDisabledReason, getDesktopUpdateInstallConfirmationMessage, isDesktopUpdateButtonDisabled, @@ -230,6 +231,18 @@ function AboutVersionSection() { } void bridge .installUpdate() + .then((result) => { + const actionError = getDesktopUpdateActionError(result); + if (actionError) { + toastManager.add( + stackedThreadToast({ + type: "error", + title: "Could not install update", + description: actionError, + }), + ); + } + }) .catch((error: unknown) => { toastManager.add( stackedThreadToast({ From 909389dfb1cbeaca8d8495a1863fb82578ac8103 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 30 Oct 2026 10:22:34 +0000 Subject: [PATCH 4/8] fix(desktop): Windows update preflight also checks a separate install volume Check the install folder's volume for the growth margin when it is not the temp volume, and clear an earlier refusal's message once the preflight passes so a successful retry does not report it. Co-Authored-By: Claude Opus 5.5 --- apps/desktop/src/updates/DesktopDiskSpace.ts | 23 +++++---- .../src/updates/DesktopUpdates.test.ts | 27 ++++++---- apps/desktop/src/updates/DesktopUpdates.ts | 50 ++++++++++++------- .../desktop/src/updates/updatesTestHarness.ts | 16 ++++-- 4 files changed, 71 insertions(+), 45 deletions(-) diff --git a/apps/desktop/src/updates/DesktopDiskSpace.ts b/apps/desktop/src/updates/DesktopDiskSpace.ts index a6e27ff4c9e1..c2ce54496b37 100644 --- a/apps/desktop/src/updates/DesktopDiskSpace.ts +++ b/apps/desktop/src/updates/DesktopDiskSpace.ts @@ -17,7 +17,7 @@ const NodeFSP = ((process.getBuiltinModule("original-fs") as typeof NodeFS | und export class DesktopDiskSpaceError extends Schema.TaggedError()( "DesktopDiskSpaceError", { - operation: Schema.Literals(["tempFreeBytes", "directoryBytes"]), + operation: Schema.Literals(["freeBytes", "directoryBytes"]), cause: Schema.Defect(), }, ) { @@ -29,8 +29,10 @@ export class DesktopDiskSpaceError extends Schema.TaggedError; + /** The temp directory a spawned installer inherits. */ + readonly tempDirectory: string; + /** Bytes the current user can still write on the volume holding `path`. */ + readonly freeBytes: (path: string) => Effect.Effect; /** Total size of the regular files below `path`, without following symlinks. */ readonly directoryBytes: (path: string) => Effect.Effect; } @@ -66,13 +68,14 @@ async function sumDirectoryBytes(root: string): Promise { } export const layer = Layer.succeed(DesktopDiskSpace, { - tempFreeBytes: Effect.tryPromise({ - try: () => NodeFSP.statfs(NodeOS.tmpdir()), - catch: (cause) => new DesktopDiskSpaceError({ operation: "tempFreeBytes", cause }), - }).pipe( - Effect.map((stats) => stats.bavail * stats.bsize), - Effect.withSpan("DesktopDiskSpace.tempFreeBytes"), - ), + tempDirectory: NodeOS.tmpdir(), + freeBytes: Effect.fn("DesktopDiskSpace.freeBytes")(function* (path: string) { + const stats = yield* Effect.tryPromise({ + try: () => NodeFSP.statfs(path), + catch: (cause) => new DesktopDiskSpaceError({ operation: "freeBytes", cause }), + }); + return stats.bavail * stats.bsize; + }), directoryBytes: Effect.fn("DesktopDiskSpace.directoryBytes")(function* (path: string) { return yield* Effect.tryPromise({ try: () => sumDirectoryBytes(path), diff --git a/apps/desktop/src/updates/DesktopUpdates.test.ts b/apps/desktop/src/updates/DesktopUpdates.test.ts index 78752871fdcf..9f0eea95209a 100644 --- a/apps/desktop/src/updates/DesktopUpdates.test.ts +++ b/apps/desktop/src/updates/DesktopUpdates.test.ts @@ -561,14 +561,12 @@ describe("DesktopUpdates", () => { // regression: #27486 a silent NSIS update on a full volume left a half-written install that no longer launched it.effect("keeps a Windows update retryable when the temp volume lacks space", () => { const megabyte = 1024 * 1024; - const harness = makeHarness({ - platform: "win32", - diskSpace: { - tempFreeBytes: 200 * megabyte, - installerBytes: 150 * megabyte, - installDirectoryBytes: 400 * megabyte, - }, - }); + const diskSpace = { + tempFreeBytes: 200 * megabyte, + installerBytes: 150 * megabyte, + installDirectoryBytes: 400 * megabyte, + }; + const harness = makeHarness({ platform: "win32", diskSpace }); return Effect.scoped( Effect.gen(function* () { @@ -592,6 +590,11 @@ describe("DesktopUpdates", () => { assert.equal(result.state.errorContext, "install"); assert.isTrue(result.state.canRetry); assert.match(result.state.message ?? "", /space/i); + + diskSpace.tempFreeBytes = 2000 * megabyte; + const retry = yield* updates.install; + assert.equal(harness.quitAndInstalls(), 1); + assert.isNull(retry.state.message, "a successful retry still reports the earlier refusal"); }), ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer))); }); @@ -633,12 +636,13 @@ describe("DesktopUpdates", () => { }, ); - it.effect("installs a Windows update when the temp volume has room", () => { + it.effect("keeps a Windows update retryable when a separate install volume is full", () => { const megabyte = 1024 * 1024; const harness = makeHarness({ platform: "win32", diskSpace: { tempFreeBytes: 2000 * megabyte, + installFreeBytes: 5 * megabyte, installerBytes: 150 * megabyte, installDirectoryBytes: 400 * megabyte, }, @@ -654,8 +658,9 @@ describe("DesktopUpdates", () => { }); yield* flushCallbacks; - assert.isTrue((yield* updates.install).accepted); - assert.equal(harness.quitAndInstalls(), 1); + const result = yield* updates.install; + assert.equal(harness.quitAndInstalls(), 0); + assert.match(result.state.message ?? "", /space/i); }), ).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 93ae031cb2f2..113f59e481e1 100644 --- a/apps/desktop/src/updates/DesktopUpdates.ts +++ b/apps/desktop/src/updates/DesktopUpdates.ts @@ -720,8 +720,7 @@ export const make = Effect.gen(function* () { }); // NSIS deletes the old install before staging its package in %TEMP% and copying it in, so the - // %TEMP% volume peaks near installer + install folder. - // A separate install volume only needs about new - old, so it is not checked. + // %TEMP% volume peaks near installer + install folder; a separate install volume needs the growth. const findInstallSpaceShortfall = Effect.fn("desktop.updates.findInstallSpaceShortfall")( function* () { if (environment.platform !== "win32") return Option.none(); @@ -730,29 +729,36 @@ export const make = Effect.gen(function* () { yield* logUpdaterWarning("skipping the install disk space check without an installer path"); return Option.none(); } + const installDirectory = environment.path.dirname(environment.resourcesPath); return yield* Effect.all({ - freeBytes: diskSpace.tempFreeBytes, + tempFreeBytes: diskSpace.freeBytes(diskSpace.tempDirectory), + installFreeBytes: diskSpace.freeBytes(installDirectory), installerBytes: fileSystem .stat(installer.value) .pipe(Effect.map((info) => Number(info.size))), - installDirectoryBytes: diskSpace.directoryBytes( - environment.path.dirname(environment.resourcesPath), - ), + installDirectoryBytes: diskSpace.directoryBytes(installDirectory), }).pipe( - Effect.flatMap(({ freeBytes, installerBytes, installDirectoryBytes }) => { - const requiredBytes = installerBytes + installDirectoryBytes + INSTALL_SPACE_MARGIN_BYTES; - if (freeBytes >= requiredBytes) return Effect.succeed(Option.none()); - return logUpdaterWarning("not enough disk space to install the update", { - freeBytes, - requiredBytes, - }).pipe( - Effect.as( - Option.some( - `Not enough disk space to install the update: needs about ${Math.ceil(requiredBytes / MEGABYTE)} MB free, ${Math.floor(freeBytes / MEGABYTE)} MB available.`, + Effect.flatMap( + ({ tempFreeBytes, installFreeBytes, installerBytes, installDirectoryBytes }) => { + const tempRequiredBytes = + installerBytes + installDirectoryBytes + INSTALL_SPACE_MARGIN_BYTES; + const [freeBytes, requiredBytes] = + tempFreeBytes < tempRequiredBytes + ? [tempFreeBytes, tempRequiredBytes] + : [installFreeBytes, INSTALL_SPACE_MARGIN_BYTES]; + if (freeBytes >= requiredBytes) return Effect.succeed(Option.none()); + return logUpdaterWarning("not enough disk space to install the update", { + freeBytes, + requiredBytes, + }).pipe( + Effect.as( + Option.some( + `Not enough disk space to install the update: needs about ${Math.ceil(requiredBytes / MEGABYTE)} MB free, ${Math.floor(freeBytes / MEGABYTE)} MB available.`, + ), ), - ), - ); - }), + ); + }, + ), Effect.catch((error) => logUpdaterWarning("could not check disk space before installing the update", { errorTag: error._tag, @@ -821,6 +827,12 @@ export const make = Effect.gen(function* () { yield* finishUpdateAction("install"); return { accepted: true, completed: false, failed: true }; } + // A refusal's message would otherwise read as this attempt's failure. + yield* updateState((current) => + current.errorContext === "install" + ? { ...current, message: null, errorContext: null } + : current, + ); yield* Ref.set(desktopState.quitting, true); yield* Ref.set(installRunningBackendsRef, []); diff --git a/apps/desktop/src/updates/updatesTestHarness.ts b/apps/desktop/src/updates/updatesTestHarness.ts index 9c2b97f2e7bb..96c87635c47c 100644 --- a/apps/desktop/src/updates/updatesTestHarness.ts +++ b/apps/desktop/src/updates/updatesTestHarness.ts @@ -42,9 +42,10 @@ export interface UpdatesHarnessOptions { readonly savedChannel?: DesktopAppSettings.DesktopSettings["updateChannel"]; /** Adds a WSL backend beside the primary, as on a Windows host with WSL enabled. */ readonly wslBackend?: boolean; - /** Sizes a Windows install preflight sees: free bytes on the temp volume, the downloaded installer, and the install folder. */ + /** Sizes a Windows install preflight reads, live; without `installFreeBytes` temp and install share a volume. */ readonly diskSpace?: { - readonly tempFreeBytes: number; + tempFreeBytes: number; + readonly installFreeBytes?: number; readonly installerBytes: number; readonly installDirectoryBytes: number; }; @@ -289,10 +290,15 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) { const unmeasured = (operation: DesktopDiskSpace.DesktopDiskSpaceError["operation"]) => Effect.fail(new DesktopDiskSpace.DesktopDiskSpaceError({ operation, cause: "unmeasured" })); const layerDiskSpace = Layer.succeed(DesktopDiskSpace.DesktopDiskSpace, { - tempFreeBytes: + tempDirectory: "C:\\Users\\me\\AppData\\Local\\Temp", + freeBytes: (path) => diskSpace === undefined - ? unmeasured("tempFreeBytes") - : Effect.succeed(diskSpace.tempFreeBytes), + ? unmeasured("freeBytes") + : Effect.sync(() => + path.startsWith("C:\\Users\\me\\AppData\\Local\\Temp") + ? diskSpace.tempFreeBytes + : (diskSpace.installFreeBytes ?? diskSpace.tempFreeBytes), + ), directoryBytes: () => diskSpace === undefined ? unmeasured("directoryBytes") From b3500d212e6bcc48f4dad881a111db37b8772c83 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 30 Oct 2026 10:35:03 +0000 Subject: [PATCH 5/8] test(desktop): a Windows update still installs when disk space cannot be measured Co-Authored-By: Claude Opus 5.5 --- .../src/updates/DesktopUpdates.test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/apps/desktop/src/updates/DesktopUpdates.test.ts b/apps/desktop/src/updates/DesktopUpdates.test.ts index 9f0eea95209a..b80c6db8b168 100644 --- a/apps/desktop/src/updates/DesktopUpdates.test.ts +++ b/apps/desktop/src/updates/DesktopUpdates.test.ts @@ -665,6 +665,25 @@ describe("DesktopUpdates", () => { ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer))); }); + it.effect("installs a Windows update when disk space cannot be measured", () => { + const harness = makeHarness({ platform: "win32" }); + + return Effect.scoped( + Effect.gen(function* () { + const updates = yield* DesktopUpdates.DesktopUpdates; + yield* updates.configure; + harness.emit("update-downloaded", { + version: "1.2.4", + downloadedFile: "C:\\Users\\me\\AppData\\Local\\t3code-updater\\pending\\installer.exe", + }); + yield* flushCallbacks; + + yield* updates.install; + assert.equal(harness.quitAndInstalls(), 1, "an unmeasured volume blocked the update"); + }), + ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer))); + }); + it.effect("restores only desired-running instances after an installer error event", () => { const starts: string[] = []; const stops: string[] = []; From 0ab5dbee78b6ec2e2e18f15d8417caa55f269390 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 30 Oct 2026 10:50:46 +0000 Subject: [PATCH 6/8] fix(desktop): startup recovery explains why an update did not install Co-Authored-By: Claude Opus 5.5 --- .../src/app/DesktopStartupRecovery.test.ts | 18 ++++++++++++++++++ apps/desktop/src/app/DesktopStartupRecovery.ts | 9 ++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src/app/DesktopStartupRecovery.test.ts b/apps/desktop/src/app/DesktopStartupRecovery.test.ts index d8a0ef1a999c..c8be135e735b 100644 --- a/apps/desktop/src/app/DesktopStartupRecovery.test.ts +++ b/apps/desktop/src/app/DesktopStartupRecovery.test.ts @@ -46,6 +46,24 @@ describe("resolveStartupRecoveryOffer", () => { }); }); + it("explains why the offered update did not install", () => { + expect( + resolveStartupRecoveryOffer( + updateState({ + status: "downloaded", + downloadedVersion: "0.1.4", + errorContext: "install", + message: "Not enough disk space to install the update.", + }), + "0.1.2", + ), + ).toEqual({ + _tag: "Update", + version: "0.1.4", + installError: "Not enough disk space to install the update.", + }); + }); + it("does not offer an update that already failed to apply here", () => { expect( resolveStartupRecoveryOffer( diff --git a/apps/desktop/src/app/DesktopStartupRecovery.ts b/apps/desktop/src/app/DesktopStartupRecovery.ts index 4d2dbcfb1440..5ad25ba6d648 100644 --- a/apps/desktop/src/app/DesktopStartupRecovery.ts +++ b/apps/desktop/src/app/DesktopStartupRecovery.ts @@ -29,7 +29,7 @@ const { logInfo, logWarning } = DesktopObservability.makeComponentLogger( export type StartupRecoveryOffer = | { readonly _tag: "Checking" } - | { readonly _tag: "Update"; readonly version: string } + | { readonly _tag: "Update"; readonly version: string; readonly installError?: string } | { readonly _tag: "Downloading"; readonly version: string; readonly percent: number | null } | { readonly _tag: "Reinstall"; readonly version: string } | { readonly _tag: "Releases" }; @@ -53,7 +53,10 @@ export function resolveStartupRecoveryOffer( update.downloadedVersion ?? (update.status === "available" ? update.availableVersion : null); // A version that already failed to apply here would loop through install and relaunch. if (updateVersion !== null && updateVersion !== update.notAppliedVersion) { - return { _tag: "Update", version: updateVersion }; + const installError = update.errorContext === "install" ? update.message?.trim() : undefined; + return installError + ? { _tag: "Update", version: updateVersion, installError } + : { _tag: "Update", version: updateVersion }; } if (update.enabled && (update.status === "idle" || update.status === "checking")) { return { _tag: "Checking" }; @@ -80,7 +83,7 @@ function describeOffer(offer: StartupRecoveryOffer): { text: string; action: str return { text: "Checking for a newer version…", action: "" }; case "Update": return { - text: `Version ${offer.version} is available. It can contain a fix.`, + text: offer.installError ?? `Version ${offer.version} is available. It can contain a fix.`, action: actionLink("update", `Update to ${offer.version}`, true), }; case "Downloading": From c75f2353295d1b9e6ed4b4c8f8da76e7519c6a1f Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Nov 2026 00:18:17 +0000 Subject: [PATCH 7/8] test(desktop): drop the disk space threshold test that mirrored the margin constant AI-assisted; verified with the tests and tools listed above. --- .../src/updates/DesktopUpdates.test.ts | 37 ------------------- 1 file changed, 37 deletions(-) diff --git a/apps/desktop/src/updates/DesktopUpdates.test.ts b/apps/desktop/src/updates/DesktopUpdates.test.ts index ed4c659c59d7..8d71b18caaa0 100644 --- a/apps/desktop/src/updates/DesktopUpdates.test.ts +++ b/apps/desktop/src/updates/DesktopUpdates.test.ts @@ -600,43 +600,6 @@ describe("DesktopUpdates", () => { ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer))); }); - it.effect( - "installs a Windows update only with room for the installer, install folder and margin", - () => { - const megabyte = 1024 * 1024; - const requiredBytes = (150 + 400 + 128) * megabyte; - const installWithTempFreeBytes = (tempFreeBytes: number) => { - const harness = makeHarness({ - platform: "win32", - diskSpace: { - tempFreeBytes, - installerBytes: 150 * megabyte, - installDirectoryBytes: 400 * megabyte, - }, - }); - return Effect.scoped( - Effect.gen(function* () { - const updates = yield* DesktopUpdates.DesktopUpdates; - yield* updates.configure; - harness.emit("update-downloaded", { - version: "1.2.4", - downloadedFile: - "C:\\Users\\me\\AppData\\Local\\t3code-updater\\pending\\installer.exe", - }); - yield* flushCallbacks; - yield* updates.install; - return harness.quitAndInstalls(); - }), - ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer))); - }; - - return Effect.gen(function* () { - assert.equal(yield* installWithTempFreeBytes(requiredBytes - 1), 0); - assert.equal(yield* installWithTempFreeBytes(requiredBytes), 1); - }); - }, - ); - it.effect("keeps a Windows update retryable when a separate install volume is full", () => { const megabyte = 1024 * 1024; const harness = makeHarness({ From 03e577816386672a2435444b685040b931307977 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 13 Nov 2026 23:55:38 +0000 Subject: [PATCH 8/8] fix(desktop): Windows update preflight no longer trusts a partial size or a full install volume A nested directory or file the walk could not read counted as zero bytes, so a partial total could approve the installer. Any failure now fails the measurement. A separate install volume also needs room for a second install folder, because NSIS keeps the old files when it cannot run the old uninstaller. Co-Authored-By: Claude Opus 5.5 --- apps/desktop/src/updates/DesktopDiskSpace.ts | 19 +++++-------------- .../src/updates/DesktopUpdates.test.ts | 2 +- apps/desktop/src/updates/DesktopUpdates.ts | 5 +++-- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/apps/desktop/src/updates/DesktopDiskSpace.ts b/apps/desktop/src/updates/DesktopDiskSpace.ts index c2ce54496b37..7f20e1389d94 100644 --- a/apps/desktop/src/updates/DesktopDiskSpace.ts +++ b/apps/desktop/src/updates/DesktopDiskSpace.ts @@ -43,12 +43,8 @@ async function sumDirectoryBytes(root: string): Promise { let entries = 0; const pending = [root]; for (let directory = pending.pop(); directory !== undefined; directory = pending.pop()) { - const children = await NodeFSP.readdir(directory, { withFileTypes: true }).catch( - (cause: unknown) => { - if (directory === root) throw cause; - return []; - }, - ); + // A partial total would understate the space the installer needs, so any failure fails the walk. + const children = await NodeFSP.readdir(directory, { withFileTypes: true }); entries += children.length; if (entries > MAX_DIRECTORY_ENTRIES) { throw new Error(`More than ${MAX_DIRECTORY_ENTRIES} entries below the directory.`); @@ -56,18 +52,13 @@ async function sumDirectoryBytes(root: string): Promise { for (const child of children) { const childPath = NodePath.join(directory, child.name); if (child.isDirectory()) pending.push(childPath); - else if (child.isFile()) { - total += await NodeFSP.lstat(childPath).then( - (stats) => stats.size, - () => 0, - ); - } + else if (child.isFile()) total += (await NodeFSP.lstat(childPath)).size; } } return total; } -export const layer = Layer.succeed(DesktopDiskSpace, { +export const layer = Layer.sync(DesktopDiskSpace, () => ({ tempDirectory: NodeOS.tmpdir(), freeBytes: Effect.fn("DesktopDiskSpace.freeBytes")(function* (path: string) { const stats = yield* Effect.tryPromise({ @@ -82,4 +73,4 @@ export const layer = Layer.succeed(DesktopDiskSpace, { catch: (cause) => new DesktopDiskSpaceError({ operation: "directoryBytes", cause }), }); }), -}); +})); diff --git a/apps/desktop/src/updates/DesktopUpdates.test.ts b/apps/desktop/src/updates/DesktopUpdates.test.ts index b9d87ce462dd..8af51f055fb9 100644 --- a/apps/desktop/src/updates/DesktopUpdates.test.ts +++ b/apps/desktop/src/updates/DesktopUpdates.test.ts @@ -774,7 +774,7 @@ describe("DesktopUpdates", () => { platform: "win32", diskSpace: { tempFreeBytes: 2000 * megabyte, - installFreeBytes: 5 * megabyte, + installFreeBytes: 200 * megabyte, installerBytes: 150 * megabyte, installDirectoryBytes: 400 * megabyte, }, diff --git a/apps/desktop/src/updates/DesktopUpdates.ts b/apps/desktop/src/updates/DesktopUpdates.ts index 0ff4f52b1a81..a49fde88af7a 100644 --- a/apps/desktop/src/updates/DesktopUpdates.ts +++ b/apps/desktop/src/updates/DesktopUpdates.ts @@ -804,7 +804,8 @@ export const make = Effect.gen(function* () { }); // NSIS deletes the old install before staging its package in %TEMP% and copying it in, so the - // %TEMP% volume peaks near installer + install folder; a separate install volume needs the growth. + // %TEMP% volume peaks near installer + install folder. A separate install volume keeps the old + // files when the old uninstaller cannot run, so it needs room for a second install folder. const findInstallSpaceShortfall = Effect.fn("desktop.updates.findInstallSpaceShortfall")( function* () { if (environment.platform !== "win32") return Option.none(); @@ -829,7 +830,7 @@ export const make = Effect.gen(function* () { const [freeBytes, requiredBytes] = tempFreeBytes < tempRequiredBytes ? [tempFreeBytes, tempRequiredBytes] - : [installFreeBytes, INSTALL_SPACE_MARGIN_BYTES]; + : [installFreeBytes, installDirectoryBytes + INSTALL_SPACE_MARGIN_BYTES]; if (freeBytes >= requiredBytes) return Effect.succeed(Option.none()); return logUpdaterWarning("not enough disk space to install the update", { freeBytes,