Skip to content

Hosted scan's rm -f … && bundle install remedy does nothing for a native gem left in another Ruby's tree (vendor/bundle/ruby/3.2.0 after a Ruby upgrade): vex keeps omitting the gem and a re-scan prints the same command again #2242

Done

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 vex keeps omitting those gems as not_applied, on every run;
  • a re-scan reports "its installed gemspec is unreadable: No such file or directory" and prints the same rm -f command 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 before

What 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 whole vendor/bundle/ruby/3.2.0 tree): vex then writes all statements and the scan stops warning.
  • Running the printed command's bundle install with Ruby 3.2 on PATH: Bundler fetches the patched gems into ruby/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): one rm -f … && bundle install remedy 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

  1. added
    bug
    bughunt
    pm:bundler
    ux
    on Nov 25, 2026
  2. mikolalysenko commented on Nov 25, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] Claiming this issue. Branch: agent/fix-gem-refresh-foreign-ruby-remedy.


    Generated by Claude Code

  3. mikolalysenko commented on Nov 25, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] #2251 changes the scan's remedy for the two states this issue describes, and is written as Refs, not Fixes, because two parts are left:

    • Fixed there: a native gem whose extension the Ruby on PATH builds into another gem home now gets rm -rf <gem dir> <gemspec> <archive> && bundle install and a retry that names the owning Ruby. A gem directory that already lost its gemspec gets rm -rf <gem dir> && bundle install, with no rm -f of files that are gone and no re-run that fails the same way.
    • Left: a copy in another Ruby's tree still gets the old rm -f remedy when the refresh stops before the Ruby probe (--no-gem-install-refresh, a download or offline failure, --no-gem-native-rebuild).
    • Left: vex does not name the path behind a not_applied omission. That message is shared by every ecosystem.

    Generated by Claude Code

  4. mikolalysenko commented on Nov 25, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] Claiming the first part left of this issue (the rm -f remedy 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

  5. mikolalysenko commented on Nov 26, 2026

    @mikolalysenko
    CollaboratorAuthor

    [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:

    Re-run `socket-patch scan` with the Ruby that installed the gem first on `PATH` to retry, or run `rm -rf vendor/bundle/ruby/3.2.0/gems/json-2.9.1 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 gem directory is removed too: `bundle install` does not replace a copy that has no gemspec or is in the gem home of another Ruby.
    

    After running the two printed commands, socket-patch vex writes 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

  6. added a commit that references this issue on Nov 26, 2026
    8abb243
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:triagedbugbughuntpm:bundlerpriority:p1ux

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions