Skip to content

Hosted gem scan sends a gemspec-declared gem to --mode vendored, which refuses it for the same reason and names no remedy #2151

Closed

Description

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

Summary

In a gem library project (a Gemfile with gemspec), a patched gem that only the gemspec declares is refused by hosted mode with redirect_gem_declaration_not_visible. The warning offers two ways out: add a literal gem line, "or patch it with --mode vendored or --mode agent". Vendored mode refuses the same gem for the same reason, exits 1, and its error names no remedy at all. Only the gem line and --mode agent work.

docs/ecosystems.md repeats the claim under the refusal table: "--mode vendored or --mode agent can still patch a gem hosted mode skips."

Impact

Friction, no damage: neither run writes anything for the gem. But the user follows the tool's own advice, gets a hard error (exit 1, which fails a CI step), and has to guess the next move. Every gem library with an add_development_dependency on a patched gem hits this (a runtime add_dependency gem is wired as a transitive dependency and is fine), and the same text is printed for an eval_gemfiled file and a loop.

Repro

Any patch for rack-test 2.1.0 will do. I used a local mock of the patch API ($MOCK stands for --api-url … --patch-server-url … --api-token … --org …).

mkdir -p mylib/lib && cd mylib && git init -q .
cat > mylib.gemspec <<'RB'
Gem::Specification.new do |s|
  s.name = "mylib"; s.version = "0.1.0"; s.summary = "lib"; s.authors = ["a"]
  s.files = Dir["lib/**/*.rb"]
  s.add_development_dependency "rack-test", "2.1.0"
end
RB
echo 'module Mylib; end' > lib/mylib.rb
printf 'source "https://rubygems.org"\n\ngemspec\n' > Gemfile
bundle config set --local path vendor/bundle && bundle install

socket-patch scan --mode hosted --yes $MOCK      # exit 0, the warning below
socket-patch scan --mode vendored --yes $MOCK    # the remedy: exit 1
socket-patch scan --mode agent --yes $MOCK       # works

Actual

Hosted:

Warning: Gemfile.lock lists rack-test as a direct dependency, but Gemfile declares it somewhere the rewriter cannot edit (an `eval_gemfile`d file, a loop, a gemspec); adding a second declaration would make bundler refuse the Gemfile — redirect skipped (declare it with a literal `gem "rack-test"` line in Gemfile, or patch it with `--mode vendored` or `--mode agent`)

Vendored, as the warning suggests:

Error: Cannot vendor pkg:gem/rack-test@2.1.0: Gemfile.lock lists "rack-test" as a direct dependency, but the Gemfile declares it somewhere the line grammar cannot edit (an `eval_gemfile`d file, a loop, a gemspec); refusing to append a second declaration (bundler hard-fails on duplicates)
Vendored 0 packages; 1 failed.

Exit 1, nothing written.

The other two remedies work on Bundler 4.0.18: --mode agent patches the installed gem, and after echo 'gem "rack-test"' >> Gemfile && bundle install a hosted scan wires it, the frozen install passes and the app loads the patched code.

Expected

A remedy the tool prints should work when followed (the bar #2091 set for the other vendored refusals):

  • the hosted warning for this refusal offers the gem line and --mode agent only, and the sentence in docs/ecosystems.md under the "When a gem is left alone" table doesn't promise vendored mode for it;
  • the vendored refusal names its way out too: declare the gem with a literal gem "<name>" line in the Gemfile, or use --mode agent.

Versions

socket-patch Bundler Ruby Result
main 4fe0859 (5.1.0) 4.0.18 3.3.6 Reproduces (two projects)
main 4fe0859 (5.1.0) 2.5.22 3.3.6 Reproduces

Linux only; nothing here is platform-specific.

Suspect code

  • crates/socket-patch-core/src/patch/redirect/mod.rs:8267 builds the hosted warning that names --mode vendored.
  • crates/socket-patch-core/src/vendor/gem.rs:1646 (refuse_append_of_direct_dependency) is the vendored refusal with no remedy; Fix vendored gem refusals naming no remedy (#2091) #2127 added remedies to the other vendored refusals but not this one.
  • docs/ecosystems.md:2048.

Generated by Claude Code

Activity

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

    @mikolalysenko
    CollaboratorAuthor

    [agent] Claiming this issue. Branch: agent/fix-gem-not-visible-remedy.


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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions