Repository navigation
Hosted mode: patch gems locked as precompiled platform gems (nokogiri), on MRI and JRuby - #2150
Conversation
Bundler installs a native gem such as nokogiri as a precompiled platform
gem, and the lock then has one entry per platform
(`nokogiri (1.18.10-arm64-darwin)`) and usually no ruby-platform
`nokogiri (1.18.10)`. Hosted mode skipped such a lock with
`redirect_gem_platform_unsupported`, because the patch registry served
the ruby gem alone. The registry can now serve a patched platform gem (a
"prebuild") per platform, and the patch API lists them.
API: a package artifact may carry `platform`, and the registry override's
identifiers may carry `gemPlatforms` (`[{platform, gemChecksumSha256}]`).
Both default to none. A grant's platform names and digests are held to
the shape the lock takes before a grant becomes a candidate.
Rewrite: when every platform entry of the gem at the patched version has
a prebuild, every entry of that version (spec line and sub-lines,
verbatim, plus a ruby-platform entry beside them) moves to the patch
registry's `GEM` section, `DEPENDENCIES` is pinned as before, and each
`CHECKSUMS` entry takes the sha256 of its own build. A lock with no
`CHECKSUMS` section gets none. A locked platform with no prebuild keeps
the skip, and the warning now names the missing builds and what the
registry serves. A second scan of a moved lock is a no-op: the agreement
check and the converge step look for the builds of the version, not for
exactly one `name (version)` spec.
Restore: every platform entry goes back to the upstream section where
Bundler sorts it (by full name), and each `CHECKSUMS` entry is re-pinned
to its own build's upstream sha256, the compact index's
`<version>-<platform>` line. One `info/<name>` document is read per gem.
Discovery: the platform specs of one gem version under a Socket `GEM`
section of its own are one hosted pin, content-pinned only when
`CHECKSUMS` holds a sha256 for every build. The engine drops a rewrite
discovery cannot attribute, so this lands with the rewrite.
Stale installs: an installed platform copy
(`gems/nokogiri-1.18.10-arm64-darwin`) and its archive in Bundler's cache
dir are judged against the patched artifacts, prebuilds included, and
refreshed from `<index>/gems/<leaf>.gem` against that platform's own
sha256. A platform gem declares no extensions, so nothing is built. After
a rollback the same copy and archive go back to the upstream platform
gem; a patched archive left in the cache dir would fail every install on
the restored checksum.
Lock-only discovery: the lock inventory lists a gem by its ruby-platform
entry, so a gem locked only as platform builds was found only through an
installed copy. A hosted run (the disk scan, `get --mode hosted` and the
in-memory engine) now also reads those gems from the lock. Agent and
vendored runs are unchanged.
Nothing changes for a lock that names a gem by its ruby-platform entry
alone.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Three real-Bundler capstones in e2e_redirect_gem_build (`#[ignore]`, like their neighbours). The fixture gem is published as a ruby gem and as platform gems for this machine and for a foreign platform; a platform gem needs no binary, a pure-Ruby gem with `s.platform` set is one. The real Bundler locks the platform builds, the hosted scan moves them, and the lock is compared byte for byte with what `bundle lock` writes for the redirected Gemfile. A fresh checkout's frozen `bundle install` fetches exactly this machine's prebuild, leaves the lock untouched, and Ruby loads the patched file from the platform build. A re-scan changes nothing, `rollback` restores the pair byte for byte and the installed copy, and standalone `vex` attests the installed platform build. The arms: a `CHECKSUMS` lock holding the platform builds alone, the same without `CHECKSUMS`, and a lock that keeps the ruby-platform entry beside them (what Bundler 4 writes by default for a gem that also ships a ruby gem). Two hermetic tests need no Ruby: a stale platform install and its committed cache archive are replaced with the prebuild and put back by `rollback`; and a fresh checkout is pinned from the lock alone, or left untouched when a locked platform has no prebuild. The in-memory and disk engines are compared on the new golden fixture. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The CLI contract and the ecosystems guide said a gem locked as precompiled platform builds is always skipped in hosted mode. They now say when it is redirected (a prebuild for every locked platform), what the lock looks like afterwards, how an installed platform copy is judged and refreshed in both directions, how the lock is restored, and that the skip is left for a locked platform with no prebuild. `redirect_gem_platform_unsupported` gets its row in the warning table. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The rollout's recorded view reads a hosted gem pin from the manifest's `source:` option and takes the version from the lock. It read the version from ruby-platform specs only, so a gem the lock names as precompiled platform builds alone was never a recorded manifest pin, and a capped re-scan spent a new-patch slot on it every time. Any build of the gem now names the version; builds of two versions still name none. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The hosted lock supplement read the Bundler lock from disk a second time, beside the snapshot the lock inventory is taken from, and cloned the whole inventory to append the platform-only gems to it. It now reads the lock through the project context's snapshot and walks the two lists of purls without copying either. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Review fixes for hosted platform prebuilds. Installed copies are judged by leaf. The stale-install guard and the unwind's refresh took the first installed dir of a gem version in each gem home, and `<name>-<version>` sorts before the platform dirs. In a home holding both builds, the ruby-platform dir stood in for the platform build the lock names: the guard called the gem patched (or stale) by the wrong copy and left the build Bundler loads unpatched and unreported, and a rollback did not put it back. Both now look for the dir of every build the project's lock names, under its own leaf, and judge each one found. A build the lock does not name (another project's copy in a shared home) is never judged, reported or replaced, by the archive check, the record check or the pinned-patch check. Where no lock names the gem (a global scan) the first copy is judged, as before; an unwind whose lock cannot be read keeps to the ruby-platform gem. One reader says which builds a lock names. The restore's own platform list disagreed with `GemfileLock::locked_builds` about a platform named only under `CHECKSUMS`; it is gone, and the rewrite, the restore and the refresh all ask `locked_builds`. A build's lock token and file name come from `GemId` everywhere, and the cache-dir listing that re-implemented the crawler's platform-dir rule is replaced by a look at the archive of each named build. A prebuild sha256 is written only on entries that moved. The rewriter pinned `CHECKSUMS` before it knew the lock converges, so a lock it keeps MIXED (a 5.0 / 5.1 `source … do` block over a lock that cannot be converged) got prebuild sha256s on platform entries that still resolve from rubygems.org, and every `bundle install` failed on the checksum. The `CHECKSUMS` edits are now decided after the source attribution, and a gem locked as platform builds gets none while the lock stays mixed. The restore re-pins a platform entry to its upstream sha256 in every wiring state, not only when the gem has a section of its own. `gemPlatforms` cannot fail a reference response. One response answers for every package of a batch, and the list was read strictly: `null`, or an entry with a `null` checksum, failed the whole response and cost every package its grant. `null` (or anything that is no list) now reads as no prebuild, and an entry without a platform or a checksum string is dropped, which leaves that platform without a prebuild. An artifact's `platform` that is no string reads as absent. An entry that is two strings in the wrong shape still fails its own grant, and only that one. The unwind's refresh reads the restored lock once and uses one registry client (`GemUpstream`), so a gem's compact-index document is fetched once for all of its builds and is no longer cloned on a cache hit; it crawls the gem homes once for the platform builds of all restored gems instead of once per gem. `rewrite_gem` parses the lock once per call instead of once per dependency. Tests: a shared gem home holding both builds through scan, a refresh on request and rollback; the mixed lock through rewrite and unwind, byte for byte; a response whose prebuild lists are `null`, not lists, or full of holes; a wrong prebuild failing only its own grant. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The stale-install guard and the unwind's refresh judge the installed copy of every build the lock names, each under its own leaf, and no copy of a build it does not name. The contract described the first installed copy of the version. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The nokogiri script gains a hosted scenario. It scans a real install whose lock pins nokogiri as platform gems against a stand-in for the patch service, which serves a patched build of each real platform gem (repacked the way the service repacks one: the gemspec member byte for byte, the files and checksums rewritten). It then installs from a fresh checkout with the lock frozen, checks that the scanned project's own copy was refreshed, runs vex, and rolls back to a byte-identical lock. Four legs run it: Ruby 3.4 and 3.1 on Linux, Ruby 3.4 on macOS, and JRuby 9.4, where the platform is java. The script also carries the vendored scenario; its legs come with the vendored change. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PR SummaryMedium Risk Overview Discovery and staleness follow the lock per build, not a single ruby-platform CI and contract add nokogiri hosted matrix legs and path filters for gem redirect/refresh code; Reviewed by Cursor Bugbot for commit e311a74. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ 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 e311a74. Configure here.
The hosted gem rewrite refused a gem with redirect_gem_missing_sha256 before it looked at the lock's platform builds. A lock that names only platform builds pins no ruby-platform entry, so a grant whose prebuilds cover every locked platform needs no ruby gem checksum: the builds now move with their prebuilds' sha256. A lock with the ruby entry beside them still needs it and still warns. Assisted-by: Claude Code:claude-opus-5-5
|
One more run, beyond what the description lists, on a local build of this branch merged with the other two open gem changes (#2150, #2154, #2155). The stand-in patch service in Ruby 3.4.10, Bundler 4.0.15, macOS arm64: 45 checks pass across the hosted and vendored scenarios.
The option that serves a prebuilt gem ( |
|
[agent] PR shepherd: review brief for the approver What it does Risk: medium. It edits users' lockfiles across a large surface (~5k lines, 47 files). Several things limit the risk:
The Windows and macOS e2e jobs were skipped on this PR. Look here
Verified
Changes I made Open questions (neither blocks merging)
Generated by Claude Code |
Wenxin Jiang (Wenxin-Jiang)
left a comment
There was a problem hiding this comment.
[agent] Reviewed at 50d6b28. The platform move is all-or-nothing (one locked platform without a prebuild, or a Bundler < 2.2 merged lock, skips the gem with redirect_gem_platform_unsupported), a lock that stays mixed gets no prebuild CHECKSUMS edits, grant validation rejects ruby, injected lock text, non-hex digests and duplicate platforms, and rollback re-pins each build from its own compact-index line. The Bugbot finding on the ruby checksum requirement is fixed by the platform_only gate. Non-blocking: (1) in scan/hosted.rs wanted, when no prebuild matches the stale copy's platform the accepted sha256 set is every artifact of the gem, which is looser than that build's own sha256; (2) on a platform-only lock, an unfrozen bundle install or --add-platform for an unlisted platform fails after the redirect unless the registry also serves the ruby gem, and no warning says so; (3) uppercase hex is written into CHECKSUMS as sent.
…orm-prebuilds # Conflicts: # crates/socket-patch-cli/CLI_CONTRACT.md # crates/socket-patch-cli/tests/e2e_redirect_gem_stale_install.rs
#2114, which this branch was stacked on, landed on main as a squash (6014caf). Merged against its tip (7bdc058) as the base, so the reactor/property work is taken once and #2150 (f297a90) comes in unchanged. Two conflicts kept both sides: the MAVEN_ARGS and REPIN entries in the Bazel harness, and the mirror and declared_maven modules in formats/maven. CHANGELOG.md is main's. Assisted-by: Claude Code:claude-opus-5-5

Summary
Hosted mode now patches a gem that
Gemfile.lockpins as precompiledplatform gems. nokogiri is the gem this is for: Bundler installs it as
nokogiri-1.18.10-x86_64-linux-gnu.gemand friends, the lock has one entryper platform and often no plain
nokogiri (1.18.10), and until now a hostedscan skipped such a lock with
redirect_gem_platform_unsupported, leavingthe gem unpatched. On JRuby the platform is
java, and the same pathcovers it.
It needs Socket's backend to serve a patched build of each platform gem (a
"prebuild"). Where it serves none, the behaviour is what it was: the lock is
left alone and the skip is reported.
How it works
registryOverride.identifiers.gemPlatforms: [{platform, gemChecksumSha256}], one per platform gem the patch registry serves. Thefield is additive and read leniently:
null, a non-list or an entrywithout a platform or checksum reads as "no prebuild for that platform"
and never fails the batch it arrives in.
prebuild, the scan moves all of them (blocks and dependency lines
verbatim) into the patch registry's
GEMsection, pins the dependencywith
!, and writes each platform's sha256 intoCHECKSUMSwhere thelock has that section. A plain
name (version)entry beside them movestoo. The
Gemfileedit is the one hosted mode already makes. One platformwithout a prebuild and nothing moves.
rollback,removeand a withdrawn patch put every platformentry back on its upstream entry and its upstream sha256 (the lock's own
record, else the registry's compact index, one request per gem), in every
wiring state.
and refresh the directory of every build the lock names, each against its
own platform's sha256. A gem home that holds both the ruby-platform and a
platform build no longer has the first one found judged in place of the
one Bundler loads.
only when every build has a sha256.
lock, so a hosted scan of a fresh checkout sees it.
CLI_CONTRACT.mdanddocs/ecosystems.mddescribe it.What a reviewer should weigh
ones for a gem that also ships a source gem (Bundler 4.0.15 adds
rubyto
PLATFORMS). Both shapes are handled and tested: platform entriesalone, and with the ruby entry beside them.
CHECKSUMScounts as locked and needs aprebuild.
cannot be converged) gets no
CHECKSUMSedit at all.match the upstream platform gem's byte for byte, the rule the ruby gem
already has. If the backend regenerates it, the refresh is refused and the
stale warning stays; fresh installs are unaffected.
and drop unknown fields, and keep skipping a platform lock.
Code review
/code-review highraised ten findings, all fixed: the stale-install guardjudging only the first installed directory per gem home; a
nullorincomplete
gemPlatformsfailing the whole batch response; the unwindjudging platform copies the restored lock does not name; prebuild checksums
written into a lock that then stays mixed, which rollback did not undo; a
platform-only hosted pin not recorded as a manifest pin; and five
efficiency or duplication points (a crawl per restored gem, a registry
client per call, a second lock read from disk, three readers of "which
builds does the lock name", a lock parse per dependency).
Two partial points remain: the vendored unwind's cache advisory still builds
its own registry client per gem, and the unwind still crawls once per
judging step, as on
main.Testing
tests/nokogiri/nokogiri_e2e.rb, against a stand-in for the patchservice that repacks the real platform gems:
all eight platform entries to the patch registry with their checksums; a
fresh checkout installs with the lock frozen and compiles nothing; Ruby
loads the patched gem there and in the scanned project (its installed
copy is refreshed);
vexattests;rollbackleaves the lock and theGemfile byte for byte as they were.
same sequence on the
javaplatform gem (a lock withoutCHECKSUMS).JRuby 9.4.
e2e_redirect_gem_build(52 pass, three new):a
CHECKSUMSlock with platform entries alone, the same withoutCHECKSUMS, and a lock that keeps the ruby-platform entry beside them.Each compares the scan's lock byte for byte with what
bundle lockwrites, then checks the frozen install, a no-op re-scan, rollback and
standalone
vex.main: core lib 7,972, CLI lib 955,redirect_goldenandupstream_restore_golden1 + 64,e2e_redirect_gem_stale_install55,in_process_rollback_hosted41,hosted_memory_parity44. After it:cargo fmt --checkand CI's clippycommand pass, and the two real-nokogiri runs above; the suites run again in
CI.
gates; a real patch service (the backend change that serves prebuilds is
in review).
The nokogiri script also carries a vendored scenario, which this branch's
CLI does not pass; its legs come with the vendored change.
🤖 Generated with Claude Code
Generated by Claude Code