Repository navigation
docs: propose a linked package root and staged candidate handoff for updates - #197949
fuller-stack-dev wants to merge 35 commits into
Conversation
Design proposal for two changes to `openclaw update`: package generations on OpenClaw-owned prefixes inside the existing package update path, and moving update work from the installed updater to the candidate in stages. It records why a launcher in the npm package and an extension of the immutable installation owner were both rejected, the measured step timings from two published-driver cell runs, and the decisions a maintainer must settle before any further slice starts.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: stale review; fresh review needed. Summary Next step Review history (1 earlier review cycle)
|
Version four of the proposal. The installed package directory keeps its path and becomes a link to a release directory, so activation and rollback are one rename each. Rebinding the service to a release path moves to the rejected approaches. Also corrects the measured timings (the swap step includes the Gateway stop and the post-swap Doctor run), the macOS layout row, and the first hop table, which now names the untested case that gates adoption.
A maintainer accepted the seven decisions on November 13, 2026. The table now states each answer and what remains open. Published 2026.10.9 and 2026.11.3 were run on a linked package root. Both finish the update with the Gateway ready and sessions intact. They follow the link and swap the new release into the directory behind it, so the link stays and the release directory is rewritten in place. The page predicted the link would be replaced by a directory. Route 3 gains a release identity rule because of this.
No handoff rule is needed for a linked package root. The parent already rebinds the post-core child to the activated root, which is how a pnpm generation change passes; the updater that flips must return the stable package path as its result root. The page lists three other comparisons of resolved roots that need work when the flip is built. Journaled activation for a linked root is a storage design of its own. The journal is keyed by the package's real path, settlement selects by directory identity, and an older release refuses to update when it meets a record it does not know. The page states what the trace found and the seven questions the design record has to answer.
A design pass at 649ca5f recommends against extending the activation journal for a linked package root, and decision 2 is revised to match. The journal exists to survive a missing package path and launchers replaced one at a time; a link switch has neither. Extending it would anchor the journal inside the old release and make older releases refuse to update on a record they do not know. The page now records the design: the link is the source of truth, the update run record gains one optional field with the two release identities, the order of an activation, what each crash point leaves, and what the design does not cover. The largest gap is that nothing in the updater holds the link's own path today, so a slot resolver comes first. Slice 2 is split into four changes that an existing installation cannot observe.
openclaw#197922 merged. The linked-root cell is in review as openclaw#198489.
Slice 2 is the linked-root cell and the recorded design. The resolver and the link lifecycle move to slice 4, where the switch first calls them, so no unused code lands ahead of its caller. The existing resolveOpenClawInstallationRootSync is the owner to extend.
Decision 3: leases plus a 24-hour minimum age. Decision 4: release directories go inside the service copy's prefix, at <stateDir>/npm/releases/. Backups already exclude <stateDir>/npm, and plugin discovery and Doctor walk only the prefix root and projects/. Slice 3 folds into slice 4. The shared step runner already exists; the private-prefix installer has no second caller until the switch.
Releases live under the npm prefix; the link is the installation identity, with the selected release mapped to it; adoption is two renames with a documented manual recovery; origin.packageRelease is written before the database capture; rollback reads the link; Gateway leases and deselection stamps drive collection; a service bound to a release path is refused. Records what the Docker cells in openclaw#198835 proved and what they did not.
|
Input for the Git-install case, which this design leaves on today's swap ("Dev is a Git installation ... Route 3 does not apply"). Offered as data for the design, not as an implementation. One all-PostgreSQL Git install (macOS, Gateway under an external root LaunchDaemon, 13 PostgreSQL stores, about 1.1 GB) has updated since 2026-11-13 with an operator script built only on upstream's own commands. It keeps two clones of the repository and a symlink that the service starts through. While the Gateway serves:
With the Gateway stopped:
On a failure after the stop, the script runs
The two runs cross different commit ranges, so the comparison is indicative. In the stopped native run the slowest steps were the database snapshot (161 s), candidate-state-snapshot (111 s), preflight-build (103 s), updater-runtime-retention (60 s), preflight-runtime-stage (51 s) and candidate-doctor (39 s). Only the snapshot and the migrations need the Gateway stopped. Two observations from that run (also on #196154):
The script also drains before the stop now ( On the shape: the two full clones could be replaced by |
…ound service The plan to switch the link and then rebind the service failed in Docker: the post-update ownership check ran first and left the Gateway stopped. As landed in openclaw#198835, the update replaces the release the service starts in place and the restart's service refresh binds the service to the package path. The launcher comparison covers only the launchers the swap publishes. Decision 8 is closed, and the separate --no-restart race on main points at openclaw#200181.
…ase link (#199706) ## Problem A Git checkout install runs its Gateway from `<checkout>/dist/index.js`, and `openclaw update` rewrites that same tree. Everything around the rewrite exists to survive it: the updater copies its own runtime first (133–892 s on a 183k-file checkout), builds the candidate in a private repository and imports it through a pack (256 MB cap), stops and parks the serving Gateway, and rewrites the service definition every update. ## Change Extends #198835's linked package root (merged as `b868ed4c`) to Git checkouts, per the #197949 design. Based on `main`. It reuses #198835's release resolver, `switchPackageReleaseLink`, leases and 24 h collection unchanged. Its fallback follows `installStagedPackage`: when the layout can't be used, the update runs in place with a `recoverable-maintenance` warning, and the next update tries the layout again. The Gateway process never writes the release link. The only other writer is the boot launcher, and it only points the link back to the release recorded in a failed trial. - **Layout.** `<stateDir>/git-install/lib/node_modules/openclaw -> releases/<id>/lib/node_modules/openclaw`. Each release is `git worktree add --detach` off the developer's checkout (shared object store, no clone or copy). - **Stage.** The existing candidate preflight (candidate walk, local-commit replay, `pnpm install --frozen-lockfile`, build, candidate checks) runs in the new release's worktree, then `--version` with the service's Node. A same-source no-op requires the serving release to be at the checkout's commit and its artifacts to verify (#158931). - Deviation from the design: the worktree is built at `releases/<id>/build`, then moved into place with `git worktree move`. Node refuses to strip types under `node_modules` (`ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING`), and the build runs `.mts` scripts. The built tree has no absolute symlinks, so the move is safe. - **Switch.** `switchPackageReleaseLink` from #198835. The serving Gateway keeps its release (Node resolves the entry's real path), so nothing is stopped, parked or verified before the flip. - **Restart.** The serving Gateway's maintenance tick sees the link move (installation replacement) and restarts itself into the new release. The updater waits for that successor (up to 90 s), then verifies. It falls back to a native restart only if no successor appears. A native restart from inside the service job (`update.run`) would end the updater itself. - **Service.** Written once, at conversion, to a frozen launcher `<stateDir>/git-install/openclaw-launcher.mjs`. A unit that names the launcher is never regenerated. The launcher is needed because a release that fails while loading never reaches Gateway code. - **Trial.** The switch writes `releases/.trial`. The launcher counts starts. - After two failed starts it switches the link back and restores the trial build's `*.pre-<buildId>` state files (falling back to #198389's `*.pre-<version>`). Each SQLite family is restored together, and trial-created WAL/journal/SHM/seal files without a preserved predecessor are removed. The launcher mirrors #198389's `companionRemovals` list because it must not load release code. - The trial ends when the Gateway's first maintenance tick runs, or when the updater verifies the restarted Gateway. The second path also covers targets that predate this PR. - Writes made during a failed trial are lost (approved). - **The layout never fails an update** (#197949 decision 8). If `releases/` cannot be created, or something other than a release link sits at the package path, the update records a warning and takes the in-place runner. The next update tries the layout again. - **Post-core work** (requested-channel persistence, plugin convergence) runs in the updater, but only after the restarted release verified and its trial ended. A failed trial therefore never leaves plugins that require the release it switched away from. It runs without Doctor maintenance, which the Gateway holds, and without a plugin cohort, because no core rollback exists to pair it with. If plugins changed, the Gateway is asked to restart again (SIGUSR2). Under `--no-restart` the release is unverified, so only the requested channel is persisted and plugins converge on a later update. - **The developer's checkout** is never written. The first update builds the commit that serves now as the first release, rewrites the unit once, then stages the target. - **Retention.** #198835's collection, followed by `git worktree prune`. `git-install` is excluded from backups and from the startup state-upgrade copy. The latter is the same change as #199770, included here so the stack stands alone. - **One owner.** `usesGitReleases` selects releases. Windows checkouts and package-to-Git switches keep the in-place runner, and the in-place CLI tests are pinned to that runner. For Git releases this skips: - runtime retention - the pack transfer/import - the managed-service stop/park - the database rollback capture - the checkout's source-artifact lock - the native restart from inside the service job - per-update service regeneration ## In-place fallback (decided) Windows Git checkouts, package-to-Git switches, and checkouts with no installed Gateway service still use the in-place runner, so this PR bypasses that runner on POSIX instead of deleting it. A checkout with no service is run by hand, so nothing would start through the release link and its next start would run the old commit. `gatewayServiceOwnsGitInstall` reads the installed service once and accepts it only when the service owns the checkout or its release link. The command decides once and hands that decision to the runner. Prod LOC is net **+980**. Decided 2026-11-16: Windows Git updates are not refused. A follow-up, slice 4b (stacked on this PR), moves Windows to releases using junctions and then deletes the in-place Git runner. ## E2E (mbp-m5, launchd, isolated profiles, shared-clone checkout; ≤15 min per run, ≤3 in parallel) **Final head `0b96d640` (rebased on `main` at `8a82b5e0`): local ClawSweeper review clean** (gpt-6.1-sol, normal speed). After the rebase: `sweepPackageReleaseTemporaryLinks` is exported again, because the first Git publish uses it. The CI ratchets are satisfied: a lazy generation name, Node-only release tests, and an allocation record for the regression tests. A conversion's first release is now the commit the checkout's `dist` serves, not a pulled HEAD that was never rebuilt. A failed trial also restores a symlinked config: a preserved symlink is judged by its own time, not its target's. Rollback across same-version upgrades (decision d): the state upgrade now keeps a replaced file as `<file>.pre-<buildId>`, named after the build that replaced it, so two builds of one version each keep their own predecessor. Builds without a build ID, and earlier releases, still write `.pre-<version>`. Retention handles both forms. A failed trial restores the `.pre-<buildId>` of its own build, falling back to `.pre-<version>`. Fixes to the trial and launcher from the review rounds: - the inventory is recorded before anything is restored, so an interrupted rollback can resume without losing a restored WAL; - the trial's applied or interrupted upgrade plan is retired and the files it added are removed; a removal that fails is retried at the next start; - the config path is the one the update resolved (`~` and external paths included); - state is restored before the link moves back. The release layout is used only when the release switch actually reaches the next start: either the service already starts the launcher, or it owns the checkout and this update rewrites its definition and restarts it. `--no-restart` on a converted install leaves the serving release selected. The next start, which the operator triggers, selects the new release, without the two-start fallback. A first conversion requested with `--no-restart` stays in place. | Run (mbp-m5, isolated launchd profiles) | Head | Result | |---|---|---| | Release that crashes on boot | `d6d30a5e` (the final head changes only how a symlinked backup is dated) | update reports `build-id-mismatch` after 179 s; two "e2e boot crash" starts, then "failed to start twice; switched back"; link back on the previous release, trial cleared, `ready` | | Conversion before the crash run | `d6d30a5e` | ok, 267 s | **Current head `6d9acd6e` (on `main`), mbp-m5, isolated launchd profiles:** | Run | Result | |---|---| | Conversion (first update from a checkout service) | ok, root on the release link; 610 s with three runs in parallel; longest outage 9.7 s | | Release → release | ok, 239 s, longest outage 9.9 s | | `update.run` through the Gateway | `finished\|succeeded`, 135 s; link moved, Gateway restarted, plist unchanged; outage 7.8 s | | Checkout with no Gateway service | updated in place: checkout HEAD moved to the target, no `git-install/releases`, result `ok`, mode `git` | | Release that crashes on boot (at `0e3fefae`) | update reports `build-id-mismatch` after 188 s; after two "e2e boot crash" starts the launcher logs "failed to start twice; switched back", and the previous release serves `ready` | | v2026.11.4 state → this head | see Data-model compatibility | Older rows below ran at earlier heads. Rows marked ‡ ran at head `8a720e49`, rows marked † at `6032dedf`; the rest ran at `1140b601`, before plugin convergence moved after verification. At the final head `99b7f080` (rebased onto `823fa6d2`), three runs ran in parallel on mbp-m5. (1) Conversion and release→release passed again, with the root on the release link and a longest outage of 7.6 s. (2) `update.run` finished `succeeded` (link moved, Gateway restarted, plist unchanged, outage 8.0 s). (3) A checkout with **no Gateway service** updated in place: checkout HEAD moved to the bumped commit, no `git-install/releases` was created, and the result was `ok`, mode `git`, root the checkout. An intermediate head `2d2387b6` keyed this choice on a preflight fact that Git installs never fill in, so conversion fell back to in-place (about 120 s outage). That head was never pushed. | Case | Result | | --- | --- | | † First update of a checkout install (conversion, head→head+1) | ok, 402 s wall (two builds, three runs in parallel), longest outage 7.6 s, total 13.1 s (unit rewrite, then a restart after plugin convergence); unit rewritten once to the launcher; checkout tree clean; no retention, pack or handoff steps | | ‡ Release→release (head+1→head+2) | ok, 180 s wall, one outage of 7.2 s; unit untouched (mtime unchanged since conversion); service runs from `releases/` | | ‡ `--no-restart` on a switched release | the updater leaves the Gateway running and converges no plugins; within the next maintenance tick the Gateway restarts itself into the release, and the trial is cleared; outage 7.5 s | | † `update.run` via the Gateway (`openclaw gateway call update.run`) | run `finished|succeeded`, 140 s; link moved; the Gateway restarted itself; unit untouched; outage 7.4 s | | Already-current rerun from the preserved checkout after conversion (head `60503ab3`) | `skipped: already-current`, link unchanged, 113 s | | † Release that crashes on boot | two crashes, the launcher switched back to the previous release, Gateway ready again; the update reports `build-id-mismatch`; longest outage 28.9 s | | kill -9 mid-stage | link and serving Gateway unchanged; the rerun succeeds; a partial release directory left by the killed run is collected after 24 h | | kill -9 right after the link moves, before restart | the old Gateway keeps serving; the rerun reports `skipped: already-current`; the Gateway restarts itself into the new release and the trial is cleared | | `env -i` + `umask 077` (conversion, then release→release) | ok, 376 s and 198 s, outages 5.5 s and 7.5 s; launcher `0700` under umask 077 | | Install whose unit and state were written by 2026.11.3, moved to head, then converted | ok, 229 s, outage 5.9 s; state DB `integrity_check` ok. 2026.11.3's own updater could not reach head on mbp-m5: it walked back to `already-current` (Node 24.21 below head's `engines`), so that hop was done with `git reset` + `ocx build` | | Production-shaped install (207,229-file checkout, +3 GB SQLite in state), release→release | ok, 145 s, outage 6.9 s, no retention step. Main was not timed on this host. Peanutto's production main run `90c601fc` took 4,150 s, with 892 s retention and a 300 s outage | Not exercised: a plugin-only restart (SIGUSR2) after npm plugins actually change; the fixtures have no npm plugins. ## Data-model compatibility - **No new state schema.** This diff adds or changes no SQLite schema, migration, or config schema file. The update ledger (`update_runs`), Gateway owner lease and config are read and written exactly as on the base. - **`origin` stays compatible.** `UpdateRunRecordSchema.origin` (including #198835's `packageStage` and `packageRelease`) is unchanged, and Git-release updates write no new `origin` key. A Git release records its switch in the result step and the release directories, not the ledger. So rows written by older builds parse as before, and rows written by this build parse in an older build. A Git checkout that can't use the layout falls back to the in-place runner with a `recoverable-maintenance` advisory (`git-release-layout` step), the same contract as `installStagedPackage`'s swap fallback. - **New on-disk state is additive and lives under `<stateDir>/git-install/`:** `releases/<id>/` (detached worktrees), the `lib/node_modules/openclaw` link, `releases/.trial`, and the launcher. An install without them is treated as unconverted and gets the conversion path. If the layout is unusable, the update falls back to in-place (decision 8). - **Existing data proof: v2026.11.4 state upgraded and converted (E2E, `6d9acd6e`).** - The v2026.11.4 Gateway, started with `--profile`, created `state/openclaw.sqlite` (schema 22) and an agent DB. - This head's `gateway install` then stopped with "Client credentials require backed-up migration custody; … run openclaw doctor --fix". Plain `main` (`964ab522`) stops with the same message on a copy of that state, so it comes from `main`, not this diff. - Following the message, `openclaw doctor --fix --non-interactive` migrated the state to schema 40. After that, install succeeded and the update converted the checkout onto the release link. The `update_runs` row in the stable-created database reads `finished|succeeded`, and the stable config (Gateway port) still reads back. - **Rollback keeps data readable:** the crash-release trial switches the link back to the previous release, and the launcher restores the SQLite family (`openclaw.sqlite`, `-wal`, `-shm`) captured before the trial. The previous build reopens its own database (crash row, 28.9 s). ## Tests - `src/infra/git-release.test.ts`: - trial fallback restores the SQLite family and drops trial-only companions - trial settlement - launcher mapping - a launcher unit is owned without regeneration - a non-link package path falls back to the in-place runner with a reason - `src/infra/update-runner-git-release.test.ts`: - a same-commit release with unverified artifacts is rebuilt - a current release is reported prepared, so finalization never regenerates it - the first release comes from the serving worktree's commit, and the checkout's different target is still built - `update-command-post-update.test.ts`: a switched release converges plugins only after its restart. - `git-release.test.ts`: a checkout with no owning Gateway service keeps the in-place runner. The test fails without the gate. - `update-command-execution-validation.test.ts`: when a developer build holds the checkout's artifact lock, a Git release update still runs. It never takes that lock, because releases build in their own worktrees. The test fails without the fix. - `update-command-convergence-authority.test.ts`: under `--no-restart`, a switched release persists the channel and leaves plugins alone; an already-current rerun from the checkout of a converted install completes. - `update-runner-git-release.test.ts`: a successful rebuild of an incomplete runtime reports the new release's verdict. - `update-command-convergence-authority.test.ts`: release convergence runs in the updater, with no fresh process and no Doctor. - `update-command-verification.test.ts`: - a verified release ends its trial - a switched release's Gateway restarts itself without a native restart - `src/state/state-upgrade.test.ts`: `git-install` stays out of the startup upgrade copy. - Gates: `pnpm tsgo:core`, `pnpm check:test-types`, oxlint/oxfmt on changed files. On mbp-m5 at `99b7f080`, the broad update suite plus the package-release and package-update tests pass 1,944 / 1,948, with 1 skipped. The 3 failures are environmental: - `update-runner-git-node-preflight` ×3: mbp-m5's Node 24.21 is below `engines`. ## LOC prod +1018 / −38 (net +980); test +951 / −3. Draft: lands after #198835. #198389 has merged; #199770 carries the same startup-copy exclusion for main. Co-authored-by: Ayaan Zaidi <[email protected]>
…ase link (openclaw#199706) ## Problem A Git checkout install runs its Gateway from `<checkout>/dist/index.js`, and `openclaw update` rewrites that same tree. Everything around the rewrite exists to survive it: the updater copies its own runtime first (133–892 s on a 183k-file checkout), builds the candidate in a private repository and imports it through a pack (256 MB cap), stops and parks the serving Gateway, and rewrites the service definition every update. ## Change Extends openclaw#198835's linked package root (merged as `540d13a5`) to Git checkouts, per the openclaw#197949 design. Based on `main`. It reuses openclaw#198835's release resolver, `switchPackageReleaseLink`, leases and 24 h collection unchanged. Its fallback follows `installStagedPackage`: when the layout can't be used, the update runs in place with a `recoverable-maintenance` warning, and the next update tries the layout again. The Gateway process never writes the release link. The only other writer is the boot launcher, and it only points the link back to the release recorded in a failed trial. - **Layout.** `<stateDir>/git-install/lib/node_modules/openclaw -> releases/<id>/lib/node_modules/openclaw`. Each release is `git worktree add --detach` off the developer's checkout (shared object store, no clone or copy). - **Stage.** The existing candidate preflight (candidate walk, local-commit replay, `pnpm install --frozen-lockfile`, build, candidate checks) runs in the new release's worktree, then `--version` with the service's Node. A same-source no-op requires the serving release to be at the checkout's commit and its artifacts to verify (openclaw#158931). - Deviation from the design: the worktree is built at `releases/<id>/build`, then moved into place with `git worktree move`. Node refuses to strip types under `node_modules` (`ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING`), and the build runs `.mts` scripts. The built tree has no absolute symlinks, so the move is safe. - **Switch.** `switchPackageReleaseLink` from openclaw#198835. The serving Gateway keeps its release (Node resolves the entry's real path), so nothing is stopped, parked or verified before the flip. - **Restart.** The serving Gateway's maintenance tick sees the link move (installation replacement) and restarts itself into the new release. The updater waits for that successor (up to 90 s), then verifies. It falls back to a native restart only if no successor appears. A native restart from inside the service job (`update.run`) would end the updater itself. - **Service.** Written once, at conversion, to a frozen launcher `<stateDir>/git-install/openclaw-launcher.mjs`. A unit that names the launcher is never regenerated. The launcher is needed because a release that fails while loading never reaches Gateway code. - **Trial.** The switch writes `releases/.trial`. The launcher counts starts. - After two failed starts it switches the link back and restores the trial build's `*.pre-<buildId>` state files (falling back to openclaw#198389's `*.pre-<version>`). Each SQLite family is restored together, and trial-created WAL/journal/SHM/seal files without a preserved predecessor are removed. The launcher mirrors openclaw#198389's `companionRemovals` list because it must not load release code. - The trial ends when the Gateway's first maintenance tick runs, or when the updater verifies the restarted Gateway. The second path also covers targets that predate this PR. - Writes made during a failed trial are lost (approved). - **The layout never fails an update** (openclaw#197949 decision 8). If `releases/` cannot be created, or something other than a release link sits at the package path, the update records a warning and takes the in-place runner. The next update tries the layout again. - **Post-core work** (requested-channel persistence, plugin convergence) runs in the updater, but only after the restarted release verified and its trial ended. A failed trial therefore never leaves plugins that require the release it switched away from. It runs without Doctor maintenance, which the Gateway holds, and without a plugin cohort, because no core rollback exists to pair it with. If plugins changed, the Gateway is asked to restart again (SIGUSR2). Under `--no-restart` the release is unverified, so only the requested channel is persisted and plugins converge on a later update. - **The developer's checkout** is never written. The first update builds the commit that serves now as the first release, rewrites the unit once, then stages the target. - **Retention.** openclaw#198835's collection, followed by `git worktree prune`. `git-install` is excluded from backups and from the startup state-upgrade copy. The latter is the same change as openclaw#199770, included here so the stack stands alone. - **One owner.** `usesGitReleases` selects releases. Windows checkouts and package-to-Git switches keep the in-place runner, and the in-place CLI tests are pinned to that runner. For Git releases this skips: - runtime retention - the pack transfer/import - the managed-service stop/park - the database rollback capture - the checkout's source-artifact lock - the native restart from inside the service job - per-update service regeneration ## In-place fallback (decided) Windows Git checkouts, package-to-Git switches, and checkouts with no installed Gateway service still use the in-place runner, so this PR bypasses that runner on POSIX instead of deleting it. A checkout with no service is run by hand, so nothing would start through the release link and its next start would run the old commit. `gatewayServiceOwnsGitInstall` reads the installed service once and accepts it only when the service owns the checkout or its release link. The command decides once and hands that decision to the runner. Prod LOC is net **+980**. Decided 2026-11-16: Windows Git updates are not refused. A follow-up, slice 4b (stacked on this PR), moves Windows to releases using junctions and then deletes the in-place Git runner. ## E2E (mbp-m5, launchd, isolated profiles, shared-clone checkout; ≤15 min per run, ≤3 in parallel) **Final head `0b96d640` (rebased on `main` at `78d37094`): local ClawSweeper review clean** (gpt-6.1-sol, normal speed). After the rebase: `sweepPackageReleaseTemporaryLinks` is exported again, because the first Git publish uses it. The CI ratchets are satisfied: a lazy generation name, Node-only release tests, and an allocation record for the regression tests. A conversion's first release is now the commit the checkout's `dist` serves, not a pulled HEAD that was never rebuilt. A failed trial also restores a symlinked config: a preserved symlink is judged by its own time, not its target's. Rollback across same-version upgrades (decision d): the state upgrade now keeps a replaced file as `<file>.pre-<buildId>`, named after the build that replaced it, so two builds of one version each keep their own predecessor. Builds without a build ID, and earlier releases, still write `.pre-<version>`. Retention handles both forms. A failed trial restores the `.pre-<buildId>` of its own build, falling back to `.pre-<version>`. Fixes to the trial and launcher from the review rounds: - the inventory is recorded before anything is restored, so an interrupted rollback can resume without losing a restored WAL; - the trial's applied or interrupted upgrade plan is retired and the files it added are removed; a removal that fails is retried at the next start; - the config path is the one the update resolved (`~` and external paths included); - state is restored before the link moves back. The release layout is used only when the release switch actually reaches the next start: either the service already starts the launcher, or it owns the checkout and this update rewrites its definition and restarts it. `--no-restart` on a converted install leaves the serving release selected. The next start, which the operator triggers, selects the new release, without the two-start fallback. A first conversion requested with `--no-restart` stays in place. | Run (mbp-m5, isolated launchd profiles) | Head | Result | |---|---|---| | Release that crashes on boot | `d6d30a5e` (the final head changes only how a symlinked backup is dated) | update reports `build-id-mismatch` after 179 s; two "e2e boot crash" starts, then "failed to start twice; switched back"; link back on the previous release, trial cleared, `ready` | | Conversion before the crash run | `d6d30a5e` | ok, 267 s | **Current head `6d9acd6e` (on `main`), mbp-m5, isolated launchd profiles:** | Run | Result | |---|---| | Conversion (first update from a checkout service) | ok, root on the release link; 610 s with three runs in parallel; longest outage 9.7 s | | Release → release | ok, 239 s, longest outage 9.9 s | | `update.run` through the Gateway | `finished\|succeeded`, 135 s; link moved, Gateway restarted, plist unchanged; outage 7.8 s | | Checkout with no Gateway service | updated in place: checkout HEAD moved to the target, no `git-install/releases`, result `ok`, mode `git` | | Release that crashes on boot (at `0e3fefae`) | update reports `build-id-mismatch` after 188 s; after two "e2e boot crash" starts the launcher logs "failed to start twice; switched back", and the previous release serves `ready` | | v2026.11.4 state → this head | see Data-model compatibility | Older rows below ran at earlier heads. Rows marked ‡ ran at head `8a720e49`, rows marked † at `6032dedf`; the rest ran at `1140b601`, before plugin convergence moved after verification. At the final head `99b7f080` (rebased onto `823fa6d2`), three runs ran in parallel on mbp-m5. (1) Conversion and release→release passed again, with the root on the release link and a longest outage of 7.6 s. (2) `update.run` finished `succeeded` (link moved, Gateway restarted, plist unchanged, outage 8.0 s). (3) A checkout with **no Gateway service** updated in place: checkout HEAD moved to the bumped commit, no `git-install/releases` was created, and the result was `ok`, mode `git`, root the checkout. An intermediate head `2d2387b6` keyed this choice on a preflight fact that Git installs never fill in, so conversion fell back to in-place (about 120 s outage). That head was never pushed. | Case | Result | | --- | --- | | † First update of a checkout install (conversion, head→head+1) | ok, 402 s wall (two builds, three runs in parallel), longest outage 7.6 s, total 13.1 s (unit rewrite, then a restart after plugin convergence); unit rewritten once to the launcher; checkout tree clean; no retention, pack or handoff steps | | ‡ Release→release (head+1→head+2) | ok, 180 s wall, one outage of 7.2 s; unit untouched (mtime unchanged since conversion); service runs from `releases/` | | ‡ `--no-restart` on a switched release | the updater leaves the Gateway running and converges no plugins; within the next maintenance tick the Gateway restarts itself into the release, and the trial is cleared; outage 7.5 s | | † `update.run` via the Gateway (`openclaw gateway call update.run`) | run `finished|succeeded`, 140 s; link moved; the Gateway restarted itself; unit untouched; outage 7.4 s | | Already-current rerun from the preserved checkout after conversion (head `60503ab3`) | `skipped: already-current`, link unchanged, 113 s | | † Release that crashes on boot | two crashes, the launcher switched back to the previous release, Gateway ready again; the update reports `build-id-mismatch`; longest outage 28.9 s | | kill -9 mid-stage | link and serving Gateway unchanged; the rerun succeeds; a partial release directory left by the killed run is collected after 24 h | | kill -9 right after the link moves, before restart | the old Gateway keeps serving; the rerun reports `skipped: already-current`; the Gateway restarts itself into the new release and the trial is cleared | | `env -i` + `umask 077` (conversion, then release→release) | ok, 376 s and 198 s, outages 5.5 s and 7.5 s; launcher `0700` under umask 077 | | Install whose unit and state were written by 2026.11.3, moved to head, then converted | ok, 229 s, outage 5.9 s; state DB `integrity_check` ok. 2026.11.3's own updater could not reach head on mbp-m5: it walked back to `already-current` (Node 24.21 below head's `engines`), so that hop was done with `git reset` + `ocx build` | | Production-shaped install (207,229-file checkout, +3 GB SQLite in state), release→release | ok, 145 s, outage 6.9 s, no retention step. Main was not timed on this host. Peanutto's production main run `90c601fc` took 4,150 s, with 892 s retention and a 300 s outage | Not exercised: a plugin-only restart (SIGUSR2) after npm plugins actually change; the fixtures have no npm plugins. ## Data-model compatibility - **No new state schema.** This diff adds or changes no SQLite schema, migration, or config schema file. The update ledger (`update_runs`), Gateway owner lease and config are read and written exactly as on the base. - **`origin` stays compatible.** `UpdateRunRecordSchema.origin` (including openclaw#198835's `packageStage` and `packageRelease`) is unchanged, and Git-release updates write no new `origin` key. A Git release records its switch in the result step and the release directories, not the ledger. So rows written by older builds parse as before, and rows written by this build parse in an older build. A Git checkout that can't use the layout falls back to the in-place runner with a `recoverable-maintenance` advisory (`git-release-layout` step), the same contract as `installStagedPackage`'s swap fallback. - **New on-disk state is additive and lives under `<stateDir>/git-install/`:** `releases/<id>/` (detached worktrees), the `lib/node_modules/openclaw` link, `releases/.trial`, and the launcher. An install without them is treated as unconverted and gets the conversion path. If the layout is unusable, the update falls back to in-place (decision 8). - **Existing data proof: v2026.11.4 state upgraded and converted (E2E, `6d9acd6e`).** - The v2026.11.4 Gateway, started with `--profile`, created `state/openclaw.sqlite` (schema 22) and an agent DB. - This head's `gateway install` then stopped with "Client credentials require backed-up migration custody; … run openclaw doctor --fix". Plain `main` (`14466930`) stops with the same message on a copy of that state, so it comes from `main`, not this diff. - Following the message, `openclaw doctor --fix --non-interactive` migrated the state to schema 40. After that, install succeeded and the update converted the checkout onto the release link. The `update_runs` row in the stable-created database reads `finished|succeeded`, and the stable config (Gateway port) still reads back. - **Rollback keeps data readable:** the crash-release trial switches the link back to the previous release, and the launcher restores the SQLite family (`openclaw.sqlite`, `-wal`, `-shm`) captured before the trial. The previous build reopens its own database (crash row, 28.9 s). ## Tests - `src/infra/git-release.test.ts`: - trial fallback restores the SQLite family and drops trial-only companions - trial settlement - launcher mapping - a launcher unit is owned without regeneration - a non-link package path falls back to the in-place runner with a reason - `src/infra/update-runner-git-release.test.ts`: - a same-commit release with unverified artifacts is rebuilt - a current release is reported prepared, so finalization never regenerates it - the first release comes from the serving worktree's commit, and the checkout's different target is still built - `update-command-post-update.test.ts`: a switched release converges plugins only after its restart. - `git-release.test.ts`: a checkout with no owning Gateway service keeps the in-place runner. The test fails without the gate. - `update-command-execution-validation.test.ts`: when a developer build holds the checkout's artifact lock, a Git release update still runs. It never takes that lock, because releases build in their own worktrees. The test fails without the fix. - `update-command-convergence-authority.test.ts`: under `--no-restart`, a switched release persists the channel and leaves plugins alone; an already-current rerun from the checkout of a converted install completes. - `update-runner-git-release.test.ts`: a successful rebuild of an incomplete runtime reports the new release's verdict. - `update-command-convergence-authority.test.ts`: release convergence runs in the updater, with no fresh process and no Doctor. - `update-command-verification.test.ts`: - a verified release ends its trial - a switched release's Gateway restarts itself without a native restart - `src/state/state-upgrade.test.ts`: `git-install` stays out of the startup upgrade copy. - Gates: `pnpm tsgo:core`, `pnpm check:test-types`, oxlint/oxfmt on changed files. On mbp-m5 at `99b7f080`, the broad update suite plus the package-release and package-update tests pass 1,944 / 1,948, with 1 skipped. The 3 failures are environmental: - `update-runner-git-node-preflight` ×3: mbp-m5's Node 24.21 is below `engines`. ## LOC prod +1018 / −38 (net +980); test +951 / −3. Draft: lands after openclaw#198835. openclaw#198389 has merged; openclaw#199770 carries the same startup-copy exclusion for main. Co-authored-by: Ayaan Zaidi <[email protected]>
|
Closing as superseded. The design this proposed (release folders, a link switch and a staged handoff) is now tracked in #204775, which records what landed and who owns each part. The branch stays in place for reference. |
Related: #145252
What Problem This Solves
Update reliability work has no written plan for its two structural causes: a package update moves the running release off its path, and the installed updater drives the whole run, so a fix in a new release cannot help the release that is failing.
User Impact
User impact: none. This is a design proposal for maintainers to accept, change, or reject. It adds one page under
docs/reference/and changes no behavior.The page records seven decisions, which a maintainer accepted on November 13, 2026. Decision 2 was revised the same day, from extending the activation journal to not extending it. Three are ones this repository reserves for explicit approval: recording a pointer intent in the activation journal, the retention rule for release directories, and the package marker that #197922 adds. Accepting them sets the direction; each slice still needs its own review.
Why This Change Was Made
#197922, now merged, implements the first slice of this plan, and its reviewers had no place to see where it leads. The page records:
2026.10.9and2026.11.3: the update passes and the link stays, but the updater rewrites the release directory behind the link in place. The page predicted the link would be replaced by a directory, and it now adds a release identity rule to the recommended route because of the result.649ca5f879f1e. No handoff rule is needed for a linked package root, because the updater already rebinds its post-core child to the activated root. A later design pass recommends against extending the activation journal for the link switch, and decision 2 is revised to match: the link is the record, and the update run record gains one optional field naming the two releases. The page records that design, the order of an activation, what each crash point leaves, and what it does not cover.openclaw updatesettles and finishes a killed update (fix: let the next update settle a package publication that a killed update left behind #200550, fix: let the next update continue after a killed update when nothing is left to repair #200680, fix: let the next update finish a killed update that had already installed the new version #200866, fix: let the next update finish a killed update after the machine restarted #200994, fix: let the next update finish a killed source checkout update #201009). They list what still needsopenclaw update repairby hand and what each change was not shown to do.This is the fourth version of the page. The third recommended rebinding the service to a release path. That rested on a wrong premise, which the page states under rejected approaches.
It follows the form of the existing
team-immutable-update-design.md. Like that page, it is not listed indocs/docs.json.Evidence
Docs-only change. Latest update, at
30ab4d83b2a(merged withmainat9e917f010bc):pnpm check:docs(formatting, MDX, links, config examples, changelog) passed in this worktree with dependencies linked from another checkout, andgit diff --checkis clean. The killed-update notes were checked against the merged source onmain, chieflysrc/cli/update-cli/update-plugin-cohort-settlement.ts.First version, run against this page at
526f6d63cab40:scripts/check-docs-mdx.mjson the page: passed.oxfmt --checkon the page: clean.markdownlint-cli2with the repository config: 0 issues.git diff --check: clean.Not run:
pnpm docs:check-links. The worktree is a sparse checkout without installed dependencies, so the audit could not start there.The design comes from reading source, from two tests with toy packages on macOS (Node resolving a linked entry, and npm's handling of a linked global package), from the Docker runs recorded on #197922, and from one new Docker test.
Published updaters on a linked package root. In the published-driver update cell on linux/arm64, I moved the installed release into
releases/<version>/and left a relative link at the package path, then ran a normal update to a build of089d8b8.The cell's installed-tree budget check refuses a linked root, so I pointed it at the link's target for these runs; the harness copy with that change and the layout recording was not committed. Not covered: rollback after a failed update on a linked root, a second update, a Gateway-initiated update, older updaters, and Windows.
The link switch itself has not run on an OpenClaw installation. The page's "Evidence limits" section lists the rest.