Skip to content

feat(update): stage runtime slots, flip one pointer, restart through a frozen launcher - #198375

Closed
obviyus wants to merge 11 commits into
perf/update-remove-candidate-canaryfrom
feat/update-runtime-slots
Closed

obviyus wants to merge 11 commits into
perf/update-remove-candidate-canaryfrom
feat/update-runtime-slots

Conversation

@obviyus

@obviyus obviyus commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

What failed in the field

  • openclaw update changes the running install in place, then stops, rewrites and restarts the service. Most failures happen in that activation step, after the candidate already passed its checks.
    • Report on 78 days of automated upgrades on the dev branch using Codex #197195 (78 nights, one host): 8 of 32 failed nights were the service handoff — the unit generator rejected its own unit under an inherited umask, "manager identity changed" refused the restart, a closed systemd read scope, inspection deadlines, no XDG_RUNTIME_DIR/D-Bus in cron, a different PID namespace. Two more were the 256 MB pack cap on a git update that had passed every check.
    • evidence/class*.jsonl, layer service: 295 reports. Largest causes: managed-service handoff/preflight/stop failed (~75), service file not regenerated or regenerated wrongly (~30), Gateway left stopped after the update (~25), ownership/manager identity not verifiable (~15), systemd/launchctl inspection deadlines and a missing user bus.
  • Disk on that host: 269 GB of 348 GB was update staging that was never removed. Doctor removes a retained runtime only when a process census proves no holder, and the census was always incomplete (48 retained runtimes, 142 GB).

What changed

An update only ever writes into a runtime slot that no Gateway runs, and switches with one rename. openclaw update, chat /update and the Control UI use the same path on Linux and macOS for user npm and git installs.

Layout <state>/runtime/:

  • launcher.mjs — frozen copy of scripts/openclaw-runtime-launcher.mjs (~100 lines, no dependencies). Written once, mode set with fchmod (not the umask).
  • slots.json — {current, previous, origin, trial?, failed?, run?}. Every write is temp + fsync + rename(2).
  • a/, b/ — the two slots. origin is the existing install and is never changed by a slot update.

Update:

  1. Stage the slot that no Gateway can be running, in a per-attempt directory .stage-<slot>-<uuid>, then rename it onto the slot. npm: npm install --prefix. git: git worktree add --detach of the checkout (shared object store), then pnpm install --frozen-lockfile --package-import-method=auto (copy-on-write clones or hardlinks from the pnpm store) and pnpm build, then git worktree move. No copy, no pack cap. A killed updater's orphaned npm/pnpm child writes only into its abandoned stage directory.
  2. Smoke <slot>/openclaw.mjs --version with the Node named in the service definition (read from the unit/plist file, not PATH).
  3. Flip slots.json: {current: slot, previous, trial: 2, run?}.
  4. Restart:
    • CLI: ask the Gateway on the service's own port to restart (fallback systemctl --user restart / launchctl kickstart -k; neither answers → "applies on the next Gateway start", exit 0), then wait up to 180 s for confirmed (exit 0), returned (exit 1) or pending (exit 0).
    • Chat /update / Control UI (update.run): the Gateway acknowledges, persists the restart sentinel, stages in-process, flips, then restarts itself. The Gateway that confirms the slot finishes the update run as succeeded; a Gateway the launcher returned to finishes it as rolled-back. The existing run watcher delivers the chat notice.
    • First update on an install whose service does not run the launcher yet: the staged release runs gateway install --force once (its program arguments now name the launcher) and that restart is the update's restart. Without a reachable service manager the update uses the restart request instead; the origin entry still hands off to the launcher (below), and the next CLI update or Doctor repair rewrites the unit.

Start:

  • The service runs node <state>/runtime/launcher.mjs gateway --port N. The launcher execves current/openclaw.mjs (same PID: supervisor identity and existing ownership checks do not change).
  • A start while trial is set spends one attempt; at zero the launcher selects previous and records failed (keeping run). A Gateway on trial exits 1 instead of 78 on config errors, so RestartPreventExitStatus=78 cannot park a bad slot. It reads its trial from slots.json; there is no new environment variable.
  • The Gateway clears trial when it reports "gateway ready" (listening, channels started).
  • program-args names the launcher for every Gateway service of a slot layout, so gateway install, Doctor's expected plan and the update agree; the service definition never changes when the version changes. service-layout maps a launcher entry to the selected slot, so status and Doctor drift checks compare the right package root.
  • The CLI on PATH, node-host services and units that still name the origin entry run runtime-slot-redirect.mjs first, which hands off to the launcher (a CLI call never spends a trial).

The updater needs no D-Bus, XDG_RUNTIME_DIR, Node on PATH, umask or PID namespace. It holds runtime/update.lock with a heartbeat; a killed updater's lock goes stale after 60 s.

What got deleted, and what did not

  • Doctor's process-census gate on retained-runtime cleanup: doctor --fix removes leftover openclaw-update-runtime-* directories again (Report on 78 days of automated upgrades on the dev branch using Codex #197195: 48 retained runtimes, 142 GB).
  • On Linux/macOS user npm/git installs, neither openclaw update nor update.run reaches runtime retention, update-capture sets, the managed-service stop/handoff, the service-definition refresh or the in-place swap.
  • Not deleted here: the in-place pipeline itself. Windows, Homebrew, system packages, Bun, --recovery/resume workers and the Doctor source update still run it, and fix(update): refuse missing host prerequisites in one line and record a cause per attempt #198355 (plan item 3) and the copy-and-swap work (plan item 4) edit those files. Deleting it is the next stage: move Windows onto slots (needs a Windows VM proof), then remove the in-place pipeline, retained runtimes, capture sets, the process census and service regeneration in one cutover. See design note 1.

Lines vs. the PR #198268 head: production +1344 −57; tests +212 −152; docs +37. Net production is still positive; see "Open" below.

Proof

Status: partial. Runs below are on 60f8c83/d9e52d0 (same slot code as the current head except the service-port fix in b38809a). Hosts: OrbStack Ubuntu 24.04 VM (systemd user service) and macOS 27 (launchd). Each run starts from a fresh install of this head as 2026.11.3 whose service still runs the origin entry. Updates run cron-like (env -i, umask 077, Node off PATH, no D-Bus).

Scenario Linux macOS
First slot update (login shell) exit 0, outage 5–8 s; unit now runs <state>/runtime/launcher.mjs exit 0, outage 12–13 s; plist now runs the launcher
Second update (cron-like) exit 0, outage 15–16 s exit 0, outage 14 s
kill -9 new Gateway on trial start confirmed, exit 0 confirmed, exit 0
kill -9 updater at Staging / npm install / Staged / Selected / Asked healthy 0–16 s each healthy 0 s (Staging, npm install); rest of the run was interrupted
Bad build launcher returned to previous slot, failed recorded, exit 1, healthy 5 s later not rerun on this head
No service manager "applies on next start", exit 0; next start confirms —
Chat /update not proven: the harness sent /update through a non-owner client and got the owner refusal; rerun through an owner chat client is pending —

Git slot disk (btrfs VM, df delta): worktree checkout files 855 MiB; node_modules with --package-import-method=hardlink 33 MiB (vs. ~3.1 GiB copied before); dist ~480 MiB per slot is the remaining cost.

Found by the proof and fixed: the first launcher rewrite dropped the service's --port (macOS Gateway moved to the configured port; fixed in b38809a).

Open

  • Deletion / net size. POSIX npm and git installs no longer reach the in-place pipeline, but it is not deleted: Windows, Homebrew, system packages, Bun and recovery/resume still run it, and Homebrew on Linux/macOS also uses the managed-service handoff and unit refresh. Making this PR net-negative needs one owner decision: move Windows and Homebrew onto slots (or drop in-place for them), then remove the in-place activation, retained runtimes, capture sets, process census and service regeneration in one cutover.
  • Migration at slot start. A Doctor run from the launcher is refused inside the service process tree; the state upgrade at Gateway start belongs to plan item 4 (copy-and-swap). Until then a slot whose schema is newer than the state relies on the Gateway's own startup migration.
  • CI. check-lint-core-3 flags three files this PR does not change (same oxlint result on the base). help-exit.process.test.ts reproduces red on base b6c6aef. The qa-lab e2e, update-command-runtime and Codex worker reds are not yet reproduced on the base; perf(update): replace the candidate canary with a runtime contract check #198268's own CI skips these jobs, and main is green.

Accepted edge cases

  • A Gateway that hangs before "gateway ready" without exiting keeps its trial until its next start (the launcher execs away; no watchdog).
  • Two profiles that share one install share one pointer; the first healthy Gateway confirms.
  • Between the flip and the restart, a CLI started by the old Gateway runs the new slot (the redirect follows current).
  • Flip-back restores code only. Restoring pre-migration state is plan item 4 (copy-and-swap keeps .pre-<ver>); until it lands, an old slot can refuse a newer state schema.
  • Git installs follow origin/main (dev) or v<release> tags (stable/beta); a pinned dev target must be reachable from origin/main. Custom upstreams are not followed.
  • The frozen launcher has no upgrade path; changing it needs a new file name and a one-time unit rewrite, the same step this PR uses for the first migration.

Design note: owner decisions

  1. Windows stays on the in-place updater in this PR. Its scheduled task can run the launcher in spawn mode (already supported), but the restart contract and staging need a Windows VM proof. Proposed next stage: Windows on slots, then delete the in-place pipeline (net-negative).
  2. Migration is automatic: the first update after this release creates the layout with the existing install as origin (nothing is copied) and points the service at the launcher once. Alternative: opt-in.
  3. Packaged macOS app, Homebrew, system packages, Bun/standalone, containers: unchanged.
  4. Git installs no longer move the user's checkout; the slots carry the builds, and the checkout's CLI follows current. A developer who wants their own edits runs another worktree.

Coordination

@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime cli CLI command changes scripts Repository scripts docker Docker and sandbox tooling size: XL labels Nov 13, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 13, 2026
@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head 9e33d7cf213a1ee249bdaebc3ba78add21a7d777, but the PR head is now 3c903dd9ebc53dbd6c43daabaf86aa1ef382a0e0. Its old verdict and PR readiness labels are no longer current.

Next step
Comment @clawsweeper re-review when the current head is ready; pushes after the first review are not reviewed automatically.

Review history (1 earlier review cycle)
  • reviewed 2026-11-13T17:11:00.401Z sha 9e33d7c :: blocked before merge. :: [P1] Preserve installation-owner checks before selecting the slot path | [P1] Resolve slot storage from the selected service's environment | [P1] Preserve the executing Git tree when replacing a pending slot | [P1] Preserve installed-version channel inference | [P2] Retain newest-of-beta-and-latest target selection | [P2] Preserve the npm-to-Git dev-channel transition

@obviyus
obviyus force-pushed the feat/update-runtime-slots branch from 9e33d7c to 3c903dd Compare November 13, 2026 17:29
@obviyus
obviyus marked this pull request as ready for review November 13, 2026 18:34
@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 13, 2026
obviyus and others added 8 commits November 14, 2026 02:40
…uncher, stage per attempt

- chat /update and the Control UI stage the runtime slot inside the Gateway, restart it, and the Gateway that confirms or rolls back the slot finishes the update run
- a slot layout's Gateway service runs <state>/runtime/launcher.mjs; the first slot update rewrites the service once
- each staging attempt uses its own directory and renames onto the slot, so an orphaned npm/pnpm child cannot block or corrupt the next update
- git slots import pnpm packages with clones or hardlinks
- drop OPENCLAW_RUNTIME_SLOT and OPENCLAW_RUNTIME_TRIAL: a Gateway reads its trial from slots.json

Co-authored-by: obviyus <[email protected]>
@obviyus
obviyus force-pushed the feat/update-runtime-slots branch from d9e52d0 to b38809a Compare November 13, 2026 21:10
@obviyus
obviyus marked this pull request as draft November 14, 2026 04:45
obviyus and others added 3 commits November 14, 2026 10:26
…ackage, Bun, app and container installs

Co-authored-by: obviyus <[email protected]>
The task supervisor stays on the origin install; each Gateway child it starts
reaches the launcher through the origin entry.

Co-authored-by: obviyus <[email protected]>
… delete the in-place updater entry

openclaw update, the wizard, Doctor's update offer and automatic updates now
dispatch only to immutable activation or runtime slots. The hidden protocol
subcommands that earlier releases' helpers call (admit, preflight, finalize,
migrate/restore/finish, migration-plan) stay registered for the upgrade
window. update repair now points at doctor --fix.

Co-authored-by: obviyus <[email protected]>
@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator Author

Closing in favor of #198835, which reaches the same goal (stage the new release beside the old one, switch with one rename, roll back by switching back) through the linked package root accepted in #197949. That design rejects the launcher and service-definition rewrite this PR uses.

Git checkouts are out of scope for #198835 and keep the copy-and-swap. A possible route for them from this branch: git worktree add --detach from the checkout's object store plus pnpm install --frozen-lockfile from the shared store, which avoids copying the checkout. Leaving that as input for #197949 rather than a competing implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes commands Command implementations docker Docker and sandbox tooling docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. scripts Repository scripts size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant