Repository navigation
fix(update): openclaw cannot start when the first release-layout update is killed mid-conversion - #200273
Conversation
…te is killed mid-conversion 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.
|
🦞👀 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 changesThis PR atomically exchanges the installed package directory with a prepared release link where supported, preserving the existing fallback. Example: The updater is killed during the first release-directory conversion of an OpenClaw-owned npm prefix.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenanceRegression provenance — verified: source commit Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR addresses a source-confirmed interruption window on current main, with no actionable introduced defect found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe package updater passes a verified staged release to the release-switch owner, which adopts the installed directory, selects the candidate, and retains the previous release for rollback. flowchart TD
A[Installed updater] --> B[Verified staged release]
B --> C[Release switch owner]
C --> D[Adopt package directory]
D --> E[Atomic path exchange]
D --> F[Existing rename fallback]
E --> G[Select candidate release]
F --> G
Technical reviewBest possible solution: Keep atomic adoption in the existing release-slot owner while preserving the documented fallback and unchanged release format. Do we have a high-confidence way to reproduce the issue? The base source exposes the missing-path interval directly, and the supplied red run identifies that exact rename boundary; no target code was executed during this read-only review. Is this the best way to solve the issue? Atomic exchange fixes the missing-path invariant at its existing owner, and the separate platform adapter is justified by Node lacking a standard exchange operation; the added tests cover distinct crash, fallback, cleanup, and leftover-recovery failures. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 48cd549b1c48. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +179, Tests +336, Docs +18, Other +10. Total +543 across 11 files. Added test files: 2. 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:
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, 5:31 PM ET / 22:31 UTC. |
|
Merged via squash.
|
…te is killed mid-conversion (openclaw#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.
…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: #198835
What Problem This Solves
Fixes:
openclawcannot start when the updater dies (SIGKILL, power loss) partway through the first update that converts an OpenClaw-owned npm prefix to release directories.That conversion renamed the package directory
lib/node_modules/openclawintoreleases/and then renamed a link onto the package path. Between the two renames the package path did not exist. Recovery was a manual rename of a leftoverlib/node_modules/.openclaw.release-link-*.User Impact
User impact: on macOS, and on Linux with a system perl (x64, arm64) or Node 26, the package path names a complete package at every instant of that conversion, also when the updater is killed. Nothing needs manual recovery.
Where no atomic exchange is available (Alpine without perl on Node 24, other architectures without Node FFI, a filesystem that refuses the call) the update still converts the directory with the previous two renames. The brief missing-path instant and its documented recovery remain there. An update never fails because the exchange is unavailable. The
package-swapstep text says which method ran, for example...; the package directory became that release by an atomic exchange (perl).No config, schema, protocol or dependency changes.
Update behavior. The installed version's updater performs the conversion, not the candidate's. Published updaters do not know release directories, so an installation that updates from a published version to a build with this change gets a plain package swap, as before, and its package path stays a plain directory. The first update that such a build runs itself converts the directory with the exchange. A build between #198835 and this change converts with the two renames, and nothing in a later candidate can change that. The exchange adds no marker and no state. If the updater is killed before the exchange, an unused directory in
releases/holding one link that names nothing is left behind. Existing code already skips it inopenclaw update statusand removes it once it is a day old, so an older build that later reads the prefix handles it too.Why This Change Was Made
POSIX
renamecannot replace a non-empty directory with a link, so two renames always leave that window. One atomic exchange of two paths closes it:renameat2(RENAME_EXCHANGE)on Linux,renamex_np(RENAME_SWAP)on macOS. Adoption now creates the link inside the release, where the directory will live, and exchanges the two paths in one step.Node has no API for either call, so
src/infra/path-exchange.tsruns one short-lived tool with absolute paths, no shell, an empty environment and a 30 second limit:node:ffiwhen the running Node accepts--experimental-ffi(26.8.1 and 26.12.1 here, 26.13.1 in Docker; not 24.x). Detection readsprocess.allowedNodeEnvironmentFlags, so the parent never loads the module and its experimental warning reaches no output./usr/bin/osascript(JavaScript for Automation) on macOS./usr/bin/perlwithsyscallon Linux, where perl's own build picks the number (316 on x86_64, 276 on aarch64) and any other architecture is refused.The exchange never trusts an exit code. It records
dev:inoof both paths first and decides fromlstatafterwards: exchanged, unchanged (try the next route, then report unavailable), or anything else (throw, another writer). Cleanup after a failed adoption is no longer recursive. It removes the waiting link and the empty directories, so it cannot delete a package that already moved.Production growth is the new 136-line module (three embedded tool scripts and the identity check) and 43 net lines in
adoptPackageReleaseSlotand its caller. The plain directory swap and Windows are untouched.Design notes for review:
mv --exchange(coreutils 9.5+) would be another Linux route, andsrc/commands/doctor-sqlite-nocow.tsalready probes with it. I left it out to keep this change small. It is a reasonable follow-up, together with the same window in the plain directory swap.Evidence
Head
9ae24fde38fon base48cd549b1c4. The red and green runs and the Docker run were made oneb0f76cc24f(basebd25e9ef60c), the same change before a rebase. The ten commits in between touch none of the changed files, the release slot, its callers or its fixtures, so only the focused tests and the changed-scope checks were rerun on the rebased head.Regression, red then green.
src/infra/package-update-release-switch.process.test.tsruns the real release switch (swapStagedPackageInstallon a plain package directory) in a child process once to the end, then once per boundary with the child SIGKILLed right after that boundary. A boundary is one completedfs/promisesmutation or the start or end of one exchange tool process, counted by interposing at the Node API in the child. After each kill the package path must serve a complete package.Command:
node scripts/run-vitest.mjs run src/infra/package-update-release-switch.process.test.ts src/infra/package-release-slot.test.ts src/infra/path-exchange.test.ts --maxWorkers=1package-release-slot.tsandpackage-update-release-switch.tsfrombd25e9ef60c) with these tests: 3 failed, 15 passed. The sweep fails with exactly one boundary that leaves no package,rename lib/node_modules/openclaw -> releases/2026.11.3/lib/node_modules/openclaw. The other two failures are tests of behavior that exists only on head (the reported method and the waiting link).node:ffi, 10 boundaries) and 18 passed on Node 24.22.1 (routeosascript), macOS 27.2 arm64.Other tests.
path-exchange.test.ts: a directory and a link in different directories, under a path with spaces and non-ASCII names, exchange with both inodes preserved and the route named. A kernel refusal (a directory with its own descendant) and a missing path report unavailable with nothing changed. A path replaced while the tool ran throws.package-release-slot.test.ts: adoption refused before the exchange removes the waiting link and its release directory and leaves the package directory untouched.listPackageReleases(whatopenclaw update statusreads) does not list the leftover andcollectPackageReleasesremoves it after a day.package-update-release-switch.test.ts,package-release-retention.test.tsandupdate-managed-service-handoff-interrupted-release.test.ts: 6 files, 40 tests passed on the rebased head. The twosrc/cli/update-cli/*release-link.test.tsfiles: 4 passed (before the rebase).Routes run by hand with one probe that exchanges a directory and a link under a non-ASCII path: macOS arm64 Node 26.12.1 and 26.8.1 (
node:ffi), Node 24.22.1 (osascript); Dockernode:24.22.1-trixie-slimarm64 and amd64 (perl),node:26-trixie-slimandnode:26-alpinearm64 (node:ffi, glibc and musl).node:24.22.1-alpinereportsperl: ENOENTand stays unavailable.Docker, Linux.
pnpm test:docker:published-driver-release-adoptionwith the candidate packed fromeb0f76cc24f(imagenode:24.22.1-trixie-slim, aarch64, perl 5.40.1 present).Installed candidate tree exceeds the release budget (52228 entries, 613092717 bytes). The budget is 47,500 entries. A package built the same way from basebd25e9ef60chas the same 27,102 tarball entries as this head, so this change did not cause it. Published 2026.11.4 has 15,230 files.PASS published 2026.11.4 → candidate 2026.11.4 (eb0f76cc24ff...). The candidate's own follow-up update adopted the published updater's plain directory, and itspackage-swapstep reads...; the package directory became that release by an atomic exchange (perl). This PR adds an assertion on that text to the cell, and it passed.Checks.
git diff --check,oxfmt --checkon the changed files,pnpm tsgo:all,node scripts/run-oxlint.mjs <changed files>,pnpm check:test-lines-ratchet(+336 net test lines, allowance 400),pnpm check:test-mock-exports, andOPENCLAW_CHECK_CHANGED_SKIP_DEADCODE=1 node scripts/check-changed.mjsall pass. The dead-export scan (scripts/check-deadcode-exports.mts) exits 1 with 122 entries. None is an export this PR adds. Three are in a touched file but predate it (isOpenClawOwnedPackagePrefix,resolvePackageReleaseTarget,sweepPackageReleaseTemporaryLinksinpackage-release-slot.ts, from #198835).Test audit. Files audited in full:
package-update-release-switch.process.test.ts, its child fixturepackage-update-release-switch.process.test-support.ts,package-release-slot.test.ts,package-update-release-switch.test-support.ts. Removed: the named cutadoption-windowand its test "between the adoption renames". The fallback sweep covers the same boundary more strictly (it also proves no other boundary is broken) and keeps the same recovery assertions. No other case was pruned. The three link-switch cuts and the seven older slot cases still prove distinct behavior. The compensation case inpackage-release-slot.test.tsnow mocksprocess.platformasfreebsdto reach the two-rename path through the real "no route on this platform" branch. Test time for the process file rose from about 1.5 s to about 5.3 s (26 more child processes, run in parallel).Review. The autoreview helper cannot run on this machine. A fresh read-only agent reviewed the diff instead. Resolved from its findings: the sweep is gated on the environment and can no longer skip on a regression; route names are asserted; cleanup is non-recursive; tools get an empty environment (no
NODE_OPTIONSorPERL5OPT); Bun is excluded from the FFI route; killed runs are matched to boundary labels; the refused-adoption and other-writer cases have tests; the method is a typed result that the caller formats. Not changed: route order (see above) and errno detail in the FFI and osascript failure text.Not proven.
install-cli.shinstallation, or on filesystems other than APFS and the Docker volume and overlay filesystems.execFilewithENOENT. A really missing tool was observed only in the Alpine probe.