Skip to content

fix(update): recognize custom npm prefix installations - #146091

Merged
steipete merged 4 commits into
mainfrom
steipete/upd-package-owner-custom-prefix
Sep 12, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/upd-package-owner-custom-prefix

Conversation

@steipete

@steipete steipete commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #146038

Additional instructions

This branch is in the upstream repository and is available for maintainer edits.

What Problem This Solves

Fixes an issue where users updating an npm installation under a custom prefix such as ~/.npm-global receive an unknown-package-manager outcome when npm's global-root probe differs from the running installation. The prefix contains an OpenClaw launcher but normally no npm executable, so the existing fallback discarded valid installation evidence.

Reported by a Discord user (Rex Horizon), support thread "As usual update fails" (#146038). The Linux installer and Node installation docs recommend this prefix layout.

Why This Change Was Made

The shared installed-owner resolver now checks npm's configured global prefix using the Node running OpenClaw, leaving npm itself responsible for npmrc precedence and expansion. It also recognizes a global OpenClaw launcher resolving into the corresponding npm package tree when command probes do not match. Windows custom prefixes use the same layout owner. Existing pnpm and Bun detection stays intact, and the selected npm update target remains the running package prefix.

Update status now uses this resolver instead of its separate lockless-package heuristic. Unknown-owner guidance includes the inspected package root, probe results, inferred prefix, and launcher path. Repair and rollback already retain the selected package transaction; Doctor delegates package updates to the same update command.

User Impact

Updates on custom npm prefix installs (nvm + ~/.npm-global) no longer refuse with "package manager owner is unknown" solely because the prefix has no npm executable and the global-root probe differs. Status and update admission agree about installation ownership. Unknown layouts remain unchanged and provide actionable inspection details.

Evidence

  • Installed dependencies with pnpm install --frozen-lockfile --prefer-offline.
  • Focused proof: node scripts/run-vitest.mjs src/infra/update-runner.test.ts src/infra/update-global-lifecycle.test.ts src/infra/update-global.test.ts src/infra/update-global.bun-owner.test.ts src/infra/update-global.pnpm11-discovery.test.ts src/infra/update-check-status.test.ts src/infra/update-check.test.ts src/infra/update-check-install-kind.test.ts src/infra/detect-package-manager.test.ts src/cli/update-cli/shared.command-runner.test.ts — 335 tests passed across ten files.
  • Pre-fix tests: Linux/macOS/Windows custom-prefix cases each returned null instead of npm; the pinned prefix-probe case also returned null; unmanaged status reported npm instead of unknown; admission lacked inspection diagnostics. All pass with the fix.
  • Real isolated macOS npm proof: nvm-shaped Node 26.8.2 path, ~/.npm-global launcher/package, ~/.npmrc prefix line, no prefix environment variables. npm 11.19.1, shared update admission, and target selection all resolved the custom npm prefix.
  • node scripts/check-changed.mjs — passed on the final consolidated tree, including core/test typechecks, full core lint, dead-export scans, and zero runtime import cycles. git diff --check passed.
  • node scripts/run-vitest.mjs test/scripts/tsgo-core-test-shards.test.ts -t 'covers the repository test roots exactly once with headroom below the hard cap' — passed; the 700-root budget is unchanged.
  • Initial CI run https://github.com/openclaw/openclaw/actions/runs/34701614339 exposed an extra npm prefix probe on standalone packages. The repair checks global layout eligibility before probing; the existing runner test passes with its strict command-list assertion unchanged. The next run, https://github.com/openclaw/openclaw/actions/runs/34702550786, caught the added test file exceeding the infra shard's 700-root budget. The cases now live in the existing npm lifecycle suite, preserving all assertions and the unchanged budget. Pre-fixup CI: https://github.com/openclaw/openclaw/actions/runs/34703250632 completed successfully at 5ac8222475adf21334383ebac679cfb20da54177. The exact-head watcher reports GREEN with zero pending checks after reconciling 12 superseded contexts.

Known gaps: the exact reason the reporter's npm probe differed is unconfirmed; stock npm correctly reads an isolated ~/.npmrc. The regression models the observed mismatching probe and proves the missing launcher inference. No full Linux Testbox update/dry-run or published-driver-to-candidate update was run; platform layout tests and the isolated npm/admission proof cover this bounded repair. The installed 2026.9.3 updater cannot acquire this fix before admission; the reporter's explicit prefix environment workaround is still needed to get past that older driver.

Latest fixup CI: run 34705209671 at c2731dda081009379f6661654552872db16db6b4 is blocked by checks-node-compact-small-29: test/scripts/tsgo-core-test-shards.test.ts:51 reports gateway-other: 701 test roots exceeds the 700 limit. This is inherited from main: the CI merge 6f7bfd32b498b4e4db228633376113c479ba2ac2 and its main parent 31c8b990cb5c95741796a3c79727cd0dc3e3be4a have identical gateway tests, shard configs, and shard checker, with 701 matching gateway-other test paths in both. This PR adds no test files. That attempt stopped before the native wrapper; no budget or assertion was weakened. The main shard repair is now present in refreshed merge ref 1580397fd2ef54a4c2a73d30446031a50bb62df4 (git merge-base --is-ancestor 5587a15c3d1 refs/pull/146091/merge passed). Fresh pull-request CI https://github.com/openclaw/openclaw/actions/runs/34707801181 passed on the unchanged approved head c2731dda081009379f6661654552872db16db6b4; the exact-head watcher reported GREEN with zero pending checks.

ClawSweeper review

Maintainer decision: land this bounded ownership repair with the documented full published-driver upgrade qualification gap. Detection and target-selection evidence do not claim a complete upgrade transition. The lead re-reviewed and approved c2731dda081009379f6661654552872db16db6b4 after the Windows fixup.

Applied the Windows npm shim finding: ownership detection now selects the package entrypoint immediately before %*, skipping npm's preceding node.exe existence check. The existing fixture now contains the complete npm-generated shim. With only that fixture changed, node scripts/run-vitest.mjs src/infra/update-global-lifecycle.test.ts -t 'recognizes a custom npm prefix' failed on Windows with expected null to be 'npm' (1 failed, 2 passed); with the parser fix, 143 tests passed across the lifecycle, global, Bun, pnpm discovery, status, and CLI command-runner suites. The bounded fixup passed Codex autoreview through P2 and node scripts/check-changed.mjs -- src/infra/update-global.ts src/infra/update-global-lifecycle.test.ts (including core/test typechecks, lint, dead exports, and repository guards).

The data-model request is inapplicable: update-check.ts derives installation status and this diff adds no persistent schema, retention, or recovery changes. Full published-driver-to-candidate preservation proof remains an explicit limitation of this bounded landing, as recorded above; it is not claimed by the layout tests. Older installed updaters still need NPM_CONFIG_PREFIX for the first hop.

Resolve npm ownership from its configured prefix and installed launcher when global-root probes diverge. Share installed-owner detection with update status and include inspected paths in unknown-owner guidance.

Refs #146038
@clawsweeper

clawsweeper Bot commented Sep 12, 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 cli CLI command changes size: M maintainer Maintainer-authored PR labels Sep 12, 2026
@steipete
steipete marked this pull request as ready for review September 12, 2026 15:14
@clawsweeper clawsweeper Bot added P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 12, 2026
@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 12, 2026, 1:26 PM ET / 17:26 UTC (Revision 7).

ClawSweeper review

What this changes

Recognizes custom npm installation prefixes through npm configuration and installed launchers, shares detection with update status, and improves unknown-installation guidance.

Merge readiness

⛔ Blocked before merge - 3 items remain

The repair remains necessary and has no identified blocking code defects. The Windows finding is addressed, and the recorded maintainer acceptance satisfies the previous request to explicitly accept the bounded upgrade-proof exception.

Priority: P0
Reviewed head: c2731dda081009379f6661654552872db16db6b4

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful regression coverage, the earlier Windows defect resolved, and an explicitly accepted upgrade-qualification limitation.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied MEMBER classification exempts ordinary contributor proof. The body reports real macOS npm detection and target-selection success, separately records regression tests, and explicitly accepts the unperformed complete upgrade transition.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied MEMBER classification exempts ordinary contributor proof. The body reports real macOS npm detection and target-selection success, separately records regression tests, and explicitly accepts the unperformed complete upgrade transition.
Evidence reviewed 9 items Current main still lacks the fallback: The fetched main resolver ends with prefix-local npm detection and otherwise returns null; it does not inspect npm's configured prefix or the OpenClaw launcher.
Latest release retains the same detection gap: The v2026.9.4 source likewise returns null after the existing probes and prefix-local npm fallback; this requested repair is not present in that release.
Introduced repair and target preservation: The introduced delta adds configured-prefix and launcher evidence after existing manager checks. Target selection retains the running npm package root, and the CLI passes that selected target into package replacement.
Findings None None.
Security None None.

How this fits together

OpenClaw’s updater identifies the package manager responsible for the running installation before selecting its replacement target. This resolver feeds both update admission and installation status.

flowchart TD
  A[Running installation] --> B[Package manager probes]
  B --> C[Installed layout and launcher checks]
  C --> D{Owner identified}
  D -->|Yes| E[Update target at original prefix]
  D -->|No| F[Skipped update with diagnostics]
  D --> G[Installation status]
Loading

Before merge

  • Resolve merge risk (P1) - Newly recognized custom-prefix installations can proceed to replacement, but complete upgrade preservation of their prefix, existing state, and Gateway service has not been observed; the PR body explicitly accepts this qualification gap.
  • Resolve merge risk (P1) - The reporter's original npm-root mismatch remains unexplained, so coverage of that exact Debian/Raspberry Pi environment is unconfirmed.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +38, Tests +177, Docs +10. Total +225 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 4 115 77 +38
Tests 3 189 12 +177
Docs 1 10 0 +10
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 314 89 +225

Review metrics

Metric Value Why it matters
Production versus test growth production +38 net lines; tests +177 net lines Production growth implements missing installation evidence while removing the separate status heuristic; tests cover platform layouts and detection outcomes.

Stored data model

Persistent data-model change detected: serialized state: src/infra/update-check.ts, unknown-data-model-change: src/infra/update-check.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #146038
Summary: This PR is the explicit implementation candidate for the linked custom-prefix update report; the issue should remain open until resolution.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Retain the recorded qualification exception (recommended)
    Proceed under the maintainer's documented acceptance of bounded detection proof without representing it as a complete upgrade qualification.

Technical review

Best possible solution:

Keep one installation-owner resolver and preserve the original update target under the accepted qualification exception; older-driver recovery should ultimately be exposed through a guided Fix action.

Do we have a high-confidence way to reproduce the issue?

Yes for the conditional defect: current main returns no owner when global-root probes mismatch and the custom prefix lacks npm despite having an OpenClaw launcher. The exact cause of the reporter's probe mismatch remains unconfirmed.

Is this the best way to solve the issue?

Yes. Extending the existing resolver and sharing it with status is a focused repair, and the Windows parser now follows npm's shim contract; complete upgrade qualification remains an accepted limitation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 50877be9476d.

Labels

Label justifications:

  • P0: The linked community report describes blocked self-update on a documented installation layout whose recovery requires a technical environment override.
  • merge-risk: 🚨 compatibility: Additional existing installations become eligible for replacement without complete upgrade-preservation evidence, an explicitly accepted qualification risk.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied MEMBER classification exempts ordinary contributor proof. The body reports real macOS npm detection and target-selection success, separately records regression tests, and explicitly accepts the unperformed complete upgrade transition.

Evidence

What I checked:

  • Current main still lacks the fallback: The fetched main resolver ends with prefix-local npm detection and otherwise returns null; it does not inspect npm's configured prefix or the OpenClaw launcher. (src/infra/update-global.ts:1271, 50877be9476d)
  • Latest release retains the same detection gap: The v2026.9.4 source likewise returns null after the existing probes and prefix-local npm fallback; this requested repair is not present in that release. (src/infra/update-global.ts, 3a9d69db306c)
  • Introduced repair and target preservation: The introduced delta adds configured-prefix and launcher evidence after existing manager checks. Target selection retains the running npm package root, and the CLI passes that selected target into package replacement. (src/infra/update-global.ts:1256, c2731dda0810)
  • Windows finding resolved: The parser now matches the quoted launcher-relative package argument immediately before %*, avoiding the preceding node.exe check. The lifecycle test contains the complete shim shape and checks detection plus original-prefix target selection. (src/infra/update-global.ts:1313, c2731dda0810)
  • Authoritative Windows shim contract: The changed Windows parser depends on npm's generated shim format. The upstream generator places the package target immediately before %*, separately from its interpreter existence check, matching the repaired parser. (lib/index.js:116, 7667c245e7d9)
  • Proof scope and prior-review disposition: The supplied body, corroborated by the live body, reports isolated macOS npm/admission/target-selection success and 143 passing tests after the Windows fix. It expressly accepts landing without a full published-driver-to-candidate upgrade, resolving the previous rank-up alternative. No complete upgrade is claimed. (c2731dda0810)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Patrick-Erichsen: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (6 earlier review cycles)
  • reviewed 2026-09-12T15:20:35.703Z sha 42595ef :: blocked before merge. :: [P2] [P2] Select the package entrypoint from the Windows npm shim
  • reviewed 2026-09-12T15:44:21.440Z sha b6a4056 :: blocked before merge. :: [P2] [P2] Select the package entrypoint from the Windows npm shim
  • reviewed 2026-09-12T15:53:17.149Z sha 5ac8222 :: blocked before merge. :: [P2] Select the package entrypoint from the Windows npm shim
  • reviewed 2026-09-12T16:15:55.415Z sha 5ac8222 :: blocked before merge. :: [P2] Select the package entrypoint from the Windows npm shim
  • reviewed 2026-09-12T16:32:29.097Z sha c2731dd :: blocked before merge. :: none
  • reviewed 2026-09-12T16:45:23.156Z sha c2731dd :: blocked before merge. :: none

Check the installed layout before probing npm configuration. Preserve the existing standalone-package command boundary and exercise unknown-owner diagnostics with an orphaned global layout.
Keep custom prefix and lifecycle coverage in the existing npm global suite without increasing the infra test-root budget or dropping assertions.
Select the launcher-relative package argument before percent-star instead of the earlier node.exe existence check. Cover the complete npm-generated shim in the existing custom-prefix ownership regression.
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Addressed the Windows npm shim finding in c2731dd. The PR body records the complete-shim failing-before/passing-after regression, focused tests, changed-file checks, and the remaining upgrade-proof limitation.

@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added 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 rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 12, 2026
@steipete steipete closed this Sep 12, 2026
@steipete steipete reopened this Sep 12, 2026
@steipete
steipete merged commit f1bd047 into main Sep 12, 2026
385 of 388 checks passed
@steipete
steipete deleted the steipete/upd-package-owner-custom-prefix branch September 12, 2026 17:45
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 13, 2026
Recognize npm ownership for custom prefix installations such as nvm with ~/.npm-global when global-root probes disagree and the prefix has no npm executable. Use npm's configured prefix and the installed OpenClaw launcher, share the resolver with update status, and include inspected paths in unknown-owner refusals. Windows npm shims resolve their package entrypoint instead of the earlier node.exe check.

Keep update target selection on the running package prefix. Older installed updaters still need the explicit NPM_CONFIG_PREFIX workaround for the first hop. Full published-driver-to-candidate upgrade preservation remains unverified; focused ownership, target-selection, status, and CLI admission tests pass, including the failing-before/passing-after complete Windows shim regression.

Fixes openclaw#146038

Reported by Discord user Rex Horizon in the support thread "As usual update fails" (openclaw#146038).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

[Bug]: update refused with "package manager owner is unknown" on nvm + ~/.npm-global installs

1 participant