A failed `npm root -g` probe reads as "no global install": scan -g reports nothing to scan, and rollback drops the record of a copy that is still patched
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 53/100
Research direction
Start with get_npm_global_prefix and get_global_node_modules_paths in crates/socket-patch-core/src/crawlers/npm_crawler.rs, comparing the Bun probe and warning behavior nearby. Then trace patched_in_other_scope in crates/socket-patch-cli/src/commands/rollback.rs and read the rollback contract in CLI_CONTRACT.md. Run the proposed injected CommandRunner cases and rollback CLI test; done means failed npm probes warn during global scans and project rollback preserves records and blobs when the global copy cannot be checked.
Written by the indexing model from the issue text.
Description
[agent] Filed by the architecture refactor routine (lead L33, run on main at cfc870f).
Kind: bug, an error that lies. A package manager's global-directory probe that fails is read as "this manager has no global install". Bun's probe was taught the difference in #1009 (for #443); npm's was not.
Problem
The npm crawler asks each manager where its global packages are (npm root -g, pnpm root -g, yarn global dir, bun pm ls -g). For npm, pnpm and yarn a probe that gives no answer is dropped without a word ([npm_crawler.rs L3401-L3426](https://github.com/SocketDev/socket-patch/blob/cfc870f55f5910e48e331ae460585ac2dea878a4/crates/socket-patch-core/src/crawlers/npm_crawler.rs#L3401-L3426)): get_npm_global_prefix returns Err, and the caller's if let Ok(..) skips it. "No answer" covers a manager that is not installed, one that exits non-zero, and one that is still running at the 10 s probe budget. On Linux there is no other discovery path for npm's directory.
Bun's probe already tells these apart. resolve_bun_global_prefix returns Ok(None) for "Bun is not in use" and Err for "Bun is in use but its global dir can't be told", "so a global scan can say so instead of reporting a clean, empty result" ([L2500-L2535](https://github.com/SocketDev/socket-patch/blob/cfc870f55f5910e48e331ae460585ac2dea878a4/crates/socket-patch-core/src/crawlers/npm_crawler.rs#L2500-L2535)), and the caller prints Warning: could not determine Bun's global package directory (…), so Bun's global packages were not scanned. That came with 2044d9ee (git log -S'fn resolve_bun_global_prefix').
Two things follow for npm.
1. A global scan reports a clean, empty result. scan -g prints No global packages found. and exits 0, with status: success and scannedPackages: 0 under --json and no warning.
2. A project rollback drops the record of a copy that is still patched. The contract says that before a rollback drops a record it checks the other scope, and that "a copy there that still holds the patch's afterHash bytes, or has a patched file that exists but cannot be hashed, keeps the record (with its variant group) and its blobs" (CLI_CONTRACT.md L2494). patched_in_other_scope (rollback.rs L341-L390) crawls the default global install for that. When the probe fails, the crawl finds no copy, so the record leaves the manifest and its blobs are freed. The run says nothing, and the rollback -g the user would run next finds no record.
apply -g and rollback -g are honest over the same failure: apply -g exits 1 (package_not_installed), and rollback -g warns that "a copy this run did not find stays patched until the package is reinstalled".
Evidence
The binary built from main. A project whose [email protected] holds its original files, a manifest record and blobs for a patch of it, and a global node_modules whose [email protected] holds the patched files. PATH holds one npm:
- answers: a script that prints the global
node_modulesforroot -g; - fails:
echo "npm ERR! code EACCES" >&2; exit 1; - hangs:
exec sleep 600.
socket-patch rollback --offline --yes in the project, then socket-patch rollback -g --offline --yes:
=== npm answers
Rolled back 1 package:
pkg:npm/[email protected] (already original)
Warning: pkg:npm/[email protected]: its copy in the global install (…/os-global/lib/node_modules/left-pad) is still patched or could not be verified, so its manifest record was kept; run `socket-patch rollback pkg:npm/[email protected] -g --cwd …/os-proj` to restore it
exit=0 (0s)
manifest records: 1 blobs left: 4 global index.js: module.exports = 2
then: rollback -g
Rolled back 1 package:
pkg:npm/[email protected]
exit=0 global index.js: module.exports = 1
=== npm fails
Rolled back 1 package:
pkg:npm/[email protected] (already original)
Removed 1 patch from manifest.
Freed 66 B of unused blobs and archives
exit=0 (0s)
manifest records: 0 blobs left: 0 global index.js: module.exports = 2
then: rollback -g
No patches in this project; nothing to roll back.
exit=0 global index.js: module.exports = 2
=== npm hangs
(the same output as "npm fails")
exit=0 (10s)
manifest records: 0 blobs left: 0 global index.js: module.exports = 2
Under --json the first run carries warnings: ["patched_in_other_scope"], removed: 0. The other two carry no warning, removed: 1, bytesFreed: 66, and nothing on stderr.
A global scan on this machine, against a local stand-in for the patch API that offers no patch (--proxy-url, left out below with the token notice), with its real npm (199 global packages) and then with a failing npm, pnpm and yarn first on PATH:
$ socket-patch scan -g --ecosystems npm --mode agent --dry-run
Found 199 packages (199 npm)
No patches available for installed packages.
$ PATH=<failing npm, pnpm, yarn>:$PATH socket-patch scan -g --ecosystems npm --mode agent --dry-run
No global packages found. (exit 0)
scan -g --ecosystems gem gives the same pair with a failing gem and ruby (17 packages, then No global packages found.). I did not trace the gem crawler's probe.
Not checked: how often npm root -g fails or takes over 10 s on a machine whose global install is otherwise in use. The cases run here are a script that exits 1 and one that never returns.
Planned fix
- Give npm's probe Bun's shape:
Ok(None)whennpmis not onPATH,Err(why)when it is andnpm root -ggave no usable answer.get_global_node_modules_pathsthen warns once, as it does for Bun, that npm's global packages were not scanned and names--global-prefix. - In
patched_in_other_scope, when the other scope is the global install and npm's directory could not be determined, keep the npm records it was asked about, and say so. That is the rule the function already follows for a file it cannot hash: "keep the record rather than strand it". - Tests: a unit test over an injected
CommandRunnerfor the three answers, and a CLI test that runs the rollback above with a failingnpmonPATHand expects the record and blobs to stay.
Two things to settle in the PR:
- pnpm and yarn.
yarn global dirfails for every Yarn Berry install, which has noglobalcommand, so a warning on any failed yarn probe would be noise. The first slice is npm alone; pnpm and yarn need their benign failures told from real ones first. - The
--jsoncode for step 2.patched_in_other_scopenames a copy's path, and here no path is known. Reusing it with a different detail, or adding a code, is an addition towarnings[]that the contract does not name yet.
Generated by Claude Code
- Dominant language
- Rust
- Stars
- 9
- Forks
- 2
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 313
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from SocketDev/socket-patch
-
agent:triaged arch-audit bug priority:p2
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
SocketDev/socket-patch#2306 ·
Maintainers usually reply within 1 day
-
agent:triaged arch-audit bug priority:p3
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
SocketDev/socket-patch#2296 ·
Maintainers usually reply within 1 day
-
agent:needs-human agent:triaged ci-janitor priority:p1
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SocketDev/socket-patch#2270 · 3 comments ·
Maintainers usually reply within 1 day
-
agent:triaged arch-audit bug priority:p1
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
SocketDev/socket-patch#2259 ·
Maintainers usually reply within 1 day
-
agent:triaged arch-audit priority:p3 refactor
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
SocketDev/socket-patch#1860 ·
Maintainers usually reply within 1 day
All issues in SocketDev/socket-patch
Similar issues
-
Bash init calls `cygpath` unconditionally on Windows, which breaks non-Cygwin shells like `brush`Possibly taken @iliqiliev claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ajeetdsouza/zoxide#1381 ·
Maintainers usually reply within 5 days
-
triage
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
kornia/kornia-rs#1416 · 1 comment ·
Maintainers usually reply within 2 days
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
paritytech/revive#749 ·
Maintainers usually reply within 3 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
swc-project/swc-next-issues#1043 ·