Composed bundle rewrites project binstubs when Bundler bin is set

Ouverte
#4,280 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@efegokdemir y travaille déjà.

Depuis le 23/11/2026.

  • #4284 par @efegokdemir — ouverte

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
42/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
À l'abandon
Stack technique
ruby

Piste de recherche

Work in lib/ruby_lsp/setup_bundler.rb: bundle_install (~line 342) and update (~line 353) run Bundler in process in launcher mode, while bundler_settings_as_env (~430) strips bin. Run the reporter's repro.sh first and watch the BUNDLE_GEMFILE line in exe/rake across the four steps. Check the existing setup_bundler tests for launcher-mode install/update and extend them to assert project binstubs are untouched when Bundler.settings[:bin] or an inherited BUNDLE_BIN is set; done means the stubs still point at ../Gemfile after the composed install and after an update.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

bug
Description
Ruby LSP Information
  • Ruby LSP server gem: 0.26.11
  • Ruby LSP VS Code extension: 0.10.8
  • VS Code: 1.146.0
  • Ruby: 3.4.8, installed with mise
  • Bundler: 2.6.9
  • OS: Ubuntu 26.04.1
  • Launcher: enabled
Reproduction steps
  1. Install the prerequisites:

    gem install ruby-lsp
    gem install bundler -v 2.6.9
    
  2. Save the script below as repro.sh. It creates a temporary project with bin set to exe in .bundle/config, then runs ruby-lsp-launcher against it.

  3. Run bash repro.sh.

  4. Compare the BUNDLE_GEMFILE line in exe/rake after each step.

Expected: exe/rake keeps pointing at ../Gemfile, because the binstubs belong to the project's main bundle.

Actual: both the first composed bundle install and the later background update rewrite exe/rake to point at ../.ruby-lsp/Gemfile. Commands run through those binstubs then use the composed bundle.

Personal takes

I have used AI to generate the bug report, however the problem has been real for a while. I have 2 different unrelated machines (one debian, one ubuntu) and they both keep facing this problem: I run stuff in a project and every once in a while I get gem errors, because I use binstubs (in my path) and they get replaced with ruby-lsp generated binstubs.

This is incredibly annoying because the errors are very cryptic at times.
When I figure out what's going on, I have to repair them with:

rm -rf exe; BUNDLE_GEMFILE="$PWD/Gemfile" bundle binstubs --all

The worst part of this is that it's not consistent, it depends IF I run vscode and for HOW LONG I run it.

Code snippet or error message

#!/usr/bin/env bash
# Requires: gem install bundler -v 2.6.9 && gem install ruby-lsp
set -euo pipefail
unset BUNDLE_APP_CONFIG BUNDLE_BIN BUNDLE_GEMFILE BUNDLE_PATH

launcher="$(ruby -e 'puts Gem::Specification.find_by_name("ruby-lsp").bin_file("ruby-lsp-launcher")')"
project="$(mktemp -d)"
cd "$project"

bundle() { command bundle _2.6.9_ "$@"; }
launch() { ruby "$launcher" "file://$project" </dev/null >/dev/null 2>&1; }
show() { printf '%-28s %s\n' "$1:" "$(grep BUNDLE_GEMFILE exe/rake)"; }

printf 'source "https://rubygems.org"\ngem "rake", "13.2.1"\n' > Gemfile
bundle config set --local path vendor/bundle
bundle config set --local bin exe
bundle install >/dev/null
show "after bundle install"

launch
show "after first launcher run"

bundle binstubs rake --force >/dev/null
show "after repairing binstubs"

echo "2020-01-01T00:00:00+00:00" > .ruby-lsp/last_updated
launch # Flags .ruby-lsp/needs_update.
show "after stale launcher run"
launch # Runs the update.
show "after update"

Output:

after bundle install:        ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
after first launcher run:    ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../.ruby-lsp/Gemfile", __dir__)
after repairing binstubs:    ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
after stale launcher run:    ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
after update:                ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../.ruby-lsp/Gemfile", __dir__)

This looks like a remaining case of #2440, which #3277 closed. bundler_settings_as_env excludes bin from the hash it returns (lib/ruby_lsp/setup_bundler.rb:430), but in launcher mode bundle_install and update run Bundler in process (:342 and :353). When the stubs were written during the update, Bundler still had:

Bundler.default_gemfile  <project>/.ruby-lsp/Gemfile
Bundler.root             <project>
Bundler.settings[:bin]   ./exe, from <project>/.bundle/config
Bundler.bin_path         <project>/exe

An inherited BUNDLE_BIN environment variable triggers the same rewrite during the update, with no bin entry in .bundle/config.

With launcher mode off, the update left the binstubs unchanged. Removing the persistent bin setting and the BUNDLE_BIN variable also avoids the rewrite.

Langage dominant
Ruby
Étoiles
2k
Forks
300
Merge moyen
2 h 54 min
PR mergées (30 j)
9

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de Shopify/ruby-lsp

Toutes les issues de Shopify/ruby-lsp

Issues similaires

Plus d'issues Ruby

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.