OTA Updates & zn-updates Server
Over-the-air updates in zero-native are part of the core architecture, not a fragile add-on.
Every zero-native bundle is a signed, contract-checked artifact — paired with automatic crash rollback, staged rollouts, bsdiff patches, and a self-hosted dashboard (zn-updates).
1. How the Capability Contract Works
Section titled “1. How the Capability Contract Works”Every time you build a bundle, the compiler inspects what your app actually uses and writes a requires block into zn-bundle.json:
requires.registry— lowest UI registry version that supports every component/prop in the bundlerequires.hostApi— required JS ↔ native bridge versionrequires.bytecode— exact Hermes bytecode format versionrequires.modules— native modules and minimum versions required on both OSesrequires.os.{android,ios}— platform-specific native module requirements (one-OS modules go only under their OS)
When a phone checks for updates (POST /v1/check), it sends the native capabilities compiled into its installed binary. Both the server and the phone verify compatibility — a phone never downloads or boots a bundle whose native requirements it doesn’t satisfy.
2. Trust & Cryptographic Signing
Section titled “2. Trust & Cryptographic Signing”- ECDSA P-256 signatures protect both the bundle archive and the channel pointer (which bundle is live on
production,staging, etc.). - Main & backup keys:
zn keygenstores your main private key locally in~/.zero-native/keys(and prints the public key). Keep your backup private key offline, and bake both public keys into your app binary so you can rotate keys without stranding users. - Browser-signed pointers: In the
zn-updatesweb dashboard, channel pointers are signed in your browser using WebCrypto — the server never holds your private signing key.
3. Rollouts, Patches & Safety Nets
Section titled “3. Rollouts, Patches & Safety Nets”-
bsdiff binary patches: Phones download a tiny binary patch against their current bundle (measured at 3–93 KB on one production Android app vs. ~824 KB full) and verify the reconstructed bundle’s SHA-256 before installing. Android and iOS apply the same
znbsdiff1patches; if a patch fails, the phone downloads the full bundle in the same check. -
Staged rollouts, rollback & kill switch: Roll out by percentage (
--rollout/rollout --percent), roll back to any previous bundle, or trigger the kill switch (kill, pointing phones back to their built-in bundle). -
Boot watchdog & automatic rollback:
- When a new bundle boots, native marks it pending until JS starts cleanly and renders the first screen.
- If the new bundle crashes before becoming healthy, the runtime automatically rolls back to the last known-good bundle (or built-in bundle), marks the bad bundle blocked, and reports the failure outcome to the server.
-
Update priority & apply timing (
zn publish --priority normal|high|critical):normal(default) — downloads in the background and runs from the next cold start (callUpdates.applyNow()from JS to apply sooner).high— may fetch and apply during the cold-start splash launch gate (bounded by a ~4 s cap), or on next start /Updates.applyNow().critical— gets a longer launch-gate cap (~5.8 s) to apply at cold start; otherwise runs from the next start or when your app callsUpdates.applyNow()at a safe moment.
-
What the user sees, per priority (Android and iOS):
Priority Use it for At a cold start or a fresh start Later in the visit normalEveryday releases Nothing: the app opens at once. The update downloads in the background Nothing. It runs from the next start, or when your app calls Updates.applyNow()highA fix users should get today If the check answers within launchDecisionMs: the update screen (“Updating for a better experience”, a progress bar), then the app opens on the new bundle. If the download can’t end within 4 s of the tap, the app opens on the old bundleAs normalcriticalAn urgent fix (a crash, a broken payment). The kill switch is always critical As high, with 5.8 sAs normal: your app’s own gates decide (see below) -
Why don’t I see the update screen? Check these, in order:
- The priority is
normal. It never shows the update screen. - It wasn’t a start with UI. The gate runs at a cold start (no process) or a fresh start (the user closed the app from Recents and opened it again). Coming back from the background (Home, then the app) is neither.
- The check didn’t answer within
launchDecisionMs(800 ms from the tap, inZnOta.Config). The app opens on the old bundle and the update downloads in the background. On a slow network, or on a debug build, this is common. - The phone already had the update downloaded. Then it runs from this start with no screen: there is nothing to wait for.
- JS holds updates (
Updates.holdApply()) or a payment app’s answer is pending: the swap is refused, payments first. launchDecisionMs = 0turns the gate off.
- The priority is
-
Your app’s gates apply any waiting update, whatever its priority. When your JS calls
Updates.applyNow()at a calm moment (back on the home screen, after a payment), it swaps to the downloaded update even if it was published asnormal. The app reopens the same screens on the new bundle, with no update screen. CheckUpdates.status().pendingRestart(an update is waiting) andnextPriority(0 normal, 1 high, 2 critical) to decide. More detail: ota-patches.md §7–8. -
Silent push triggers: When configured with
zn app --push '{"fcmProject":"<project-id>"}', the server automatically sends an FCM/APNs “check now” push after a publish, rollout, or kill — handled natively (without waking JS) to trigger a background download. (On iOS, silent pushes are not delivered if the user swiped the app away.) -
Payment / critical flow protection (
Updates.holdApply()):import { Updates } from "@zeronative/core"const release = Updates.holdApply()try {await runSensitiveCheckoutFlow()} finally {release()}While a hold is active, the runtime defers any live bundle swap until your flow finishes.
4. JS API (Updates)
Section titled “4. JS API (Updates)”Import Updates from @zeronative/core:
import { Updates } from "@zeronative/core"
// Current bundle state (enabled, phase, channel, running, builtIn, next, pendingRestart, nextPriority, healthy, ...)const status = await Updates.status()
// Manually trigger an update checkconst result = await Updates.check()
// Apply a downloaded update immediately (refuses safely if a hold is active)await Updates.applyNow()
// Prevent live reload during a sensitive flowconst release = Updates.holdApply()5. Host Configuration (Android & iOS)
Section titled “5. Host Configuration (Android & iOS)”OTA is off by default until your native host configures it with your HTTPS server URL, channel, and pinned public keys. (Release builds refuse non-https:// servers.)
- Android (
Application.onCreate()):ZnOta.configure(this,ZnOta.Config(server = "https://updates.example.com",channel = "production",publicKeys = listOf(mainPublicKeyPem, backupPublicKeyPem),),) - iOS (
AppDelegate.swift):ZnOta.configure(ZnOta.Config(server: "https://updates.example.com",channel: "production",publicKeys: [mainPublicKeyPem, backupPublicKeyPem]))
Every store build shipped to Google Play or the App Store receives a serial number via zn store-build so phones never downgrade from a newer store build to an older OTA bundle.
6. CLI Workflow (zn)
Section titled “6. CLI Workflow (zn)”Create a zn-updates.json file in your app folder (zn new does not create it yet):
{ "app": "my-app", "server": "https://updates.example.com", "build": ["bun", "run", "../zero-native/tools/zn-build.ts", "app", "--name", "my-app"], "assets": "android/app/src/main/assets"}Auth tokens from zn login live in ~/.zero-native/updates.json (or ZN_UPDATES_TOKEN).
# 1. One-time setup: sign in, generate keys, register appzn login --server https://updates.example.com --token <ADMIN_TOKEN> --by "Your Name"zn keygen --name main # private key saved in ~/.zero-native/keyszn keygen --name backup # move backup private key offlinezn app --keys <main.pub>,<backup.pub> --name "My App"
# 2. Register a Play / App Store build (takes its serial & uploads the base for patches); the full order, and the# Gradle check that stops a wrong upload: releasing-your-app.mdzn store-build --os android --channel production --label "play AAB" --version-code 10 --version-name 1.0.0
# 3. Build and upload a new OTA bundle (never publishes automatically)zn release
# 4. Publish to staging, mark stable, then roll out to productionzn publish --channel staging --bundle 12 --rollout 100zn stable --bundle 12 --note "Verified on test phone"zn publish --channel production --bundle 12 --rollout 5 --priority normal # requires typing PRODUCTION #12zn rollout --channel production --percent 50
# 5. Operations: status, dashboard, kill switch, delete/keep, source mapszn statuszn dashboard # opens signed-in web dashboard (12 h session)zn kill --channel production --reason "Revert checkout" # requires typing KILL PRODUCTIONzn delete --bundle 12 # 30-day soft delete (undo with `zn keep --bundle 12`)zn maps # uploads any local source maps not yet on the server- Symbolicating stack traces: With
zn-updates, the server symbolicates crash traces using uploaded maps. For the older local OTA store, runzn ota symbolicate [file] [--bundle <id|sha>]. - Other commands:
zn rule(store-update rules),zn title,zn builtin,zn base,zn patches,zn push. - Every command’s flags:
zn <command> --help(orzn help <command>), e.g.zn store-build --help. - Releasing to Play / the App Store: Releasing your app: the order of the steps, crash symbols, the baseline profile, and native fixes on older store builds.
7. Self-Hosting zn-updates
Section titled “7. Self-Hosting zn-updates”The server/ directory is a self-hosted update server built with Bun, PostgreSQL (or embedded PGlite for local dev), local filesystem or Google Cloud Storage, and a built-in web dashboard (signed in via one-time link + session cookie from zn dashboard).
Run locally (with demo data)
Section titled “Run locally (with demo data)”bun run updates:server --demo# or: zn server --demoRun in production
Section titled “Run in production”bun run server/src/index.ts# or from server/: bun run startEnvironment variables (server/src/index.ts)
Section titled “Environment variables (server/src/index.ts)”| Variable | Purpose |
|---|---|
DATABASE_URL |
postgres://... or pglite:<dir> (migrations run automatically on start) |
STORAGE |
file:<dir> or gs://<bucket>/<prefix> for bundle & patch blobs |
CACHE_DIR |
Local cache directory (default ./.cache) |
ADMIN_TOKEN |
Admin bearer token (at least 16 characters) for CLI & one-time dashboard login links |
PORT |
HTTP port (default 3000; run behind TLS / a CDN in production) |
FCM_ACCESS_TOKEN |
Optional token for local “check now” push testing |
For Docker and Kubernetes deployment details, see zn-updates-deploy.md.