Repository navigation
Description
[agent] Found by the scheduled Bundler (RubyGems) bug-hunt routine (ledger #316).
Summary
A gem locked as precompiled platform gems (nokogiri) that was patched in hosted mode and then moved to vendored mode keeps its patched installed copy and its patched cache/*.gem in the project's own vendor/bundle after rollback. Gemfile and Gemfile.lock come back byte for byte, but:
- the app keeps loading the patched code after
rollbackandbundle install, and - on a lock with
CHECKSUMS(Bundler 2.6+ / 4.x) the nextbundle pristinefails with "Bundler found mismatched checksums", after it has already removed the installed nokogiri, so the app no longer loads at all.
This is #2083 again for the platform-gem shape that #2150 / #2154 added. The same sequence with a ruby-platform gem (rack 2.2.8) is fine on this commit: rollback prints "Replaced the installed copy of 1 gem with the upstream build" and pristine passes. A plain hosted rollback of the same nokogiri (no vendored step) also restores the upstream build.
Impact
"Do no harm" is broken on rollback: a project that installed cleanly before socket-patch touched it fails bundle pristine (and any reinstall from the gem home's cached archive) afterwards, and until then runs code the user asked to have removed. The rollback output only says "1 unwired package keeps its patched bytes in installed trees until the next package-manager install", which is not true here: bundle install keeps the installed gem.
Repro
Linux x86_64, Ruby 3.3.6, Bundler 4.0.18. The patch service is the repo's own stand-in, tests/nokogiri/patch_service.rb (PatchService.new("nokogiri", "1.18.10", %w[x86_64-linux-gnu aarch64-linux-gnu arm64-darwin x86_64-darwin x86_64-linux-musl], …), mark SOCKET_PATCHED = true appended to lib/nokogiri.rb); $URL is its address.
sp() { socket-patch "$@" --api-url $URL --patch-server-url $URL --api-token fake --org nokogiri-e2e; }
mkdir app && cd app && git init -q .
printf 'source "https://rubygems.org"\n\ngem "nokogiri", "1.18.10"\n' > Gemfile
printf '**/vendor/bundle/\n' > .gitignore
bundle config set --local path vendor/bundle
bundle install
# keep only the platforms the patch has a prebuild for
bundle lock --remove-platform aarch64-linux-musl arm-linux-gnu arm-linux-musl
cp Gemfile G0; cp Gemfile.lock L0
sp scan --mode hosted --yes # "Replaced the installed copy of 1 gem with the patched build"
sp scan --mode vendored --yes # "was hosted; restored its upstream registry entry … (mode takeover)", "Vendored 1 package."
sp rollback --yes
cmp Gemfile G0 && cmp Gemfile.lock L0 # identical
bundle install
bundle exec ruby -e 'require "nokogiri"; p defined?(SOCKET_PATCHED)'
bundle pristine
bundle exec ruby -e 'require "nokogiri"'Actual
$ sp rollback --yes
Reverted vendoring for pkg:gem/nokogiri@1.18.10?platform=ruby
Note: 1 unwired package keeps its patched bytes in installed trees until the next package-manager install.
$ bundle install
Bundled gems are installed into `./vendor/bundle`
$ bundle exec ruby -e 'require "nokogiri"; p defined?(SOCKET_PATCHED)'
"constant"
$ bundle pristine
Installing racc 1.8.1 with native extensions
Bundler found mismatched checksums. This is a potential security risk.
nokogiri (1.18.10-x86_64-linux-gnu) sha256=ff5ba26b… from the lockfile CHECKSUMS at Gemfile.lock
nokogiri (1.18.10-x86_64-linux-gnu) sha256=60e711cd… from the gem at …/vendor/bundle/ruby/3.3.0/cache/nokogiri-1.18.10-x86_64-linux-gnu.gem
$ bundle exec ruby -e 'require "nokogiri"'
…: cannot load such file -- nokogiri (LoadError)
ff5ba26b… is the upstream gem, 60e711cd… the patched prebuild the hosted scan put in the gem home.
Expected
What the same sequence does for rack: the rollback replaces the project's installed copy (and its gem-home archive) with the upstream build, or names what is left and the command that fixes it. docs/ecosystems.md ("Ruby gems: gems already installed") and the "Gem stale-install guard" section of crates/socket-patch-cli/CLI_CONTRACT.md describe the vendored unwind bringing a copy that a hosted scan had replaced back to the upstream gem (#2083).
Versions
| Bundler | Ruby | Gem | Result |
|---|---|---|---|
| 4.0.18 | 3.3.6 | nokogiri 1.18.10 (platform gems, CHECKSUMS) |
reproduces (twice): patched code after rollback, pristine fails and removes nokogiri |
| 2.6.9 | 3.1.6 | nokogiri 1.18.10 (platform gems, bundle lock --add-checksums) |
reproduces |
| 4.0.18 | 3.3.6 | rack 2.2.8 (ruby platform) | does not reproduce: upstream build restored |
| 4.0.18 | 3.3.6 | nokogiri 1.18.10, hosted then rollback (no vendored step) |
does not reproduce |
Tested on main 6579162. Linux only; nothing here looks platform-specific, so macOS should behave the same with its arm64-darwin build. No first bad release: vendoring a platform gem is new on main (#2154) and not in 5.1.0.
Suspect
crates/socket-patch-cli/src/commands/gem_refresh.rs:1239 (after_vendored_unwind): it judges only the ruby-platform leaf of each unwound gem (GemBuild::ruby(purl), with the comment "A vendored gem is the ruby-platform gem: a platform build installed beside it was never the vendored copy's stand-in"). Since #2154 a vendored gem can be a set of platform builds, and the installed copy is nokogiri-1.18.10-x86_64-linux-gnu, so it is never looked at. The takeover itself (scan --mode vendored over the hosted pin) also leaves the patched copy in place.
Generated by Claude Code
Activity
mikolalysenko commentedon Nov 20, 2026
[agent] Two more ways into the same state, both on Bundler 4.0.18 / Ruby 3.3.6 at
6579162: afterscan --mode hostedthenscan --mode vendored,socket-patch remove pkg:gem/nokogiri@1.18.10andsocket-patch vendor --revertalso restore theGemfilepair byte for byte and leave the patchednokogiri-1.18.10-x86_64-linux-gnuinvendor/bundle(the app still printsdefined?(SOCKET_PATCHED)as"constant"afterbundle install).Generated by Claude Code
mikolalysenko commentedon Nov 20, 2026
[agent] Claiming this issue. Branch: agent/fix-gem-vendored-unwind-platform-builds.
Generated by Claude Code
Test the vendored unwind of a platform gem
Refresh platform builds on a vendored gem unwind
Name platform archives on a vendored gem unwind
Judge the ruby archive beside platform builds