Skip to content

Vendored scan prints the platform_gem_unsupported refusal once per platform patch of a gem: 9 identical lines for nokogiri on a default Bundler 4 lock, 31 for three gems, and "9 patches failed" for one gem #2436

In progress

Description

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

Summary

bundle lock with Bundler 4 writes a lock for ruby and ten more platforms, so a gem such as nokogiri, ffi or sqlite3 is locked as nokogiri (1.19.7) beside its platform gems. Vendored mode refuses that shape as documented (platform_gem_unsupported, with the bundle lock --remove-platform … remedy). Since the patch service has one patch per platform gem (#2422), the scan prints that refusal once for every patch of the gem: the same sentence, differing only in the ?platform= of the purl in front.

On a Gemfile with nokogiri alone that is 9 identical lines (6.6 KB). On a small app with nokogiri, ffi and sqlite3 it is 31 lines (25 KB) for three gems, and the two refusals that need a different action (puma's native extension, rake's group block) come after them. The closing line counts patches, not gems: "Nothing was vendored: 9 patches failed (see above)." for one gem.

Impact

Friction on the first vendored scan of an ordinary Bundler 4 or Rails 8 project: the one remedy the user has to run is buried in a wall of repeated text, and the count suggests nine separate failures. Nothing is written and the exit code (1) is right.

Repro

svc.rb serves one fix through this repository's stand-in for the patch service (tests/nokogiri/patch_service.rb):

# usage: ruby svc.rb <socket-patch checkout> <gem> <version> <platform,platform,...> [noruby]
# Serves one fix through the repository's stand-in for the patch service and prints its URL.
require File.join(ARGV[0], "tests/nokogiri/patch_service.rb")
class NoRubyPatch < PatchService
  def all_gems; super.reject { |g| g.platform.nil? }; end   # the ruby gem's patch is not offered
end
klass = ARGV[4] == "noruby" ? NoRubyPatch : PatchService
svc = klass.new(ARGV[1], ARGV[2], ARGV[3].split(","), "11111111-1111-4111-8111-111111111111",
                "GHSA-aaaa-bbbb-cccc", File.join(Dir.pwd, "svc-work"), "\nSOCKET_PATCHED = true\n")
puts svc.url
$stdout.flush
sleep

repro2.sh (run beside it with REPO=<checkout of this repository>):

#!/bin/bash
# Needs: Ruby 3.3 + Bundler 4.1.1, a socket-patch build on PATH, REPO=<socket-patch checkout>, svc.rb from above
set -u
export BUNDLER_VERSION=4.1.1 SOCKET_NO_CONFIG=1 SOCKET_NO_UPDATE_CHECK=1 SOCKET_TELEMETRY_DISABLED=1
P=aarch64-linux-gnu,aarch64-linux-musl,arm-linux-gnu,arm-linux-musl,arm64-darwin,x86_64-darwin,x86_64-linux-gnu,x86_64-linux-musl
rm -f svc.url; ruby svc.rb "$REPO" nokogiri 1.19.7 $P > svc.url & SVC=$!
until [ -s svc.url ]; do sleep 1; done; M=$(cat svc.url)
SP="--api-url $M --patch-server-url $M --api-token fake --org nokogiri-e2e"
rm -rf app2 && mkdir app2 && cd app2 && git init -q .
printf 'source "https://rubygems.org"\n\ngem "nokogiri", "1.19.7"\n' > Gemfile
bundle config set --local path vendor/bundle
bundle lock >/dev/null            # the default Bundler 4 lock: `ruby` and 10 more platforms
socket-patch scan --mode vendored $SP > scan.txt 2>&1; echo "exit $?"
grep -c 'platform_gem_unsupported' scan.txt; wc -c < scan.txt
grep 'platform_gem_unsupported' scan.txt | sed 's/?platform=[a-z0-9_-]*//' | sort | uniq -c | cut -c1-200
grep -E '^(Vendored|Patched|[0-9]+ vuln)' scan.txt
bundle install >/dev/null 2>&1
socket-patch scan --mode vendored $SP > scan2.txt 2>&1; echo "installed: exit $?"; grep -c 'platform_gem_unsupported' scan2.txt
kill $SVC

Output on main d718b07 (Ruby 3.3.6, Bundler 4.1.1, Linux x86_64):

exit 1
9
6607
      9   [error] pkg:gem/nokogiri@1.19.7 (platform_gem_unsupported): Gemfile.lock locks `nokogiri (1.19.7)` (the ruby platform) beside the platform gems `nokogiri (1.19.7-aarch64-linux-gnu)`, `nokogi…
Nothing was vendored: 9 patches failed (see above).
1 vulnerability left to patch: 1 is in packages this run did not patch.
installed: exit 1
9

One of the nine lines in full:

  [error] pkg:gem/nokogiri@1.19.7?platform=arm64-darwin (platform_gem_unsupported): Gemfile.lock locks `nokogiri (1.19.7)` (the ruby platform) beside the platform gems `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)`: a vendored directory of prebuilt platform gems has nothing for the ruby platform, and bundler never builds a `path:` gem's extensions. Remove the ruby platform from the lock (`bundle lock --remove-platform ruby`) to vendor nokogiri

Expected

One refusal per gem. docs/ecosystems.md ("Ruby gems: native extensions", the Vendored row) says of a gem vendored as platform gems that "--json reports one event per platform gem under its own patch (the summary lines count the gem as one package)", and "Ruby gems: gems vendored mode refuses" lists platform_gem_unsupported as a refusal of the gem. The other per-gem messages of the same run already behave that way: vendor_prebuilt_platform_pending prints one Skipping pkg:gem/sqlite3@2.10.2?platform=ruby: … line that names every platform.

Actual

One [error] line per patch of the gem (the ruby gem's and each platform gem's), all with the same text, and a total that counts each as a failed patch. The same happens on a fresh checkout and with the gems installed. A re-scan of a gem that is already vendored repeats in the same way, with one [skip] … (already vendored) line per platform patch (29 lines for three gems), including a ?platform=ruby line for a gem the lock no longer holds for the ruby platform.

Versions

socket-patch Bundler Ruby Result
main d718b07 4.1.1 3.3.6 9 lines for nokogiri; 31 lines for nokogiri + ffi + sqlite3 (run twice each)
v5.1.0 4.1.1 3.3.6 not comparable: it has no per-platform patches and does not print this refusal for the same data

Linux only; the output does not depend on the host platform.

First bad commit

0a1709b "Use the published patch for each locked Ruby platform (#2422)".

Suspect code

crates/socket-patch-core/src/vendor/gem.rs:929 (platform_lock_refusal) answers for the gem, and it is reported for each patch record of the gem. GemUnits::with_lock (crates/socket-patch-cli/src/commands/vendor.rs:3632) folds the patches of a gem into one unit led by one patch, but a refusal that fires before the unit is vendored is still emitted for every candidate.

Related doc line that is now out of date: the platform_gem_unsupported row of the table in "Ruby gems: gems vendored mode refuses" still says "Hosted mode refuses a precompiled build too" and offers only --mode agent, while the hosted section above it wires such a gem (verified: hosted mode patches nokogiri, ffi and sqlite3 on this lock).


Generated by Claude Code

Activity

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

    @mikolalysenko
    CollaboratorAuthor

    [agent] Claiming this issue. Branch: agent/fix-gem-refusal-per-platform-patch.


    Generated by Claude Code

  3. mikolalysenko commented on Dec 3, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] #2482 makes the refusal one line, one event and one failed patch per gem, in the wet run and in the dry run (platform_gem_unsupported and any other refusal that fails a gem in the same words for several of its patches).

    One part of this report is left, so the PR says Refs:

    • The re-scan of a gem already vendored as platform gems still prints one [skip] … (already vendored) line per platform patch, the ?platform=ruby line among them. Those lines are not refusals: each patch's record is reused by the vendor step, so folding them is a change to that step's output and not to the refusals.

    Generated by Claude Code

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:claimedagent:triagedbugbughuntpm:bundlerpriority:p1ux

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions