macOS updater: reuse unchanged files from the installed app (delta updates)

Open
#930 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
macos, zig

Research direction

Start with installDownloadedUpdate in src/platform/macos/appkit_host.m and the native update sign command to understand the current feed, archive-verification, staging, and install flow. The proposed path must add a separately signed delta feed, file manifests, base-version patch generation, staging, and whole-tree verification while retaining the full-ZIP fallback. Done means an applicable patch reuses byte-identical installed files, and any missing base, mismatch, or verification failure safely falls back to the full update.

Written by the indexing model from the issue text.

Description

The problem

The macOS updater downloads the whole app on every update. In installDownloadedUpdate (src/platform/macos/appkit_host.m), it checks the ZIP’s size and SHA-256 against the signed feed, extracts it with ditto, and swaps the bundle with mv. It never reuses a file from the installed copy, even when most of the bundle hasn’t changed. This is true in 0.11.0 and on current main.

That gets expensive for an app that ships large files that rarely change. Sage, a Native SDK 0.11.0 app, carries a pinned Ollama (local AI server) and a pinned Node.js in Contents/Resources. Its update ZIPs:

Release Update ZIP Notes
0.2.2 78 MB before Ollama was bundled
0.3.0 226 MB first with Ollama
0.6.0 225 MB same Ollama as 0.3.0

About 148 MB of each update is the same Ollama files. Six updates have shipped since 0.3.0, so a user who installed them all downloaded the same Ollama bytes six times, about 0.9 GB.

The app can’t work around this on its own side. Moving the large files out of the bundle means the app has to download, check, and clean them up itself. It also takes them out from under the app’s code signature. The updater already knows both bundles, so it is the right place to skip the unchanged files.

The proposal

Add an optional delta path that reuses unchanged files from the installed bundle, and keep the full ZIP as the fallback.

What a release publishes
  1. The full update ZIP and native-update.json, exactly as today.
  2. A file list for the new bundle. It gives every file’s relative path, size, mode, and SHA-256, plus each symlink and its target.
  3. One patch ZIP for each recent base version. It holds only the files that are new or changed since that version.
  4. A second signed feed, such as native-update-delta.json. It holds the file list’s URL, size, and SHA-256, and, for each patch, the base version, URL, size, and SHA-256.

The file list doesn’t fit in the existing payload. Sage’s bundle has 8,118 files, and max_payload_bytes is 32 KB. So the signed feed carries the list’s hash, and the list itself is a separate download.

The delta feed has to be a separate file. verifyEnvelope parses both the envelope and the payload with ignore_unknown_fields = false. A new field in native-update.json would make every installed 0.11.0 copy reject the feed, so those copies could never update again. A separate file leaves them on the full ZIP.

What the updater does
  1. Fetch and verify native-update-delta.json with the same key as the main feed. If it’s missing or has no patch for the installed version, use the full ZIP.
  2. Download the file list and the matching patch, and check each against its signed size and SHA-256.
  3. Clone the installed bundle into the staging folder it already uses, .<App>.app.native-update-<uuid> next to the app. APFS clonefile makes this instant and uses no extra disk space. On another file system, copy it instead.
  4. Extract the patch over the clone, then delete every file the list doesn’t name.
  5. Check the whole staged tree against the file list: paths, sizes, modes, symlink targets, and SHA-256. Any difference, such as a file someone changed in the installed copy, sends it back to the full ZIP.
  6. Run the checks it runs today: bundle ID, version, and the codesign requirement when the app has a team ID.
  7. Swap the bundle with the same install script, so rollback stays as it is.
What native update sign gains
  • A way to pass the update ZIPs of earlier releases, such as --base <zip> given more than once. It writes the file list, one patch ZIP for each base, and the signed delta feed.
  • The same archive checks it runs today, on the new bundle.

Notes

  • Unchanged files must be byte-identical. For Sage they are. The bundled Ollama files match the cached download byte for byte, because codesign --deep leaves Contents/Resources alone. Ad-hoc signing an unchanged Mach-O twice also gives identical bytes.
  • Skipped versions. A user who skips several releases may have no matching patch. Publishing patches against the last few versions covers most people, and the full ZIP covers the rest.
  • Why not one asset per file. A GitHub release holds at most 1,000 assets, and an app like Sage has thousands of files. One patch ZIP per base version keeps the asset count small.
  • What it saves. The most a delta can be is everything that isn’t Ollama, which was 78 MB at 0.2.2. It is smaller when Node and the agent’s dependencies don’t change either.
Dominant language
Zig
Stars
7.9k
Forks
335
Avg merge
10h 33m
Merged PRs (30d)
147

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vercel-labs/native

All issues in vercel-labs/native

Similar issues

More Desktop Dev issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.