Skip to content

Let a global package group with a deleted node_modules be replaced - #15092

Closed
zkochan wants to merge 1 commit into
mainfrom
followup/global-repair-removed-tree
Closed

zkochan wants to merge 1 commit into
mainfrom
followup/global-repair-removed-tree

Conversation

@zkochan

@zkochan zkochan commented Sep 18, 2026

Copy link
Copy Markdown
Member

Summary

Delete a global package's node_modules and pnpm update -g could not put it back. It stopped with ERR_PNPM_PACKAGE_MANIFEST_IO_ERROR, naming the manifest that was gone, and took every other global package in the command down with it. pnpm remove -g failed the same way.

Enumerating the bins a group owns read every declared dependency's package.json and propagated any error. That read happens before activation touches global state, deliberately, so a group whose ownership cannot be established is never partially rewritten. A dependency whose directory is gone is not that case: the manifest is what named its bins, and with the tree removed there is nothing left on disk for the group to own. Both CLIs now read a missing directory as "no bins" and keep failing closed on every other read or parse error, which is what stops an unreadable manifest from being mistaken for an unowned bin.

getGlobalPackageDetails, right next to it in the same file, already skipped a missing manifest this way, so the two now agree.

This is pre-existing in both pnpm 11 and pnpm 12 and is fixed in both. It came out of #15029, where a test written to assert that update -g repairs such a group failed in CI and showed that it never had.

Squash Commit Body

Enumerating a group's bins read every declared dependency's manifest and
failed if one was missing, so `pnpm update -g` and `pnpm remove -g` aborted
with ERR_PNPM_PACKAGE_MANIFEST_IO_ERROR once a group's `node_modules` had
been removed. One damaged group took the whole command with it, and the
group it described could not be repaired by the command meant to repair it.

A dependency whose directory is gone owns no bins: the manifest is what
named them, and nothing is left on disk to protect. Both CLIs now read it
that way and keep failing closed on every other read or parse error, which
is what stops an unreadable manifest from being mistaken for an unowned bin.

Related to pnpm/pnpm#15029.

Checklist

  • I checked the referenced issue and verified that none of the PRs
    already linked to it solves it.
  • New features are implemented only in the Rust pnpm v12 CLI. Bug fixes
    are implemented in every affected version.
  • Added a changeset (pnpm changeset) if this PR changes any published
    package. Keep it short and written for pnpm users — it becomes a release note.
  • Added or updated tests.
  • Updated the documentation if needed.

🤖 Generated with Claude Code

Enumerating a group's bins read every declared dependency's manifest and
failed if one was missing, so `pnpm update -g` and `pnpm remove -g` aborted
with ERR_PNPM_PACKAGE_MANIFEST_IO_ERROR once a group's `node_modules` had
been removed. One damaged group took the whole command with it, and the
group it described could not be repaired by the command meant to repair it.

A dependency whose directory is gone owns no bins: the manifest is what
named them, and nothing is left on disk to protect. Both CLIs now read it
that way and keep failing closed on every other read or parse error, which
is what stops an unreadable manifest from being mistaken for an unowned bin.

`getGlobalPackageDetails` next to it already skipped a missing manifest, so
this makes the two agree.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@zkochan

zkochan commented Sep 18, 2026

Copy link
Copy Markdown
Member Author

Closing this unmerged: the change is wrong, and the reason is worth recording.

It made a missing dependency manifest mean "this dependency owns no bins". Two end-to-end tests exist to prevent exactly that, and the wider test selection caught them after my first scoped run on pnpm-global alone had passed:

  • global_update_preflights_incomplete_target_ownership_before_activation
  • global_remove_preflights_all_targets_before_mutating_any_group

Both seed a group whose dependency directory holds no manifest, put a matching bin in the global bin directory, and assert that the command fails and the global bin tree is unchanged byte for byte. The remove test is the sharper one: remove -g victim-a victim-b must not delete victim-a while victim-b's ownership is unknown. Relaxing the read lets both commands mutate bins they cannot account for, which is the thing the preflight is there to stop. The behavior is deliberate, not an oversight.

The underlying dead end is still real: a group whose node_modules was deleted cannot be updated or removed, and it blocks every other global package in the same command. That needs a decision about global bin safety rather than a patch, so it is now #15093, with the evidence, a possible narrower line that would keep both preflight tests green, and the two implementation constraints that come with it.


Written by an agent (Claude Code, claude-opus-5).

@zkochan zkochan closed this Sep 18, 2026
@zkochan
zkochan deleted the followup/global-repair-removed-tree branch September 18, 2026 23:48
@github-actions

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.00     12.6±0.20ms    29.6 MB/sec    1.00     12.7±0.15ms    29.6 MB/sec
packument/parse                                  1.09     44.1±0.33µs  1503.7 MB/sec    1.00     40.6±0.52µs  1634.0 MB/sec
tarball/download_dependency                      1.71      8.6±0.69ms   506.1 KB/sec    1.00      5.0±0.23ms   864.8 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.31    268.8±7.67ms 59.5 KElem/sec    1.00    205.7±9.12ms 77.8 KElem/sec
workspace_resolution/hoist_heavy                 1.00    266.9±6.13ms        ? ?/sec    1.07    284.4±6.76ms        ? ?/sec
workspace_sort/chained_projects                  1.45     21.8±4.18ms        ? ?/sec    1.00     15.1±1.38ms        ? ?/sec

@blacksmith-sh

blacksmith-sh Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Found 4 test failures on Blacksmith runners:

Failures

Test View Logs
test/getInstalledBinNames.test.ts/getInstalledBinNames.test View Logs
test/getInstalledBinNames.test.ts/getInstalledBinNames.test View Logs
test/globalRemove.test.ts/globalRemove.test View Logs
test/globalRemove.test.ts/globalRemove.test View Logs

Fix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

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