Skip to content

Route a hosted pnpm lock under a rules_js hub whose build takes a routed lock - #2232

Open
Mikola Lysenko (mikolalysenko) wants to merge 7 commits into
mainfrom
bazel-guard/pnpm-hub-route
Open

Mikola Lysenko (mikolalysenko) wants to merge 7 commits into
mainfrom
bazel-guard/pnpm-hub-route

Conversation

@mikolalysenko

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

Copy link
Copy Markdown
Collaborator

Hosted mode now routes a pnpm lock through the patch's named registry also where an aspect_rules_js hub of a Bazel workspace reads the lock in a shape whose build takes a routed lock, and a hosted scan under --no-trust-lockfile-config no longer writes a pin that the pnpm of such a hub rejects.

Main at e685fb1 is merged in (74e1bbb), and the findings of the code review are applied in one commit on top of it (49438ce): see "Code review" at the end.

The Windows job of in_process_gem_multi_platform overflowed the stack of a test thread on this branch, where it passes on main. A scan builds the future of the hosted flow on its own frame in every mode, and an agent scan that applies a gem in place needs 2,013,673 of the 2,097,152 bytes of such a thread on main already (macOS arm64, debug); this branch had made that future 192 bytes larger, with the answers about Bazel in the files a hosted run reads, and that chain 576 bytes deeper, and it had made a hosted scan 12 to 15 KB deeper with the two passes of a run under the option, boxed in line in rewrite_once. ed9693b holds the answers in a box and builds the two passes off the frame of the rewrite: the gem test needs what it needs on main (2,013,673 bytes; 2,014,841 before), no future of the command-line crate is larger than on main, and the three deepest hosted tests need 7 to 8 KB less than on main. It was not run on Windows, and the gem tests stay as close to the limit as they are on main.

Decisions for the maintainer

  1. Under --no-trust-lockfile-config: withhold, or keep pinning with a warning? This change withholds. Where a hub keeps the lock up to date (update_pnpm_lock), lists pnpm-workspace.yaml in data, runs a pnpm that may be 11 or later, and the file does not already hold trustLockfile: true, a scan with the option writes nothing for the root pnpm lock, exits 0 and warns redirect_pnpm_bazel_workspace_hidden with what to do. Before, it exited 0 with a pin, and the next bazel build failed (ERR_PNPM_TARBALL_URL_MISMATCH). The other choice is to keep the pin and the warning that pnpm 11 rejects it, which keeps a command that exits 0 and breaks the build. The price of withholding: the package stays unpatched in the Bazel build until the option is dropped or the setting is written by hand. A project that is routed already is not withheld: its file holds the route, so the run has nothing to write there and reports the package as applied. Nor is a scan that crawls nothing: it adds no pin, and takes out what a route left as it does on main.
  2. Only a call of five attributes is routed. A routed lock holds the patched release under another version (socket-<id>:1.0.0). A hub whose patches entry is keyed by the package's name and version then names no package, and rules_js fails the build (measured). So the route is taken only where the hub's call passes nothing but the attributes of the calls that were built: name, pnpm_lock, data, update_pnpm_lock, use_pnpm. Every other attribute keeps today's pin, also the ones that most likely change nothing (npmrc, verify_node_modules_ignored), because no build was run with them. Many real hubs have one of those, so say which attributes should be built next to widen the route.
  3. The option still keeps the registries of the route out of the file. --no-trust-lockfile-config opts out of every write to pnpm-workspace.yaml, the route's entries included. That rule is main's and is not changed here. So the option on a hub that would be routed is the withheld case of 1; dropping the option routes it. If the option should only mean "no trustLockfile", that is a separate change for every pnpm project.
  4. A pnpm below 11.20 stays off the route although its first build is the patched one. With the workspace file listed, pnpm 11.19.0 and pnpm 10.34.9 built the routed lock on all three Bazel releases. They do not survive the next change of package.json: pnpm 11.19.0 puts the upstream release back without a word, and pnpm 10.34.9 fails the build. The hub's pnpm has to be stated as a release of 11.20.0 or later: three numbers, no prerelease.
  5. A trustLockfile: false in the listed file still withholds, also where the lock would be routed. A routed lock needs no setting, but that answer is given before the route is planned, as on main, and no build was run with such a file. The warning now says that taking the line out is enough. Say if the route should go ahead there.
  6. Four more limits on purpose. Only a project at the root of the Bazel workspace is routed: no build of a project in a subdirectory was run. Only a project with one pnpm lock is routed: one that keeps a lock per workspace member (sharedWorkspaceLockfile: false) keeps the pin, whichever lock the hub names, because the route records its overrides in every lock and the pnpm of a hub resolves beside the one its call names (new with the review; no build of it was run). A pnpm that only a use of the extension with dev_dependency states does not count: Bazel drops the tags of such a use under --ignore_dev_dependency, and the hub then runs the pnpm that rules_js picks (new with the review; read in Bazel's source at 7.7.2, 8.8.2 and 9.3.2, not built). And the rules_js release is not checked: every build here was on 3.6.0.
  7. The warning code is reused. redirect_pnpm_bazel_workspace_hidden already covers a listed file that hosted mode does not write the setting to; the option is a third reason for the same thing.
  8. A problem that is not new, found on the way. On Bazel 7, a hosted npm pin beside a hub with a patches entry for the package builds the output of the earlier build until bazel clean, and vex says not_affected meanwhile. It is listed as a known problem, and a flow records it. Whether the scan should warn, or vex should not attest there, is for a separate change.
  9. isolate = False is now the use that every module shares (changed with the review). Before, any isolate on the use_extension of the pnpm extension kept the hub on the pin, to keep the reader small. The workspace reader now reads isolate as it reads dev_dependency: False is what Bazel takes it for (read in its source at the three releases), True and a value that is not written out keep the pin. Say if any isolate should keep the pin as before.
  10. The second rewrite under the option is left as it is (review finding 5). Under --no-trust-lockfile-config beside a hub of decision 1, the rewrite runs once without the withhold to learn whether the run ends routed, and again with it when it does not. The cost is one more in-memory rewrite, for that case alone. Deciding it in the route step instead needs a second way to withhold, after the rewriters have run, which is more code than the function of sixteen lines there is (rewrite_told, which is built off the frame of every other rewrite since ed9693b). A guard of about five lines would skip the first run where pnpm-workspace.yaml holds no route at all; say if you want it.

What the code does today

On main (e685fb1), for pnpm 11.20 and later, hosted mode routes each patched release through one named registry of pnpm-workspace.yaml in place of trustLockfile: true. For a lock that an npm.npm_translate_lock hub reads it never does: the project is pinned with trustLockfile: true, and the warning says that a lock that a hub reads is not routed yet. The docs give the reason: no Bazel test builds a routed lock with update_pnpm_lock.

Where a hub keeps the lock up to date with a pnpm 11 that does not see pnpm-workspace.yaml, hosted mode writes nothing and warns redirect_pnpm_bazel_workspace_hidden. That answer does not look at --no-trust-lockfile-config: with the option the lock is pinned without the setting, the command exits 0, and the pnpm that Bazel runs rejects the lock. docs/ecosystems.md lists this as a known problem, measured by hand.

What was measured, and where

On macOS arm64, real Bazel 9.3.2, 8.8.2 and 7.7.2, each with aspect_rules_js 3.6.0, the fixture and the loopback stand-in of the existing npm flows. The routed checkout was written by hosted mode itself. Every pnpm was one that rules_js 3.6.0 holds a checksum for.

Hub Result on the three releases
No update_pnpm_lock Patched build, tarball from the patch host. A build that may update nothing passes right after the scan. A second build changes no file. rollback restores every file and the upstream build.
update_pnpm_lock = True, file in data, pnpm 11.28.10 by pnpm_version, by pnpm_version_from / packageManager, by a use_pnpm label; pnpm 11.20.0 and 12.17.0 by pnpm_version Patched build. The hub's pnpm asks the patch's registry and leaves the lock byte for byte; the build rewrites only the hashes under .aspect/. Before that build a frozen build fails, as after any lock change; after it frozen builds pass. rollback restores the files, and the next build is the upstream one.
The same without the file in data Build fails: ERR_PNPM_MISSING_NAMED_REGISTRY.
The same with pnpm 11.19.0, and with no pnpm stated (rules_js runs 10.34.9) First build patched. After package.json asks for another package (Bazel 9.3.2): 11.19.0 rewrites the lock to the upstream release, 10.34.9 fails with ERR_PNPM_SPEC_NOT_SUPPORTED_BY_ANY_RESOLVER. pnpm 11.20.0, 11.28.10 and 12.17.0 keep the patched release.
No update_pnpm_lock, and a patches entry keyed by the package's name and version, with a routed lock Build fails: Patch file key `…@1.0.0` does not match any npm packages. rollback restores the build.
The same hub with the pin and trustLockfile: true Patched build on Bazel 8.8.2 and 9.3.2. On 7.7.2 the build keeps the earlier output until bazel clean, then it is the patched one; after rollback the same holds the other way.
Today's pin written with --no-trust-lockfile-config Build fails: ERR_PNPM_TARBALL_URL_MISMATCH.
A routed lock, then the scan with --no-trust-lockfile-config Nothing changes, the package is reported applied, the build stays patched.

Nothing here contradicts what main's docs state. No build was added for the review commit: the two shapes it takes off the route keep the pin that main writes for them, and what it says of --ignore_dev_dependency and of isolate is read in Bazel's source (ModuleFileGlobals.useExtension at 7.7.2, 8.8.2 and 9.3.2).

What changes

  • The route under a hub. bazel::pnpm now says of every call that reads a lock whether its build takes a routed lock. Hosted mode routes the lock when the project is at the root of the Bazel workspace, its root pnpm-lock.yaml is its one pnpm lock, and every call that reads it names it in a plain string, passes nothing but name, pnpm_lock, data, update_pnpm_lock and use_pnpm, and is one of two shapes: no update_pnpm_lock (or False); or update_pnpm_lock = True, a written-out data that lists the pnpm-workspace.yaml beside the lock, and a pnpm that the root module states as a release of 11.20.0 or later. The run is then the one of the same project without Bazel, byte for byte. A trustLockfile: true that an earlier run wrote goes as it does outside Bazel.
  • Which pnpm counts as stated, for the route. The release has to be written in full, its repository has to be one of the use of the pnpm extension that every module shares, and no use with dev_dependency may state it. The hub has no use_pnpm, or a use_repo on the name of a proxy of that extension takes the repository. A use_repo on another extension's proxy can take a repository under the name of a pnpm.pnpm tag, a use with isolate = True has tags of its own, an inject_repo on the extension is not read, and the tags of a dev dependency are gone under --ignore_dev_dependency: each keeps the hub on the pin. What hosted mode withholds, and when, is decided as before.
  • Everything else keeps today's pin, and the redirect_pnpm_trust_lockfile warning names what kept the hub off the route: a pnpm_lock that is not written out, a workspace member's own lock, a project below the Bazel root, a project with members' own locks, an attribute no routed lock was built with, an update_pnpm_lock that is not written out, a data without the file, a pnpm that is not stated as 11.20 or later or is not shown to be the one the hub runs in every build. What the reader could not see (a missing include, a WORKSPACE file that brings in rules_js) still blocks the route, also beside a call in one of the two shapes.
  • The option. As in decision 1. The answer is read with the Bazel files and applied in the rewrite, where the option is known, so the in-memory engine gives it too. A run that ends routed is let through. A scan that crawls nothing is not held back by it: it takes out what a route left and no lock uses, as on main. A hub that runs no pnpm, or a pnpm known to be older than 11, is pinned under the option as before.
  • Two warning texts. For a listed file that says trustLockfile: false, redirect_pnpm_bazel_workspace_hidden now says to set it to true or to take the line out. For a run under the option it says to let hosted mode write to pnpm-workspace.yaml, that this run was told not to, and that this is --no-trust-lockfile-config on the command line: the in-memory engine gives the same text to a caller that has no such flag.
  • One reader of proxies, and one read of the files. The workspace reader now tells isolate of a tag's use beside dev_dependency, and lists the use_repo and inject_repo calls that take a proxy, so the hub reader no longer finds them a second way. And one answer about a project reads the pnpm-workspace.yaml beside the lock, the package.json that a tag takes its release from and MODULE.bazel.lock once, where it read them two or three times.
  • Docs. docs/ecosystems.md ("Bazel workspaces: npm", the tested shapes, the known problems), docs/testing/pnpm-compatibility.md and the rows of CLI_CONTRACT.md say what is now true. The known problem of the option is removed from the list, and the Bazel 7 one of decision 8 is added.

Limits

  • Only a project at the root of the Bazel workspace is routed. One in a subdirectory keeps the pin.
  • A hub that names a workspace member's own lock keeps the pin, and so does every hub of a project that keeps a lock per member.
  • A hub whose call has any attribute but the five keeps the pin, as in decision 2.
  • The hub's pnpm has to be stated by the root module, in a way that is read as written out, by a use of the extension that is no dev dependency. A constant, latest, a prerelease, a package.json that is not read, or no tag at all keep the pin, also where the pnpm is in fact new enough. So does a use_repo that takes the repository from the extension call written in place (use_repo(use_extension(...), ...)), and a dev dependency also where the hub itself is one: only the plain forms are followed.
  • A listed pnpm-workspace.yaml has to hold a line of the user's own, as before: one that would hold only what hosted mode writes is left alone, because rollback would delete it under the call that names it.
  • Under the option, a run that would have to add to a route (a new patch for a routed project) writes nothing and warns, and a run that crawls a package and holds no pin for the root lock still gets the warning.
  • In memory, a pnpm_version_from file that is not among the project's own manifests reads as no version, so a lock that a checkout routes can be pinned there.
  • rollback, remove, repair and scan --prune read no Bazel file, as before.

Contents

Four commits of this change and a merge of main. Two commits for the check of a Cargo flow are on the branch as well (bdce0b5, 43a201e).

  1. Tests only (e00c402): three flows on a real Bazel for the hub that lists the workspace file and runs pnpm 11.28.10, one per way of stating that pnpm, and one flow for the option, each recording what main does (the trust pin; the failing build). Two tests without Bazel. npm.rs +283 lines; the header of bazel-npm.yml, whose legs run every npm:: flow.
  2. The change (ab9eb75).
  3. The merge of main at e685fb1 (74e1bbb).
  4. The review commit (49438ce). Implementation +176 / −130 lines, code lines +15: bazel/pnpm.rs +118 / −87 (code +12), bazel/workspace.rs +45 / −27 (code +10), hosted/engine.rs +12 / −12 (code −4), commands/scan/gc.rs +1 / −4 (code −3, the file is main's again). Unit tests in those files +276 / −14. Integration tests +48 / −29. Docs +27 / −12.
  5. The stack commit (ed9693b): hosted/engine.rs +75 / −23 implementation lines (code lines +36) and one unit test, +51 / −1.

The whole branch against main: implementation +512 / −134 lines (code lines +230): bazel/pnpm.rs +352 / −80, bazel/workspace.rs +44 / −26, hosted/engine.rs +99 / −15, hosted/guidance.rs +17 / −13. Unit tests in those files +908 / −91. Integration tests +1063 / −123 (e2e_bazel_build/npm.rs, in_process_redirect_pnpm.rs, hosted_memory_parity.rs, in_process_pnpm_registry_cleanup.rs, e2e_redirect_pnpm_build.rs, and e2e_bazel_build/cargo.rs of the two Cargo commits). Docs +172 / −62. The bazel group of scripts/loc-budget.json goes from 3917 to 4091, the count of the tree.

Existing expectations that changed, because their hub is one that is routed now: the flow npm::hosted_npm_translate_lock and its twin without Bazel; hosted_registry_route_is_not_taken_for_a_lock_a_bazel_hub_reads (rewritten around a hub whose pnpm decides); the unit tests a_lock_that_a_bazel_hub_reads_is_not_routed and a_hub_reads_the_lock_it_names_whatever_else_it_says; and the second half of the real-pnpm leg registry_route_is_left_for_a_bazel_hub_added_later, which now uses a hub that runs pnpm 10. The unit tests that hold the trustLockfile: false advice follow its new words. The full hosted flow on the trust pin is kept as a flow of its own (npm::hosted_npm_translate_lock_on_the_trust_pin).

Expectations that the review commit changed: the row of the hub table for a use that says isolate = False, which is on the route now (decision 9); the reader of a project with a member's lock and no root lock in a_checkout_and_a_project_in_memory_are_told_the_same, which is now the clause about members' own locks; the test of a scan that crawls nothing under the option, which held the withheld cleanup and now holds the cleanup (a_scan_that_crawls_nothing_tidies_beside_a_listing_hub_also_under_the_option, with a hub that hides the file as the case that is still left alone); and the four tests that hold the words of the option's advice.

What it proves, and where

  • Real Bazel 9.3.2 on macOS arm64, the eleven npm:: flows at the head ed9693b: pass (152 s, one Bazel at a time). The four routed flows hold the patched build, the second build that changes no file, the build that may update nothing, rollback to the upstream build, and the VEX documents of the routed build. The flow of the option holds nothing written, the unpatched build passing, the routed build once the option is dropped, and the option again on the routed project. The flow with patches holds the pin, the warning that names the attribute, and the build of the pin.
  • Real Bazel 8.8.2 and 7.7.2: the eleven flows passed at ab9eb75, before the merge and the review commit. They were not run again here; the workflow legs run them.
  • The first commit alone: its tests without Bazel pass, and its nine flows pass on Bazel 9.3.2, on main's product code (run before the merge, not again).
  • With the product files put back to main, eight hermetic tests of the change fail, and so do six of the eleven flows on Bazel 9.3.2 (run before the merge).
  • The review commit: each of its new tests was run against the product code of before and failed there (the dev dependency and the members' own locks were routed, the files were read twice, the scan that crawls nothing warned and left the record, both engines gave the old words). With the product files put back to 74e1bbb under the head's tests, three tests without Bazel fail and so does the flow of the option on Bazel 9.3.2. Nineteen single mutations of the product code, one or more for each new or changed assertion, are each caught by a test.
  • The stack commit: the smallest stack on which a test passes, on main, before the commit and after it (macOS arm64, debug, to about 1 KiB): rollback_all_over_broad_manifest_succeeds of in_process_gem_multi_platform 2,013,673 / 2,014,841 / 2,013,673; of the hosted tests the three deepest, scan_redirect_npm_stale_legacy_bundle_mirror_still_attests 1,722,841 / 1,734,521 / 1,714,665 and redirect_vex_verifies_manifest_patches_normally 1,720,505 / 1,733,353 / 1,713,497 (in_process_redirect), hosted_pnpm_vex_emits_redirected_attestation 1,719,337 / 1,731,017 / 1,712,329 (in_process_redirect_pnpm). None of the 186 tests of those three targets and of in_process_rollback_hosted writes more stack than on main. Five mutations of the commit are each caught by a unit test.
  • Without Bazel, at the head: the unit suite of socket-patch-core (8549 passed, 1 ignored), the hosted pnpm integration targets of the core (92; no file under the core's tests differs from main, so main's golden files for the registry route pass unchanged), nineteen CLI targets that run hosted pnpm (1046 passed, 24 ignored, the real-pnpm legs), in_process_gem_multi_platform (9), e2e_bazel_build without Bazel (69 passed, 36 ignored), the cli target (120), the script tests (423), cargo check of all targets, clippy with -D warnings, the line budget.

Not covered

  • Linux: the flows ran on macOS only. The workflow legs run them on Linux.
  • The real-pnpm leg registry_route_is_left_for_a_bazel_hub_added_later needs a pnpm from Corepack and was not run; an in-process test holds the same files for its changed half.
  • A hub with npm_package_lock, yarn_lock or preupdate, where a pnpm writes the lock anew, and every other attribute beyond the five: no build with a routed lock was run, so they keep the pin.
  • A use_pnpm repository of another extension, an isolated use of the pnpm extension and an inject_repo were not built on a real Bazel: tests without Bazel hold that they keep the pin.
  • A pnpm of a dev dependency under --ignore_dev_dependency, and a project with members' own locks under a hub, were not built on a real Bazel either: tests without Bazel hold that they keep the pin, and the pin of each is main's.
  • A project below the Bazel root, and any rules_js release but 3.6.0: not measured.
  • pnpm 11.28.13 and 12.22.0: rules_js 3.6.0 holds no checksum for them, so no hub could run them.
  • The two failures of an older pnpm after a package.json change were measured on Bazel 9.3.2 only.
  • The Bazel 7 problem of decision 8 was measured with a patches entry; rules_js unpacks a package with lifecycle hooks the same way, which was not measured.
  • The cleanup of a scan that crawls nothing beside a listing hub was not built on a real Bazel: a test without Bazel holds that the lock it leaves is the one without the record, byte for byte, which is the lock of the project before it was routed, and the flows build such a lock.
  • Vendored npm under update_pnpm_lock and WORKSPACE-mode rules_js are not part of this change.

Code review

/code-review high on the draft gave seven findings. Six are fixed in 49438ce; one is left with its reason.

  1. A scan that crawls nothing was held back under the option. Fixed: the cleanup runs as on main. It adds no pin, takes out only what no lock uses, in the lock and in pnpm-workspace.yaml together, and the file that the option's answer is about holds a line of the user's own, so the lock it leaves is one that the hub's pnpm takes. The warning that described a pin is gone for this path; a hub that hides the file is left its lock as before.
  2. A pnpm that a dev dependency states counted for the route. Fixed: a release that a use of the pnpm extension with dev_dependency states (written as True, or not written out) does not count, and the warning names it. The pin is not held to it.
  3. The option's advice told the in-memory engine's caller to drop a flag it does not have. Fixed: the text says what the run was told and what that is called on the command line.
  4. A hub of the root lock was routed in a project with members' own locks. Fixed: more than one pnpm lock keeps the pin, with the reason named.
  5. The rewrite runs twice to learn whether a run under the option ends routed. Not changed in what it does: see decision 10. It is paid by a run under the option beside a hub of decision 1 and by no other; the single-run form needs a second way to withhold after the rewriters have run, which is more code and a second mechanism to keep equal to the first. Where the two passes are built did change (ed9693b): inside rewrite_once they cost every hosted rewrite stack, so they are a function of their own now, behind a pointer.
  6. The pin's answer ran twice and the route read the hub's pnpm again. Fixed: the file beside the lock and the pnpm of each hub are read once and shared by the three answers, and the hubs are listed once. The pin's answer still makes its two passes, over what is read already. About seven more code lines; a test counts the reads.
  7. The hub reader had its own proxy resolution. Fixed: Tag::isolate and Tags::handed in the workspace reader, used by the hub reader: about fifteen fewer code lines there, ten more in the workspace reader. isolate = False is read as the shared use with it (decision 9).

🤖 Generated with Claude Code

…rkspace file

Tests only. They record what hosted mode does today for two cases of a
hub that keeps its lock up to date (`update_pnpm_lock = True`), lists the
user's `pnpm-workspace.yaml` in `data` and runs pnpm 11.28.10. The next
commit changes both.

A registry is offered. The patch service offers the patch's own registry
and the checkout proves pnpm 12, so outside Bazel the lock would be
routed through a named registry. Beside the hub hosted mode pins the lock
with `trustLockfile: true` instead and says the hub is why. Three flows
build that pin on a real Bazel, one for each way a workspace states the
pnpm of a hub that socket-patch reads as written out: `pnpm_version` on
the `pnpm.pnpm` tag, `pnpm_version_from` with the `packageManager` of
`package.json`, and a `use_pnpm` label for the repository of a named
tag. Each ends in the patched build, and `rollback` in the upstream one.

The scan is told not to write the setting
(`--no-trust-lockfile-config`). It exits 0 and pins the lock without
`trustLockfile: true`, and the pnpm that Bazel runs rejects that lock:
the build fails with `ERR_PNPM_TARBALL_URL_MISMATCH` until `rollback`.
This is the known problem that docs/ecosystems.md lists for such a hub,
measured by hand so far; a flow now builds it.

Two tests without Bazel hold the same files and warnings, the second
also for a hub that runs pnpm 10, which has no such check.

The flows ran on Bazel 9.3.2, 8.8.2 and 7.7.2 (macOS) against this
commit's product code. The workflow runs every `npm::` flow of the
target, so its legs pick them up; its header names them.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ted lock

Hosted mode can route a patched pnpm release through a named registry of
pnpm-workspace.yaml in place of `trustLockfile: true`. So far it never
did for a lock that an `npm.npm_translate_lock` hub of a Bazel workspace
reads, because no build had shown what the pnpm of a hub with
`update_pnpm_lock` does with such a lock. And a scan under
`--no-trust-lockfile-config` on such a hub exited 0 with a pin that the
pnpm of the build rejects (`ERR_PNPM_TARBALL_URL_MISMATCH`), a known
problem of docs/ecosystems.md.

What was built, on Bazel 9.3.2, 8.8.2 and 7.7.2 with rules_js 3.6.0
(macOS), with a lock that hosted mode routed:

- A hub without `update_pnpm_lock` builds the patched package. A second
  build changes no file, a `--lockfile_mode=error` build passes right
  after the scan, and `rollback` restores every file and the upstream
  build.
- A hub with `update_pnpm_lock = True`, pnpm-workspace.yaml in `data`
  and pnpm 11.20.0, 11.28.10 or 12.17.0 does the same. Its pnpm asks the
  patch's registry about the package and writes the lock back as it is,
  also after a `package.json` asks for another package. The pnpm was
  stated by `pnpm_version`, by `pnpm_version_from` and by a `use_pnpm`
  label.
- The same hub without the file in `data` fails the build
  (`ERR_PNPM_MISSING_NAMED_REGISTRY`).
- With the file and a pnpm below 11.20 the first build is the patched
  one, but once that pnpm resolves again pnpm 11.19.0 puts the upstream
  release back without a word and pnpm 10.34.9 fails the build
  (`ERR_PNPM_SPEC_NOT_SUPPORTED_BY_ANY_RESOLVER`; Bazel 9.3.2).
- A hub of the first shape with a `patches` entry that is keyed by the
  package's name and version fails the build on a routed lock (`Patch
  file key ... does not match any npm packages`): the lock holds the
  patched release under another version, which the entry does not name.
  The pin keeps the package's key and builds.

So `bazel::pnpm` now says of every call that reads a lock whether its
build takes a routed lock (`Reader::Takes`), and the route is taken
under a hub exactly in the first two shapes: the project is at the root
of the Bazel workspace, the call names the root lock in a plain string
and passes nothing but the attributes those builds had (`name`,
`pnpm_lock`, `data`, `update_pnpm_lock`, `use_pnpm`; no `*` or `**`),
and it either runs no pnpm, or lists the workspace file and runs a pnpm
that the root module states as a release of 11.20.0 or later. Any other
attribute keeps the pin: `patches` for the reason above, and
`npm_package_lock`, `yarn_lock` and `preupdate` because a pnpm then
writes the lock anew, which no build was run for. A prerelease and a
number of fewer than three parts are not such a release. And the stated
release counts for the route only where its repository is one of the
use of the pnpm extension that every module shares: a `use_repo` on
another extension's proxy can take a repository under the name of a
tag, a use with `isolate` has tags and repositories of its own, and an
`inject_repo` on the extension is not read. The pin is not held to
that: what is withheld, and when, is decided as before.

Under such a hub the run is the one of the same project without Bazel,
byte for byte. Everything else keeps today's pin, and the
`redirect_pnpm_trust_lockfile` warning now names what kept the hub off
the route. What the reader may not have seen (a missing include, a
`WORKSPACE` file that brings in rules_js) still blocks the route, also
beside a call in one of the two shapes. A hub whose listed file would
hold only what hosted mode writes is still left alone, so no `rollback`
leaves the call naming a missing file. So is one whose listed file says
`trustLockfile: false`, also where the lock would be routed; the
warning there now says that taking the line out is enough.

`--no-trust-lockfile-config` keeps hosted mode from writing to
pnpm-workspace.yaml: the setting, and the registries of the route too.
Where a hub lists that file, runs a pnpm that may be 11 or later, and
the file does not hold `trustLockfile: true` already, such a run now
writes nothing for the root lock, exits 0 and warns
`redirect_pnpm_bazel_workspace_hidden` with what to do (drop the option,
or set the setting yourself). The code's meaning covers it: the pnpm of
the hub reads a file that hosted mode does not write the setting to.
The build stays the unpatched one that passes. A run that ends routed
is not withheld: in a project that an earlier run routed, whose file
holds the route of every pin, it has nothing to write there and reports
the packages as it does without Bazel. A hub that runs no pnpm or a
pnpm known to be older than 11 is pinned under the option as before.
The answer is read with the Bazel files and applied where the option is
known, in the rewrite, so the in-memory engine gives it too, and a scan
that crawls nothing gives the same warning.

Tests. On a real Bazel the flows now hold the routed build: the hosted
flow of the fixture's hub, which runs no pnpm, and the three flows of
the previous commit, one for each way of stating pnpm 11.28.10 (first
build, second build, the build that may update nothing, `rollback`, the
VEX documents). The hosted flow runs a second time on the pin with
`trustLockfile: true`, for a patch service that offers no registry. The
flow of the option holds nothing written with the unpatched build
passing, then the routed build once the option is dropped, then the
option again on the routed project. A new flow holds the pin beside a
`patches` entry of the hub. Without Bazel: the table of shapes in
`bazel::pnpm`, the engine (the same files as without Bazel, a trust pin
that moves to the route and loses its setting, a second run that
changes nothing, a project that leaves the route when its hub stops
qualifying), the same transitions through the commands with `rollback`,
a scan that crawls nothing, and the in-memory engine against a
checkout.

The flow with `patches` also records a problem that is not new: on
Bazel 7 an output base that built the package keeps that output after
the pin, and after its `rollback`, until `bazel clean`. For a package
with a `patches` entry rules_js hands the build a directory it unpacked
at fetch time, and Bazel 7 does not look into a source directory.
docs/ecosystems.md lists it.

Existing expectations that changed, because their hub is one that is
routed now: the flow `npm::hosted_npm_translate_lock` and its twin
without Bazel (`a_lock_that_a_hub_reads_stays_on_the_trust_pin_...`,
renamed), which held the trust pin beside the fixture's hub;
`hosted_registry_route_is_not_taken_for_a_lock_a_bazel_hub_reads`
(in_process_redirect_pnpm; rewritten around a hub whose pnpm decides);
the unit tests `a_lock_that_a_bazel_hub_reads_is_not_routed` (split in
two) and `a_hub_reads_the_lock_it_names_whatever_else_it_says`
(replaced by the table); and the second half of the real-pnpm leg
`registry_route_is_left_for_a_bazel_hub_added_later`, which now uses a
hub that runs pnpm 10. That leg needs a pnpm from Corepack and was not
run here; an in-process test holds the same files. The unit tests that
hold the `trustLockfile: false` advice follow its new words.

The loc budget of the `bazel` group follows the tree.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Main brought vendored mode for a Maven patch of a pinned
rules_jvm_external hub. One conflict: the line cap of the `bazel` group,
which is the count of the merged tree, 4069.

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

The route through named registries is taken under a rules_js hub only in
shapes whose build was run with a routed lock. Two shapes that no build
was run for were taken all the same, and the answer for
`--no-trust-lockfile-config` reached one command that pins nothing.

A pnpm that a dev dependency states. `use_extension(...,
dev_dependency = True)` makes a proxy whose tags Bazel drops under
`--ignore_dev_dependency` (`ModuleFileGlobals.useExtension` at 7.7.2,
8.8.2 and 9.3.2). A hub whose pnpm 11.28.10 was stated on such a proxy
was routed, and a build under that option runs the pnpm that rules_js
picks instead, a pnpm 10 at 3.6.0, which builds a routed lock only until
it resolves again (measured for this branch: once a `package.json` asks
for another package the build fails). A release that a use with
`dev_dependency` states, written as `True` or not written out, no longer
counts for the route, and the warning names that. The pin is not held
to it: its setting is in the file the hub lists, for whichever pnpm
asks for it.

More than one lock. A hub of the root lock was taken for the route also
in a project that keeps a lock per workspace member
(`sharedWorkspaceLockfile: false`). The route records its overrides in
every lock of the project, and the pnpm of a hub resolves in a directory
that holds the one lock its call names. Such a project keeps the pin
now, whichever of the two shapes its hub is in, and the warning says so.

A scan that crawls nothing. Under `--no-trust-lockfile-config` it was
kept from taking out what a route left, beside a hub that lists
pnpm-workspace.yaml and runs a pnpm 11, and warned that `bazel build`
would fail on a lock that it had not rewritten. That answer is about a
pin which the pnpm of the hub would reject, and this scan adds none: it
takes out what no lock uses, in the lock and in the file together, and
the file it is about holds a line of the user's own. It tidies again as
it does on main, and says nothing of the hub. A hub that hides the file
is left its lock as before, which the test of this path now holds too.

The words of that warning. Core gives it to the in-memory engine as
well, whose caller has no `--no-trust-lockfile-config` to drop. It now
says to let hosted mode write to pnpm-workspace.yaml, that this run was
told not to, and what that is called on the command line.

One read for the three answers. Every hosted scan asked the question of
the pin twice, for a run that writes the setting and for one that does
not, and the route's answer read the pnpm of the hub again. So
pnpm-workspace.yaml, the `package.json` that a tag takes its release
from and `MODULE.bazel.lock` were read and parsed two or three times a
scan. The file beside the lock and the pnpm of each hub are now read
once, when the first answer asks for them, and the hubs are listed once.
A test counts the reads.

One reader of proxies. The hub reader had its own way of finding the
`use_repo` and `inject_repo` calls of a proxy and the `use_extension`
behind a tag, beside the one of the workspace reader. `Tag` now carries
`isolate` beside `dev_dependency`, and `Tags::handed` lists the calls
that take a proxy by its name, so the hub reader asks the workspace
reader. One reading changes with it: `isolate = False` is the use that
every module shares, as Bazel takes it and as `dev_dependency = False`
is read, where any `isolate` used to keep the hub on the pin. An
`isolate` that is not written out still does.

Existing expectations that changed: the row of the hub table for a use
that says `isolate = False` (now on the route); the reader of a project
with a member's lock and no root lock in
`a_checkout_and_a_project_in_memory_are_told_the_same` (now the clause
about several locks); the test of a scan that crawls nothing under the
option, which held the withheld cleanup and is rewritten around the
cleanup; and every test that holds the words of the option's advice.

Not built on a real Bazel: a pnpm of a dev dependency under
`--ignore_dev_dependency`, and a project with members' own locks under a
hub. Both keep the pin that main writes for them.

The loc budget of the `bazel` group follows the tree.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…gnore line

`cargo::vendored_from_cargo_with_config` comments out the line the scan
wrote in `.bazelignore` and expects `bazel cquery //...` and
`bazel query 'deps(//...)'` to fail on a repository that the main
repository does not see. It looked for the hub's repository
(`@crates__...`) alone. The build file that cargo-bazel writes into the
committed copy names `@platforms` as well, and Bazel reports the first one
it meets: on a Linux runner with Bazel 9.3.2 the query named `@platforms`
and the flow failed on its own check.

The flow now takes either name for that failure. Test only: nothing the
command does changes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The check of the commands that fail once the ignore line is commented out
now reads the name out of Bazel's message and takes it only when the
message is about the main repository's view: `platforms`, or a repository
of the crate hub. The same words about another repository's view, or
about another name, are a different failure and no longer pass for the
expected one. A test without Bazel holds the check to the two messages
that were seen and to three it must not take.

The module docs, the comment at the call and the section on the build
file in a vendored crate said the commands end on the dependency's
repository alone. They now name `platforms` as well, which is what a
user who comments the line out can see.

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

cursor Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes when and how pnpm lockfiles and pnpm-workspace.yaml are rewritten for Bazel/rules_js consumers; mistakes would break installs or leave builds unpatched, but behavior is heavily covered by new e2e and integration tests.

Overview
Hosted pnpm mode no longer forces every aspect_rules_js npm_translate_lock hub onto the trustLockfile: true pin. When the hub’s call matches a built, supported shape (plain lock path; only name, pnpm_lock, data, update_pnpm_lock, use_pnpm; either no update_pnpm_lock or update_pnpm_lock = True with pnpm-workspace.yaml in data and root-module pnpm ≥ 11.20 stated in a readable way), scans route the lock through Socket named registries like a non-Bazel project—no Bazel warning, byte-aligned outputs.

Hubs that don’t qualify (extra attributes such as patches, pnpm < 11.20, missing workspace in data, member locks, dev-only pnpm extension uses, unreadable MODULE.bazel, etc.) still get the trust pin, with redirect_pnpm_trust_lockfile / redirect_pnpm_bazel_workspace_hidden text naming why routing was skipped.

--no-trust-lockfile-config: beside an updating hub that would reject an unpinned lock, hosted scans withhold root lock/workspace writes and warn how to fix (drop the flag or set trustLockfile manually). Projects already routed or scans that crawl nothing behave as on main (re-apply / GC without adding a bad pin).

Bazel workspace parsing gains isolate on extension tags and tracks use_repo / inject_repo handoffs for pnpm hub detection; duplicate file reads are consolidated.

CI/docs and e2e Bazel npm tests expand: routed vs trust-pin flows, update_pnpm_lock + registry, --no-trust-lockfile-config, and hub patches edge cases.

Reviewed by Cursor Bugbot for commit 43a201e. Configure here.

@mikolalysenko Mikola Lysenko (mikolalysenko) added Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review and removed Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review labels Nov 25, 2026
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

Not ready yet: a Windows run of this branch (workflow dispatch, os=windows) overflows the stack of one in-process test, in_process_gem_multi_platform, which passes on main and on the other open branches. The required checks do not include that job, so they are green. A fix is in progress; please hold review until the label is back.

A scan is one large async function, and a debug build builds every
future on the poll frame of the function that awaits it, also in a
branch that is not taken. The scan awaits the hosted flow in line, so
the size of that flow's future is stack for a scan in every mode. An
agent scan that applies a gem in place needs 2,013,673 bytes of the
2 MiB a test thread has on main (macOS arm64), and the Windows job of
`in_process_gem_multi_platform`, which passes on main, overflowed on
this branch.

Two things of this branch were in that size.

The answers about a Bazel workspace (`bazel::pnpm::Hubs`) grew from 80
to 144 bytes, with the answer for `--no-trust-lockfile-config` and the
reason a hub is off the route, and the files a hosted run reads hold
them by value (`CandidateFiles::pnpm_bazel`). The hosted flow keeps
three copies of those files, so its future grew by 192 bytes, the poll
frame of the scan by 384 and the frame that builds the scan's future
by 192: 576 bytes more on that chain on macOS arm64. The files now hold
the answers in a box, and are 72 bytes smaller than on main.

The two passes of a run under `--no-trust-lockfile-config` were a
recursion inside `rewrite_once`, boxed in line. The future of the inner
pass was built on the frame of every hosted rewrite, with the option or
without, and the clone of the files it takes stayed in the future of
every pass (3,024 to 3,608 bytes, and `rewrite` from 5,488 to 6,200),
which the hosted flow builds on its own frame in turn: a hosted scan
needed 12 to 15 KB more stack than on main. `rewrite_once` is main's
again. The two passes are a function of their own, `rewrite_told`, and
`rewrite_pass`, which is no `async fn`, builds and boxes it on a frame
that is gone before anything is polled: a pass is `rewrite_once` or
that pointer. What a run does is unchanged.

The smallest stack on which a test passes (macOS arm64, debug, to about
1 KiB), on main, before this commit and after it:

- in_process_gem_multi_platform,
  rollback_all_over_broad_manifest_succeeds:
  2,013,673, 2,014,841, 2,013,673
- in_process_redirect,
  scan_redirect_npm_stale_legacy_bundle_mirror_still_attests:
  1,722,841, 1,734,521, 1,714,665
- in_process_redirect, redirect_vex_verifies_manifest_patches_normally:
  1,720,505, 1,733,353, 1,713,497
- in_process_redirect_pnpm,
  hosted_pnpm_vex_emits_redirected_attestation:
  1,719,337, 1,731,017, 1,712,329

No future of the command-line crate is larger than on main now
(`-Zprint-type-sizes`), and no test of those three targets or of
in_process_rollback_hosted writes more stack than it does on main; the
gem tests write 640 bytes less. A unit test holds the two sizes: the
files hold the answers behind one pointer, and a pass is no larger than
`rewrite_once` and a pointer.

Not run on Windows. The gem tests stay as close to the limit as they
are on main, because the future of the hosted flow is still built on
the frame of the scan.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 25, 2026
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

The stack overflow is fixed in ed9693b: a Windows run of this head passes test (windows-latest, 2), the job that failed. The two Windows jobs that still fail there are the ones main fails (seven pnpm unit tests on fixtures that the Windows checkout converts to CRLF, and one pnpm end-to-end test). Ready for review again.

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.

1 participant