Skip to content

Vendored scan on a fresh checkout skips a gem locked only as platform gems (nokogiri) without a word and reports "Nothing left to patch", also after following the printed --remove-platform ruby remedy #2394

Done

Description

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

Summary

socket-patch scan --mode vendored on a checkout with nothing installed never looks up a gem that Gemfile.lock holds only as precompiled platform gems (nokogiri (1.19.7-x86_64-linux-gnu), no plain nokogiri (1.19.7)). The gem is left out of the patch lookup, so the run vendors the other gems, prints Nothing left to patch. and exits 0, with no line about the gem it could not consider. The same scan after bundle install vendors it, and a hosted scan of the same checkout patches it.

Not a regression: 5.1.0 behaves the same in vendored mode (and in hosted mode too, which main has since fixed).

Impact

  • A lock with only platform entries for nokogiri is what Bundler 2.x writes by default, and what a Bundler 4 lock becomes after bundle lock --remove-platform ruby.
  • That command is the remedy the vendored refusal platform_gem_unsupported prints. Followed on a fresh checkout it makes things worse without saying so: before it, the scan names nokogiri as refused and counts its vulnerability as left to patch; after it, nokogiri is gone from the output and the "left to patch" count drops by one, as if it had been dealt with. On a project where nokogiri is the only refused gem the run ends with Nothing left to patch.
  • A scheduled job that runs scan --mode vendored on a clean CI checkout (the scan help says "Supported lockfiles can be scanned from a fresh checkout before installing dependencies") never picks up a patch for such a gem, and nothing in its output or --json (status: "success", no warnings) shows it.

Nothing is broken on disk: the pair is untouched for the skipped gem, and a gem that is already vendored stays vendored and verified on a fresh clone.

Repro

No Socket API access needed. The script starts a loopback stand-in for the patches API that answers "no patches" and prints which gems each scan asked about.

# ruby repro.rb <socket-patch binary>      (Ruby 3.x, Bundler 2.5+; `bundle lock` needs rubygems.org)
# A loopback stand-in for the patches API that answers "no patches" and prints
# which gems each scan asked about.
require "fileutils"; require "json"; require "socket"; require "tmpdir"
bin = File.expand_path(ARGV[0])
asked = Queue.new
server = TCPServer.new("127.0.0.1", 0)
Thread.new do
  loop do
    s = server.accept
    line = s.gets.to_s; len = 0
    while (h = s.gets) && h != "\r\n"
      k, v = h.split(":", 2); len = v.to_i if k.casecmp("content-length").zero?
    end
    body = len > 0 ? s.read(len) : ""
    asked << JSON.parse(body)["components"].map { |c| c["purl"] } if line.include?("/patches/batch")
    out = JSON.generate("packages" => [], "canAccessPaidPatches" => false)
    s.write("HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: #{out.bytesize}\r\nConnection: close\r\n\r\n#{out}")
    s.close
  end
end
url = "http://127.0.0.1:#{server.addr[1]}"
Dir.chdir(Dir.mktmpdir("platform-only-"))
File.write("Gemfile", %(source "https://rubygems.org"\n\ngem "rack", "3.2.9"\ngem "nokogiri", "1.19.7"\n))
system("bundle config set --local path vendor/bundle", out: File::NULL) or abort
system("bundle lock", out: File::NULL) or abort
# Bundler 4 adds the `ruby` platform to a new lock; Bundler 2.x does not.
system("bundle lock --remove-platform ruby", out: File::NULL, err: File::NULL)
puts "locked: " + File.read("Gemfile.lock").scan(/^    (?:nokogiri|rack) \(.*\)$/).map(&:strip).join(", ")
scan = lambda do |mode|
  system("#{bin} scan --mode #{mode} --dry-run --api-url #{url} --api-token fake --org o", out: File::NULL, err: File::NULL)
  purls = asked.pop
  puts format("  %-8s asks about rack: %-5s nokogiri: %s", mode, purls.any? { |p| p.include?("/rack@") }, purls.any? { |p| p.include?("/nokogiri@") })
end
puts "fresh checkout, nothing installed:"
%w[hosted vendored].each(&scan)
system("bundle install", out: File::NULL, err: File::NULL) or abort
puts "after `bundle install`:"
%w[hosted vendored].each(&scan)

Output on main 1b3f422 (Ruby 3.3.6, Bundler 4.1.1; the same with Bundler 2.6.9):

locked: nokogiri (1.19.7-aarch64-linux-gnu), nokogiri (1.19.7-aarch64-linux-musl), nokogiri (1.19.7-arm-linux-gnu), nokogiri (1.19.7-arm-linux-musl), nokogiri (1.19.7-arm64-darwin), nokogiri (1.19.7-x86_64-darwin), nokogiri (1.19.7-x86_64-linux-gnu), nokogiri (1.19.7-x86_64-linux-musl), rack (3.2.9)
fresh checkout, nothing installed:
  hosted   asks about rack: true  nokogiri: true
  vendored asks about rack: true  nokogiri: false
after `bundle install`:
  hosted   asks about rack: true  nokogiri: true
  vendored asks about rack: true  nokogiri: true

With a patch service that has a patch for both gems (the repo's tests/nokogiri/patch_service.rb, one instance per gem behind one port, answering batch only for the gems asked about), the fresh checkout prints:

$ socket-patch scan --mode vendored
Found 22 packages (22 ruby)
Vendored 1 package.
  HIGH  rack@3.2.9  GHSA-e2e1-e2e1-0000
...
Patched 1 package, fixing 1 vulnerability (1 high).
Nothing left to patch.

and after bundle install the same command vendors nokogiri from its eight prebuilds, a frozen install passes and the app loads both patched gems.

The remedy path, on a sinatra app locked by Bundler 4.1.1 (nine platforms, ruby among them), nothing installed:

  1. scan --mode vendored: [error] pkg:gem/nokogiri@1.19.7?platform=ruby (platform_gem_unsupported): … Remove the ruby platform from the lock (bundle lock --remove-platform ruby) to vendor nokogiri, and 3 vulnerabilities left to patch.
  2. bundle lock --remove-platform ruby
  3. scan --mode vendored: no line names nokogiri, 2 vulnerabilities left to patch, nokogiri is not vendored.

Expected

The vendored docs (docs/ecosystems.md, "Ruby gems: native extensions", the Vendored row) say a gem the lock pins as precompiled platform gems "is vendored from prebuilt patched platform gems", and the refusal's remedy ends "to vendor nokogiri". Neither says an installed copy is needed first. CLI_CONTRACT.md ("Lockfile supplement") does record that such a gem "joins the supplement of a hosted run alone … agent and vendored runs see it only through an installed copy", and gives agent runs "a stderr note that they are not installed". That sentence predates vendoring from prebuilds; the engine no longer needs the installed copy (when a stand-in returns the patch anyway, the fresh checkout vendors the gem from the lock alone).

So either the vendored supplement should name these gems as the hosted one does, or, if the limit stays, the run should say which locked gems it could not look up and that bundle install first makes them vendorable, and the totals should not read Nothing left to patch.

Actual

The gem is skipped without a message, the totals count it as if it did not exist, exit 0.

Versions

socket-patch Bundler / Ruby vendored, fresh checkout hosted, fresh checkout vendored, installed
main 1b3f422 4.1.1 / 3.3.6 nokogiri skipped found found
main 1b3f422 2.6.9 / 3.3.6 nokogiri skipped found found
5.1.0 4.1.1 / 3.3.6 nokogiri skipped skipped found

Linux only. The discovery code has no platform branch, so macOS and Windows should behave the same.

The open platform-gem pull request #2273 keeps the same line in discovery.rs and the same contract sentence, so it does not change this.

Suspect code

  • crates/socket-patch-cli/src/commands/scan/discovery.rs:120: platform_gems.iter().filter(|_| hosted) keeps platform-only gems out of every supplement that is not hosted.
  • crates/socket-patch-core/src/vendor/lock_inventory/gem.rs:21: "platform gems are unsupported for vendoring anyway", which is no longer true.

Agent mode leaves the gem out of its "not yet installed (lockfile-only)" note the same way (it counts 2 where 3 gems of the lock are missing), so a fresh-checkout scan --mode agent --dry-run under-reports what is left as well.


Generated by Claude Code

Activity

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

    @mikolalysenko
    CollaboratorAuthor

    [agent] Claiming this issue. Branch: agent/fix-vendored-scan-platform-only-gems.


    Generated by Claude Code

  3. added 2 commits that reference this issue on Dec 2, 2026
    fdb8d80
    94099f5
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