Skip to content

Pin no pnpm lock that a Bazel hub would reject with pnpm 11 - #2213

Merged
Mikola Lysenko (mikolalysenko) merged 4 commits into
mainfrom
bazel-guard/pnpm11-workspace-hidden
Nov 24, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 4 commits into
mainfrom
bazel-guard/pnpm11-workspace-hidden

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Hosted mode no longer pins a pnpm lock that a Bazel hub would reject with pnpm 11: it skips the package, exits 0 and says which line to add to the hub.

Decisions for the maintainer

  1. Uncertain readings withhold where a call that names the lock is seen, and never where only the reader's general doubts exist. That covers an update_pnpm_lock or a data that is a constant, and a use_pnpm whose repository cannot be followed to a pnpm.pnpm tag. The price: a hub whose data is a constant that already lists the file built patched before and gets no new pin until the list is written out in the call. The warning says so. A lock that is pinned already stays pinned.
  2. A hub that lists the file is no longer passed over unseen. Hosted mode pins nothing beside a listed pnpm-workspace.yaml that would hold only what hosted mode writes: none, an empty one, one with the root-only packages alone, the file of an earlier hosted run. Such a hub built patched before this change; rollback then removed the file, the call named a missing one, and the build failed. Now the pin waits for a comment line in the file. If a patch that builds today matters more than the undo, this half can go: it is one match arm.
  3. The pnpm that rules_js picks by itself is taken as older than 11 only for the releases it was read in: aspect_rules_js 1.x to 3.x, 4.0.0-alpha.0 and 4.0.0-alpha.1. For any later release a hub that states no pnpm and hides the file is withheld, with the usual way on. If a later release still picks pnpm 10, that is a patch held back until the file is listed or a pnpm.pnpm tag states the release. The other choice is to assume pnpm 10 for every release, which breaks the build on the first one that moves to 11.
  4. Path selection of the in-memory engine asks for the MODULE.bazel beside a pnpm-lock.yaml: one more text file per such root. Without it the in-memory engine would still pin such a lock. Dropping the lines in select.rs keeps hosts as they are.
  5. One known problem is left, and listed in the docs: with --no-trust-lockfile-config the lock is pinned without the setting, with the existing warning that pnpm 11 rejects it, and the pnpm of such a hub does reject it (measured with the option on Bazel 9.3.2). The step that leaves the lock out does not have that option. A trustLockfile: false of the project's own is no longer part of this: hosted mode pins nothing beside it.
  6. rollback still removes a pnpm-workspace.yaml it cannot tell from one hosted mode created. No new pin is written beside such a file any more (decision 2), so this is left for a pin an earlier release wrote. Keeping a listed file on rollback would be a change to rollback; it is in the docs' known problems.
  7. One spelling is still read as the pnpm rules_js picks: a use_pnpm that names @pnpm where another extension makes a repository of that name. If that pnpm is 11 or later the lock is pinned and the build fails. Closing it needs the workspace reader to say which extension a use_repo belongs to. The docs list it under what is not read.
  8. Size. 302 implementation code lines, 209 before the code review. The 93 more are the two cases of a listed file, the rule for the ruleset's own pnpm and the corrected warning text.

What the code does today

In a Bazel workspace whose npm.npm_translate_lock (aspect_rules_js) has update_pnpm_lock = True, rules_js runs a pnpm of its own during the build whenever the lock or a package.json differs from the hashes it keeps under .aspect/. It runs pnpm install --lockfile-only in a directory that holds the lock, the package.json files and the files the call lists as data, and nothing else of the checkout.

Hosted mode pins the lock and writes trustLockfile: true to pnpm-workspace.yaml, the setting without which pnpm 11 and later reject a lock whose tarball URL is not the registry's. When the hub does not list that file, its pnpm never reads the setting:

  • socket-patch scan --mode hosted --yes exits 0 and reports the patch applied;
  • the next bazel build fails with ERR_PNPM_TARBALL_URL_MISMATCH.

Measured on Bazel 9.3.2 with aspect_rules_js 3.6.0 and pnpm 11.28.10. The first commit adds a test that holds exactly this, and passes on the product code as it is.

What changes

Hosted mode writes nothing for the project's root pnpm lock when one call names that lock in a plain string and all three hold for it:

  1. update_pnpm_lock is True;
  2. data does not list the pnpm-workspace.yaml beside the lock, or lists one that a pin and its undo would not leave standing (below);
  3. the pnpm it runs is stated as 11 or later.

The run exits 0 with status success. Each package is a skipped event: redirect_unconfirmed, or redirect_unattributable in a project that also has a lock of npm's, which is then not pinned either. One warning, redirect_pnpm_bazel_workspace_hidden, names the call by file and line, as the file writes it, and the way on:

MODULE.bazel:7: this npm.npm_translate_lock has Bazel run pnpm 11.28.10 to keep pnpm-lock.yaml up to date (update_pnpm_lock), and its data does not list pnpm-workspace.yaml. That pnpm reads only the lock, the package.json files and the data of the call, so it would not see the trustLockfile: true that hosted mode writes to pnpm-workspace.yaml, and without it pnpm 11 and later reject a lock that names the patch server (ERR_PNPM_TARBALL_URL_MISMATCH): bazel build would fail; pnpm-lock.yaml was not rewritten — list //:pnpm-workspace.yaml in the data of that call and re-run

For a project below the Bazel root the warning starts MODULE.bazel:7, with paths from the root of the Bazel workspace: …, because its paths are not the ones of a run in the project's directory.

The file has to be one that a pin and its undo leave standing. Two cases need a step of their own, which comes before the label, or alone where the hub lists the file already:

  • The file would hold only what hosted mode writes: there is none, or it is empty, or holds only packages: and - '.', or is the file of an earlier hosted run. The step is put a comment line in pnpm-workspace.yaml (create the file where there is none: …). Hosted mode would create or fill the file, but rollback removes a file that holds nothing else, and a hub that names a missing file fails the build (measured on Bazel 9.3.2). It is one wording for a missing file and a bare one: while a vendored patch is being taken over the file is briefly gone when the hub is judged, and the earlier text then told the user to create a file the checkout has.
  • Hosted mode does not write the setting to the file: it says trustLockfile: with another value than true, which hosted mode leaves as the user's call, or it is YAML a line cannot be added to (a flow-style root, several documents). The pnpm of the hub would read the file and still reject the lock. The step is to set trustLockfile: true in it.

One more form: where data is not written out as a list of strings, the last step is to write it out as one that holds the label. The value may list the file already, and adding the label elsewhere would change nothing.

Where the pnpm release is read: rules_js takes the pnpm from the repository the call's use_pnpm names (@pnpm without one). A pnpm.pnpm tag of that name makes it from pnpm_version, or from the packageManager of the package.json that pnpm_version_from names. Of several tags the newest release counts. A workspace that states no release gets the pnpm rules_js picks: its newest pnpm 8 through 2.9.3 (8.15.3 at 1.42.3), its newest pnpm 10 from 3.0.0 through 3.6.0 and at 4.0.0-alpha.0 and 4.0.0-alpha.1 (DEFAULT_PNPM_VERSION in npm/private/pnpm_repository.bzl, read at those tags). None rejects the lock, so nothing is withheld for those releases: the one the root module asks for with bazel_dep or pins with a single_version_override, and the one MODULE.bazel.lock selected, where that file is there. For any later release, a version that is not written out and a ruleset that an override takes from elsewhere than a registry, the choice is not known and counts as a pnpm that may be 11 or later.

A use_pnpm is a label of the root module, so it is followed to a tag only where a use_repo takes its repository by position, under the tag's own name, and, unless that name is pnpm, a tag makes it. With use_repo(pnpm, eleven = "pnpm") and use_pnpm = "@eleven//...", Bazel runs the pnpm 11 of the tag pnpm: measured on Bazel 9.3.2 on an earlier state of this branch, which pinned that lock, and the build failed. Such a rename, a repository of another extension and a repository of a repository rule are now read as a release that is not written out, and withhold.

What a call does not write out counts against writing, because a failing build is worse than a patch that a warning explains: an update_pnpm_lock that is not True or False, a data that is not a list of strings, an attribute a ** may pass, a release that is no version (latest, a constant, a package.json that cannot be read), a use_pnpm that is not followed, and a call that is not a statement of its own. What the reader may not have seen at all (an included file that is missing, a WORKSPACE file) withholds nothing.

Nothing changes:

  • for a project in no Bazel workspace;
  • for a project whose lock no hub names, and for one without a root pnpm-lock.yaml, where no Bazel file is read at all;
  • for a hub without update_pnpm_lock, one that runs pnpm 10 or states no release under a release of the ruleset whose choice is known, and one that lists a file of the user's own that takes the setting;
  • for the members' own locks of a workspace with sharedWorkspaceLockfile: false, which no hub of this answer reads: they are pinned as on main while the root lock is left out.

A vendored patch that a hosted scan would take over stays vendored. A lock that is pinned already stays pinned.

The in-memory engine gives the answer of a checkout with the same files. For that, path selection now asks for the MODULE.bazel beside a pnpm-lock.yaml. It is not handed MODULE.bazel.lock, nor a pnpm_version_from file outside the project's own manifests: such a file reads there as a release that is not written out, so a lock that a checkout pins can be left as it is in memory.

Contents

Part Lines
crates/socket-patch-core/src/bazel/pnpm.rs, new: the answer, read only through the existing workspace reader +411 (286 code)
hosted/engine.rs: one branch beside the existing pnpm refusals; member locks read beside it +29 / -3 (12 code)
hosted/guidance.rs: is_trust_scaffold, which the undo in patch/redirect/upstream/npm.rs now asks too +8, and +1 / -2
hosted/memory/select.rs, bazel/mod.rs +9 / -1 (5 code)
Unit tests in bazel/pnpm.rs (8) and one in hosted/engine.rs +632 and +44
tests/e2e_bazel_build/npm.rs: two flows on real Bazel, five tests without Bazel +671
tests/hosted_memory_parity.rs: one parity test +57
docs/ecosystems.md, CLI_CONTRACT.md +123 / -9
.github/workflows/bazel-npm.yml, comments only +10 / -5
scripts/loc-budget.json: the bazel group's cap, 2486 to 2773 1

No fixture file is added: the flows edit MODULE.bazel in their own workspace copy, so the three existing npm flows are as they were. 302 implementation code lines in all.

In docs/ecosystems.md the npm cell of the Bazel table carries the condition, the entry for this case leaves the list of known problems, two entries of that list say what is left (--no-trust-lockfile-config; the rollback of a pin an earlier release wrote beside a bare listed file), and a section "Bazel workspaces: npm" says when hosted mode withholds and what is not read.

What it proves, and where

On real Bazel 9.3.2, 8.8.2 and 7.7.2 (macOS arm64, the whole npm leg, five flows, 40 to 44 s per release):

  • npm::hosted_update_pnpm_lock_on_pnpm_11: the scan pins nothing and warns; the same build passes on the upstream package; after exactly what the warning says (the file, then the label) the same scan pins the lock and the build is the patched one; rollback leaves the user's file and the build is the upstream one again.
  • npm::hosted_update_pnpm_lock_on_pnpm_10: the same hub with the pnpm rules_js picks. Pinned and patched as before, with no line added.
  • Both hold what rules_js does with its hash file: after the lock changed, a build under ASPECT_RULES_JS_FROZEN_PNPM_LOCK fails until one without it has rewritten the file.

Without Bazel:

  • the scan, its dry run and get --mode hosted pin nothing, for a project at the root and for one in a directory of the workspace, with the warning's start and end held exactly;
  • a hub that lists the file pins nothing beside an empty file, one with the root-only packages alone and one that says trustLockfile: false, each with the step the file needs and no label;
  • a project with both a pnpm lock and an npm lock gets neither pinned, as redirect_unattributable, with no file changed;
  • seven hubs that hide nothing leave the run equal to the run of the same checkout without MODULE.bazel: exit code, both streams byte for byte, every file;
  • a vendored patch stays;
  • the in-memory engine and the disk run give the same redirect block, for a hub that hides the file, one that lists a file of the user's own, and one that lists a bare file;
  • the members' own locks of a workspace with sharedWorkspaceLockfile: false are read and pinned while the root lock is left out (a unit test of the engine);
  • unit cases hold each reading: the rename, a rename under the name of another tag, a repository of another extension, a repository no use_repo takes, @pnpm and a named repository followed to a pnpm 10, the newest of several tags, the releases of the ruleset whose own pnpm is known and the ones it is not (by bazel_dep, by a pin, by an override, by Bazel's lock), each case of a listed file, and each form of the way on, including which files rollback would remove.

Checks of the tests themselves:

  • with the product change reverted, the pnpm 11 flow on 9.3.2, two tests without Bazel and the parity test fail (run before the last corrections; the flows are unchanged since);
  • mutations of the product code each fail at least one test. Seven were run for the readings of the second commit; one survived at first and showed a rule no test needed, and the unit case added for it now fails that mutation. Eight more were run for the third commit, one per rule it adds, and each fails a test;
  • a binary of the base and the built binary were run side by side on fourteen hub shapes: the two that name a pnpm 10 by use_pnpm give identical output and files, and the shapes above are withheld where the base pins.

Not covered

  • A WORKSPACE file, and a hub whose pnpm_lock is not a plain string: not read, pinned as before.
  • A hub that names the lock of a workspace member (pnpm_lock = "//packages/a:pnpm-lock.yaml"): not read, pinned as before.
  • --no-trust-lockfile-config (decision 5).
  • A pnpm release that another Bazel module of the build asks for, and a repository named pnpm that another extension makes (decision 5): pinned as before.
  • A hub with npm_package_lock or yarn_lock, where rules_js runs pnpm import: not measured.
  • Rush locks.
  • In memory: a hub in a file that MODULE.bazel includes, a Bazel root above the project, MODULE.bazel.lock, and a pnpm_version_from file outside the project's own manifests, which withholds there where a checkout pins.
  • The third commit's cases ran without Bazel: a listed file that hosted mode does not write the setting to, a listed bare file, and the rule for the ruleset's own pnpm, which rests on the ruleset's source at the tags named and on no build with a release that picks pnpm 11. On real Bazel that commit ran the five npm flows on 9.3.2 only (they pass); 8.8.2 and 7.7.2 ran at the second commit.
  • The workspace files are read again on each read of the candidate files, and the reading shares no code with the other hub readers of bazel/built.rs: time and tidiness, left for a change of their own.
  • Hosted mode still withholds where the setting reaches the pnpm of the build another way (pnpm_config_trust_lockfile in Bazel's environment), where ASPECT_RULES_JS_DISABLE_UPDATE_PNPM_LOCK switches the update off, and on Windows, where rules_js switches it off itself. The warning's way on works in each.
  • After the correction for a renamed use_pnpm, that workspace was run without Bazel only: the scan writes nothing there, so the build is the one before the scan. The comment-line form of the way on was likewise run without Bazel only.
  • pnpm 9 and pnpm 12 were not run here.
  • Linux and the GitHub Actions legs have not run yet.

Code review

Nine findings on the first two commits, each checked against the code. The third commit takes them as follows.

Fixed, each with a test that fails without it:

  • A hub that lists the file was passed over without a look at it. Beside a listed file that says trustLockfile: false, or that a line cannot be added to, the lock was pinned without the setting and the pnpm of the hub rejects it. Hosted mode now pins nothing there and says to set the key.
  • A listed file that rollback would remove. Beside a listed file with nothing of the user's own, the lock was pinned, and a later rollback removed the file and left the call with a missing one. Now withheld until the file holds a comment line (decision 2).
  • The ruleset's own pnpm was assumed older than 11 for every release. It is now known for the releases it was read in, and counts as unknown for any other (decision 3).
  • Member locks were lost. Once the hub stood against the root lock, the members' own locks of a workspace with sharedWorkspaceLockfile: false were not read. They are read and pinned as on main.
  • The warning during a takeover of a vendored patch told the user to create a file the checkout has: the file is briefly gone while the hub is judged. Confirmed by a run. The step is now one wording that is true with and without the file.
  • The warning's text: of several pnpm 11 tags it named the oldest; it called the hub npm.npm_translate_lock whatever the file calls it; and for a project below the Bazel root it gave paths from that root without saying so.
  • The rule for a file that rollback removes was written twice. It is one function now, which the undo asks too.

Not fixed:

  • --no-trust-lockfile-config still pins without the setting. The step that leaves the lock out is not handed that option, and handing it over changes about fifteen call sites. It stays a known problem in the docs (decision 5).
  • The in-memory engine is not handed a pnpm_version_from file outside the project's manifests, so it withholds where a checkout pins. Path selection works on paths alone and cannot follow a label; the docs say so.
  • A hub that names a member's lock is not read. It was not covered before and is listed.
  • The workspace is read on each read of the candidate files, and some helpers repeat ones of bazel/built.rs. Time and tidiness only; sharing them touches files other open changes rewrite.

Generated by Claude Code

…h pnpm 11

With `update_pnpm_lock = True`, aspect_rules_js runs a pnpm of its own
during the build whenever the lock or a `package.json` differs from the
hashes it keeps under `.aspect/`: `pnpm install --lockfile-only`, in a
directory that holds the lock, the `package.json` of each importer and the
files the hub lists as `data`, and nothing else of the checkout (rules_js
3.6.0, npm/private/npm_translate_lock_state.bzl).

Hosted mode pins the lock and writes `trustLockfile: true` to
`pnpm-workspace.yaml`, the setting without which pnpm 11 and later reject a
lock whose tarball URL is not the registry's. A hub that does not list
that file as `data` hides the setting from the pnpm Bazel runs.

The new flow `npm::hosted_update_pnpm_lock_on_pnpm_11` holds what the
command does there today, on real Bazel: the fixture's hub with
`update_pnpm_lock = True` and no `data`, and a `pnpm.pnpm` tag that states
pnpm 11.28.10. The first build passes and prints the unpatched marker;
`scan --mode hosted --yes` exits 0 and reports the patch applied; the next
`bazel build` fails with ERR_PNPM_TARBALL_URL_MISMATCH. Measured on Bazel
9.3.2 with the product code as it is. A command that exits 0 and leaves a
failing build is what the next commit removes; this one only records it.

The flow edits the `MODULE.bazel` of its workspace copy, so the fixture
and the three existing flows are as they were. The pnpm that Bazel runs
gets the stand-in as its registry through `pnpm_config_registry` (and
`npm_config_registry`, which pnpm 10 reads), and the stand-in serves the
package's registry document, because pnpm 11 holds every lock entry to
what the registry publishes before it does anything else. The pnpm itself
is the one download the flow adds to a leg: the `pnpm` package of the
public registry, about 5 MB, held to the checksum rules_js has for it.
The workflow's header says so.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`scan --mode hosted` exited 0, reported the patch applied, and the next
`bazel build` failed with ERR_PNPM_TARBALL_URL_MISMATCH, in a workspace
whose `npm.npm_translate_lock` has `update_pnpm_lock = True`, runs pnpm 11
or later and does not list `pnpm-workspace.yaml` as `data` (measured on
Bazel 9.3.2 with aspect_rules_js 3.6.0 and pnpm 11.28.10; the previous
commit holds it). rules_js runs that pnpm in a directory with the lock,
the `package.json` files and the hub's `data` only, so it never reads the
`trustLockfile: true` hosted mode writes, and pnpm 11 rejects a lock whose
tarball URL is not the registry's.

Hosted mode now writes nothing for the pnpm lock of such a project. The
run exits 0 with status `success`, each package is a `skipped` event
(`redirect_unconfirmed`), and one warning,
`redirect_pnpm_bazel_workspace_hidden`, names the call by file and line
and the way on: list the label of `pnpm-workspace.yaml` in the `data` of
that call and run the command again. `scan`, its dry run and
`get --mode hosted` behave alike, and a vendored patch that a hosted scan
would take over stays vendored. In a project that also has a lock of
npm's, that lock is not pinned either: the pnpm lock still names the
registry's tarball, so the package is skipped as
`redirect_unattributable`.

The way on has three more forms:

- The project has no `pnpm-workspace.yaml`: create it first (a comment
  line is enough). Hosted mode would create it, but `rollback` removes a
  file hosted mode created, and a hub that names a missing file fails the
  build (measured).
- The file would be nothing but what hosted mode creates once the setting
  is in it (an empty file, one with only `packages:` and `- '.'`, a file
  of an earlier hosted run): add a comment line first. `rollback` cannot
  tell such a file from one it created and removes it (measured on Bazel
  9.3.2: the build then fails on the missing file).
- `data` is not written out as a list of strings: write it out as one
  that holds the label. The value may list the file already, and adding
  the label somewhere else would change nothing.

The answer is in a file of its own, bazel/pnpm.rs, and reads the
workspace only through the existing reader. It needs one call that names
the project's `pnpm-lock.yaml` in a plain string, and for that call:

- `update_pnpm_lock` is `True`;
- `data` does not list the `pnpm-workspace.yaml` beside the lock;
- the pnpm it runs is stated as 11 or later. rules_js takes that pnpm
  from the repository the call's `use_pnpm` names (`@pnpm` without one),
  which a `pnpm.pnpm` tag of that `name` makes from `pnpm_version` or
  from the `packageManager` of the `package.json` that
  `pnpm_version_from` names (npm/private/pnpm_extension.bzl at 3.6.0).

A workspace that states no release gets the pnpm rules_js picks: its
newest pnpm 10 at 3.x and 4.0.0-alpha.1, its newest pnpm 8 at 2.x. Those
take the pinned lock (measured for 3.6.0 on Bazel 9.3.2), so nothing is
withheld there.

A `use_pnpm` is a label of the root module, so it is followed to a tag
only where a `use_repo` takes its repository by position, under the
tag's own name, and, unless that name is `pnpm`, a tag makes it. With
`use_repo(pnpm, eleven = "pnpm")` and `use_pnpm = "@eleven//..."`, Bazel
runs the pnpm 11 of the tag `pnpm` (measured on 9.3.2, where that build
fails on a pinned lock), and a repository of another extension or of a
repository rule can be any pnpm: both are read as a release that is not
written out, and withhold. One case is still read as the pnpm rules_js
picks: a `use_pnpm` that names `@pnpm` where another extension makes a
repository of that name. The docs list it under what is not read.

What a call does not write out counts against writing, because a failing
build is worse than a patch that a warning explains: an `update_pnpm_lock`
that is not `True` or `False`, a `data` that is not a list of strings, an
attribute a `**` may pass, a release that is no version (`latest`, a
constant, a `package.json` that cannot be read), a `use_pnpm` that is
not followed, a call that is not a statement of its own. So a hub whose
`data` is a constant gets no new pin until the list is written out in
the call, also where the constant lists the file and the build would
take the pin (measured), and a hub whose `update_pnpm_lock` is a constant
is taken as one that keeps the lock up to date; a lock that is pinned
already stays pinned. What the reader may not have seen at all (an
included file that is missing, a `WORKSPACE` file) withholds nothing: a
project whose lock no listed call names is pinned as before.

Nothing changes for a hub without `update_pnpm_lock`, one that runs
pnpm 10, one that lists the file, a project whose lock no hub names and a
project in no Bazel workspace: tests hold each of those runs to the run
of the same checkout without its `MODULE.bazel`, both streams byte for
byte and every file. For a project without a root `pnpm-lock.yaml` (one
with npm's lock, say) no Bazel file is read at all.

The in-memory engine gives the same answer for the same files (a parity
test holds it to the disk run). For that, path selection now asks for the
`MODULE.bazel` beside a `pnpm-lock.yaml`. A hub in a file that
`MODULE.bazel` includes, and a Bazel root above the project, are not seen
in memory.

The flow of the previous commit now holds the new behaviour on real
Bazel: the scan pins nothing and warns, the same build passes on the
upstream package, and after exactly what the warning says (the file and
the label) the same scan ends in the patched build; `rollback` then
leaves the user's file, and the build is the upstream one again. A second
flow is the same hub with the pnpm rules_js picks: pinned and patched as
before, with no line added. Both also hold what rules_js does with its
file of hashes: after the lock changed, a build under
ASPECT_RULES_JS_FROZEN_PNPM_LOCK fails until one without it has
rewritten that file.

Unit cases hold each reading above, the three forms of the way on among
them, and a test without Bazel holds the project with both locks.

docs/ecosystems.md: the npm cell of the Bazel table carries the
condition, a section "Bazel workspaces: npm" says when hosted mode
withholds and what is not read, and the entry leaves the list of known
problems. One entry joins that list, found on the way and not changed
here: with `--no-trust-lockfile-config` the lock is pinned without the
setting, and the pnpm of such a hub rejects it (measured by hand on
9.3.2). The size budget of the bazel group follows the new file.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…or miss one

A review of the change that keeps hosted mode from pinning a pnpm lock
which a Bazel hub would reject with pnpm 11 found cases it still let
through, one it took a patch away in, and three places where the warning
said the wrong thing.

A hub that lists pnpm-workspace.yaml was passed over without a look at
the file. Hosted mode now pins nothing beside a listed file in two cases:

- It would not write `trustLockfile: true` to the file: the file sets the
  key to another value, which is left as the user's call, or it is YAML
  that a line cannot be added to. The pnpm of the hub reads the file and
  rejects the pinned lock all the same (ERR_PNPM_TARBALL_URL_MISMATCH).
- The file would hold only what hosted mode writes: there is none, or it
  is empty, or holds the root-only `packages` alone, or is the file of an
  earlier hosted run. `rollback` removes such a file with the pin, because
  it cannot tell it from one hosted mode created, and a call that names a
  missing file fails the build.

The warning names what the file needs. Where the hub does not list the
file yet, the same step comes before the label, and the two wordings for
"no file" and "a file of hosted mode's bytes" are one: during a takeover
of a vendored patch the file is briefly gone while the hub is judged, and
the old text then said to create a file the checkout has.

Where no `pnpm.pnpm` tag states a release, rules_js runs a pnpm of its
own choice. That was taken to be older than 11 for every release of the
ruleset. It is known for the releases it was read in: the newest pnpm 8
through 2.9.3, the newest pnpm 10 from 3.0.0 through 3.6.0 and at
4.0.0-alpha.0 and 4.0.0-alpha.1 (DEFAULT_PNPM_VERSION in
npm/private/pnpm_repository.bzl). The release is read from the root
module's `bazel_dep` and `single_version_override` and from
MODULE.bazel.lock where there is one; for any later release, a version
that is not written out and a ruleset an override takes from elsewhere,
the choice counts as a pnpm that may be 11 or later.

The members' own locks of a workspace with `sharedWorkspaceLockfile:
false` were no longer read once the hub stood against the root lock, so
their pins, which no hub reads, were lost. They are read and pinned as
on main; the root lock alone is left out, and the warning says
"<lock> was not rewritten" where it said that no pnpm lock was.

The warning also named the oldest of several pnpm 11 tags where rules_js
runs the newest, called the hub `npm.npm_translate_lock` whatever the
file calls its proxy, and gave paths from the Bazel root to a run in a
project below it without saying so.

The rule for a file that `rollback` removes is now one function,
`hosted::guidance::is_trust_scaffold`, which the undo itself asks.

Not changed: `--no-trust-lockfile-config` still pins without the setting
(the reading step does not have the option; it stays a known problem in
the docs), a hub that names a workspace member's lock is not read, and
in memory a `pnpm_version_from` file outside the project's manifests
reads as a release that is not written out.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 24, 2026 03:50
@cursor

cursor Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes hosted-mode rewrite decisions for Bazel/npm workspaces and could leave patches unapplied until users fix MODULE.bazel, but avoids worse build failures and is heavily tested.

Overview
Hosted mode now refuses to rewrite the root pnpm-lock.yaml when aspect_rules_js runs pnpm 11+ during update_pnpm_lock but does not list pnpm-workspace.yaml in hub data, since that pnpm would never see trustLockfile: true and would fail the build on a pinned lock. The run still exits successfully but skips packages as unconfirmed and emits redirect_pnpm_bazel_workspace_hidden with file/line and steps (e.g. list //:pnpm-workspace.yaml in data, add a user comment line so rollback does not delete the file).

A new bazel/pnpm module parses MODULE.bazel to detect these hubs (pnpm version resolution, data shape, scaffold-only workspace files). The hosted engine withholds only the root lock in that case; member locks under sharedWorkspaceLockfile: false continue to pin. In-memory parity loads MODULE.bazel beside the lock.

Docs, CLI_CONTRACT, CI workflow notes, e2e Bazel flows (pnpm 10 vs 11 hubs), and unit/parity tests cover the new behavior and remediation paths.

Reviewed by Cursor Bugbot for commit 92a71c6. Configure here.

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 24, 2026
@mikolalysenko

Mikola Lysenko (mikolalysenko) commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does: In a Bazel workspace where an aspect_rules_js npm_translate_lock has update_pnpm_lock = True, doesn't list pnpm-workspace.yaml in data, and runs pnpm 11 or later, hosted mode now leaves the root pnpm-lock.yaml alone. Until now it pinned the lock, and the next bazel build failed with ERR_PNPM_TARBALL_URL_MISMATCH. Instead the run exits 0, skips those packages and prints one warning (redirect_pnpm_bazel_workspace_hidden) naming the call's file:line and the line to add.

Risk: medium. The change only holds pins back, and only when a project has a root pnpm lock and a matching hub. The worst a wrong reading can do is miss a patch, which the warning explains; it can't break a build that works on main. It does add about 290 code lines of Starlark reading, and the bazel LOC budget goes up from 2486 to 2773.

Look here:

  • bazel/pnpm.rs:137 judge: which calls count, and the cases where the file is listed but still not usable (trustLockfile set to another value, or a bare file that rollback would remove).
  • bazel/pnpm.rs:288 release: follows use_pnpm to its pnpm.pnpm tag; anything it can't follow is treated as pnpm 11 or later.
  • bazel/pnpm.rs:374 picks_an_older_pnpm: the hard-coded rules_js releases whose default pnpm is known to be older than 11 (decision 3 in the description).
  • hosted/engine.rs:1639: the hub is judged before the member locks are read, so a member's own lock is still pinned.
  • hosted/memory/select.rs:185: the in-memory engine now also asks for MODULE.bazel when a pnpm-lock.yaml is present.

Verified:

  • Read the whole product diff. The direction is safe throughout: when the reader isn't sure, it withholds the pin, and it never writes one.
  • The cleanup_side_config refactor behaves the same (is_trust_scaffold is the old comparison, moved).
  • Windows: the path separator is normalised to /, and the scaffold check accepts either line ending.
  • CHANGELOG.md is untouched.
  • No open review threads.
  • CI on 92a71c6: ci-ok and clippy green, all 169 check runs pass, including the npm Bazel legs on 9.3.2, 8.8.2 and 7.7.2.
  • Locally: cargo test -p socket-patch-core --lib bazel::pnpm and the new engine test, 9 passed.

Changes I made: none.

Open questions: decisions 2 and 3 in the description are product calls. Decision 2: a hub that lists a bare pnpm-workspace.yaml is now withheld until the file holds a comment line, so that rollback can't delete it. Decision 3: rules_js releases after 4.0.0-alpha.1 are assumed to pick pnpm 11 or later. Both cost a missed patch, never a broken build. Agreeing with the PR's choices needs no change.


Generated by Claude Code

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[agent] Reviewed pnpm version and settings checks, both planner paths, and rollback ownership of the settings file. The guard leaves the affected root lock untouched.

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 24, 2026
Resolve scripts/loc-budget.json: main raised the bazel group to 2665 and
this branch to 2773 from the same base; the merged tree counts 2952, so
the bazel max is set to that.

Assisted-by: Claude Code:claude-opus-5-5
Merged via the queue into main with commit 447e822 Nov 24, 2026
76 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the bazel-guard/pnpm11-workspace-hidden branch November 24, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants