Repository navigation
Description
[agent] Found by the scheduled Bundler (RubyGems) bug-hunt routine (ledger #316).
Summary
A project whose vendor/bundle still holds the gem tree of an earlier Ruby (vendor/bundle/ruby/3.2.0 next to vendor/bundle/ruby/3.3.0 after a Ruby upgrade) gets a hosted scan that patches everything the current Ruby loads, and correctly warns that it could not rebuild the native gems in the old tree. The remedy it prints for them, rm -f <spec> <archive> && bundle install, does not work there: bundle install runs with the current Ruby, which installs into ruby/3.3.0 and never touches ruby/3.2.0. The gem directories stay in the old tree without a gemspec, and from then on:
socket-patch vexkeeps omitting those gems asnot_applied, on every run;- a re-scan reports "its installed gemspec is unreadable: No such file or directory" and prints the same
rm -fcommand again, for files that no longer exist.
Neither message names the directory that is in the way or a step that clears it.
Impact
The app is patched (bundle exec loads the patched gems), but the user cannot get a complete VEX document by following the tool's own instructions: the printed command, "Re-run socket-patch scan to retry" and bundle clean --force all leave the state as it is. Only the gems with a native extension are affected (json, racc, puma, bootsnap, …); pure-Ruby gems in the old tree are replaced by the scan. A leftover tree of the previous Ruby is what every developer machine, Docker volume and vendor/bundle CI cache not keyed by Ruby version has after a Ruby upgrade. Nothing breaks in bundle install, so this is friction, not harm.
Repro
Two Rubies (3.2.6 and 3.3.6 here), the same Bundler on both, only Ruby 3.3 on PATH when socket-patch runs. Hosted patches for json 2.9.1 and racc 1.8.1, both with a native extension (I used the repo's stand-in, tests/nokogiri/patch_service.rb; $MOCK stands for --api-url … --patch-server-url … --api-token … --org …).
mkdir proj && cd proj
printf 'source "https://rubygems.org"\n\ngem "json", "2.9.1"\ngem "racc", "1.8.1"\n' > Gemfile
printf 'require "bundler/setup"\nrequire "json"\nrequire "racc"\nputs "ok"\n' > app.rb
bundle config set --local path vendor/bundle
PATH=/path/to/ruby-3.2.6/bin:$PATH bundle install # fills vendor/bundle/ruby/3.2.0
bundle install # Ruby 3.3: fills vendor/bundle/ruby/3.3.0
socket-patch scan --mode hosted $MOCK
# Warning: 2 gems are still unpatched on disk after the switch to hosted patches.
# - Not refreshed (its native extension could not be rebuilt: no Ruby owning this install was found
# (…/3.3.6/bin/ruby builds into …/ruby/3.2.0/extensions/x86_64-linux/3.3.0/json-2.9.1, but the installed
# extension is …/ruby/3.2.0/extensions/x86_64-linux/3.2.0/json-2.9.1 (another Ruby's))): json 2.9.1.
# Re-run `socket-patch scan` to retry, or run `rm -f vendor/bundle/ruby/3.2.0/specifications/json-2.9.1.gemspec
# vendor/bundle/ruby/3.2.0/cache/json-2.9.1.gem && bundle install`.
# (the same for racc 1.8.1)
# Next steps: … 2. Install the patched gems with the command in the warning above …, then run `socket-patch vex` …
rm -f vendor/bundle/ruby/3.2.0/specifications/json-2.9.1.gemspec vendor/bundle/ruby/3.2.0/cache/json-2.9.1.gem && bundle install
rm -f vendor/bundle/ruby/3.2.0/specifications/racc-1.8.1.gemspec vendor/bundle/ruby/3.2.0/cache/racc-1.8.1.gem && bundle install
# "Bundle complete!", nothing fetched; vendor/bundle/ruby/3.2.0/gems/json-2.9.1 and racc-1.8.1 are still there
socket-patch vex --output vex.json --product pkg:generic/app@1 $MOCK
# Warning: omitting 2 packages from VEX: the patched files still hold the original content (not_applied): json@2.9.1, racc@1.8.1
socket-patch scan --mode hosted $MOCK
# Warning: 2 gems are still unpatched on disk after the switch to hosted patches.
# - Not refreshed (its installed gemspec is unreadable: No such file or directory (os error 2)): json 2.9.1, racc 1.8.1.
# Re-run `socket-patch scan` to retry, or run `rm -f vendor/bundle/ruby/3.2.0/specifications/json-2.9.1.gemspec …
# vendor/bundle/ruby/3.2.0/cache/racc-1.8.1.gem && bundle install`.
bundle clean --force # cleans ruby/3.3.0 only; vex and the scan say the same as beforeWhat does clear it (none of it is named by the tool):
rm -rf vendor/bundle/ruby/3.2.0/gems/json-2.9.1 vendor/bundle/ruby/3.2.0/gems/racc-1.8.1(or the wholevendor/bundle/ruby/3.2.0tree):vexthen writes all statements and the scan stops warning.- Running the printed command's
bundle installwith Ruby 3.2 onPATH: Bundler fetches the patched gems intoruby/3.2.0.
Expected
docs/ecosystems.md, "Ruby gems: gems already installed": a copy that cannot be replaced is reported with a warning "naming the files to remove by hand", and the scan's next step reads "Install the patched gems with the command in the warning above …, then run socket-patch vex to verify the installed patches". Following that command should leave a project vex attests in full. The same section says a gem directory left with no gemspec is one that "nothing loads" and that vex and apply --check don't count it; that holds only while another build of the gem version has a gemspec in the same gem home (the #2087 case), not for the last copy in another Ruby's home.
For a copy the scan already knows belongs to another Ruby ("another Ruby's"), the remedy should be one that works without that Ruby: name the gem directories (or the stale ruby/<abi> tree) to delete, or say that bundle install has to run with the Ruby that owns the tree. A re-scan should not offer an rm -f of files that are already gone, and vex should name the path it objects to.
Actual
The printed command is a no-op for the old tree, vex omits the gems indefinitely (exit 0, fewer statements), and the re-scan prints the same command again with "its installed gemspec is unreadable".
Versions
Bundler (Ruby 3.2.6 tree + Ruby 3.3.6 on PATH) |
Result |
|---|---|
| 4.1.1 | reproduces (twice) |
| 4.0.25 | reproduces |
2.5.22 (no CHECKSUMS) |
reproduces |
any, with only one Ruby's tree in vendor/bundle |
does not reproduce: the gems are rebuilt in place |
| any, pure-Ruby and precompiled gems in the old tree (rack, rake, nokogiri) | does not reproduce: the scan replaces them |
main e685fb1, Linux x86_64. Nothing here is Linux-specific; macOS should behave the same.
First bad commit: not searched. The remedy text predates the "another Ruby's" check.
Suspect code
crates/socket-patch-cli/src/commands/gem_refresh.rs:439(reinstall_command) and:407(retry_hint): onerm -f … && bundle installremedy for every failure reason, including a copy in a gem home the current Ruby does not install into, and a copy whose gemspec is already gone.crates/socket-patch-core/src/patch/gem_refresh.rs:390: the "installed gemspec is unreadable" failure for a directory that is no longer an install.crates/socket-patch-core/src/crawlers/ruby_crawler.rs:1546(retain_loaded_gem_builds): keeps a gemspec-less directory when it is the only copy of the version in its gem home, by design, which is the state the remedy leaves.
Generated by Claude Code
Activity
bundler: run 2026-11-25 (Bundler 4.1.1, 4.0.25; #2242)
mikolalysenko commentedon Nov 25, 2026
[agent] Claiming this issue. Branch: agent/fix-gem-refresh-foreign-ruby-remedy.
Generated by Claude Code
Test the gem remedy for a copy no Ruby owns
Fix gem remedy for a copy in another Ruby's tree
Keep the gem-dir remedy to refreshes that failed
mikolalysenko commentedon Nov 25, 2026
[agent] #2251 changes the scan's remedy for the two states this issue describes, and is written as
Refs, notFixes, because two parts are left:PATHbuilds into another gem home now getsrm -rf <gem dir> <gemspec> <archive> && bundle installand a retry that names the owning Ruby. A gem directory that already lost its gemspec getsrm -rf <gem dir> && bundle install, with norm -fof files that are gone and no re-run that fails the same way.rm -fremedy when the refresh stops before the Ruby probe (--no-gem-install-refresh, a download or offline failure,--no-gem-native-rebuild).vexdoes not name the path behind anot_appliedomission. That message is shared by every ecosystem.Generated by Claude Code
mikolalysenko commentedon Nov 25, 2026
[agent] Claiming the first part left of this issue (the
rm -fremedy for a copy in another Ruby's tree when the refresh stops before the Ruby probe). Branch: agent/fix-gem-remedy-sibling-ruby-tree.Generated by Claude Code
Test the gem remedy beside another Ruby's tree
Fix gem remedy beside another Ruby's tree
Keep a default gem's dir in the gem remedy
mikolalysenko commentedon Nov 26, 2026
[agent] Re-checked by the scheduled Bundler bug-hunt routine on main
cfc870f: fixed by c40cc39 (#2251).Same repro (Ruby 3.2.6 tree beside Ruby 3.3.6, Bundler 4.0.18, hosted patches for json 2.9.1 and racc 1.8.1). The scan's warning now reads:
After running the two printed commands,
socket-patch vexwrites both statements with no omission warning, and a re-scan says "2 packages are already on hosted patches; nothing to rewrite." with no stale-copy warning.Generated by Claude Code
bundler: run 2026-11-26, filed #2269, closed #2242