Repository navigation
fix(gateway): leave a replaced installation to the update run that holds it - #200389
Conversation
…lds it While an update run holds the install lease it stops and restarts the Gateway itself. The Gateway's installation check could restart it into the new package first, racing the update's Doctor and Gateway start; with --no-restart that failed the update and rolled it back. The check now skips the self-restart while a live update run holds the installation, and a later check restarts a Gateway the run leaves stale. Co-authored-by: obviyus <[email protected]>
The installation check runs on the serving Gateway thread. Lease reads and process probes are synchronous, so they now run through the existing handoff worker, and the lease key is captured with the installation root. Co-authored-by: obviyus <[email protected]>
|
🦞👀 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: needs maintainer review before merge. What this changesThe Gateway defers automatic installation-replacement restart while a live updater holds the existing installation lease. Example: Run openclaw update --no-restart with a launchd Gateway running when its installation check observes the replacement build.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR addresses a documented update race still present on main, and the introduced diff has no actionable correctness or security findings. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherGateway maintenance compares running and installed build identities; the existing update coordination worker supplies lease and process-liveness facts before the observer requests a restart. flowchart TD
A[Gateway maintenance tick] --> B[Read installed build identity]
B --> C[Installation replacement observer]
C --> D[Existing handoff worker]
D --> E[Update lease and process identity]
E --> C
C --> F[Defer or request restart]
Technical reviewBest possible solution: Keep installation handoff with the existing live update-lease owner and retain automatic replacement detection after that owner releases it. Do we have a high-confidence way to reproduce the issue? Current source exposes the competing restart path, and this PR plus #198835 report matching real-update failures; this read-only review did not execute the reproduction. Is this the best way to solve the issue? The patch is a focused repair of installation ownership: it reuses canonical root resolution, the existing lease store, and its worker rather than adding another coordinator or updater gate. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b6db4fad70c4. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +45, Tests +22. Total +67 across 2 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes: No label changes. Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 16, 2026, 10:40 PM ET / November 17, 2026, 03:40 UTC. |
|
Landed as f31a0b1. While an update run holds the install lease, the Gateway no longer restarts itself. That self-restart was racing |
…lds it (#200389) Adapt existing managed handoff worker to inspect live update lease off the serving thread. Retain observer generation and suspension guards; preserve missing-runtime recovery and unreadable-lease fallback. Backport of f31a0b1. Parent reviewed bounded worker operation, existing lease owner and observer effect check; reuse worker real-lease red/green13 and sibling3 proof. Co-authored-by: RomneyDa <[email protected]>
…lds it (openclaw#200389) ## Problem During `openclaw update --no-restart` with the Gateway running, the Gateway's installation check (`src/gateway/server-maintenance.ts`, every 30 s) sees the new `build-info.json` and restarts the Gateway into the new package while the update still owns the installation. The update's own Gateway start then waits on state ownership held by the self-restarted process, stalls for 120 s, and the update fails with `activated-gateway-startup-failed` and rolls back (exit 1). This happens on plain package installs and on the release-directory layout from openclaw#198835. The natural rate is about the race window divided by 30 s. openclaw#198835 measured that window at 1.75–1.88 s, which gives about 6% per run; I did not re-measure the window. ## Change The update run is the one owner of the installation while it holds the install lease (the same `managed-update-handoffs` row the updater's executor takes). `checkGatewayInstallationReplacement` (`src/gateway/stale-install.ts`) now skips the self-restart while a live process holds that lease. A Gateway the run leaves stale restarts on a later check, after the lease is released. - The lease key is captured with the installation root when the observer registers. - Lease reads and process-identity probes are synchronous, so they run in the existing handoff worker (`prepareManagedHandoffParentStore`), never on the serving thread. They run only when a changed build is observed. - An unreadable lease keeps today's behavior (self-restart). - No new gate in the updater, no schema or config change. ## Impact `--no-restart` updates with a running Gateway no longer race the update's Doctor and Gateway start. Behavior outside an update run is unchanged. ## Evidence **Unit:** `src/gateway/stale-install.test.ts` › "leaves a replaced installation to the update run that holds it". It holds a real lease, checks that a changed build does not restart the Gateway, releases the lease, then checks that the next tick does restart it. Red on `dd40e0123cdc` (handoff called once while the lease is held), green on this head; the other 14 tests in the file pass. **E2E (mbp-m5, real `openclaw update --no-restart` against a launchd Gateway, isolated `--profile`):** the reproduction makes the installation check fire every 250 ms in the *running* build. Only `server-maintenance` changes in a packed copy; the build ID differs, the code is otherwise identical. Each arm: install, start the Gateway service, then `update --no-restart --tag <next build>` with the Gateway running. | Arm | Layout | Result | Update wall time | |---|---|---|---| | main `dd40e012` | release dirs (`install-cli.sh` prefix, adopted) | **fail**: self-restart at T+0.25 s, `activated-gateway-startup-failed`, rolled back | 351 s | | main `dd40e012` | plain user npm prefix | **fail**: same | 455 s | | this PR `d6f23896` | release dirs | **ok**, no self-restart signal, Gateway healthy on the new build | 133 s | | this PR `d6f23896` | plain user npm prefix | **ok**, no self-restart signal, Gateway healthy on the new build | 188 s | Gates: `pnpm tsgo:core`, `pnpm check:test-types`, oxlint and oxfmt on changed files all pass. Local ClawSweeper review (gpt-6.1-sol, normal speed) at `d6f23896`: patch is correct, 0 findings. The previous head's single finding (synchronous lease reads on the Gateway thread) is fixed by the worker move. Not covered: the missing-runtime-chunk path in `classifyGatewayStaleInstall` still restarts on a request failure during an in-place swap. That path triggers on a real load failure and was left as is. Co-authored-by: Ayaan Zaidi <[email protected]>
…lds it (#200389) ## Problem During `openclaw update --no-restart` with the Gateway running, the Gateway's installation check (`src/gateway/server-maintenance.ts`, every 30 s) sees the new `build-info.json` and restarts the Gateway into the new package while the update still owns the installation. The update's own Gateway start then waits on state ownership held by the self-restarted process, stalls for 120 s, and the update fails with `activated-gateway-startup-failed` and rolls back (exit 1). This happens on plain package installs and on the release-directory layout from #198835. The natural rate is about the race window divided by 30 s. #198835 measured that window at 1.75–1.88 s, which gives about 6% per run; I did not re-measure the window. ## Change The update run is the one owner of the installation while it holds the install lease (the same `managed-update-handoffs` row the updater's executor takes). `checkGatewayInstallationReplacement` (`src/gateway/stale-install.ts`) now skips the self-restart while a live process holds that lease. A Gateway the run leaves stale restarts on a later check, after the lease is released. - The lease key is captured with the installation root when the observer registers. - Lease reads and process-identity probes are synchronous, so they run in the existing handoff worker (`prepareManagedHandoffParentStore`), never on the serving thread. They run only when a changed build is observed. - An unreadable lease keeps today's behavior (self-restart). - No new gate in the updater, no schema or config change. ## Impact `--no-restart` updates with a running Gateway no longer race the update's Doctor and Gateway start. Behavior outside an update run is unchanged. ## Evidence **Unit:** `src/gateway/stale-install.test.ts` › "leaves a replaced installation to the update run that holds it". It holds a real lease, checks that a changed build does not restart the Gateway, releases the lease, then checks that the next tick does restart it. Red on `2435c1faa791` (handoff called once while the lease is held), green on this head; the other 14 tests in the file pass. **E2E (mbp-m5, real `openclaw update --no-restart` against a launchd Gateway, isolated `--profile`):** the reproduction makes the installation check fire every 250 ms in the *running* build. Only `server-maintenance` changes in a packed copy; the build ID differs, the code is otherwise identical. Each arm: install, start the Gateway service, then `update --no-restart --tag <next build>` with the Gateway running. | Arm | Layout | Result | Update wall time | |---|---|---|---| | main `2435c1fa` | release dirs (`install-cli.sh` prefix, adopted) | **fail**: self-restart at T+0.25 s, `activated-gateway-startup-failed`, rolled back | 351 s | | main `2435c1fa` | plain user npm prefix | **fail**: same | 455 s | | this PR `d6f23896` | release dirs | **ok**, no self-restart signal, Gateway healthy on the new build | 133 s | | this PR `d6f23896` | plain user npm prefix | **ok**, no self-restart signal, Gateway healthy on the new build | 188 s | Gates: `pnpm tsgo:core`, `pnpm check:test-types`, oxlint and oxfmt on changed files all pass. Local ClawSweeper review (gpt-6.1-sol, normal speed) at `d6f23896`: patch is correct, 0 findings. The previous head's single finding (synchronous lease reads on the Gateway thread) is fixed by the worker move. Not covered: the missing-runtime-chunk path in `classifyGatewayStaleInstall` still restarts on a request failure during an in-place swap. That path triggers on a real load failure and was left as is. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit f31a0b1) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 0fe37f15175014cc29f37b7a2140e299c1c9f766)
Problem
During
openclaw update --no-restartwith the Gateway running, the Gateway's installation check (src/gateway/server-maintenance.ts, every 30 s) sees the newbuild-info.jsonand restarts the Gateway into the new package while the update still owns the installation. The update's own Gateway start then waits on state ownership held by the self-restarted process, stalls for 120 s, and the update fails withactivated-gateway-startup-failedand rolls back (exit 1). This happens on plain package installs and on the release-directory layout from #198835. The natural rate is about the race window divided by 30 s. #198835 measured that window at 1.75–1.88 s, which gives about 6% per run; I did not re-measure the window.Change
The update run is the one owner of the installation while it holds the install lease (the same
managed-update-handoffsrow the updater's executor takes).checkGatewayInstallationReplacement(src/gateway/stale-install.ts) now skips the self-restart while a live process holds that lease. A Gateway the run leaves stale restarts on a later check, after the lease is released.prepareManagedHandoffParentStore), never on the serving thread. They run only when a changed build is observed.Impact
--no-restartupdates with a running Gateway no longer race the update's Doctor and Gateway start. Behavior outside an update run is unchanged.Evidence
Unit:
src/gateway/stale-install.test.ts› "leaves a replaced installation to the update run that holds it". It holds a real lease, checks that a changed build does not restart the Gateway, releases the lease, then checks that the next tick does restart it. Red on2435c1faa791(handoff called once while the lease is held), green on this head; the other 14 tests in the file pass.E2E (mbp-m5, real
openclaw update --no-restartagainst a launchd Gateway, isolated--profile): the reproduction makes the installation check fire every 250 ms in the running build. Onlyserver-maintenancechanges in a packed copy; the build ID differs, the code is otherwise identical. Each arm: install, start the Gateway service, thenupdate --no-restart --tag <next build>with the Gateway running.2435c1fainstall-cli.shprefix, adopted)activated-gateway-startup-failed, rolled back2435c1fad6f23896d6f23896Gates:
pnpm tsgo:core,pnpm check:test-types, oxlint and oxfmt on changed files all pass.Local ClawSweeper review (gpt-6.1-sol, normal speed) at
d6f23896: patch is correct, 0 findings. The previous head's single finding (synchronous lease reads on the Gateway thread) is fixed by the worker move.Not covered: the missing-runtime-chunk path in
classifyGatewayStaleInstallstill restarts on a request failure during an in-place swap. That path triggers on a real load failure and was left as is.