# Stable release automatic updates

An update is a complete stable GitHub Release verified against its manifest. New commits are not updates. The update unit is the whole product: wheel, Web, Programs, OCR, Browser and models are never updated separately. The macOS App and terminal installs take a whole package; Windows and Linux Apps take a signed [sealed version](#official-replay).

An App that can replace itself downloads and checks the release in the background, then shows **New** beside the sidebar wordmark; one click on **Restart to update** swaps it in.

## From Release to platform

1. **GitHub latest** Non-draft, non-prerelease, `vX.Y.Z`
2. **Release gate** Unique assets
3. **Manifest gate** Version, bytes, SHA-256
4. **Desktop** macOS; Windows and Linux when the shell changes Select the exact installer; stream to a resumable `.part` file; verify bytes and SHA-256; on Windows check Authenticode for this App's line; prepare it and offer Restart to update, or open the installer where the App cannot replace itself
5. **Managed CLI and server** macOS, Linux, Windows Fetch the installer from the immutable tag; verify archive and capability manifest; version probe and isolated worker cold start; macOS, Linux: switch `current`; Windows: replace launchers; the user restarts a running worker

| Install type | Path |
| --- | --- |
| `managed_release` | The route above. Immutable markers take precedence |
| `source_checkout` | Explicit Git ref: preflight, checkout, dependencies and build, probe, restart. Never shown as a stable Release |
| `unknown` | Stable error pointing to the official installer or a source checkout. PyPI, binary and Git paths are not guessed |

`openprogram upgrade` applies; `--check` reports current and latest read-only; `--dry-run` prints the plan. `pip_wheel` is not an install type: developer wheels are build inputs only.

## Desktop installers

| Platform | Asset |
| --- | --- |
| macOS | A Developer ID App in a writable folder unpacks `OpenProgram-<version>-mac-<arch>.zip` in its data folder and keeps the copy only if `codesign --verify --deep --strict` passes, the team is its own and the version is the release's. On restart a detached shell waits for the App to exit, swaps the bundles with two renames (undoing the first if the second fails) and opens the App |
| macOS, otherwise | A local build (no team), a translocated or read-only App, or a release without the `.zip`: `-mac-<arch>.dmg`, then `-unsigned.dmg`, saved where the user picks |
| Windows | Only when the release needs a newer shell: `OpenProgram-<version>-win-<arch>.exe`, or `-unsigned.exe` on an App built unsigned. Downloaded to the App's data folder and checked; Restart to update quits and runs it with `/S --updated --force-run`, which installs silently and starts the new App |
| Linux deb | Only when the release needs a newer shell. The App sits under `/opt`, which it cannot write, so it replaces nothing itself: the `.deb` is saved where the user picks and opened with the system's package installer, which asks for the administrator password |
| Linux AppImage | Only when the release needs a newer shell. Downloaded beside the running file, verified and made executable; Restart to update renames it over the running file in one step, and the App restarts from the new one. In a folder it cannot write, the file is saved where the user picks |

## Settings → Versions and updates → Application

| State | Shows |
| --- | --- |
| Not checked | Cache absent or expired. Automatic checks default on |
| Checking | All windows share one in-flight Promise. Check button disabled |
| Up to date | Same or lower version. Stable downgrades are not offered |
| Update available | Version, date, plain-text notes summary. Full notes open only the fixed GitHub Release page |
| Downloading | Bytes and percent, published at most every 250 ms, with a guaranteed final state |
| Ready | Downloaded, checked and prepared; `readyVersion` names it. Settings shows **Restart to update**, the sidebar shows **New** beside the wordmark with the same action and the release page, and the App menu (File on Windows and Linux) gets **Restart to Update to X**. The menu says when a task is running, since the new App restarts the worker. A later check of the same release keeps it ready |
| Retryable error | Keeps verified release metadata, so retry needs no new check. `errorKind` is `rate-limited`, `network` or `failed` |
| Not published | A newer release exists with no file for this computer. The current App keeps working |

Plain Web shows the CLI instruction instead.

## Scheduling

Automatic checks discover; on an App that can replace itself they also download and prepare the release, at start too for one found before the last quit. Nothing is installed until the user restarts. Manual checks always refresh. Development mode does not check automatically.

| When | Next check |
| --- | --- |
| App start (packaged) | 30 s later, or the cached due time |
| After success | `lastSuccessAt` + 24 h |
| After failure | `lastAttemptAt` + 6 h |
| Resume or settings change | Clear the old timer, check at most once, reschedule |

**`update-state.json`**

Schema 1. Holds `automaticChecks`, `lastAttemptAt`, `lastSuccessAt` and the latest verified release metadata. Written with a temporary file and rename; POSIX sets the mode, Windows inherits the user-directory ACL.

Invalid JSON, unknown schemas, future timestamps, version or architecture mismatches and missing releases are normalized and rewritten. A write failure must not leave hidden in-memory setting changes.

## Trust boundaries

| Boundary | Rule |
| --- | --- |
| GitHub responses | Untrusted. HTTPS, fixed hosts, at most 5 redirects validated per hop, size limit, 30 s request timeout, 60 s download idle timeout. Requires `draft === false`, `prerelease === false`, tag `vX.Y.Z`, unique asset names and manifest basenames, GitHub size equal to manifest bytes. |
| Network path | Chromium's network stack, so the system proxy applies. On API 403, 429, 5xx or no answer: the `releases/latest` redirect plus `release-manifest.json`. If that fails too, an optional `update-source.json`, only with an Ed25519 signature from a built-in key |
| Renderer IPC | Exposes only state, check, boolean settings, download, open release, subscribe. Accepts no URL, path, hash, repository or command. Public state strips asset name, URL and SHA-256. Closing a window aborts nothing |
| Downloaded files | Random exclusive temporary files, short writes handled, deleted on any mismatch. CLI verifies in a new version directory and rejects archive path traversal. A launcher failure keeps the old `current` |
| Signed Windows line | A signed App accepts only an installer with a valid Authenticode signature from its own publisher: the same certificate, or the same subject after a renewal. The publisher comes from the App's own file. If that read failed or timed out, or the App's signature is damaged, it is read again before the comparison; with no publisher known, the installer is refused |
| Unsigned Windows line | An App built unsigned accepts an installer that is `NotSigned` and matches the size and SHA-256 in `release-manifest.json`. That catches a damaged, truncated or substituted download. It does not prove the publisher: the manifest is unsigned and trusted through HTTPS to the fixed hosts, so whoever can publish a release there can publish an installer. A signed App never takes this line |
| What the update signature covers | `update-manifest.json.sig` covers the version-store files: version, base, toolchain and `repo.bundle`. It does not cover App installers or `release-manifest.json` |
| Installer child process | Pinned repository and version. Allowed environment only: PATH, HOME, temp, locale, proxy, XDG, OpenProgram state. No provider or API credentials, no archive or checksum overrides. `--json` emits one JSON document |

## Failures

| What happened | Result |
| --- | --- |
| Offline, timeout, rate limit | Falls back to the web route first. Automatic: record and back off 6 h. Manual: retryable error with a plain reason. The App keeps running |
| Invalid Release or manifest | Rejected before download. No fallback to a wheel, source archive, other architecture or older version. The last valid metadata may stay |
| Stall, size, hash or Windows signature error | A dropped download retries and resumes through its `.part` file, across restarts. A size, hash or signature mismatch deletes the file and restores retry. An unverified file is never opened |
| CLI archive, cold start or launcher failure | Non-zero exit before the final switch. The previous version stays selected (`current` on macOS and Linux, launchers on Windows) |
| Switch done, worker still old | The command says so and prints the restart instruction. Running requests are not interrupted |

**References**

| Reference | Use |
| --- | --- |
| [GitHub Releases API](https://docs.github.com/en/rest/releases/releases#get-the-latest-release) | Adopted for metadata, notes and assets; clients still validate independently |
| [Electron update lifecycle](https://www.electronjs.org/docs/latest/tutorial/updates) | Adapted: check, available, download, ready, restart to install, error |
| [Electron `autoUpdater`](https://www.electronjs.org/docs/latest/api/auto-updater/) | Not used. No built-in Linux updater, and the swap it does on macOS (Squirrel) is a few lines here, held to the manifest's hash and the running App's team |
| [`electron-updater`](https://www.electron.build/docs/features/auto-update/) | Not used. No new updater package: Electron, Node, Python and shell cover it |

**Code**

| File | Holds |
| --- | --- |
| [`update-service.js`](https://github.com/Fzkuji/OpenProgram/blob/main/apps/desktop/main/self-update/update-service.js) | Metadata, state, cache, scheduling, asset selection, download, hash, public projection |
| [`app-replace.js`](https://github.com/Fzkuji/OpenProgram/blob/main/apps/desktop/main/self-update/app-replace.js) | Replacing the App on restart: macOS unpack, signature and swap; silent NSIS; AppImage rename |
| [`windows-signature.js`](https://github.com/Fzkuji/OpenProgram/blob/main/apps/desktop/main/self-update/windows-signature.js) | Authenticode status, subject, thumbprint |
| [`apps/desktop/main.js`](https://github.com/Fzkuji/OpenProgram/blob/main/apps/desktop/main.js) | Timer, resume, IPC, multi-window broadcast |
| [`main/preload.js`](https://github.com/Fzkuji/OpenProgram/blob/main/apps/desktop/main/preload.js) | Fixed renderer bridge |
| [`general-section.tsx`](https://github.com/Fzkuji/OpenProgram/blob/main/apps/web/components/settings/sections/general-section.tsx) | Settings states and Web fallback |
| [`update-badge.tsx`](https://github.com/Fzkuji/OpenProgram/blob/main/apps/web/components/sidebar/update-badge.tsx) | New beside the wordmark and its restart menu |
| [`commands/updates/upgrade.py`](https://github.com/Fzkuji/OpenProgram/blob/main/openprogram/interfaces/cli/commands/updates/upgrade.py) | Install-type routing, Release gate, dry-run, JSON, installer execution |
| [`github_release/github.py`](https://github.com/Fzkuji/OpenProgram/blob/main/openprogram/operations/self_update/github_release/github.py) | Stable metadata, manifest, immutable installer retrieval |
| [`scripts/install-release.sh`](https://github.com/Fzkuji/OpenProgram/blob/main/scripts/install-release.sh), [`.ps1`](https://github.com/Fzkuji/OpenProgram/blob/main/scripts/install-release.ps1) | Published compatibility entry points; fetch the real installer from the same tag |
| [`scripts/release/install-release.sh`](https://github.com/Fzkuji/OpenProgram/blob/main/scripts/release/install-release.sh), [`.ps1`](https://github.com/Fzkuji/OpenProgram/blob/main/scripts/release/install-release.ps1) | Download, verify, cold start, launcher staging, atomic activation |
| [`official/assets.py`](https://github.com/Fzkuji/OpenProgram/blob/main/openprogram/operations/self_update/official/assets.py) | Release asset format: packing, signing, verification, unpacking |
| [`official/replay.py`](https://github.com/Fzkuji/OpenProgram/blob/main/openprogram/operations/self_update/official/replay.py) | Replays the owner's commits onto a verified release and drops them on failure |
| [`create-update-assets.py`](https://github.com/Fzkuji/OpenProgram/blob/main/scripts/release/create-update-assets.py) | Builds one platform's assets and finalizes the signed release directory |
| [`release.yml`](https://github.com/Fzkuji/OpenProgram/blob/main/.github/workflows/release.yml) | Artifact publication and the latest-endpoint gate |

## Official updates on a version store

An installation on the version store updates from signed release assets and replays the owner's own commits onto the release.

| Part | Rule |
| --- | --- |
| Assets | Every release publishes `version-<platform>.tar.zst`, `base-<platform>.tar.zst`, `toolchain-<platform>.tar.zst`, `repo.bundle`, `SHA256SUMS` and `update-manifest.json` with its Ed25519 signature, so a machine that skipped releases can still update. A client downloads only what it lacks: a base it already holds is skipped, and the toolchain is fetched only for owner commits to build. The version archive leaves out the venv's links and the seal, because they name the build machine; unpacking recreates the venv with the build's own command and seals the version here |
| Fetch | Bare `openprogram upgrade` resolves the latest release, verifies manifest, signature and sums in memory, then downloads this platform's files to `<runtime>/downloads/<release>`, each held to its signed size and hash, resuming on the next run. `--from <directory>` applies files already on the computer |
| Verification | Signature before the manifest is parsed, sums against the manifest, each asset this platform uses against the sums. The bundle moves `refs/heads/release` forward only, so an older signed release cannot replace a newer one. A build with no trusted key accepts no release |
| Replay | The owner's commits are `release..local`, so the squashed official line is enough. Oldest first, each is cherry-picked in `work/official-<release>`. A conflict is saved to `unreplayable/<release>/` and the others continue. A commit the release already has is skipped. The candidate builds on the release's own version, so an untouched Web bundle is cloned |
| Failure | A build or trial failure saves the newest commit and tries the rest, at most 5 retries before going straight to the unmodified release. Lack of disk drops nothing. A failed switch does not retry. A release needing a `shell_compat` or Python minor outside the installed shell waits for the shell update and moves nothing |

## Implementation status

| Part | Status |
| --- | --- |
| Desktop path | Implemented. `npm run check --workspace apps/desktop`. Windows and Linux routes are tested with stand-ins; never exercised on a published release |
| Managed CLI path | Implemented. `pytest tests/component/config/test_formal_release_updates.py tests/component/config/test_distribution_release` |
| Security and failure paths | Verified. `apps/desktop/tests/self-update/check-update-service.js` |
| Release gate | Every stable release passes runtime, CLI, Desktop, manifest and checksum checks before publication. These prove what was published, not behaviour on a running client |
| Installed client | Open: the background download, the macOS swap and the silent Windows install on a real install of a published release; long runs and sleep/resume, operated on a real install; Authenticode with a real certificate on an official runner; real GitHub responses, a real proxy |
| Version-store assets and replay | Implemented, tested with a local directory as the release source. `pytest -q tests/component/self_update/official/test_replay.py` |
| Version-store release path | Implemented and passing end to end on macOS against a local server imitating GitHub (update, resume, go back, refusals). Installed copies trust the official signing key. The Release workflow has published signed update files for Linux only, in v1.1.0; its macOS and Windows asset steps failed in that run and have not run since. Linux activation needs one more run |
| Upgrading from v0.6.6 or earlier | No updater before v0.7.0: install the current DMG once by hand. CLI and server rerun the public installer once |

Out of scope: Windows sandboxing, PyPI product installation, replacing a running App while it runs: the swap happens only on Restart to update.
