Repository navigation
fix(update): keep openclaw runnable when an npm update is killed while publishing the package - #200460
Conversation
…e publishing the package
|
🦞👀 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 uses an atomic exchange for journaled npm package publication while preserving existing recovery and two-move fallback behavior. Example: An npm updater receives SIGKILL while replacing OpenClaw 2026.11.3 with 2026.12.1.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR addresses a verified npm update interruption failure that remains on main. No blocking defect found; CI is still pending. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe package publication owner receives a staged npm package and durable journal, publishes the package and launchers, and retains the previous generation for recovery or rollback. flowchart TD
A[Installed updater] --> B[Staged package and journal]
B --> C[Publication owner]
C --> D[Atomic path exchange]
C --> E[Two move fallback]
D --> F[Installed package and retained previous package]
E --> F
F --> G[Recovery rollback and retirement]
Technical reviewBest possible solution: Publish through the existing journal owner using atomic exchange where available, retaining its established fallback and recovery contracts. Do we have a high-confidence way to reproduce the issue? Current-main source exposes the two-move gap, and the supplied baseline kill sweep reports seven boundaries without a package; this read-only review ran no target code. Is this the best way to solve the issue? The change uses the existing exchange primitive and publication owner, restores the one intermediate layout before classification, and preserves fallback, rollback, and retirement behavior. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 22d5c8735a84. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +175, Tests +400, Docs +25, Other +34. Total +634 across 18 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:
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 17, 2026, 2:02 AM ET / 07:02 UTC. |
|
Merged via squash.
|
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]>
…e publishing the package (openclaw#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
…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: #200366, #200273
What Problem This Solves
When an ordinary
npm install -ginstallation updates, the updater moves the installed package aside and only then moves the new one into place. If the updater is killed in between (SIGKILL, power loss), there is noopenclawat all until the managed helper, if it survived, or a recovery command printed earlier finishes the job.That gap was not short. On
mainit spans the move itself, two directory syncs, the preservation of localdistedits, a recheck of the new package and a journal write: 7 of the 37 filesystem and journal steps of one update.User Impact
User impact: on macOS, and on Linux with a system perl (x64, arm64) or Node 26, a normal npm update now publishes with one atomic exchange. The package path names a complete package at every instant, also when the updater, its helper or the machine dies. A killed update leaves either the old version running or the new one, never neither.
Where no exchange is available (no tool, a filesystem that refuses the call) the update installs with the previous two moves, and the existing recovery covers the gap as before. One thing differs from before in that fallback: the journal records the
publishintent and tries the exchange first, then recordsdisplaceand runs the old sequence. Thepackage-swapstep text says which ran:published by an atomic exchange (perl)orpublished by two moves (atomic exchange unavailable: <reason>).Things to know:
openclaw update repair, refuse withPackage publication is incompleteuntil the printed recovery command runsrepair(which aborts the update) andretire. That is how an interrupted publication that had not touched the package already behaved.distedits are captured from the old package at its path just before publication, not after it has been moved aside. A publication that is then refused still leaves that recovery bundle behind.Update behavior. The installed version's updater publishes, not the candidate's. An installation on a published release that updates to a build with this change is published by that release's code, with the two moves. The first update the new build runs itself uses the exchange. The recovery helper for an update is sealed from the updater that starts it, so the helper always knows the layouts its own updater can leave.
Why This Change Was Made
A journaled publication now records its
publishintent, gives the candidate the namepreviousinside the journal's recovery directory, and exchanges that name with the package path in one call (exchangePathsfrom #200273). After the exchange the layout is exactly what the two moves produced: new package installed, old one underprevious. Everything that runs afterwards (launchers, verification, rollback, settlement, retirement) is unchanged, and so is everything an older release might read after the update.The alternative was to exchange the package path with the candidate's own name and move the old package to
previousafterwards. I did not take it, because its in-between state has the new package installed. Any release can be the new package, including an older one after a downgrade, and none of them knows that layout. With the order chosen here, the one new state has the old package installed, and that is the build whose updater wrote the journal.The one new state. Journal
publishing/publish, package path holds the previous package,previousholds the candidate,candidateis absent. It is accepted only with that recorded intent and the recorded identities of all three directories. The owner returns the candidate to its own name before it classifies anything, so no other reader had to learn the state.candidatepreviouspreparedpublishing/publishdisplacestate beforepublishing/publishrestorereturns the candidate, then as the row above. Admission,update repairand remount settlement refuse it as incomplete, as they refuse the row abovepublishing/publishWhen the exchange is unavailable the candidate returns to its name, that return is synced, and the old sequence runs from its first step.
Who can read a journal in the new state.
openclawat the package path: in the new state that is the old package, the build whose updater wrote the journal. A candidate is never installed in that state, so a downgrade cannot put older code in front of it.previouswith the recorded previous package before it does anything and refuses; admission and settlement decide from the phase and the installed identity and do not look inside the recovery directory. No release restores, deletes or completes anything from that layout.package-update-publication-owner.tssits at the 700-line lint limit, so the exchange lives in a new module,package-update-publication-exchange.ts, and the owner gains six lines.Evidence
What was checked. A real journaled update runs in a child process to the end, then once per boundary with the child SIGKILLed right after that boundary. A boundary is one completed filesystem mutation, one journal commit, or the start or end of the exchange tool. After each kill the package path must hold a complete package; then recovery runs on every killed installation.
Before, on
main(f52f728d341, production code untouched): 7 of 37 boundaries leave no package.displacerecordedpublishing/displacepreviouspublishing/displacedistfiles preserved (5 steps)publishing/displacepublishrecordedpublishing/publishpublishing…publication-completeAt 24–30 admission refuses the next update, and only
repairrestores an installation, by publishing the candidate.After:
abortedwith the old package and the candidate back under its own name; a run killed after it endspublication-completewith the new one. A secondrepairleaves the same layout (after an abort it refuses withForward publication is disarmed (aborted)),retireremoves the recovery directory, and publication admission accepts the next update.previousand the commit that recordspublish.repairpublishes forward from both. This is the negative control. It was seven onmain; the five steps that preserve localdistfiles now run before the first move on macOS and Linux, whichever way the package is then published.previouswithout the recordedpublishintent (no intent, ordisplace) is still refused withPackage publication object changed, journal untouched.update repairrefuse, the transaction's rollback restores the layout and aborts.publish;repairrefuses until the sync works, then completes.Docker, Linux (image
node:24.22.1-trixie-slim, aarch64, perl 5.40.1).published-drivercell with thelauncherfollow-up, candidate built fromc4b45d3f668: passed. Published 2026.11.4 installs the candidate with its own updater and its two moves. The candidate's updater then runs the follow-up update, a plain package directory published through the journal. The cell now asserts that this update printedPackage publication recovery:and that itspackage-swapstep names the exchange. The step readreplaced openclaw; published by an atomic exchange (perl).package-installed-recovery, cutanchor-before, candidate built from835b005e905. This lane kills the installed updater between the two moves, so its fault preload now also keeps the exchange tools from starting for that cut; the run reportedexchange-tool-withheldand then the kill in the displaced state. The lane does not pass, on this branch or onmain, for two reasons this change does not touch:mode & 0o7700). fix(update): keep restored npm packages readable by non-root services #193272 changed recovery to clear only write bits (0o7755). The first tree comparison fails withmode 755 -> 755 (expected 700).anchor-beforerow passes: displacement kill, status,repairtwice, killed and resumed retirement, completed status, archive. The lane's finalopenclaw updateis then refused withUpdate <id> has unfinished recovery; reconcile it before starting another update.A package built from this branch with the three production files taken from
maingives the same row, field for field, and the same refusal. Both failures need their own fix.Commands, counts, review and test audit
Base for the reproduction:
origin/mainatf52f728d341. Branch created fromorigin/mainatdf78722789e;origin/mainmerged in three times since, last at8f0d03fe9c4. None of that movement touches the publication owner, the swap or the exchange. The last merge brought two commits (Codex app-server tests, model registry sources) after the Docker cell and the test runs; nothing was rerun for them.Reproduction and red/green
src/infra/package-update-release-switch.process.test.ts, layoutjournal. The child is a real updater process that runsswapStagedPackageInstallwith a prepared journal and is SIGKILLed after one boundary.main(package-update-publication-owner.ts,package-update-swap.ts,package-update-swap-publish.ts): the four journal test files fail 9 of 101, andupdate-managed-service-handoff-interrupted.test.tsfails 1 of 17 (the newexchangingcut).Tests (macOS arm64)
node scripts/run-vitest.mjs run <86 files>on the local default runtime (pinned Bun 1.4.4, exchange routeosascript): 6 shards passed. unit-fast 3 files / 15 tests, unit-fast-isolated 2 / 18, tooling 7 / 334, infra 55 / 762 passed and 1 skipped, cli-process 5 / 102, cli 14 / 206. Run on the first merge ofmain; the four journal files edited afterwards were rerun: 4 files / 101 passed. After the last merge ofmain, the two listed tests it changed and the script tests (update-restart-module-outcome,eager-import-closure,pr-wrapper-source-closure,vitest-worker-artifacts) were rerun: 6 files / 137 passed.OPENCLAW_VITEST_RUNTIME=node(Node 26.12.1, exchange routenode:ffi), the seven journal and exchange files: 7 files / 129 passed.src/infra/package-update-*andpackage-activation*test, thesrc/cli/update-cli*tests that publish or recover a package,path-exchange.test.ts, bothupdate-managed-service-handoff-interrupted*tests, andtest/scripts/update-restart-module-outcome.test.ts,eager-import-closure.test.ts,pr-wrapper-source-closure.test.ts,vitest-worker-artifacts.test.ts,check-deadcode-exports.test.tsand the two CI test-plan tests.src/cli/update-cli/update-command-handoff.test.tsfails 3 of 14 on this machine with and without this change (its fixture guard under Bun).Checks
pnpm tsgo:all: passed.oxfmt --checkandnode scripts/run-oxlint.mjson the 17 changed code files: clean.OPENCLAW_CHECK_CHANGED_SKIP_DEADCODE=1 node scripts/check-changed.mjs: exit 0.pnpm check:test-lines-ratchet: net +400 of 400.pnpm check:test-mock-exports: OK.node --import ./scripts/tsx.mjs scripts/check-session-identity-ratchet.mts --base origin/main --no-merge-base: OK, 1672 files, 6576 grandfathered pins.pnpm format:docs:check,pnpm docs:check-links,pnpm docs:check-mdx: clean (1434 files formatted, 16716 internal links with 0 broken, MDX check passed).git diff --check: clean.Review
The autoreview helper does not run on this machine, so a fresh read-only agent that had not seen my reasoning reviewed the diff against the contract, and a second one audited every touched test file in full. Findings and what changed:
package-installed-recoveryDocker lanes need the two-move window: their fault preload now withholds the exchange tools for the displaced cut.Test files read in full
package-update-release-switch.process.test.tsand its child fixture,package-update-publication-boundary.test.ts,package-update-publication-durability.test.ts,package-update-activation-durability.test.ts,package-update-activation-recovery-command.test.ts,package-update-swap.assertions.test-support.ts,update-managed-service-handoff-interrupted.test.tsand its two fixtures. No test was removed, skipped or loosened. Existing tests that inject a fault into one of the two moves now state which publication they exercise (publishWithoutPathExchange()orrefusePathExchange()), so they still run the path they were written for.Not proven.
osascriptunder Bun,node:ffiunder Node 26). On Linux the perl route ran only to completion, in the Docker cell. No Docker lane kills the updater around the exchange.repair; the transaction rollback test starts from the waiting-candidate state.package-installed-recoverylane does not pass onmain(see above), so it is not a passing lane here either. Only itsanchor-beforecut ran.