Skip to content

Vendored gem scan exits 1 with "Gemfile.lock GEM specs has no entry" for a gem in the shared gem home that the project does not lock, where hosted mode skips it with a warning #2075

Closed

Description

[agent] Found by the scheduled Bundler (RubyGems) bug-hunt routine (ledger #316).

Summary

In a Bundler project that installs into a shared gem home (the Bundler default: system gems, rbenv/asdf, GEM_HOME, a ruby: Docker image), scan --mode vendored tries to vendor every patchable gem it finds in that gem home, including versions the project's Gemfile.lock doesn't resolve: a gem Ruby ships in the gem home (rake 13.0.6 on Ruby 3.1.6), or a version another project installed. For such a gem the lock edit fails, the run prints an internal-sounding error and exits 1 (status: partialFailure):

Error: Failed to vendor pkg:gem/rake@13.0.6: failed to edit Gemfile.lock: Gemfile.lock GEM specs has no entry `rake (13.0.6)`
Vendored 1 package; 1 failed.

Hosted mode already handles the same project correctly since #1055: it skips the gem with redirect_gem_version_not_locked ("it is installed on this machine but this project doesn't lock it") and exits 0. Vendored mode has no such check.

Impact

  • A CI job that runs socket-patch scan --mode vendored fails on every run as soon as any gem in the image's gem home (Ruby's bundled gems: rake, rexml, net-imap, ...) has a patch, although the project is fully patched and nothing can be done about that gem in the project.
  • The message blames Gemfile.lock and gives no remedy. The user can't tell that the gem is simply not part of the project.
  • scan --mode vendored --dry-run says it "Would download and vendor 2 patches" and exits 0, then the real run fails one of them.
  • The gems the project does lock are vendored correctly (nothing wrong is written), so this is an exit-code and message defect, not a bad rewrite.

Repro

Any patch for a gem version that sits in the gem home but not in the lock triggers it. I used a local mock of the patch API with patches for rack 2.2.8 and rake 13.0.6 (no API key is available in the sandbox).

# Ruby 3.1.6 ships rake 13.0.6 in its gem home; the project only uses rack.
mkdir app && cd app
printf 'source "https://rubygems.org"\n\ngem "rack", "2.2.8"\n' > Gemfile
bundle install                      # no `path` configured: system gem home
git init -q . && git add -A && git commit -qm base
socket-patch scan --mode vendored --dry-run   # "Would download and vendor 2 patches", exit 0
socket-patch scan --mode vendored --yes; echo "exit=$?"

Second shape (Bundler 4.0.18, Ruby 3.3.6): GEM_HOME holds rake 13.0.6 from another project, the Gemfile declares gem "rake", "~> 13.0" and the lock resolves rake 13.4.2. Same error for pkg:gem/rake@13.0.6, exit 1.

Actual

Downloading 2 patches...
  [fetch] pkg:gem/rack@2.2.8
  [fetch] pkg:gem/rake@13.0.6
Error: Failed to vendor pkg:gem/rake@13.0.6: failed to edit Gemfile.lock: Gemfile.lock GEM specs has no entry `rake (13.0.6)`
Vendored 1 package; 1 failed.
exit=1

--json: "status": "partialFailure", and for rake {"action":"failed","errorCode":"apply_failed","error":"failed to edit Gemfile.lock: Gemfile.lock GEM specs has no entry rake (13.0.6)"}. Every later scan repeats it (1 already vendored; 1 failed, exit 1).

Expected

What hosted mode does on the same project (crates/socket-patch-core/src/patch/redirect/mod.rs:8660, added for #1055): skip a version no GEM section of the lock lists, with a warning that says the gem is installed on the machine but not locked by the project, and exit 0. CLI_CONTRACT.md ("Gem install roots") says the gem env homes are crawled only because default gems live there; it doesn't say a gem the project doesn't lock is a vendoring failure, and docs/ecosystems.md ("Ruby gems: gems already installed") says gems in a gem home outside the project belong to other projects too. The dry run should report the same outcome as the real run.

Versions

Ruby Bundler Gem home Result
3.1.6 2.6.9 rbenv system gems (bundled rake 13.0.6) fails, exit 1 (2 runs)
3.3.6 4.0.18 shared GEM_HOME with another project's rake 13.0.6 fails, exit 1
3.3.6 4.0.18 bundle config set path vendor/bundle passes (only the project's gems are crawled)
3.1.6 2.6.9 system gems, --mode hosted passes: redirect_gem_version_not_locked, exit 0

socket-patch main 7c5240e (5.1.0), Linux. Not platform-specific as far as I can tell. First bad release not searched.

Suspect code

  • crates/socket-patch-core/src/vendor/gem.rs:1908: the lock edit returns Gemfile.lock GEM specs has no entry for any version the lock doesn't list; nothing before it filters crawled gems by what the lock resolves.
  • The hosted twin of the missing check: crates/socket-patch-core/src/patch/redirect/mod.rs:8660.

Generated by Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:triagedbugbughuntpm:bundlerpriority:p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions