#20585: fix: pre-flight ownership check before global update
size: S
Cluster:
Update Handling Fixes
Fixes #20583 (part 2)
## Problem
When `openclaw update` runs a global npm install, it moves the package dir to staging then reinstalls. If files are owned by root (e.g. skill installed with sudo), npm gets EACCES and fails silently, leaving a partial directory.
## Fix
- `checkDirectoryOwnership(dirPath)` in update-global.ts — recursively checks file ownership
- Pre-flight check in update-runner.ts before global install — aborts with clear error if foreign-owned files found
## Tests
3 new tests in update-global.test.ts. All pass.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Added pre-flight ownership check to prevent global npm install failures when package directories contain root-owned files. The fix introduces `checkDirectoryOwnership()` which recursively scans for foreign-owned files and aborts the update with a clear remediation message (`sudo chown -R $(whoami) <path>`) before attempting the risky move-to-staging operation.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The implementation is defensive (gracefully handles Windows/platforms without getuid), well-tested (3 comprehensive test cases including Windows simulation and ownership mocking), and follows existing patterns in the codebase. The early-abort approach prevents data loss, and the error message provides clear remediation steps.
- No files require special attention
<sub>Last reviewed commit: b8c511d</sub>
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#17237: fix(update): guard post-install imports after npm global update
by tdjackey · 2026-02-15
82.9%
#17815: fix: use $HOME as cwd for global update to prevent path-dedot panic
by frankekn · 2026-02-16
80.7%
#19801: fix: pre-check write permissions before global install to prevent E...
by menhguin · 2026-02-18
80.2%
#18961: fix: detect pnpm package manager in openclaw update
by norci · 2026-02-17
79.0%
#17912: fix: configure git to use HTTPS instead of SSH for GitHub URLs
by MisterGuy420 · 2026-02-16
78.1%
#22406: Fix update detection for Companion App npm-prefix installs
by graysurf · 2026-02-21
77.6%
#12804: fix(daemon): use wrapper script for pnpm global installs in service...
by odinho · 2026-02-09
77.1%
#8600: fix(update): add --ignore-scripts to prevent supply chain attacks
by yubrew · 2026-02-04
77.1%
#8644: Fix Control UI asset resolution for global installs
by codvik · 2026-02-04
76.3%
#3973: fix: enhance npm package integrity checks and include critical files
by YeSuX · 2026-01-29
75.9%