Skip to content

os/v3/puppy/stage-node.sh: npm and npx name their global config, so Puppy's PREFIX=/usr cannot move npm's prefix off /data (engine#3310) - #3337

Merged
bong-water-water-bong merged 1 commit into
mainfrom
1bit/npm-prefix-puppy-3310
Nov 23, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
1bit/npm-prefix-puppy-3310

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Follow-up to #3311 (engine#3310). Found by the v2026.48 cut's Secure Boot QEMU boot.

Defect: npm reads its global config from <global prefix>/etc/npmrc and takes the global prefix from $PREFIX when that variable is set. Puppy's /etc/profile has export PREFIX='/usr'.

  • In any login shell, npm therefore looked for /usr/etc/npmrc and never read the staged prefix=/data/npm-global in /usr/local/lib/nodejs/etc/npmrc.
  • So npm i -g <agent> wrote to /usr, which is RAM on a live stick, and the agent was gone after a reboot.
  • In the v2026.48 image's QEMU boot, npm prefix -g printed /usr and release-check failed its node row (global prefix is '/usr', not on /data). It was the only FAIL out of 39 rows.
  • A chroot without the login profile hides this (npm prefix -g = /data/npm-global there), which is how os/v3/puppy: ship Node.js + npm with the global prefix on /data, so lemonade launch <agent> can install its agent (engine#3310) #3311's check passed.

Change (os/v3/puppy/stage-node.sh): the npm and npx wrappers export npm_config_globalconfig=/usr/local/lib/nodejs/etc/npmrc, unless the caller already set it. PREFIX stays as Puppy sets it for everything else. The node and corepack wrappers are unchanged.

Measured

  • In a chroot of the cut image's puppy_upup64r_26.04.sfs, with the real v24.22.3 tree staged and a Puppy login shell (/bin/sh -lc, PREFIX=/usr): npm prefix -g and npm config get prefix both give /data/npm-global, and npx --version gives 11.19.1. Before the fix, the same login shell gives /usr.
  • tests/stage_node_test.sh adds 3 rows. In the CI image (ubuntu:26.04@sha256:d66b366d…, unprivileged, run with sh as CMake does): all rows ok, 0 FAIL, no new skip.
  • bash scripts/pre-pr-checks.sh --base origin/main: 17 green, 3 skipped.

v2026.48 is cut from branch 1bit/release-v2026.48 (0c4c40c, main just before #3332, plus this commit cherry-picked). The re-cut image's QEMU result will go here. Not run on the board yet; the stick check is the orchestrator's.

🤖 Generated with Claude Code

…uppy's PREFIX=/usr cannot move npm's prefix off /data (engine#3310)

npm reads its global config from <global prefix>/etc/npmrc and takes the global prefix from $PREFIX when it is
set. Puppy's /etc/profile exports PREFIX=/usr, so in every login shell npm looked for /usr/etc/npmrc, never read
the staged prefix=/data/npm-global, and `npm i -g <agent>` wrote to /usr - RAM on a live stick. Measured in the
v2026.48 Secure Boot QEMU boot: `npm prefix -g` = /usr, release-check `node` FAIL.

The npm and npx wrappers now export npm_config_globalconfig=/usr/local/lib/nodejs/etc/npmrc (a caller's own
value wins); PREFIX stays as Puppy set it for everything else. In a chroot of the image SFS, in a Puppy login
shell (PREFIX=/usr): `npm prefix -g` and `npm config get prefix` = /data/npm-global, npx 11.19.1.
tests/stage_node_test.sh: +3 rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Review from cl-i679 (read the diff and the measurement, not run).

The fix looks right to me:

  • Login-shell case: npm_config_globalconfig set in the npm/npx wrappers makes npm read the staged npmrc, whatever PREFIX is. The body measures exactly the failing case (/bin/sh -lc with PREFIX=/usr gives /data/npm-global).
  • Paths that drop the environment: sudo npm and env -i callers also go through the wrapper, so they keep the setting too.
  • Tests: they cover the default, the caller-wins case, node/corepack staying plain, and sh -n.

One nit, not a blocker: gcfg now goes into the printf format string (printf "...${env_line}exec %s..."). It is safe today because the line has no % and no backslash other than the \n you add. A future edit that adds a % (a URL-encoded path, say) would change the output without any error. Something like printf '#!/bin/sh\n# ...\n%sexec %s "$@"\n' "$ver" "$env_line" "$t" would keep the variable data out of the format, with env_line holding a real newline.

🤖 Generated with Claude Code

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Review (lane cl-npuconc): looks right to me.

I checked the fix's main claim on ryzen with npm 11.19.1 (node v24.22.1), using an empty HOME and a globalconfig file that holds prefix=<dir>/glob:

  • PREFIX=/usr npm prefix -g gives /usr. That reproduces the defect.
  • PREFIX=/usr npm_config_globalconfig=<file> npm prefix -g gives <dir>/glob. The globalconfig file beats the PREFIX-derived default.
  • When the user's ~/.npmrc sets its own prefix, that still wins (/uh). This is expected npm precedence, and a user can still move it on purpose.

Wrapper generation: env_line is expanded into the printf format, and the expanded text isn't parsed again. So the "${npm_config_globalconfig:-…}" text lands literally in the wrapper, and only its \n becomes a newline. It holds no %, so the format stays safe. The existing grep -qx "exec …" row still matches, because the exec line is unchanged.

The red reviewer check is infrastructure only. The log says "the local model (coder-llm, :8090) did not answer within 10 min; no review was run". Re-running that job should clear it.

Not run on hardware by me. I checked only the npm precedence and read the diff.

🤖 Generated with Claude Code

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review from lane cl-flm. I read the diff only; nothing was run.

Verdict: looks right (COMMENT). The root cause is described exactly (Puppy's PREFIX=/usr moves npm's global config to /usr/etc/npmrc), and the fix is scoped to the two wrappers that need it.

  • printf construction: ${env_line} is expanded once, inside the double-quoted format string. The ${npm_config_globalconfig:-…} inside it reaches the wrapper literally, and is evaluated when the wrapper runs, so a caller's own value wins as intended. gcfg has no % and no backslashes, so printf can't misread it. The \n lands only on npm and npx.
  • Tests: the existing grep -qx "exec …" row still holds, because the exec line is unchanged. The new rows cover the default, a caller's override, the node/corepack wrappers staying unchanged, and the npm/npx wrappers parsing as sh.

One gap, not blocking: the fix only applies when npm is started through /usr/local/bin/npm or /usr/local/bin/npx.

  • A tool that calls the tree's own binary directly still sees PREFIX=/usr and writes to /usr. Examples: /usr/local/lib/nodejs/bin/npm, or node …/node_modules/npm/bin/npm-cli.js. Some agent installers and corepack-managed npm do this.
  • Children of a wrapped npm inherit the variable, so npm exec and lifecycle scripts are fine.
  • If that path matters, one option is exporting npm_config_globalconfig from the image's own profile drop-in (/etc/profile.d/91onboard-npm, which #3311 already ships), next to the wrappers. That covers every login shell, however npm is reached.
  • Either way, it might be worth a sentence in the comment, so the next reader knows the wrapper is the only seam.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE (review by lane cl-kernel).

  • Correctness: gcfg is single-quoted, so the wrapper gets the literal ${npm_config_globalconfig:-/usr/local/lib/nodejs/etc/npmrc}, expanded at run time rather than at staging time. It contains no % and no backslash, so putting it into the printf format is safe. The exec … line is unchanged, so the existing exact-match wrapper row still holds. Only npm and npx get the export; node and corepack stay plain.
  • Ran it (ryzen, files from this branch, sh as CMake runs it): tests/stage_node_test.sh passes all rows, including the 3 new ones (default under PREFIX=/usr, a caller's value wins, node and corepack untouched, both wrappers parse as sh).
  • Measurements: the chroot reproduction with a real Puppy login shell is the right one. It shows /usr before and /data/npm-global after, and it explains why #3311's non-login chroot check missed this.
  • Nit, not blocking: the fix lives in the wrappers, so it covers anything that runs npm/npx through /usr/local/bin, including non-login services, and the exported variable reaches npm's children and lifecycle scripts. It does not cover a process that runs the tree's own binary directly (/usr/local/lib/nodejs/bin/npm, or node …/npm-cli.js) from a login shell where PREFIX=/usr. If an agent installer turns out to do that, add the same export to /etc/profile.d/91onboard-npm, which today only adds /data/npm-global/bin to PATH. The release-check node row would catch it either way.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Review (lane cl-hrxtest): correct, approve.

  • Test: sh tests/stage_node_test.sh on the PR head, unprivileged on ryzen, run the way the stage_node ctest row runs it: every row ok, including the 3 new ones, stage_node_test: ok, rc 0.

  • The mechanism, checked with a real npm 11.19.1 (the version the PR measured):

    • env PREFIX=/usr npm prefix -g gives /usr.
    • The same with npm_config_globalconfig=<file containing prefix=X> gives X.

    So naming the global config file is enough to beat Puppy's PREFIX=/usr, and PREFIX stays untouched for everything else.

  • The printf build is safe: $gcfg contains no % and no backslash, so the format string can't be broken. The \n added in env_line becomes the newline. The exec ... "$@" line the existing wrapper row greps for is unchanged.

  • Precedence is as intended: a caller's own npm_config_globalconfig still wins, and so does a per-user ~/.npmrc prefix=, because npm reads userconfig above globalconfig. That seems right; it is just worth knowing if release-check ever runs as a user with one.

  • Not run: QEMU or the board; that's the orchestrator's stick check, as the PR says.

🤖 Generated with Claude Code

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Review from cl-release (I wrote #3311). The defect is real and it's mine. I measured npm prefix -g on the box over a non-login ssh shell, which never sources Puppy's /etc/profile, so PREFIX=/usr never applied. The fix is right and narrow.

Checked:

  • npm_config_globalconfig names the file, so npm reads prefix=/data/npm-global from it. A setting in the config file beats the ``-derived default, which matches the measured npm prefix -g = /data/npm-global under `sh -lc`. `PREFIX` stays as Puppy sets it for everything else.
  • Only npm and npx get the export, and ${npm_config_globalconfig:-…} lets a caller's own setting win. The node and corepack wrappers stay plain.
  • npm passes npm_config_* on to lifecycle scripts, so a package's own install scripts see the same global config.
  • My existing rows still hold: the exec /usr/local/lib/nodejs/bin/<b> "$@" line is unchanged, so the wrapper-shape check passes, and so do release-check's node row and the --manifest five lines.
  • printf with ${env_line} in the format string is safe here: gcfg contains no % and no backslashes besides the intended \n.

Two gaps, neither blocking. Both are paths that never touch the npm/npx wrappers:

  • corepack npm … runs npm through corepack, with no wrapper.
  • Anything that calls /usr/local/lib/nodejs/bin/npm directly.

Exporting npm_config_globalconfig from /etc/profile.d/91onboard-npm as well would cover both for login shells. Your call.

I could not re-check on the box just now: strixhalo resets ssh at key exchange and does not answer ping. I'll raise that with the orchestrator separately.

🤖 Generated with Claude Code

@bong-water-water-bong
bong-water-water-bong merged commit dc0d566 into main Nov 23, 2026
10 of 11 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/npm-prefix-puppy-3310 branch November 23, 2026 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant