Repository navigation
fix: print the exact package replacement command when an older updater refuses a service-account install - #208376
fuller-stack-dev wants to merge 15 commits into
Conversation
…sal fires Older installed updaters refuse a root update of a systemd unit that runs as another account. When root runs it against a root-owned npm global package and Node sits in a default sudo path directory, the refusal now prints the one-line package replacement and unit restart, filled in with the package prefix, the candidate's exact version and the quoted unit name. Every other layout keeps the docs pointer.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. |
|
Codex review: passed. What this changesThis PR prints a package replacement and service restart command for recognized root-owned npm installs when an older updater refuses a cross-account update. Example: Root updates a package in /usr/local/lib/node_modules/openclaw serving openclaw-gateway.service as the openclaw account.
Review scores
ProductKind: Feature · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it implements the update-path owner's requested recovery guidance with a focused change, and no actionable correctness or security defects were found. Reviewed head: Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherPublished updaters invoke the candidate's admission command, which inspects the installed package and matching systemd unit and returns a refusal with operator recovery instructions. flowchart TD
A[Published updater] --> B[Candidate admission]
B --> C[Package and systemd inspection]
C --> D[Cross-account refusal]
D --> E[Exact command or documentation]
E --> F[Operator replaces package and restarts unit]
Technical reviewBest possible solution: Keep recovery-command formatting in the existing candidate refusal owner while preserving documentation guidance for other layouts. Do we have a high-confidence way to reproduce the issue? Current-main source confirms the documentation-only refusal, and the supplied published-driver cell results describe the same operator-visible limitation; no target code was executed during this review. Is this the best way to solve the issue? This is a small, owner-approved improvement that reuses the existing refusal and shell quoting instead of adding restart orchestration. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d99e6c0a4e58. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +25, Tests +105, Docs +8. Total +138 across 4 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. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. 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 29, 2026, 10:35 AM ET / 15:35 UTC. |
…equests in the printed command The refusal now names the verified backup and its docs link before the command, and keeps only the docs link when the driver installs a local artifact or the operator passed --no-restart.
A Gateway that restarts into the half-written package during a slow npm install can reach systemd's start limit, after which the final restart is refused. The printed line now runs systemctl reset-failed before the restart and says to rerun the same line if the install is interrupted.
…ice's package The printed command now passes root's npm the running Node's directory in PATH, so it does not depend on sudo's secure_path, and is printed only when the unit runs that same Node and the line survives the redaction shipped updaters apply before printing. Template unit names and packages under root's home or state fall back to the docs link.
…ackage Root runs npm and its install scripts from the running Node's directory, so the line is printed only when the real paths of that Node, the npm beside it and the package are root-owned down from / without group- or world-writable directories. A run with an npm_config_* override, or a line the shipped drivers would cut at 1,021 characters, keeps the docs link.
Raw logs: final line and confirmation cellsRaw cell logs for the evidence in the PR body (Debian 12, systemd 252, Node 24.20.0). Container IDs and the service home are cell-local. i-fast-1112driver.log unitprod.log guards.log facts.log pasted.cmd pasted.exit owners.log settle.log gateway journal (systemd lifecycle and crash causes) attempt1 terminal output pasted terminal output i-fast-1110driver.log unitprod.log guards.log facts.log pasted.cmd pasted.exit owners.log settle.log gateway journal (systemd lifecycle and crash causes) attempt1 terminal output pasted terminal output d-fast-1112driver.log unitprod.log guards.log facts.log pasted.exit owners.log settle.log gateway journal (systemd lifecycle and crash causes) attempt1 terminal output g-fast-1112driver.log unitprod.log facts.log pasted.cmd pasted.exit owners.log settle.log gateway journal (systemd lifecycle and crash causes) attempt1 terminal output pasted terminal output g-slow-1112driver.log unitprod.log facts.log pasted.cmd pasted.exit owners.log settle.log gateway journal (systemd lifecycle and crash causes) attempt1 terminal output pasted terminal output g-kill-1112driver.log unitprod.log facts.log pasted.cmd pasted.exit pasted2.exit kill.log owners.log settle.log gateway journal (systemd lifecycle and crash causes) attempt1 terminal output pasted terminal output pasted2 terminal output g-rhel-1112driver.log unitprod.log rhelsudo.log facts.log pasted.cmd pasted.exit owners.log settle.log gateway journal (systemd lifecycle and crash causes) attempt1 terminal output pasted terminal output g-opt-1112driver.log unitprod.log optspace.log facts.log pasted.cmd pasted.exit owners.log settle.log gateway journal (systemd lifecycle and crash causes) attempt1 terminal output pasted terminal output |
Raw logs: base refusal and the shape cellsRaw cell logs for the evidence in the PR body (Debian 12, systemd 252, Node 24.20.0). Container IDs and the service home are cell-local. red-1112driver.log facts.log pasted.exit npmpolicy.log owners.log gateway journal (systemd lifecycle and crash causes) attempt1 terminal output red-1110driver.log facts.log pasted.exit owners.log gateway journal (systemd lifecycle and crash causes) attempt1 terminal output r-i-racedriver.log unitprod.log facts.log shape.exit owners.log gateway journal (systemd lifecycle and crash causes) attempt1 terminal output shape terminal output r-iii-racedriver.log unitprod.log facts.log shape.exit rfprobe.log owners.log settle.log gateway journal (systemd lifecycle and crash causes) attempt1 terminal output shape terminal output b-ii-fastdriver.log unitprod.log facts.log shape.exit owners.log settle.log gateway journal (systemd lifecycle and crash causes) attempt1 terminal output shape terminal output c-i-slowdriver.log unitprod.log facts.log shape.exit owners.log settle.log gateway journal (systemd lifecycle and crash causes) attempt1 terminal output shape terminal output d-ii-slowdriver.log unitprod.log facts.log shape.exit owners.log settle.log gateway journal (systemd lifecycle and crash causes) attempt1 terminal output shape terminal output |
The root-protection check now follows the path the kernel takes, link by link, so a directory reached only through a symlink is checked too.
Links are followed one component at a time and `..` applies only to the already resolved prefix, as the kernel does, so a link target cannot hide a user-owned directory behind `..`. The test baseline clears inherited npm_config_* variables that pnpm exports to scripts.
Raw logs: confirmation cells on e444707 (current code)Raw cell logs for the evidence in the PR body (Debian 12, systemd 252, Node 24.20.0). Container IDs and the service home are cell-local. j-fast-1112driver.log unitprod.log guards.log facts.log pasted.cmd pasted.exit owners.log settle.log gateway journal (systemd lifecycle and crash causes) attempt1 terminal output pasted terminal output j-fast-1110driver.log unitprod.log guards.log facts.log pasted.cmd pasted.exit owners.log settle.log gateway journal (systemd lifecycle and crash causes) attempt1 terminal output pasted terminal output |
|
Closing this without landing. The printed line works: every final cell ended with the Gateway serving the new version (fast and slow installs, an install killed and rerun, a What the cells proved about the manual procedure itself stays true and is going into the docs section the refusal already links to, as a docs-only PR (to be linked here):
The recordings and raw logs above stay as the evidence for those points. |
Related: #206343, #207873
What Problem This Solves
On Linux, a common layout is a root-owned global npm install of OpenClaw serving a systemd system unit whose
User=is a service account. When an already-published updater (2026.11.10 or 2026.11.12) runssudo openclaw update, the new version refuses before it replaces anything (#206343), because the old updater cannot safely touch another account's state. Today the refusal only links a docs page, so the operator has to read a long manual procedure and assemble the commands by hand.User Impact
In that layout the refusal now ends with one line the operator can paste, filled in with the Node directory, the package prefix, the exact target version and the real unit name:
Running exactly that line leaves the Gateway serving the target version under the service account: on fast and slow installs, with sudo's
secure_pathlacking the Node directory, with Node under a directory containing a space, and after an interrupted install when the line is run again. Nothing else about the refusal changes: it fires in the same cases, with the same code, message and admission check, and nothing is written before it. Every other layout keeps today's docs link, unchanged.This is the change the update-path owner asked for on #207873 (print the exact one-line command for this layout, filled in with the detected unit name, with a test), in place of that PR's automated restart hold. The line adds four things the cells showed are needed; see below.
Why This Change Was Made
The text is built from facts admission already has: the package root, the driver's package manager, target source and
--no-restartrequest, the candidate's own version, the binary running it and the matched unit. The line is printed only when every part of it is certain; otherwise the docs link stays.sudofrom a non-root account was not proved in a cell; that case keeps the docs link<prefix>/lib/node_modules/openclawnpm install -g --prefix <prefix>own that exact treenpm install -gnpmbeside it and the package root (walked from/one component at a time in kernel order,..applied only to the already resolved prefix, so a directory passed only through a symlink counts too) is owned by uid 0, and those directories and the final files are not group- or world-writable (lstatandreadlink, read-only; any failure keeps the docs link)npmand its install scripts with the Node directory first inPATH; a directory the service account can write would let it plant a binary for rootExecStartprogram is the binary running this candidate:PATH--no-restartnpm_config_*variable is set for the runsudo envthe line starts. Registries set in root's or the globalnpmrcdo: root's npm reads the same filesnextActionfits the shipped drivers' 1,021-character cut (UPDATE_RUN_TEXT_LIMIT - 3,src/infra/update-candidate-admission.ts:191-194on v2026.11.10 and v2026.11.12)nextActionbefore printing it (src/infra/update-candidate-admission.ts:191-203on both tags): e-mail-like text such as a template unit[email protected](src/logging/diagnostic-support-redaction.ts:42) and paths under root's home or selected state directory (:207-208) would be rewritten inside the quotesThe redaction and length check is one call to main's
redactSupportStringwith the shipped drivers' options.src/logging/diagnostic-support-redaction.tsandsrc/logging/redact-patterns.tsare byte-identical on v2026.11.10, v2026.11.12 and main;src/logging/redact.tsandredact-pattern-runtime.tsdiffer only in bounded-scan offset bookkeeping and a new bundle-file function, which the full-context path used here does not touch. Template units and packages under root's home or state therefore get the docs link.Parts of the line:
sudo env 'PATH=<node dir>:/usr/sbin:/usr/bin:/sbin:/bin' npm: root's npm, its#!/usr/bin/env nodeshebang and the package's install scripts all find the Node that runs the service, whatever sudo'ssecure_pathis. With the RHEL defaultsecure_path(no/usr/local/bin), baresudo npmgivessudo: npm: command not found; theenvform works (env_resetis on and does not touch aPATHgiven toenvas an argument). A sudoers policy that forbidsenvfrom executing (Defaults!/usr/bin/env noexec) makes it fail before anything changes:env: 'npm': Permission denied.--prefix '<prefix>': pins the install to the tree the unit runs. Without it, asudo npmwith another prefix would install a second copy and the restart would serve the old version.openclaw@<version>: the candidate's exact manifest version, never a dist-tag (the drivers in the cells asked forlatest).--allow-scripts=openclaw: required. npm 12.2.3 without it keeps.openclaw-lifecycle-pendingand still exits 0. npm 11.15.0 only warnsUnknown cli config "--allow-scripts"and installs normally.systemctl reset-failed: while npm rewrites the package, the running Gateway notices the new version ("Installation replaced"), restarts itself into the partly written tree and fails until npm finishes. On a slow install that can reach systemd's start limit, and then a plainsystemctl restartis refused (red cell below).reset-failedclears it.When
reset-failedexits 1, the line stops on purpose and leaves the unit as it was. In the cell probe it exits 0 for a unit that is active (nothing changes: same PID, same state), stopped but enabled, or failed. It exits 1 withUnit ... not loadedonly for a unit systemd has not loaded: masked, stopped and not enabled or wanted by anything (systemd unloads it), or nonexistent. A masked unit would refuse the restart anyway. A stopped unit that is not enabled is one the operator stopped and disabled; starting it would bring up a Gateway the operator turned off, so&&skips the restart. The package is already replaced, and the next start of that unit runs the new version.Every path and the unit name are single-quoted, so
\x2descapes, spaces and quotes reachenv,npmandsystemctlunchanged.Alternative considered: stop first (
systemctl stop && npm install && systemctl start). It removes the crash loop but keeps the Gateway down for the whole install: 31.3 s instead of 8.9 s on a fast install and 271.7 s instead of 111 s on a slow one, because the old Gateway keeps serving through most of the download. No crashed start in the partly written tree reached state work (below), so the shorter outage won.The verified backup stays a separate step in the docs, before the line. No new mechanism: no stored field, status, retry, child process or record.
Production net lines (added minus removed, tests and docs excluded): +90 / -2 = +88. Most of the growth is the trust walk and the guards above; each one only narrows when the line is printed.
Update behavior: the text comes from the candidate's
update admit, which the published 2026.11.10 and 2026.11.12 drivers run and print verbatim (after the redaction above), so it reaches those operators as soon as this ships in the next release they update to.src/cli/update-cli/is frozen except for minimal changes; this one touches only the refusal text, as requested on #207873.Evidence
Tested commits:
0032f71c79f5for the final-line rows,e444707124ba(the current code) for the confirmation rows. The later commits only narrow when the line is printed; the printed text is unchanged where it is printed. One cell detail matters for that: the 2026.11.12 driver in the earlier cells was installed fromdocker exec, whose umask is 0000, which left/usr/local/lib/node_modules/openclawat mode 0777. The current code prints the docs link for such a world-writable package root (seen in a cell); the confirmation cells install it with umask 022, as a root shell or sudo does, and print the line. The PR head adds only merges ofmain; the files on the refusal path (src/cli/update-cli/update-command-admit*.ts,src/daemon/,src/shared/shell-quote.ts,src/logging/diagnostic-support-redaction.ts,src/config/paths.ts, the admission contract) are identical between the two. Base for red:mainat971c9563c948.Cells: Docker, Debian 12 with systemd 252, Node 24.20.0, npm 11.19.0, root-owned npm global install in
/usr/local, unitopenclaw-gateway.servicewithUser=openclawand the restart settingsopenclaw doctorrecommends (RestartSec=5,StartLimitBurst=5per 60 s). A local registry serves the candidate under an unpublished version (2026.11.13 base; 2026.11.15 for the earlier shape rows; 2026.11.18 final). The operator ransudo openclaw update --yes; the cell cut the printed line from the refusal output and ran it as is. Slow install: the registry's responses held to 12 Mbit/s (tc netem) with root's npm cache cleared, about 4 minutes. "Not serving" runs from the first failed/healthzprobe (every 250 ms) to the first 200 from the new PID on the new version.Refusal: base vs head
971c9563c948971c9563c9480032f71c79f50032f71c79f5Confirmation on the current code (
e444707124ba, 2026.11.20, driver installed with umask 022)openclaw, 2026.11.20, /healthz 200openclaw, 2026.11.20, /healthz 200Raw logs: final-line and confirmation cells, current-code confirmation, base refusal and shape cells.
Pasting the final line (head
0032f71c79f5, 2026.11.18)openclaw, 2026.11.18, /healthz 200package.json2026.11.18,.openclaw-lifecycle-pendingpresent, npm's retired copy left, unit still retrying, /healthz 000reset-failedlet throughsecure_path="/sbin:/bin:/usr/sbin:/usr/bin"(RHEL default), Node in/usr/local/bin; update run assudo /usr/local/bin/node /usr/local/bin/openclaw update --yes/opt/node js(space, outsidesecure_path); update run assudo env "PATH=/opt/node js/bin:..." openclaw update --yes/opt/node js/bin/node, 2026.11.18, /healthz 200openclaw, 2026.11.18, /healthz 200The
/opt/node jsline as printed:sudo env 'PATH=/opt/node js/bin:/usr/sbin:/usr/bin:/sbin:/bin' npm install -g --prefix '/opt/node js' --allow-scripts=openclaw [email protected] && sudo systemctl reset-failed 'openclaw-gateway.service' && sudo systemctl restart 'openclaw-gateway.service'. Before this change that layout got the docs link, and the owner's bare form there givessudo: npm: command not found.Earlier rows that chose the line's shape (install then restart, without
env PATH=)Job for openclaw-gateway.service failed because the control process exited with error code"Start limit forced" lifts the registry throttle the moment systemd logs
Start request repeated too quickly, so npm finishes inside the 60 s window.What the Gateway does during a slow install: it keeps serving while npm downloads, then logs
Installation replaced: running 2026.11.12 ...; on-disk ..., shuts down cleanly and restarts into the partly written package. Those starts fail until npm finishes. Across 45 such starts, 43 died in module resolution (ERR_MODULE_NOT_FOUNDorMODULE_NOT_FOUND, for examplenode_modules/@openclaw/fs-safe/pathordist/index.js); the other 2 reached the package lifecycle guard indist/index.js(OpenClaw package lifecycle is incomplete. Reinstall with package scripts enabled, then retry.), whose own write into the root-owned package root was refused, and exited. None logged config, database, migration or plugin work.Interrupted install: with npm killed,
package.jsonalready showed the new version while.openclaw-lifecycle-pendingand npm's retired copy were still present; running the same line again completed the install and started the Gateway.Selected state: a 2026.11.10 run with
OPENCLAW_STATE_DIRpointing into the service home leaves 10 root-owned log and report files there (the docs keep the conditional ownership repair for this). The pasted line still left the Gateway active on the new version with /healthz 200.Files under the service home not owned by
openclaw:openclaw: none before or after in the plain runs.Recordings
Current code
e444707124ba, driver 2026.11.12, refusal and pasted line:final-e444707124ba-driver-2026.11.12-refusal.mp4
final-e444707124ba-j-fast-1112-pasted.mp4
Current code, driver 2026.11.10, refusal and pasted line:
final-e444707124ba-driver-2026.11.10-refusal.mp4
final-e444707124ba-j-fast-1110-pasted.mp4
Red, base
971c9563c948, driver 2026.11.12 (docs link only):red-base-971c9563c948-driver-2026.11.12.mp4
Red, base
971c9563c948, driver 2026.11.10:red-base-971c9563c948-driver-2026.11.10.mp4
Earlier head
0032f71c79f5(same printed line), driver 2026.11.12, the refusal with the line:final-0032f71c79f5-driver-2026.11.12-refusal.mp4
The line pasted, fast install:
final-0032f71c79f5-g-fast-1112-pasted.mp4
The line pasted, slow install (the old Gateway restarts into the partial package and reaches the start limit; the line still ends serving):
final-0032f71c79f5-g-slow-1112-pasted.mp4
npm killed mid-install, then the same line again:
final-0032f71c79f5-g-kill-1112-pasted.mp4
final-0032f71c79f5-g-kill-1112-pasted2.mp4
RHEL default
secure_path, Node in/usr/local/bin:final-0032f71c79f5-g-rhel-1112-pasted.mp4
Node under
/opt/node js, refusal and pasted line:final-0032f71c79f5-opt-space-refusal.mp4
final-0032f71c79f5-g-opt-1112-pasted.mp4
Driver 2026.11.10, refusal and pasted line:
final-0032f71c79f5-driver-2026.11.10-refusal.mp4
final-0032f71c79f5-g-fast-1110-pasted.mp4
Start limit forced, red without
reset-failed, then green with it (earlier line form withoutenv PATH=):red-start-limit-todays-line-driver-2026.11.12.mp4
green-start-limit-reset-failed-line-driver-2026.11.12.mp4
npm lifecycle option, candidate installed into a scratch prefix as root
Tests
src/cli/update-cli/update-command-admit.service-account.test.ts(whole file audited):latest.openclaw\x2dgateway.service), a Node directory with a space and a quote, and a prefix with a space, run through/bin/shwith a stand-insudothat prints each argument; the shell handsenv,npmandsystemctltheir arguments unchanged.:, a shipped driver would redact a template unit name, the package is under root's home, the package is under the selected state directory, the driver installs a local artifact, the operator deferred the restart, pnpm owns the package, the package is not in an npm global prefix, or the package root is a link; and for the trust walk: the service account owns the Node binary, owns the Node directory, the Node directory's parent is group-writable, the Node directory is a link into a user-owned directory, thenpmbeside Node links through a service-account-owned directory to a root-owned file, thenpmbeside Node links through..after a link into a user-owned directory, or nonpmsits beside Node; annpm_config_registryin the run's environment; and the full text one character over the shipped 1,021-character cut (exactly 1,021 still prints).writeInstallandwriteNodehelpers so each case can place the package and a Node withnpmbeside it in its own temp tree.fs.promises.lstatreports root ownership for that tree and its ancestors (the host's real owner is the test user), except for paths a case marks as another account's or group-writable;process.execPathandHOMEare set per case and restored after each test. Nothing was removed.Red on base production code with the head test file: the two command tests fail, the rest pass. Green on head: 33 passed (also with
npm_config_user_agentset, as under pnpm). Each guard was removed in turn and its case failed; the two link-chain cases fail against the earlier walks (realpathonly, andpath.resolveof link targets, which folds..before resolving the link in front of it).Commands
node scripts/run-vitest.mjs src/cli/update-cli/update-command-admit.service-account.test.ts src/cli/update-cli/update-command-admit.test.ts: 108 passed.node scripts/run-vitest.mjs test/scripts/update-restart-module-outcome.test.ts: passed.test/scripts/eager-import-closure.test.ts -t inventory: passed.node scripts/check-changed.mjs: all lanes ok except the dead export scan, which reports unused exports in files this PR does not touch (src/auto-reply/reply/queue/envelope.ts,src/commands/doctor-retained-runtime.ts,ui/src/components/session-menu-view.tsx,ui/src/pages/chat/chat-session-commands.ts,ui/src/pages/cron/delivery-conversations.ts).src/update/cli.ts, the shell quoting helper, the inspection error type and the admission contract as source context): no P0 to P2 findings on the final range (four rounds, none with findings)...folded before the link in front of it, and the test baseline inheriting pnpm'snpm_config_*.--no-restart; round 2 asked for the redaction, same-runtime andsecure_pathhandling above and a pasteable docs example. Round 3 asked for the trust of the Node directory, a registry selected for the run, and the shipped length limit; all addressed above. Its unloaded-unit finding is answered in thereset-failedsection. Round 4 reviews this head.Not proven
sudo(keeps the docs link; not run in a cell).