Repository navigation
fix(update): keep openclaw runnable when a pnpm or Bun update is killed while replacing the package - #200366
Conversation
…m update is killed mid-swap
|
🦞👀 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 changes before merge. What this changesThis PR uses atomic directory exchange for supported unjournaled package updates while retaining the existing two-move fallback. Example: An unjournaled update replaces OpenClaw 2026.11.3 with 2026.12.1 on Linux with system Perl.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains This PR addresses a real updater crash window and merits keeping open, but its new module import breaks the existing restart regression fixture. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe package swap owner receives a staged npm package or pnpm/Bun global project and publishes it, retaining the previous installation for verification, rollback, and cleanup. flowchart TD
A[Staged package or global project] --> B[Existing package swap owner]
B --> C[Capture local overrides]
C --> D[Atomic directory exchange]
C --> E[Two move fallback]
D --> F[Verify package and launchers]
E --> F
F --> G[Rollback or retire backup]
Technical reviewBest possible solution: Reuse the existing exchange primitive within the unjournaled swap owner and update the restart fixture to load its extracted publication owner. Do we have a high-confidence way to reproduce the issue? Current-main source moves the installed package away before override capture and candidate publication, directly exposing the reported missing-path interval; the contributor also records red/green kill sweeps, but no target code was executed during this review. Is this the best way to solve the issue? The exchange preserves the existing post-publication package and backup names, allowing current rollback and retirement owners to remain authoritative; extracting the substantial publication boundary is justified, and retaining the documented fallback avoids blocking unsupported environments. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9f441adcf1e7. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +180, Tests +364, Docs +61, Other +8. Total +613 across 16 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:
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, 9:41 PM ET / November 17, 2026, 02:41 UTC. |
…xture The fixture names each production module it runs and treats any other import as an unexpected dependency, so the new publication module failed test/scripts/update-restart-module-outcome.test.ts in CI. The fixture's context reports a fixed platform, so it keeps the two moves and never makes a host exchange call.
|
Merged via squash.
|
…ed while replacing the package (openclaw#200366) * fix(update): openclaw cannot start when a pnpm, Bun or unjournaled npm update is killed mid-swap * test(update): load the swap publication module in the restart swap fixture The fixture names each production module it runs and treats any other import as an unexpected dependency, so the new publication module failed test/scripts/update-restart-module-outcome.test.ts in CI. The fixture's context reports a fixed platform, so it keeps the two moves and never makes a host exchange call.
Backport #200366 and #200460 through the stable swap and publication owners. Use an atomic exchange where supported, preserving journal recovery, native project rollback, local overrides, and the existing two-move fallback. Revalidate the current mutation owner before exchange and fallback effects. Source commits: f52f728 and 413d9ee. Co-authored-by: RomneyDa <[email protected]>
…te is killed mid-conversion (#200273) Adoption of a plain package directory renamed it into releases/ and then renamed a link onto the package path, so the path was missing between the two renames. It now prepares the link inside the release and exchanges the two paths in one atomic step (renameat2 RENAME_EXCHANGE on Linux, renamex_np RENAME_SWAP on macOS), through Node FFI, osascript or the system perl. Where no exchange is available the two renames still run, and the package-swap step says which method ran. (cherry picked from commit 51ceecd) Release dependency: supplies the path-exchange owner required by selected #200366/#200460. Companion fixes follow in this lane. Release adaptation: none. Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit a24b6e0889ba715166e5f36d47835011932cb7a2)
…ed while replacing the package (#200366) * fix(update): openclaw cannot start when a pnpm, Bun or unjournaled npm update is killed mid-swap * test(update): load the swap publication module in the restart swap fixture The fixture names each production module it runs and treats any other import as an unexpected dependency, so the new publication module failed test/scripts/update-restart-module-outcome.test.ts in CI. The fixture's context reports a fixed platform, so it keeps the two moves and never makes a host exchange call. (cherry picked from commit f52f728) Companion disposition: #200273 prerequisite included; #200460 extends journaled publication next. Release adaptation: none. Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit e262d0822fe7c38d795a5e0491008a0070b5304e)
…e publishing the package (#200460) * fix(update): keep openclaw runnable when an npm update is killed while publishing the package * test(update): avoid a shadowed name in the surviving exchange tool test * test(update): keep the displacement refusal and manifest-read tests on their paths (cherry picked from commit 413d9ee) Companion disposition: #200273 and #200366 prerequisites included; #200532 and #200550 recovery companions follow. Release adaptation: none. Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 156510063401de1ab38e8def5d0acfe381ef813f)
Related: #200273
What Problem This Solves
If an update is killed (SIGKILL, power loss) while it replaces the installed package,
openclawcan be left with no package at all and no longer starts. This fixes that for pnpm and Bun installations, and for npm installations whose update runs without a package-publication journal.That swap moved the installed package to a backup name, preserved or replayed local
distedits, and only then moved the new package into place. The package path did not exist for that whole stretch. No journal records this swap, andopenclaw update repaircannot run without a package.Not fixed here. Most npm updates on macOS and Linux publish through the package-publication journal, which has the same missing-path window between its two moves. That path is unchanged. "The journaled path" below says why and lists the options.
User Impact
User impact: on macOS, and on Linux with a system perl (x64, arm64) or Node 26, these swaps publish with one atomic exchange. The package path names a complete package at every instant, also when the updater is killed, and nothing needs manual recovery.
This covers pnpm and Bun global projects, and npm when the journal is not used:
--reapply-local-overrides, a release replaced in place behind its package link, a target without delegated post-core execution, or an update with no executor fence.Where the exchange is unavailable (no tool, a filesystem that refuses the call, a stage on another filesystem) the update installs with the previous two moves. The
package-swapstep text says which method ran:replaced openclaw; published by an atomic exchange (perl)or...; published by two moves (atomic exchange unavailable: <reason>).Behavior changes to know about:
distedits are captured from the old package at its path immediately before publication, instead of after the old package moved to its backup. This holds on macOS and Linux for every swap without a journal, including the two-move fallback, where it shortens the missing-path window to the two moves themselves. Capture still follows service drain..openclaw.package-backup-<pid>-<time>beside the old package, which keeps serving. A later verified in-place swap removes it with the other historical backups.Windows, FreeBSD, and npm package links to a checkout are untouched. No config, schema, protocol, journal or dependency changes.
Update behavior. The installed version's updater performs the swap, not the candidate's. An installation on a published updater that updates to a build with this change gets the published updater's swap, as before. The first update that such a build runs itself uses the exchange. The change adds no marker and no state. The one new leftover is the backup-named directory above, which any updater treats like every other historical package backup.
Why This Change Was Made
POSIX
renamecannot replace a non-empty directory, so two moves always leave a window.exchangePathsfrom #200273 closes it with one call (renameat2(RENAME_EXCHANGE)on Linux,renamex_np(RENAME_SWAP)on macOS).The staged package first takes the backup name beside the package path. One exchange then leaves the new package on the package path and the old one under the backup name: the same two names the backup and activation moves produce. Nothing has to follow the exchange, so rollback, retirement, the transaction and the launcher steps are unchanged, and no step after publication can fail and strand the old package. That is why the candidate takes the backup name first, instead of exchanging stage and package path and moving the old package afterwards.
Local override capture and replay move before publication, because the old package no longer moves first. The replay helper then runs from the installed package at its own path.
package-update-swap.tssits at the 700-line lint limit, so the unjournaled publication moved into a new module,package-update-swap-publish.ts(165 lines). It holds the two-move sequence unchanged and the exchange in front of it. The swap itself grows by 7 lines.Kill states, and how existing readers treat them
Unjournaled swap with the exchange.
backupis.openclaw.package-backup-<pid>-<time>beside the package path.backupbackupas a historical backup (tested).Fallback on macOS and Linux when the exchange is unavailable: the candidate returns to the stage (the first row again), then the old package moves to
backup(package path missing, old intact underbackup, new in the stage), then the new package moves into place. That is today's window minus the override work.openclaw update repair. This path runs only when no journal was prepared. No record exists, so admission, repair and the sealed helper have nothing to interpret, and no record needs a change.backupand the new one on the package path, the staterestoreNpmPackageRootand the native restore already handle. Rollback itself still uses two moves.backupafter a later verified in-place swap, whatever it holds. A release switch does not retire historical backups, so on an OpenClaw-owned prefix the leftover stays inside the release it was left in.Two outcomes that are not a clean exchange get explicit handling. If ownership is lost after the candidate took the backup name, nothing more moves and a warning names where the candidate is. If another writer leaves the two paths in neither state, the swap claims nothing: rollback reports the installation as unverified and completion retires nothing.
native)rootLink)The package link keeps two moves because its lifecycle proves ownership on the moved entry and refuses without touching the package path. An exchange would publish before that proof.
The journaled path
A journaled npm update moves the old package to
<anchor>/previous, then moves<anchor>/candidateonto the package path. The journal records each generation under a fixed name, and every reader throwsPackage publication object changedorgeneration roles are ambiguouswhen a name holds the other generation. Publication permutes those three names cyclically, so any single exchange leaves one of them holding the wrong generation for one state. The schema would not have to change, but the recovery interpretation would, and helpers and CLIs sealed before such a change would refuse that state. I stopped there, because the journal is the most recovery-critical owner in the updater.Options, for a maintainer decision:
Evidence
What was checked. A real package swap runs in a child process once to the end, then once per boundary with the child SIGKILLed right after that boundary. A boundary is one completed filesystem mutation or the start or end of one exchange tool. After each kill the package path must serve a complete package.
distfiles. The next boundary publishes.Docker, Linux.
published-driver-release-in-place(published 2026.10.9, then the candidate's own updater replaces a release in place, which runs without a journal). Imagenode:24.22.1-trixie-slim, aarch64, perl 5.40.1.8b2ce35c5b5:PASS published 2026.10.9 → candidate 2026.11.4 (8b2ce35c5b5...). The candidate'spackage-swapstep readsreplaced openclaw; published by an atomic exchange (perl). The cell now asserts that text.replaced openclawand prints aPackage publication recovery:command: that update is journaled, and this change cannot alter it.Installed candidate tree exceeds the release budget (52228 entries). With that one assertion bypassed in a local, uncommitted edit it passed with the same step text. The bypass is not in this PR, and the run above did not need it.Commands, counts and checks
Red, then green. Command:
node scripts/run-vitest.mjs run src/infra/package-update-release-switch.process.test.ts src/infra/package-update-swap.test.ts src/infra/package-update-swap.forward-authority.test.ts --maxWorkers=151ceecd7aeb, with the first version of the sweep: 4 failed, 6 passed. The sweep names the six boundaries above.package-update-swap.tsandpackage-update-local-overrides.tsfrom base: 10 failed, 26 passed.node:ffi), macOS 27.2 arm64. With Node 24.22.1 first onPATH, those files pluspath-exchange.test.ts: 40 passed, and the fixture run directly on that Node reportspublished by an atomic exchange (osascript).b0f1596dd94, those files pluspath-exchange.test.ts,package-update-swap.windows.test.tsandpackage-update-steps.native-transaction.test.ts: 6 files, 65 passed.Affected tests: every
src/infra/package-update-*,package-release-*,package-local-overrides*andpath-exchangetest, plus every test that imports the swap or its fixtures, directly or through a shared fixture: 134 files.a08d6c94d0f, the same change beforemainwas merged in: 84 files, 1290 passed, 11 skipped, 2 failed. Both failures areupdate-command-database-rollback.test.tscases that hit the 120 s test timeout while 84 files ran in parallel. Run alone, that file passes 18 of 18, and itspackagecase takes 28.5 s here against 28.2 s with the swap frommain.a08d6c94d0f(58 passed), and 42 daemon, CLI and commands files on8b2ce35c5b5(682 passed, 8 skipped).update-command-handoff.test.tsis excluded from those lists: 3 of its 14 tests fail on this machine withFixture handoff escaped its private lease database, identically with the swap frommain.mainwas merged in three times while this ran. Those merges touch none of the changed files, the swap, its callers or its fixtures.Checks on
b0f1596dd94:oxfmt --checkandnode scripts/run-oxlint.mjson the changed files,pnpm tsgo:all,pnpm check:test-lines-ratchet(+364 net test lines, allowance 400),pnpm check:test-mock-exports,pnpm format:docs:check. On8b2ce35c5b5:OPENCLAW_CHECK_CHANGED_SKIP_DEADCODE=1 node scripts/check-changed.mjs, and before itdocs:check-linksanddocs:check-mdx. The dead-export scan exits 1 with two entries, inextensions/slackandui. Neither is touched here.On the pushed head
37922d1585c, which adds two unrelated commits frommain:git diff --checkandnode --import ./scripts/tsx.mjs scripts/check-session-identity-ratchet.mts --base origin/main --no-merge-base(Session identity ratchet OK: 1673 files, 6584 grandfathered pins). The diff adds no identity comparison and none of the counted phrases.CI on
37922d1585cfailed one job,checks-node-compact-small-2:test/scripts/update-restart-module-outcome.test.ts > retains package backups after unverified post-swap module failures, withUnexpected package dependency. Its fixturescripts/tests/update-restart-swap-fixture.mjsnames every production module it runs and rejects any other import, and it did not namepackage-update-swap-publish. The follow-up committest(update): load the swap publication module in the restart swap fixtureadds the module. The fixture's context reports a fixedlinuxplatform whatever the host is, so it setssupportsPathExchangeto false: it keeps exercising the two moves, which is what it tested before, and can never make a host exchange call under a platform that is not the host's. Red without the fixture change and green with it, same command:node scripts/run-vitest.mjs test/scripts/update-restart-module-outcome.test.ts. Also run on that commit:test/scripts/ci-changed-node-test-plan.source-owners.test.tsandtest/scripts/eager-import-closure.test.ts(2 files, 100 passed),oxfmt --check,run-oxlint.mjs, and the session identity ratchet (OK). The fixture file was read in full; nothing was removed.Test audit. Files read in full:
package-update-release-switch.process.test.ts, its child fixturepackage-update-release-switch.process.test-support.ts,package-update-release-switch.test-support.ts,package-update-swap.test.ts,package-update-swap.forward-authority.test.ts,package-update-swap.windows.test.ts,package-update-swap.assertions.test-support.ts,package-update-steps.native-transaction.test.ts,update-command-terminal-outcome.test.ts,update-command-mutable-signals-compensation.test-support.ts.publishWithoutPathExchange()turns the platform predicate off, as on Windows, and the signal fixture makes the exchange tools fail to start.mkdtempandwriteFileas boundaries too, which adds boundaries to the two existing adoption sweeps without changing what they assert.Review. The autoreview helper cannot run on this machine. Two fresh read-only agents reviewed the diff, the second after the fixes for the first. Resolved: an exchange that ends in an unknown state no longer reports a verified rollback or retires anything; ownership is checked again right before the exchange; the sweep asserts every boundary; the non-clean outcomes and pnpm have tests; the signal fixture restores
execFile; the docs name the pnpm and Bun recovery target, the in-place retirement condition and the remaining rollback window. Not changed: a failed return of the candidate to its stage still fails the update (see User Impact).Not proven.
main, only the six focused files.