Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: download only changed parts of Windows updates

ogsamrat544af8ad3b72
diff --git a/apps/desktop/electron/disk-cleanup.test.mjs b/apps/desktop/electron/disk-cleanup.test.mjs
index 14dfeca4..6269f261 100644
--- a/apps/desktop/electron/disk-cleanup.test.mjs
+++ b/apps/desktop/electron/disk-cleanup.test.mjs
@@ -85,11 +85,12 @@ test("three successive updates: the installed installers go, a newer downloaded
write(path.join(paths.userData, "app-update-installer", "OmniRush.ai-3.6.3-arm64.dmg"), 2 * MB);
write(path.join(paths.userData, "app-update-installer", "OmniRush.ai-3.6.5-arm64.dmg.part"), MB);
const dry = await cleanupPass({ paths, currentVersion: "3.6.4", dryRun: true });
- assert.ok(dry.freed >= 8 * MB, String(dry.freed));
+ assert.ok(dry.freed >= 6 * MB, String(dry.freed));
assert.ok(fs.existsSync(path.join(paths.updaterCache, "pending")), "dry run removes nothing");
const pass = await cleanupPass({ paths, currentVersion: "3.6.4" });
assert.ok(!fs.existsSync(path.join(paths.updaterCache, "pending")));
- assert.ok(!fs.existsSync(path.join(paths.updaterCache, "installer.exe")));
+ assert.ok(fs.existsSync(path.join(paths.updaterCache, "installer.exe")), "the differential update base stays");
+ assert.ok(fs.existsSync(path.join(paths.updaterCache, "current.blockmap")));
assert.ok(!fs.existsSync(path.join(paths.userData, "app-update-installer", "OmniRush.ai-3.6.3-arm64.dmg")));
assert.ok(!fs.existsSync(path.join(paths.userData, "app-update-installer", "OmniRush.ai-3.6.5-arm64.dmg.part")));
assert.equal(pass.freed, dry.freed);
@@ -178,7 +179,7 @@ test("Windows-locked files are kept and reported as in use, never thrown; the re
const pass = await cleanupPass({ paths, currentVersion: "3.6.4" });
fs.chmodSync(path.join(paths.updaterCache, "pending"), 0o700);
assert.ok(pass.items.some((i) => i.path.endsWith("pending") && i.locked));
- assert.ok(!fs.existsSync(path.join(paths.updaterCache, "installer.exe")));
+ assert.ok(fs.existsSync(path.join(paths.updaterCache, "installer.exe")));
assert.equal(pass.locked, 1);
});
diff --git a/apps/desktop/electron/disk-cleanup/index.mjs b/apps/desktop/electron/disk-cleanup/index.mjs
index 6846e7d8..8c216b92 100644
--- a/apps/desktop/electron/disk-cleanup/index.mjs
+++ b/apps/desktop/electron/disk-cleanup/index.mjs
@@ -1,6 +1,7 @@
// What the desktop app lets go of so updates do not keep eating disk space:
// - the update installer electron-updater keeps after it was installed
-// (<cache>/<updaterCacheDirName>/pending, its installer.exe/blockmap copies)
+// (<cache>/<updaterCacheDirName>/pending; the installed version's installer.exe
+// and current.blockmap stay as the base of the next differential update)
// - our own installer cache (app-update-installer: a macOS DMG/zip) once that
// version or a newer one runs
// - with "Free up space" only: Linux packages (.deb/.rpm/.pacman) this app
@@ -182,11 +183,8 @@ async function updaterCacheItems({ cacheDir, currentVersion, now, dryRun }) {
}
if (old) items.push({ kind: "installer", path: pending, reason: version ? `update ${version} installed` : "old update download", ...(await removeAsync(pending, { dryRun })) });
}
- // Differential-download copies (differential downloads are off in this app).
- for (const name of ["installer.exe", "current.blockmap"]) {
- const file = path.join(cacheDir, name);
- if (existsSync(file)) items.push({ kind: "installer", path: file, reason: "old installer copy", ...(await removeAsync(file, { dryRun })) });
- }
+ // installer.exe and current.blockmap stay: they are the installed version's
+ // installer, the base the next Windows update downloads only the changes against.
return items;
}
diff --git a/apps/desktop/electron/updater.mjs b/apps/desktop/electron/updater.mjs
index 70ac2893..6cf82ab0 100644
--- a/apps/desktop/electron/updater.mjs
+++ b/apps/desktop/electron/updater.mjs
@@ -67,7 +67,8 @@ function resolveAppVersion(app) {
// The public distribution reads `latest*.yml` from the latest GitHub release.
// There is no public Alpha feed: the Alpha channel exists only when a
// distribution ships its own feed directory (see updaterFeedOptions).
-export const STABLE_UPDATER_FEED_URL = "https://github.com/omnirush-ai/omnirush-gui/releases/latest/download";
+const GITHUB_RELEASES_URL = "https://github.com/omnirush-ai/omnirush-gui/releases";
+export const STABLE_UPDATER_FEED_URL = `${GITHUB_RELEASES_URL}/latest/download`;
/**
* Feed selection shared by every updater IPC handler. `manifestChannel` picks
@@ -291,9 +292,16 @@ async function applyElectronUpdaterFeed(
// distribution reading latest*.yml and updating itself into the public app.
// Public builds pass no channel and keep the provider's `latest` default.
if (updater?.setFeedURL) {
+ // The installed version's blockmap, for a differential download. The public
+ // feed (releases/latest/download) only has the newest release's files.
+ updater.previousBlockmapBaseUrlOverride = state.feedUrl.startsWith(GITHUB_RELEASES_URL)
+ ? `${GITHUB_RELEASES_URL}/download/v${currentVersion}`
+ : null;
updater.setFeedURL({
provider: "generic",
url: state.feedUrl,
+ // GitHub's asset storage answers a multi-range request with 501.
+ useMultipleRangeRequest: false,
...(feedOptions.manifestChannel !== "latest" ? { channel: feedOptions.manifestChannel } : {}),
});
}
@@ -861,12 +869,13 @@ export function registerUpdaterIpc({
// after a newer release was published. Quit and restart both go
// through ensureNewestDownloaded(), which re-checks the feed first.
autoUpdaterInstance.autoInstallOnAppQuit = false;
- // Differential (blockmap) downloads reconstruct the update zip from the
- // installed app + a diff. On macOS that reconstructed bundle is what
- // feeds Squirrel's fragile move-based install, and is a common trigger
- // for the "Failed to copy bundle … no such file" abort. Download the
- // full zip instead — alpha builds are swapped wholesale anyway.
- autoUpdaterInstance.disableDifferentialDownload = true;
+ // Windows downloads only the blocks of the new installer that changed
+ // since the installed one (NSIS blockmaps, about 10% of the installer
+ // between releases); any failure falls back to the full installer and
+ // the result is sha512-checked either way. macOS keeps the full zip:
+ // the reconstructed zip feeds Squirrel's move-based install, and a
+ // differential would keep a second ~230 MB update.zip in the cache.
+ autoUpdaterInstance.disableDifferentialDownload = platform !== "win32";
// Make Squirrel.Mac write contents in place rather than moving whole
// bundles (see enableSquirrelDirectContentsWrite for why).
await enableSquirrelDirectContentsWrite(shipItDefaultsDomain);
diff --git a/apps/desktop/electron/updater.test.mjs b/apps/desktop/electron/updater.test.mjs
index d878800a..1f033f89 100644
--- a/apps/desktop/electron/updater.test.mjs
+++ b/apps/desktop/electron/updater.test.mjs
@@ -885,7 +885,7 @@ describe("release channel changes", () => {
});
it("normalizes a persisted or requested alpha channel to stable on the public distribution", async () => {
- const { tempDir, handlers, feeds } = await registerFakeUpdaterIpc({ version: "0.18.0" });
+ const { tempDir, handlers, feeds, updater } = await registerFakeUpdaterIpc({ version: "0.18.0" });
try {
const channelPath = path.join(tempDir, "userData", "electron-updater-channel.v1.json");
await mkdir(path.dirname(channelPath), { recursive: true });
@@ -905,6 +905,10 @@ describe("release channel changes", () => {
assert.equal(requested.feedUrl, STABLE_FEED);
assert.equal(feeds.at(-1)?.url, STABLE_FEED);
assert.ok(feeds.every((feed) => feed.url === STABLE_FEED), "no feed may point at an Alpha release");
+ // Windows differential download: single ranges (GitHub answers multi-range
+ // requests with 501) and the installed version's blockmap from its own release.
+ assert.equal(feeds.at(-1)?.useMultipleRangeRequest, false);
+ assert.equal(updater.previousBlockmapBaseUrlOverride, "https://github.com/omnirush-ai/omnirush-gui/releases/download/v0.17.0");
const selected = await setChannel(null, "alpha");
assert.equal(selected.channel, "stable");
diff --git a/scripts/release/windows-updater-e2e.mjs b/scripts/release/windows-updater-e2e.mjs
index 7eee045e..e560e1f0 100644
--- a/scripts/release/windows-updater-e2e.mjs
+++ b/scripts/release/windows-updater-e2e.mjs
@@ -14,6 +14,10 @@
* points the app at it with OMNIRUSH_UPDATER_DEV_FEED_URL, which every
* release since the updater rewrite honors for loopback URLs only.
* --expect none: the check must report no update, and nothing may install.
+ * --from-installer <exe>: install this local build instead of the published
+ * v<from> (to test an updater change before it ships). The feed answers single
+ * Range requests and the run reports the installer bytes it served, so a
+ * differential download shows up as a fraction of the installer size.
*/
import { execFileSync, spawn } from "node:child_process";
import { createReadStream, existsSync, mkdirSync, openSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
@@ -32,6 +36,7 @@ function argValue(name) {
const from = argValue("--from");
const expect = argValue("--expect");
const feedDir = argValue("--feed");
+const fromInstaller = argValue("--from-installer");
const workDir = path.resolve(argValue("--work") ?? path.join(process.cwd(), "updater-e2e"));
if (!from || !expect) {
console.error("Usage: windows-updater-e2e.mjs --from X.Y.Z --expect X.Y.Z|none [--feed dir] [--work dir]");
@@ -62,6 +67,16 @@ async function download(url, destination) {
writeFileSync(destination, Buffer.from(await response.arrayBuffer()));
}
+// Bytes the feed sent per file.
+const served = new Map();
+
+function servedReport(directory) {
+ return [...served].map(([name, bytes]) => {
+ const size = statSync(path.join(directory, name)).size;
+ return { name, served: bytes, size, percent: Math.round((1000 * bytes) / size) / 10 };
+ });
+}
+
function serveFeed(directory) {
return new Promise((resolve) => {
const server = createServer((request, response) => {
@@ -72,9 +87,24 @@ function serveFeed(directory) {
response.writeHead(404).end();
return;
}
- response.writeHead(200, { "content-length": statSync(file).size, "content-type": "application/octet-stream" });
+ const size = statSync(file).size;
+ const range = /^bytes=(\d+)-(\d*)$/.exec(request.headers.range ?? "");
+ const start = range ? Number(range[1]) : 0;
+ const end = range && range[2] ? Math.min(Number(range[2]), size - 1) : size - 1;
+ if (range && start > end) {
+ response.writeHead(416, { "content-range": `bytes */${size}` }).end();
+ return;
+ }
+ if (request.headers.range && !range) log(`feed: multi-range request answered in full: ${request.headers.range.slice(0, 60)}`);
+ response.writeHead(range ? 206 : 200, {
+ "accept-ranges": "bytes",
+ "content-length": end - start + 1,
+ "content-type": "application/octet-stream",
+ ...(range ? { "content-range": `bytes ${start}-${end}/${size}` } : {}),
+ });
if (request.method === "HEAD") return response.end();
- createReadStream(file).pipe(response);
+ served.set(name, (served.get(name) ?? 0) + end - start + 1);
+ createReadStream(file, { start, end }).pipe(response);
});
server.listen(0, "127.0.0.1", () => resolve({ server, url: `http://127.0.0.1:${server.address().port}` }));
});
@@ -170,8 +200,8 @@ function stopApp() {
}
async function main() {
- const installer = path.join(workDir, `omnirush-win-x64-${from}.exe`);
- await download(`https://github.com/${REPO}/releases/download/v${from}/omnirush-win-x64-${from}.exe`, installer);
+ const installer = fromInstaller ? path.resolve(fromInstaller) : path.join(workDir, `omnirush-win-x64-${from}.exe`);
+ if (!fromInstaller) await download(`https://github.com/${REPO}/releases/download/v${from}/omnirush-win-x64-${from}.exe`, installer);
execFileSync(installer, ["/S"], { stdio: "inherit" });
const before = installs();
log("installed", before);
@@ -217,6 +247,7 @@ async function main() {
if (!checked?.available || checked.latestVersion !== expect) throw new Error(`the check did not offer ${expect}`);
const downloaded = await run("download()");
log("download", downloaded);
+ if (feed) log("feed bytes served", servedReport(path.resolve(feedDir)));
if (!downloaded?.ok) throw new Error(`download failed: ${downloaded?.reason}`);
// The app quits into the installer; the answer may never arrive.
void page.evaluate("window.__OMNIRUSH_ELECTRON__.updater.installAndRestart()", 180_000)