Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

rbenv activation leaks RBENV_VERSION and RBENV_DIR into process.env of the extension host

オープン
#4,238 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@efegokdemir がすでに取り組んでいます。

2026年10月15日 から。

  • #4239 @efegokdemir による — オープン

評価

難易度
3/5
見積もり時間
半日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
ruby, typescript, vscode
領域
devtools

調査の方向性

Start in vscode/src/ruby.ts, where the activated environment is assigned to process.env, and in sanitizeEnvironment, which filters the dump from rbenv exec (vscode/src/ruby/rbenv.ts). Also check versionManager.ts, where the activation script is spawned with env: process.env. Done means RBENV_VERSION and RBENV_DIR no longer reach process.env after activation, while the Ruby LSP server still gets the rbenv-selected environment. Choosing between the three proposed fixes is a maintainer decision, so ask before committing to one.

索引モデルが issue の本文から書いたものです。

説明

bug
Description

After Ruby activation, the extension replaces the environment of the whole extension host:

https://github.com/Shopify/ruby-lsp/blob/c6aec8cbb23f5a81b1608e5e676159056a951f6f/vscode/src/ruby.ts#L229-L232

With rbenv, env is the environment of rbenv exec ruby
(rbenv.ts).
rbenv exec exports its internal variables to the child process, so the dump contains:

RBENV_VERSION=4.0.6
RBENV_DIR=/path/to/first/workspace
RBENV_HOOK_PATH=...
RBENV_ORIG_PATH=...

sanitizeEnvironment removes only RUBY_GC*, VERBOSE and DEBUG, so these variables end up in
process.env. rbenv gives RBENV_VERSION priority over .ruby-version, and it looks for
.ruby-version from RBENV_DIR rather than from the current directory. Every process started from
the extension host after activation is therefore pinned to the Ruby version and the folder of the
first activation.

Impact
  1. Other extensions. All extensions share one extension host. A CLI that another extension
    starts inherits the pinned version. We hit this with the Claude Code extension: its CLI, and every
    shell it opens, had RBENV_VERSION set. After a Ruby bump in .ruby-version, Bundler fails with
    Your Ruby version is X, but your Gemfile specified Y until VS Code restarts. The integrated
    terminal is not affected, because it does not start from the extension host. That made the cause
    hard to find.

  2. Ruby LSP itself. Activation spawns the activation script with env: process.env
    (versionManager.ts). After the first activation, process.env already holds RBENV_VERSION, so
    a later rbenv exec ruby gets the old version. From reading the code, we expect this for:

    • a second folder of a multi-root workspace with a different .ruby-version,
    • "Ruby LSP: Restart" after a change of .ruby-version.

    We did not run these two cases ourselves. #3270 reports the same Bundler error with rbenv,
    including in a multi-root workspace.

Steps to reproduce
  1. Use rbenv, and open a project with a .ruby-version in VS Code with Ruby LSP.
  2. Wait until Ruby LSP activates Ruby.
  3. Start a process from another extension (for example, the Claude Code extension) and run
    env | grep RBENV.

Expected: no RBENV_VERSION or RBENV_DIR. rbenv selects the version from .ruby-version of
the current directory.

Actual: RBENV_VERSION and RBENV_DIR hold the values of the first activation.

Proposed fix

One of these, from the smallest change to the cleanest:

  1. Delete the version manager internals in sanitizeEnvironment: RBENV_VERSION, RBENV_DIR,
    RBENV_HOOK_PATH and RBENV_ORIG_PATH. Other managers can have similar variables.
  2. Copy only the variables that other extensions need into process.env: PATH, GEM_HOME and
    GEM_PATH.
  3. Remove the global assignment, and keep the activated environment for the Ruby LSP server only.

In #1997, the global assignment was called "simply the easiest option" while the integrations mature.
Option 1 or 2 keeps that purpose and removes the leak.

Related
  • #1997: the same process.env assignment broke PATH for other extensions with asdf.
  • #3270: stray RBENV_VERSION and a Bundler version mismatch with rbenv.
  • Shopify/vscode-ruby-lsp#699: introduced the assignment (Shadowenv only).
  • #1438, #1502: applied it to all version managers. #1811: rbenv uses the same path.
Environment
  • Ruby LSP extension 0.10.6 (the code on main at c6aec8cbb2 is the same)
  • VS Code 1.141.1
  • rbenv 1.3.2
  • macOS 26
  • Workaround: set RBENV_VERSION="" and RBENV_DIR="" in the environment of the affected tool.
    rbenv treats an empty value as unset.
主要言語
Ruby
スター
2k
フォーク
283
平均マージ
9時間 18分
マージ済み PR(30日)
11

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Shopify/ruby-lsp のほかの issue

Shopify/ruby-lsp の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。