Skip to content

Leave a hosted gem alone while a rules_ruby hub holds it to another sha256 - #2210

Merged
Mikola Lysenko (mikolalysenko) merged 7 commits into
mainfrom
bazel-guard/gem-checksums-hosted
Nov 24, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 7 commits into
mainfrom
bazel-guard/gem-checksums-hosted

Conversation

@mikolalysenko

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

Copy link
Copy Markdown
Collaborator

In a Bazel workspace, scan --mode hosted and get --mode hosted now leave a gem alone while a rules_ruby ruby.bundle_fetch call holds it to another sha256 in gem_checksums, and say how to go on, where they used to exit 0 and break the next bazel build.

Based on main, in three commits: tests that record what main does today, the change, and the fixes of a code review (the last section).

Decisions for the maintainer

  1. An unreadable part of MODULE.bazel does not withhold. Only a call that is read can. The alternative, to withhold every gem of a workspace with an unreadable part, is safer for the build and takes hosted mode from workspaces it patches today.
  2. A gem_checksums that is not written out withholds, also when it does not name the gem. That shape builds patched today; it loses the redirect until the dict is written out in the call.
  3. A second hub that reads the same lock and holds the gem withholds it for the project, even where the built targets use the hub without the entry. That shape builds patched today as well.
  4. A WORKSPACE call counts on every Bazel release, also where Bazel no longer reads the file, unless a tag of MODULE.bazel names the lock in a plain string. Beside such a tag the file is taken for a leftover of a migration and is not looked at, although Bazel 7 reads both files: a workspace whose targets use the hub of the WORKSPACE file, with an upstream entry there, is still pinned and its build still fails. Counting the call there would withhold the gem in a workspace that only kept the file through a migration, which builds patched today.
  5. rollback after a changed entry. This change only says so, in the warning and in the docs. rollback could warn, or put the old sha256 back; both mean reading, or editing, the call from rollback.
  6. The warning offers deletion of the entry where the lock has CHECKSUMS. It trades Bazel's check of the gem for Bundler's. Dropping the offer leaves one way on.
  7. A pin left by an earlier release stays applied, and --vex still attests it. Only the warning tells the truth about that build. Reporting it as broken, in the event or in VEX, means reading the call where the pin is confirmed and where the document is written, which this change does not do.

What the command does today

rules_ruby's ruby.bundle_fetch downloads every gem of its gemfile_lock with Bazel's downloader. Its gem_checksums = {"<name>-<version>": "<sha256>"} gives Bazel a sha256 for each gem it names, whatever the lock says. A build of the hub prints the dict to add, so many workspaces have one that names every gem.

Hosted mode points a gem at the patch registry in Gemfile and Gemfile.lock and puts the sha256 of the patched gem in the lock's CHECKSUMS section. It does not touch MODULE.bazel. Beside a call that names the upstream gem's sha256:

  1. socket-patch scan --mode hosted --yes exits 0 and reports the gem applied.
  2. The next bazel build fails. Bazel takes the upstream gem from its repository cache under the sha256 of the call, and Bundler refuses it (Bundler found mismatched checksums). With an empty repository cache Bazel refuses the patched gem itself (Checksum was ... but wanted ...). With a lock that has no CHECKSUMS section the build can also pass, on the upstream gem.

The first commit holds 1 and 2 in a test on real Bazel.

What changes

Hosted mode writes nothing for a gem when a ruby.bundle_fetch call that may read the project's lock

  • holds a build of that gem (<name>-<version>, or <name>-<version>-<platform>) in gem_checksums to another sha256 than the patched archive has, or
  • has a gem_checksums that is not written out as a dict of strings (a constant, an expression, a ** argument).

No source: option, no change to the lock. The gem is skipped (redirect_unconfirmed), the run exits 0 as for any other gem hosted mode does not pin, the other gems of the run are rewritten as before, and one warning per gem, redirect_bazel_gem_checksums_pinned, names the call by file and line, the entry, and the way on (and, where more than one call holds the gem, the others):

Warning: sp-victim@1.0.0: `ruby.bundle_fetch` at MODULE.bazel:15 holds `sp-victim-1.0.0` to another sha256 in `gem_checksums` than the patched gem has, so the next Bazel build would fail on the patched gem or keep the upstream one; redirect skipped (nothing rewritten). To patch it, change `sp-victim-1.0.0` to `<sha256 of the patched gem>` there, or delete the gem from the dict (Bundler holds it to the CHECKSUMS section of Gemfile.lock), and re-run the hosted scan. A later `rollback` does not touch the call: put the old sha256 back in a changed entry then

The two ways on were measured on Bazel 9.3.2 before they went into the warning:

  • The patched sha256 in the entry. The same scan then pins the gem and the build takes the patched one, which Bazel holds to that sha256. Always offered.
  • The gem deleted from the dict. The build then takes the patched gem too, and Bundler still holds it to the lock's CHECKSUMS line (other bytes at the patch registry fail the build). Offered only for a lock that has the section: without it nothing would hold the gem to a sha256.

The build after either changes no file of the checkout, Bazel's own lock included. A dict that names only other gems builds patched, so only an entry for the gem itself counts. An entry is compared with the patched sha256 without regard to case, as Bazel reads one. socket-patch does not edit the call.

A pin that an earlier release wrote beside such an entry, which is the state of a checkout this defect already broke, stays as it is, under whatever address the patch registry had for the gem then. The gem is still reported applied, because the pin is in the lock, and the warning says what is true there:

... so the next Bazel build would fail on the patched gem or keep the upstream one; the pin an earlier run wrote is left as it is (nothing rewritten). To build it patched, change `sp-victim-1.0.0` to `<sha256 of the patched gem>` there, or delete the gem from the dict (Bundler holds it to the CHECKSUMS section of Gemfile.lock), and re-run the hosted scan; or take that pin out with `socket-patch rollback`. A later `rollback` does not touch the call: put the old sha256 back in a changed entry then

Nothing changes for a project in no Bazel workspace, for one whose lock no call may read, beside a call without gem_checksums, for a dict that does not name the gem, and for an entry that already holds the patched sha256 or is an empty string. In a checkout without a Bazel workspace, beside a hub that reads another lock, beside a hub without gem_checksums, beside a dict that names only the other gem, and beside an entry that holds the patched sha256 in lower or upper case, a dry run, a scan and a rollback of this binary and of one built from the base gave the same exit codes, output and files, byte for byte.

What an uncertain reading does

Nothing is evaluated, and one rule decides: what is seen of a call that may hold the gem to another sha256 withholds the redirect, because a build that fails outranks a patch that is missed and explained; what is not seen changes nothing.

  • A call in a comprehension or a condition may run: it counts.
  • A gemfile_lock that is no label in a plain string may be this lock: the call counts. A call that names another file does not.
  • A gem_checksums that is not written out may name the gem: the gem is left alone, and the warning says to write the dict out.
  • Every call that may read the lock counts, whichever hub the built targets use.
  • A part of MODULE.bazel that cannot be read (an include that cannot be followed, a bazel_dep whose name is an expression) can hide a call. It is not looked at: where no call that is read may read the lock, hosted mode writes as before. Withholding there would take hosted mode from every gem of such a workspace, also where no rules_ruby hub reads the lock.
  • rb_bundle_fetch in a WORKSPACE file counts like the tag unless a tag of the module files names the lock in a plain string. Beside such a tag the file is taken for a leftover of a migration, so that shape stays one hosted mode patches. In that file @<name>// is the main repository for the name workspace(name = ...) gives.

Two shapes that built the patched gem before are left alone by this rule (measured on Bazel 9.3.2): a constant that does not name the gem, and a second call on the same lock that holds the gem while the built target uses the hub of the call without the entry. No pin is taken out of a checkout, and the way on that the warning names ends, in both, in a shape the test builds patched.

Contents

Lines
crates/socket-patch-core/src/bazel/ruby.rs (new): the calls that may read the lock, and whether one stands against a gem +245 implementation (139 of code), +348 unit tests
hosted/engine.rs: hands the calls to the gem rewriter, from the checkout and from files in memory +30, +75 tests
hosted/memory/select.rs: asks for the workspace's files beside a gem lock +10, +37 tests
patch/redirect/mod.rs: the gem rewriter asks before it takes a gem's plan, and says whether an earlier run pinned the gem +26 -5, +84 tests
bazel/mod.rs, bazel/workspace.rs +2 -1
tests/e2e_bazel_build/ruby.rs: the real-Bazel flow and two tests without Bazel +496 -46
tests/hosted_memory_parity.rs: the checkout against the in-memory engine +59
docs/ecosystems.md, CLI_CONTRACT.md +111 -14
.github/workflows/bazel-ruby.yml (one comment), scripts/loc-budget.json +6 -4

No fixture file is added: the flow edits MODULE.bazel in its workspace copy, because the sha256 of a gem is new for every run. The table is the first two commits; the third (the review's fixes) is +229 −76 in six files, most of it unit tests of bazel/ruby.rs. The cap of the bazel group in scripts/loc-budget.json follows the count, 2,486 to 2,660.

What it proves, and where

  • On real Bazel (ruby::hosted_bundle_fetch_gem_checksums, in the legs of bazel-ruby.yml: Bazel 9.3.2, 8.8.2 and 7.7.2, rules_ruby 1.0.0-rc2): the scan leaves the gem alone and changes no file; the same build passes on the upstream gem and nothing asks the patch registry; with the sha256 of the warning in the entry the same scan pins the gem, the build prints the patched marker and changes no file, and vex attests it; rollback restores the two files and leaves the call, the one file that still differs, and with the old sha256 back everything is as before; with the gem deleted from the dict the same scan pins it and the build prints the patched marker and changes no file. Locally both ruby flows passed on the three releases on macOS arm64.
  • Without Bazel (in the same target, on every pull request): the same steps through the binary, what a person reads, --dry-run, --vex, a lock without CHECKSUMS, a dict that is not written out, and the calls that stand against nothing, whose rewritten files equal those of a checkout without MODULE.bazel. Over a pin left by an earlier release: the gem is applied, the warning has the text for a pin that stays, nothing is changed, and rollback takes the pin out.
  • Checkout against the in-memory engine (parity_gem_checksums_of_a_bazel_hub_through_selection): the same warning and the same files, with the engine given what path selection asks for.
  • Unit tests of the calls that count (labels, a lock below the root, included files, another ruleset's tag, the WORKSPACE cases, an unreadable part), of the warning's texts, of a sha256 in upper case, of a pin under an older address of the patch registry, and of the rewriter and the engine.
  • With the check taken out at its call site, the unit tests, the tests without Bazel and the parity test fail; the flow failed the same way on Bazel 9.3.2 before the last corrections, which did not touch those assertions.

Not covered

  • Where the call is not read, the old defect remains: the scan pins the gem as before and the build fails as before. That is a call of another Bazel module, a macro of a .bzl file that makes the call, rb_bundle_fetch loaded under another name, an rb_bundle_fetch of the WORKSPACE file beside a tag that names the lock (decision 4), a part of MODULE.bazel that cannot be read, a label that spells the lock's name in another case, and what the command line or an rc file tells Bazel. The docs keep it in the list of known problems, with the way out.
  • rollback and remove do not touch the call either. After one of them an entry that was changed by hand still holds the sha256 of the patched gem, and the build fails until the old value is back (measured on 9.3.2). The docs list this as a known problem too.
  • A pin that an earlier release wrote beside such an entry is still reported applied and still attested by --vex, because the pin is in the lock; only the warning tells the truth about the build.
  • With --vex, a run that leaves its only gem alone has nothing to attest and exits 1 (manifest_not_found), like any run that pins nothing.
  • The in-memory engine reads the calls only where the project's directory is the Bazel root, and only from workspace files that are files of the repository themselves: a project below the root is not given the workspace's files there, and a MODULE.bazel or WORKSPACE that is a symbolic link is not read. Both are rewritten as before. On disk, three projects are not covered either: one below a workspace root that is in no git checkout, one that is a git checkout of its own below the Bazel root (a submodule), and one whose directory the call names through a symbolic link. The first two are the bounds of the lookup every Bazel lane of main uses for the workspace's root.
  • No test builds a WORKSPACE hub (its failing build was measured by hand on Bazel 7.7.2 with rules_ruby 0.21.1), a gem that is only a dependency of another gem, or a platform gem under Bazel; those have unit tests of the same check.

Code review

Ten findings, each read against the code. Six are fixed in the third commit, and a unit test fails without each of the first five (four checked by taking the fix out again):

  • A WORKSPACE label through the workspace's own name. rb_bundle_fetch(gemfile_lock = "@shop//:Gemfile.lock") beside workspace(name = "shop") was read as a lock of another repository, so the call did not count, the gem was pinned and the Bazel 7 build failed. The name that file gives the main repository is now read; under a name that is not written out any repository may be the main one.
  • A tag that only may read the lock hid the WORKSPACE file. A tag whose gemfile_lock is not written out is no sign of a leftover. Only a tag that names the lock in a plain string hides the file now.
  • An empty entry withheld the gem. rules_ruby gives Bazel no sha256 for an empty string (if sha256: in _download_gem), so it holds nothing.
  • The warning named one call. Where several calls hold the gem it now names the others too, so one round of edits is enough.
  • Path selection for the in-memory engine asked for the files of a Bazel workspace beside any gem lock, also in a run that leaves gem out. It asks only when gem is selected.
  • The calls were parsed once for every gem. The rewriter parses them once.

Not fixed, with the reason:

  • An rb_bundle_fetch beside a tag that names the lock is still not looked at. It is decision 4 above, and the docs list it under what is not seen.
  • A pin of an earlier release beside a stale entry is still applied and attested by --vex. It is decision 7: judging it is the VEX step's, where a hosted gem would be held to its gem_checksums entry.
  • A project named through a symbolic link, or one that is a checkout of its own. The lock is compared by the path its directory really has, under the bounds of the lookup for the Bazel root that every Bazel lane of main shares. Widening it belongs in a change of that lookup; the docs now name both.
  • A workspace file that is a symbolic link, in the in-memory engine. The engine is given no text for it. The docs name it.
  • What bazel/ruby.rs repeats of bazel/built.rs (the hub's identity, a label's path, the project's path from the root). Another open pull request, Decline PyPI and RubyGems vendored mode where a Bazel hub reads the lock #2208, rewrites those parts of built.rs and adds the path helper; sharing them here would only make the two conflict, so it is left to whichever lands second.
  • The plan is built before the check and then dropped. The check sits behind the planner on purpose, so that a gem the planner refuses keeps that reason's warning alone.

At the head of the third commit: cargo check on all targets, both clippy runs with -D warnings, the whole core unit suite (8,380), the golden targets, the CLI targets that exercise the gem rewriter and the in-memory engine, the script tests and the line budget pass, and both ruby:: flows pass on real Bazel 9.3.2. Bazel 8.8.2 and 7.7.2 were not rerun after the review; the legs of bazel-ruby.yml run them. Two tests of e2e_redirect_gem_stale_install fail under a BUNDLE_USER_HOME of the environment, as they do on main, and pass without it.


Generated by Claude Code

…cksums

A `ruby.bundle_fetch` call can hold gems to a sha256 of its own:
`gem_checksums = {"<name>-<version>": "<sha256>"}`. rules_ruby gives that
sha256 to Bazel's downloader for the gem, whatever `Gemfile.lock` says, and
a build of the hub prints the dict to add (Bazel's hint for a reproducible
repository). The existing flow `ruby::hosted_bundle_fetch` covers a call
without one.

This adds the flow `ruby::hosted_bundle_fetch_gem_checksums` on real Bazel:
the fixture's workspace with a `gem_checksums` on the call that names the
two gems at the sha256 of their upstream archives. It holds what the
command does there today:

- `scan --mode hosted --yes` exits 0 and reports the gem applied. It
  rewrites `Gemfile` and `Gemfile.lock`, with the sha256 of the patched gem
  in the lock's `CHECKSUMS` section, and leaves the call as it was.
- The same `bazel build` then fails. Bazel takes the upstream gem from its
  repository cache under the sha256 the call names (the patch registry is
  not asked once), and Bundler, in the `bundle install` action of the
  build, reports mismatched checksums: the lock's sha256 of the patched
  gem against the one of the upstream archive.

So the command exits 0 and leaves a build that fails. The next commit
changes the command, and this flow's expectations with it.

The test edits `MODULE.bazel` in its workspace copy, because the sha256 of
a gem is new for every run; the fixture and the existing flow's steps are
as they were. The stand-in setup of that flow moved into a helper that
both flows start with.

Measured on Bazel 9.3.2 with rules_ruby 1.0.0-rc2 on macOS arm64.

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

rules_ruby gives Bazel's downloader the sha256 that a `ruby.bundle_fetch`
call names for a gem in `gem_checksums`, whatever `Gemfile.lock` says. Hosted
mode points the gem at the patch registry and records the sha256 of the
patched archive in the lock, and never edits the call. So beside a call
that names the upstream archive's sha256, `scan --mode hosted` exited 0,
reported the gem applied, and the next `bazel build` failed: Bundler found
mismatched checksums, or, with an empty repository cache, Bazel refused the
download. With a lock that has no `CHECKSUMS` section the build could also
pass on the upstream gem. The previous commit holds that in a test.

Hosted mode now reads the calls and writes nothing for such a gem: no
`source:` option, no change to the lock. The gem is `skipped`
(`redirect_unconfirmed`), the run exits 0 as for any other gem hosted mode
does not pin, the other gems of the run are rewritten as before, and one
warning per gem, `redirect_bazel_gem_checksums_pinned`, names the call by
file and line, the entry, and the way on:

- change the entry to the sha256 of the patched archive, which the warning
  gives; or
- where the lock has a `CHECKSUMS` section, delete the gem from the dict:
  Bundler then holds the gem to that section, as in a workspace without
  `gem_checksums`. Not offered for a lock without the section, where
  nothing would hold the gem to a sha256.

Both were measured on Bazel 9.3.2 before they were written into the
warning, and the flow does both on 9.3.2, 8.8.2 and 7.7.2 (rules_ruby
1.0.0-rc2): after either, the same scan pins the gem, the build is the
patched one and it changes no file of the checkout. A dict that names only
other gems builds patched, so only an entry for the gem itself counts. An
entry is compared with the sha256 of the patched archive without regard to
the case of its letters, as Bazel reads one (`Checksum.java`: any hex
digits, lowered).

What is read. `bazel/ruby.rs` asks the reader of the workspace files for
the `bundle_fetch` tags of the rules_ruby `ruby` extension, under whatever
name the file gives the proxy, and keeps the calls that may read the
project's lock and have a `gem_checksums`. The hosted engine hands them to
the gem rewriter under a synthetic key, as it hands the Maven hub's state,
and the rewriter asks before it takes the plan of a gem, so a gem that is
refused for another reason keeps that refusal alone.

What an uncertain reading does. Nothing is evaluated, and one rule decides:
what is seen of a call that may hold the gem to another sha256 withholds
the redirect, and what is not seen changes nothing.

- A call in a comprehension or a condition may run: it counts.
- A `gemfile_lock` that is no label in a plain string may be this lock: the
  call counts. A call that names another file does not.
- A `gem_checksums` that is a constant, an expression or a `**` argument
  may name the gem: the gem is left alone, and the warning says to write
  the dict out.
- Every call that may read the lock counts, whichever hub the built
  targets use.
- The doubts of the reader (an include it cannot follow, a name that is an
  expression) can hide a call. They are not looked at: where no call that
  is read may read the lock, hosted mode writes as on main. Withholding
  there would take hosted mode from every gem of such a workspace, also
  where no hub reads the lock, and a patch that works today is not to be
  taken away for a call nobody has seen.
- `rb_bundle_fetch` in a `WORKSPACE` file counts where no tag of the module
  files may read the lock. No test builds such a hub; its failing build
  was measured by hand on Bazel 7.7.2 with rules_ruby 0.21.1. Beside a tag
  that may read the lock the file is a leftover of a migration, and the gem
  stays one that hosted mode patches.

Two shapes that built the patched gem before are left alone by this rule
(measured on 9.3.2): a constant that does not name the gem, and a second
call on the same lock that holds the gem while the built target uses the
hub of the call without the entry. No pin is taken out of a checkout, and
the way on that the warning names ends, in both, in a shape the flow
builds patched.

Nothing changes for a project in no Bazel workspace, for one whose lock no
call may read, beside a call without `gem_checksums`, and for an entry that
holds the patched sha256: in a project without a Bazel workspace, beside a
hub that reads another lock and beside one without `gem_checksums`, a dry
run, a scan and a rollback of this binary and of one built from the parent
of this branch give the same exit codes, output and files, byte for byte.

The in-memory engine gives the same answer where it has the files: the
project's directory is the Bazel root, and path selection now asks for
`MODULE.bazel`, the `*.MODULE.bazel` files it can include and the
`WORKSPACE` names beside a gem lock. A parity test holds the checkout and
the engine to the same warning and the same files. A project below the
Bazel root is not given the workspace's files in memory and is rewritten
as before.

Not covered, and said in the docs: `rollback` and `remove` do not touch the
call either, so an entry that was changed by hand goes back by hand (the
build fails on it until then: measured on 9.3.2); a pin that an earlier
release wrote beside such an entry stays, under whatever address the patch
registry had for the gem then, and is still reported as applied because it
is in the lock. Its warning says that the pin is left as it is, in place
of a redirect that was skipped, and names `rollback` as the other way out.
With `--vex` a run that leaves its only gem alone has nothing to attest
and exits 1, like any run that pins nothing. A call of another Bazel
module, a macro that makes the call, and the rule loaded under another
name are not seen: there the scan pins the gem as before and the build
fails as before, which the docs keep as a known problem.

docs/ecosystems.md: the RubyGems cell of the Bazel table, the list of what
it was tested with, the known problems (now the rollback after a changed
entry, and a gem that a call which is not read holds) and a section "Bazel
workspaces: RubyGems". CLI_CONTRACT.md: the row of the warning.
bazel-ruby.yml: the sentence of its header about the repository cache,
which the new flow uses for gems of its own run. scripts/loc-budget.json:
the cap of the bazel group follows the count, 2486 to 2626.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…l that holds a gem

A review of the change that leaves a hosted gem alone beside a
`gem_checksums` entry found two ways a run could still pin a gem that a
call holds, and four places where the check did more or less than it
should:

- `rb_bundle_fetch(gemfile_lock = "@shop//:Gemfile.lock")` in a `WORKSPACE`
  file that says `workspace(name = "shop")` names the root's lock. It was
  read as a lock of another repository, so the call did not count, the gem
  was pinned and the Bazel 7 build failed on the checksum. The name that
  file gives the main repository is now read; under a name that is not
  written out any repository may be the main one.
- A tag whose `gemfile_lock` is not written out hid every `rb_bundle_fetch`
  of the `WORKSPACE` file, although it is no sign that the file is a
  leftover of a migration. Only a tag that names the lock in a plain string
  does that now.
- An entry that is an empty string withheld the gem. rules_ruby gives Bazel
  no sha256 for it (`if sha256:` in `_download_gem`), so it holds nothing.
- The warning named the first call that holds the gem. Where several do, it
  now names the others too, so one round of edits is enough.
- Path selection for the in-memory engine asked for the files of a Bazel
  workspace beside any gem lock, also in a run that leaves gem out. It asks
  only when gem is selected.
- The gem rewriter parsed the calls it was handed once for every gem. It
  parses them once.

Stated in the docs, not changed: an `rb_bundle_fetch` beside a tag that
names the lock is still not looked at, although Bazel 7 reads both files; a
project that a call names through a symbolic link, or one that is a git
checkout of its own, is not matched; the in-memory engine does not read a
workspace file that is a symbolic link; and a pin that an earlier release
wrote beside a stale entry is still reported `applied` and attested by
`--vex`.

The `bazel` line budget goes from 2626 to 2660.

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 02:54
@cursor

cursor Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes hosted-mode gem redirect decisions for Bazel/rules_ruby workspaces; incorrect parsing could wrongly skip or apply patches, though behavior is intentionally fail-safe toward avoiding broken builds.

Overview
Hosted gem scans in Bazel workspaces no longer rewrite Gemfile / Gemfile.lock when a rules_ruby ruby.bundle_fetch call (or legacy rb_bundle_fetch) that may read the project's lock pins the gem in gem_checksums to a different sha256—or when gem_checksums is not a literal string dict. Those gems are skipped with warning redirect_bazel_gem_checksums_pinned, which names the call and tells you to update the entry, delete it (if the lock has CHECKSUMS), or roll back an existing pin.

A new bazel/ruby module parses MODULE.bazel (and related workspace files), discovers applicable hub calls, and feeds that context into the gem rewriter via a synthetic file key. Path selection and the in-memory engine now load Bazel workspace files beside gem locks when the gem ecosystem is active.

Tests and docs add real-Bazel and parity coverage for the withheld-redirect flow, plus updates to CLI_CONTRACT.md, docs/ecosystems.md, and the Ruby Bazel workflow comment.

Reviewed by Cursor Bugbot for commit 9d8e2fa. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 9d8e2fa. 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
A WORKSPACE file with no `workspace(name = ...)` gives the main
repository Bazel's default name `__main__`, so an `rb_bundle_fetch` whose
`gemfile_lock` is `@__main__//:Gemfile.lock` reads the root's lock. It
was mapped to "not this lock", and hosted mode still pinned a gem that
hub holds to another sha256. A `workspace()` call that passes `**` now
leaves the name unknown, so any repository may be the main one there.

Assisted-by: Claude Code:claude-opus-5-5
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for approval

What it does
In a Bazel workspace, scan/get --mode hosted now skip a gem when a rules_ruby ruby.bundle_fetch (or rb_bundle_fetch in WORKSPACE) that may read the project's lock pins that gem in gem_checksums to a sha256 other than the patched archive's. Before this change the scan exited 0 and the next bazel build failed on a checksum mismatch. The gem is reported skipped with a new redirect_bazel_gem_checksums_pinned warning, which names the call and file:line and gives the sha256 to put in the entry. Exit status is unchanged. socket-patch never edits MODULE.bazel.

Risk
Low to medium. The change only withholds redirects and never writes anything new. Projects outside a Bazel workspace, or with no hub reading the lock, get no hand-off key, so their runs are unchanged (unit and parity tests cover this). The risk is in the Starlark reading: a misread call can skip a gem that would have built patched. It never breaks a build.

Look here

  • bazel/ruby.rs:120: held decides which calls count. Unreadable gemfile_lock counts; the WORKSPACE fallback applies only when no module tag names the lock.
  • bazel/ruby.rs:222: stands_against. Case-insensitive compare, an empty entry holds nothing, and a dict that isn't written out withholds.
  • redirect/mod.rs:9078: the gate in the gem rewriter. It runs after every existing refusal, so those keep their own warning.
  • hosted/engine.rs:1648: the calls reach the rewriter through a synthetic files key, the same pattern as UV_ANCESTOR_OUTSIDE_KEY. Disk and in-memory views both supply it.
  • memory/select.rs:173: the in-memory engine fetches MODULE.bazel/WORKSPACE* only beside a root gem lock, and only when gem is selected.

Verified

  • Read the full diff (12 files, +1702/-77).
  • CHANGELOG.md is untouched. The workflow change is a comment only. The loc-budget bump matches the new module.
  • A gem with no patched sha256 is still refused earlier (redirect_gem_missing_sha256), so the gate can't be bypassed through an empty builds list.
  • Without this change, the new rewriter and engine tests would fail: they assert the PINNED warning and that the lock is left untouched.
  • Ran cargo test -p socket-patch-core --lib for bazel::ruby, the gem-rewriter, engine and select tests locally: 11 passed.
  • CI at b609160: ci-ok, clippy and lint-ecosystems are green, including the real-Bazel RubyGems legs. The only Bugbot thread is fixed and resolved.

Changes I made
None.

Open questions
The description lists seven product decisions with a default already chosen. These two matter most:

  • (1) An unreadable part of MODULE.bazel does not withhold.
  • (7) A pin left by an earlier release stays applied and is still attested by --vex.

If either default is wrong, say so in the review. Neither blocks merging.


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] Found a rollback instruction that can unwind unrelated patches.

docs/ecosystems.md: main added the rules_rust clause to the Cargo row
and this branch the rules_ruby gem_checksums clause to the RubyGems row;
both rows keep their side's addition.
scripts/loc-budget.json: main raised the bazel group to 2665 and this
branch to 2660 from the same base 2486; the merged tree counts 2844.

Assisted-by: Claude Code:claude-opus-5-5
The warning for a pin an earlier run wrote beside a gem_checksums entry
told the user to take the pin out with a bare `socket-patch rollback`,
which restores every hosted, vendored and in-place patch of the project.
It now names the pin as rollback selects it, by the gem's base purl:
`socket-patch rollback pkg:gem/<name>@<version>`. The unit test, the
Bazel e2e, CLI_CONTRACT.md and docs/ecosystems.md follow.

Assisted-by: Claude Code:claude-opus-5-5
@mikolalysenko Mikola Lysenko (mikolalysenko) removed the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 24, 2026
main gained the pnpm 11 and hosted NuGet withholds and the vendored crate
build-file change. Two conflicts:

- docs/ecosystems.md, the list of known problems: this branch's two gem
  entries take the place of the one gem entry, and main's three npm
  entries take the place of the one npm entry this branch still had.
- scripts/loc-budget.json: the cap of the `bazel` group is the count of
  the merged tree, 3518.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Merged via the queue into main with commit 8ffea64 Nov 24, 2026
114 of 115 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the bazel-guard/gem-checksums-hosted branch November 24, 2026 17:53
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.

3 participants