Skip to content

fix(update): finish the Gateway restart a shipped pnpm updater refused - #201906

Closed
fuller-stack-dev wants to merge 12 commits into
openclaw:mainfrom
fuller-stack-dev:fix/update-finish-gateway-restart-after-shipped-driver
Closed

fuller-stack-dev wants to merge 12 commits into
openclaw:mainfrom
fuller-stack-dev:fix/update-finish-gateway-restart-after-shipped-driver

Conversation

@fuller-stack-dev

@fuller-stack-dev fuller-stack-dev commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

A pnpm install updated by published 2026.11.5 to a release with the same database schema (2026.11.5 → 2026.11.6) keeps a working openclaw command. Since #201735 the Gateway stays down: openclaw update exits 1 with service-revalidation-failed, and the restart and the recovery restart are refused with managed-service-ownership (service-ownership-changed). In a real cell the Gateway stayed down for 402 s, until the user ran another command.

Root cause, in the installed updater, which this change cannot patch:

  • After the package swap, 2026.11.5 checks the service's loaded command against the new root (update-command-service-revalidation.ts:333-398 at v2026.11.5).
  • Its fallback compares against the pnpm global entry, which pnpm has just repointed into a new versioned store directory. The unit still names the 2026.11.5 store entry, so the service looks foreign.
  • main fixed this check (fix: keep the openclaw command and Gateway working after updating a pnpm install #201735), but only a fixed updater runs it. 2026.11.5 hands the remaining steps to the new package only when the schema migrated (update-command-migrated.ts:141-146 at v2026.11.5).
  • So schema-migrating hops already work (2026.11.4 → 2026.11.6, 2026.11.5 → 2026.11.10, both shown in real cells), and same-schema hops do not.

User Impact

On a same-schema pnpm hop driven by 2026.11.5, the Gateway now comes back on the new version without another command. The new package's Doctor, which that updater does run after the swap, prints one line saying OpenClaw will try to restart the Gateway after the updater exits. After the updater exits, a background process refreshes the service definition and starts the Gateway through the ordinary openclaw gateway install --force and openclaw gateway start owners. The installed updater still prints its own failure and exits 1, because it decides that before this code can act.

Why This Change Was Made

This is compatibility code for shipped updaters that cannot be patched. It applies to 2026.11.5 and earlier, and to 2026.11.6 and 2026.11.10 builds without the #201735 fix. The module comment names those versions, and the module is removed once no supported upgrade path starts from such an updater.

Two other routes were rejected:

  • Forcing the handoff by reporting a schema migration that did not happen. That would publish false dataAtRisk/no-rollback records and turn off the updater's own recovery.
  • Editing the unit from the Doctor during the update so the shipped check passes. On systemd the shipped check reads the manager's loaded ExecStart over D-Bus (systemd-service-files.ts:204-222 at v2026.11.5), so passing it would need daemon-reload. The updater also spawns its Doctor with service repair and activation disabled.

How it works:

  • Gate. The Doctor step "Gateway restart handoff" in src/flows/doctor-health-startup.ts acts only when all of these hold:
    • an update is in progress, and the parent's no-repair and no-activation flags are set;
    • exactly one running update run, whose recorded driver is alive and is this Doctor's parent;
    • the running package is the active pnpm global entry's store directory;
    • the service names this same pnpm home's store entry for an earlier version, is owned by this installation, and has a writable definition.
  • Spawn. The finisher is spawned detached and confirms that it took the single-instance lock before the Doctor prints its line.
  • Wait and re-check. It waits up to 60 minutes for the run to finish and the updater to exit. It acts only on service-revalidation-failed, and re-checks every gate under the Gateway service operation lock. It yields if a newer update started, if the service is running, or if the Gateway answers.
  • Fixed drivers. The driver's version cannot tell a fixed build from an unfixed one, so the gate does not use it. Under a fixed driver the finisher only waits for the run to end with another outcome and exits.
  • Recording. On success it records the verification on the run (existing fields) and a warning row. If it gives up, the warning names the reason and the verified recovery: openclaw gateway install --force, then openclaw gateway restart, or openclaw triage. A real cell showed that openclaw gateway restart alone exits 78 in this state.

Where the finisher runs. On Linux it is launched through systemd-run --user --scope --collect --unit=openclaw-update-restart-<runId>.scope, using the managed-service handoff launcher's existing systemd-run resolution (update-managed-service-handoff-launcher.ts). Without its own scope it would share the updater's cgroup and die with it. For a Gateway-started update, that cgroup is the transient openclaw-update-<id>.service (KillMode=control-group, v2026.11.5 update-managed-service-handoff-launcher.ts:49-76), which stops when its helper exits. The scope has no PartOf= on the Gateway, so the finisher's own gateway install --force cannot stop it. If systemd-run is missing, it falls back to a plain detached spawn. On macOS it is a detached process.

Single instance. A per-run file lock. The existing owners were checked and none fits:

  • the update executor fence and the managed-handoff lease are exclusive per installation, so holding either through the wait would block the openclaw update the finisher must yield to, and the lease has no row kind for this;
  • the Gateway service operation lock serializes every Gateway command, so it is taken only around the final re-check;
  • sqlite-live-owner authorizes only the Gateway's own database reads.

What readers show after a successful finish. The stored run keeps status: failed, reason: service-revalidation-failed, plus the verification and the warning row; no new field or status value was added. isRefusedRestartFinishedLater (src/infra/update-run-restart-finished.ts) recognizes that combination. With it:

  • openclaw update status leads with "✅ OpenClaw updated to 2026.11.6 (from 2026.11.5); 1 warning needs attention.";
  • it states that the recorded outcome is unchanged, and drops the failure lines and the triage advice;
  • the Control UI update card shows no failure banner, and the chat /update summary reads as updated;
  • update status --json prints the stored record unchanged;
  • a run that gave up still reads as failed.

Gateway-started updates. The shipped 2026.11.5 Gateway refuses update.run for a pnpm global-virtual-store install before changing anything (update.ts:427-432, install surface package-root). So that path never reaches the finisher. That refusal also exists on main and is handled in a separate PR.

The docs correct the earlier claim that 2026.11.4 and 2026.11.5 always hand the later steps to the new package: they do so only when the schema migrates.

Evidence

Draft. Unit tests: update-shipped-restart-finisher.test.ts, 14 tests, using a real update run ledger and a real pnpm store layout on disk. Each gate was removed in turn, and every case that guards it failed. Real Docker cells on the 2026.11.6 line (#201739 plus this commit) are running and will be added here:

  • green: 2026.11.5 → this build;
  • the user running a plain openclaw update 5 s after the failure;
  • npm control;
  • fixed-driver control;
  • forced post-swap failure;
  • 2026.11.4 start;
  • the CLI-started and Gateway-started hops on real systemd.

The red cell is published 2026.11.5 → #201739 head 848912c: exit 1, the Gateway down for 402 s, and back only after a second update.

Start layout covered. Every cell starts from a registry install made by pnpm add -g, which puts the package in store/v11/links/@/openclaw/<version>/…. That is also where a user who recovered by hand with pnpm add -g ends up, so a later update from such an install starts from the layout the cells already use. The target layout is the project-store layout the updater itself produces (global/v11/<group>/node_modules/.pnpm/openclaw@<version>…), which a real public-registry cell confirmed.

Steps left to a person

None on the covered hop. If the finisher gives up, its warning names the verified recovery and openclaw triage.

Not proven yet

  • Target layout from a registry: now covered. A real cell ran published 2026.11.5 → a plain openclaw update → published 2026.11.6 from the public registry only. The updater installs a registry target in the project-store layout (global/v11/<group>/node_modules/.pnpm/openclaw@<version>…), the same layout class the earlier tarball-target cells used. See fix(update): keep the openclaw command and Gateway working after a pnpm update #201739 (comment).
  • Still unproven: a fixed target installed from a registry. It cannot be exercised before a fixed version is published; the fixed builds were proven as tarball targets.
  • Still unproven: pnpm 11, which ignores the virtualStoreType=project setting the updater passes, so its target layout may differ. A pnpm 11 cell is being prepared.
  • Real systemd and launchd, the Gateway-initiated update path, and KillUserProcesses=yes at logout. In the last case the next openclaw update or the verified recovery heals the install.

@clawsweeper

clawsweeper Bot commented Nov 19, 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 cli CLI command changes size: L labels Nov 19, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. 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:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 19, 2026
@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head d449d1672561f6a8d9741a3bd268f45d50d6e910, but the PR head is now b597201497b84c67333fb14b60a00319f23dbcc8. 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-19T15:36:38.086Z sha d449d16 :: needs changes before merge. :: [P1] [P1] Wait for Doctor maintenance custody before reading the ledger

@openclaw-barnacle openclaw-barnacle Bot added the app: web-ui App: web-ui label Nov 19, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the app: web-ui App: web-ui label Nov 19, 2026
@clawsweeper clawsweeper Bot removed 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. labels Nov 21, 2026
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Result of trying this change on the 2026.11.7 line (applied onto v2026.11.7 + #203401 with mechanical conflicts only; its unit test file passed 29/29 there). In real pnpm cells, published 2026.11.7 → that build and published 2026.11.6 → that build, the restart did not happen:

  • The Doctor line promising a restart after the updater exits was printed.
  • The journal shows the openclaw-update-restart-<runId>.scope unit starting twice, once per Doctor run, and ending within about 1 s each time, before the updater exited. The finisher's log has only its started for run line.
  • The Gateway was still stopped 7 minutes after the updater exited, until openclaw gateway install --force and openclaw gateway restart were run.

Started by hand after the updater had exited, the same logic did bring the Gateway back about 159 s later, then exited 1 with a missing module because the update it handed off to replaced the package it was running from. The cause of the early exit in the normal path is not established. This stays a draft; the promise it prints is not kept in its current form.

@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Closing without merging.

This finisher helped pnpm installs whose updater is 2026.11.5 through 2026.11.9, on an update to a release with the same database schema. Every release still to ship has a newer schema than those versions, so their updaters hand the rest of the update to the new release, which already includes the restart fix from #201735. 2026.11.10 includes that fix too. The same-schema updates this PR targeted can only land on releases that are already published, and those do not contain this code.

A later test cell also showed that a finisher launched in a transient scope is stopped together with the updater's process tree. #204322 uses a transient service for its own recovery for that reason.

Not measured: an update from 2026.11.9 straight to 2026.11.11. If a 2026.11.6 to 2026.11.9 pnpm install still ends with the Gateway stopped after updating to 2026.11.11 or later, please open a new issue with the update output and openclaw update status. Recovery steps for installs affected today are in #204836.

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

Labels

cli CLI command changes docs Improvements or additions to documentation P1 High-priority user-facing bug, regression, or broken workflow. size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant