Skip to content

fix(update): openclaw cannot start when the first release-layout update is killed mid-conversion - #200273

Merged
fuller-stack-dev merged 1 commit into
openclaw:mainfrom
fuller-stack-dev:fix/update-adoption-atomic-exchange
Nov 16, 2026
Merged

fuller-stack-dev merged 1 commit into
openclaw:mainfrom
fuller-stack-dev:fix/update-adoption-atomic-exchange

Conversation

@fuller-stack-dev

Copy link
Copy Markdown
Member

Related: #198835

What Problem This Solves

Fixes: openclaw cannot 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/openclaw into releases/ 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 leftover lib/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-swap step 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 in openclaw update status and 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 rename cannot 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.ts runs one short-lived tool with absolute paths, no shell, an empty environment and a 30 second limit:

  • Node's built-in node:ffi when the running Node accepts --experimental-ffi (26.8.1 and 26.12.1 here, 26.13.1 in Docker; not 24.x). Detection reads process.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/perl with syscall on 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:ino of both paths first and decides from lstat afterwards: 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 adoptPackageReleaseSlot and its caller. The plain directory swap and Windows are untouched.

Design notes for review:

  • The waiting link is dangling until the exchange, not self-referential. Its text is relative to the package path's directory, so from inside the release it resolves to a path that does not exist.
  • Node FFI goes first where it exists. Each route is then the first choice in some mainstream environment (FFI on Node 26, osascript on macOS Node 24, perl on Linux Node 24), so the tests pin each one by name there. An API change in the experimental module fails safe to the system tool.
  • mv --exchange (coreutils 9.5+) would be another Linux route, and src/commands/doctor-sqlite-nocow.ts already 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 9ae24fde38f on base 48cd549b1c4. The red and green runs and the Docker run were made on eb0f76cc24f (base bd25e9ef60c), 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.ts runs the real release switch (swapStagedPackageInstall on 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 completed fs/promises mutation 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=1

  • Base production code (package-release-slot.ts and package-update-release-switch.ts from bd25e9ef60c) 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).
  • Head: 18 passed on Node 26.12.1 (route node:ffi, 10 boundaries) and 18 passed on Node 24.22.1 (route osascript), macOS 27.2 arm64.
  • Negative control, in the same file: with every exchange tool failing to start, adoption takes the two renames (14 boundaries) and the same sweep finds exactly that one boundary again, then proves the documented recovery from the leftover link.

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.
  • Leftover: a switch killed with the link waiting is followed by a real next update, which adopts again. listPackageReleases (what openclaw update status reads) does not list the leftover and collectPackageReleases removes it after a day.
  • With package-update-release-switch.test.ts, package-release-retention.test.ts and update-managed-service-handoff-interrupted-release.test.ts: 6 files, 40 tests passed on the rebased head. The two src/cli/update-cli/*release-link.test.ts files: 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); Docker node:24.22.1-trixie-slim arm64 and amd64 (perl), node:26-trixie-slim and node:26-alpine arm64 (node:ffi, glibc and musl). node:24.22.1-alpine reports perl: ENOENT and stays unavailable.

Docker, Linux. pnpm test:docker:published-driver-release-adoption with the candidate packed from eb0f76cc24f (image node:24.22.1-trixie-slim, aarch64, perl 5.40.1 present).

  • As committed, the cell stops before the follow-up update at an unrelated assertion: Installed candidate tree exceeds the release budget (52228 entries, 613092717 bytes). The budget is 47,500 entries. A package built the same way from base bd25e9ef60c has the same 27,102 tarball entries as this head, so this change did not cause it. Published 2026.11.4 has 15,230 files.
  • With only that one assertion bypassed in a local, uncommitted edit of the driver, the cell passed: 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 its package-swap step 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 --check on 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, and OPENCLAW_CHECK_CHANGED_SKIP_DEADCODE=1 node scripts/check-changed.mjs all 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, sweepPackageReleaseTemporaryLinks in package-release-slot.ts, from #198835).

Test audit. Files audited in full: package-update-release-switch.process.test.ts, its child fixture package-update-release-switch.process.test-support.ts, package-release-slot.test.ts, package-update-release-switch.test-support.ts. Removed: the named cut adoption-window and 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 in package-release-slot.test.ts now mocks process.platform as freebsd to 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_OPTIONS or PERL5OPT); 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.

  • The Docker cell did not pass as committed, for the unrelated tree budget above. The exchange proof there depends on the local bypass.
  • No run on a native x86_64 host (amd64 ran under emulation), on a real install-cli.sh installation, or on filesystems other than APFS and the Docker volume and overlay filesystems.
  • An updater killed while the exchange tool is still running: the tool can finish the one system call afterwards, which leaves either valid state. Reasoned, not tested.
  • The fixture makes tools "missing" by failing execFile with ENOENT. A really missing tool was observed only in the Alpine probe.
  • Bun as the running runtime, and Node 26.1 to 26.7.
  • CI has not run yet.

…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.
@clawsweeper

clawsweeper Bot commented Nov 16, 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 scripts Repository scripts size: L labels Nov 16, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 16, 2026
@clawsweeper

clawsweeper Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: lib/node_modules/openclaw can disappear between two renames, requiring a manual recovery rename.
  • After: On supported exchange routes, that path continues to resolve to the complete previous package until the candidate is selected.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful, focused repair with production-path upgrade evidence and targeted crash coverage; the disclosed Docker budget bypass limits the broader validation claim.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Supplied live output records the real CLI upgrading from v2026.11.4 and then running candidate-owned adoption through perl in Linux Docker, with the driver checking release selection, Gateway readiness, retained package metadata, and durable session content. Production-owner subprocess sweeps separately exercise interruption boundaries on macOS. The Docker continuation bypassed only its installed-tree budget assertion, so this supports the changed adoption behavior rather than a clean committed-cell pass. Proof predates the rebase; the intervening base comparison does not change the adoption modules or driver, and focused checks were reported rerun.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An interrupted first release-layout conversion can leave OpenClaw unable to start until someone manually restores its package link.
Reason: The maintainer-authored direction improves update recoverability without adding configuration or changing the final layout, and explicitly accepts the existing limitation on platforms without exchange support.

Regression provenance

Regression provenance — verified: source commit b868ed4c21ba by Jason (Json); canonical PR #198835 (blame-to-merge-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
Reviewed head: 9ae24fde38f58b3316134f7c1fc2717390fd1b15

Before merge

None.

Findings

None.

Agent review details

How this fits together

The 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
Loading

Technical review

Best 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

  • Release-directory adoption and recovery changes intended behavior with a stated reason (b868ed4: The release-layout feature retained complete previous releases and used two renames because ordinary rename cannot replace a nonempty directory with a symlink; manual recovery covered interruption between them.)
  • Crash-boundary coverage keeps the original intent (b868ed4: The earlier named adoption-window test protected the documented recovery path; the new fallback sweep retains that recovery assertion while checking every observed mutation boundary.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Jason (Json): Raw commit b868ed4 adds src/infra/package-release-slot.ts:281 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b868ed4c21ba; files: src/infra/package-release-slot.ts)

PR surface

Source +179, Tests +336, Docs +18, Other +10. Total +543 across 11 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 3 206 27 +179
Tests 6 358 22 +336
Docs 1 25 7 +18
Config 0 0 0 0
Generated 0 0 0 0
Other 1 10 0 +10
Total 11 599 56 +543

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: This repairs a conditional interruption failure in the newly introduced main-only adoption path; the submission does not establish an affected published release or an ongoing user outage.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: This repairs a conditional interruption failure in the newly introduced main-only adoption path; the submission does not establish an affected published release or an ongoing user outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 16, 2026, 5:31 PM ET / 22:31 UTC.

@fuller-stack-dev
fuller-stack-dev merged commit 51ceecd into openclaw:main Nov 16, 2026
139 checks passed
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merged via squash.

@fuller-stack-dev
fuller-stack-dev deleted the fix/update-adoption-atomic-exchange branch November 16, 2026 22:35
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
…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.
RomneyDa added a commit that referenced this pull request Nov 19, 2026
…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)
RomneyDa added a commit that referenced this pull request Nov 19, 2026
…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)
RomneyDa added a commit that referenced this pull request Nov 19, 2026
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant