Repository navigation
fix: npm 12 global updates no longer stop at the candidate guard - #108100
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3200ff4d9c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (installCwd && path.isAbsolute(identity)) { | ||
| // npm resolves relative allow-scripts identities against its cwd. Relativize | ||
| // first so commas in ancestor directories do not split the policy value. | ||
| const relativeIdentity = path.relative(installCwd, identity) || "."; |
There was a problem hiding this comment.
Preserve npm's file identity for packed tarballs
For packed Git/source updates, preparedSpec.installCwd is the pack directory, so this relativizes an absolute tarball path into ./openclaw-…tgz. npm 12's allowScripts matcher for file/directory keys compares the parsed key exactly against node.resolved (current @npmcli/arborist/lib/script-allowed.js matchFileOrDir), and Arborist records global tarball adds as file:/tmp/.../openclaw-…tgz; the relative key therefore does not match, npm silently skips OpenClaw's preinstall, and openclaw update main/GitHub-source updates still fail on the candidate guard. Keep the allow key in npm's resolved file:/... form, or verify the packed key against npm's matcher before using it.
Useful? React with 👍 / 👎.
ead0e29 to
0720f5a
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0720f5a825
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| path.isAbsolute(normalized) || | ||
| path.isAbsolute(unaliased) | ||
| ? unaliased | ||
| : PRIMARY_PACKAGE_NAME; |
There was a problem hiding this comment.
Use the candidate package name for npm script approval
When the installed global package has a supported scoped/custom name such as @kevins8/openclaw, resolveGlobalInstallSpec builds @kevins8/openclaw@<tag>, but this new branch still approves only openclaw. npm's allow-scripts policy for registry deps matches the real package name (the npm matcher rejects entries where the trusted package name differs from the parsed allow key), so on npm 12 the scoped candidate's preinstall remains skipped, the completion guard stays in the staged package, and the update fails even though this path already carries the installed package name through callers like runGatewayUpdate.
Useful? React with 👍 / 👎.
0720f5a to
b1210bb
Compare
There was a problem hiding this comment.
💡 Codex Review
openclaw/src/infra/package-update-steps.ts
Lines 304 to 308 in b1210bb
For main/GitHub update targets this npm pack <git spec> step runs before the new tarball install, but npm v12 defaults allow-git to none and the config docs note git fetches are blocked for other commands too. That means openclaw update main can fail during packing and never reach the added --allow-scripts install path; pass a narrow --allow-git=root/all for the explicit source spec here.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| resolveNpmInstallScriptsAllowFlag(spec, installCwd), | ||
| ...(installPrefix ? ["--prefix", installPrefix] : []), | ||
| spec, |
There was a problem hiding this comment.
Allow npm 12 remote update specs
With an OPENCLAW_UPDATE_PACKAGE_SPEC=https://... override, this npm 12 command only opts into lifecycle scripts. The npm v12 changelog/config docs say allow-remote now defaults to none for user-supplied tarball URL dependencies, so npm i -g https://... fails before OpenClaw's preinstall can run; add the matching --allow-remote=root/all opt-in for explicit remote root specs.
Useful? React with 👍 / 👎.
|
Merged via squash.
|
…nclaw#108100) * fix(update): approve candidate lifecycle on npm 12 * test(update): align npm lifecycle argv expectations
…nclaw#108100) * fix(update): approve candidate lifecycle on npm 12 * test(update): align npm lifecycle argv expectations
…nclaw#108100) * fix(update): approve candidate lifecycle on npm 12 * test(update): align npm lifecycle argv expectations
Closes #107290
Related: #107239
Follow-up to #106994
What Problem This Solves
Fixes an issue where npm 12 users running a global OpenClaw update would safely stop before activation because npm 12 blocks dependency lifecycle scripts by default, leaving the candidate completion guard in place.
Why This Change Was Made
The updater now grants lifecycle permission only to the resolved OpenClaw candidate identity. Registry packages, npm aliases, local tarballs, local directories, and packed Git sources retain the identity and working directory npm uses for policy matching. Transitive dependency lifecycle scripts remain blocked on npm 12.
This is AI-assisted maintainer work. The implementation and npm contract were reviewed against npm's current official install documentation and npm 12 release guidance.
User Impact
npm 12 global updates can complete the candidate Node-engine check and clean staged swap instead of failing at the completion guard. npm 11.9 remains compatible. Incompatible candidates still fail before the live install changes.
Evidence
src/infra/update-global.test.tsandsrc/infra/package-update-steps.test.ts.run_91388c39c39d, leasecbx_6cdc1e217077, passed 4/4 scenarios: npm 12 update, npm 11.9 compatibility, UUID-redacted npm root, and incompatible-Node candidate preservation.origin/main: no accepted or actionable findings.git diff --checkpassed.CHANGELOG.mdis unchanged because release generation owns release notes.