PubGrub drops negative `any` terms during conflict resolution, failing instead of backtracking to an older compatible gem version

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

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

まだ誰も着手していません。

評価

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

調査の方向性

Start with lib/rubygems/vendor/pub_grub/lib/pub_grub/term.rb, especially Gem::PubGrub::Term#empty?, then trace how VersionSolver#resolve_conflict handles the negative any term described in the report. Reproduce with the supplied local gem repository and bundle lock or gem install; done means both commands backtrack to aa 1.0.0 for this dependency set.

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

説明

Describe the problem as clearly as you can

When a newer version of a gem (aa 2.0.0) depends on two packages (ff and ll) whose available versions cannot be jointly satisfied across all versions of ff, both bundle lock and gem install aa fail version solving instead of backtracking to aa 1.0.0 (which has no dependencies and satisfies gem "aa").

In lib/rubygems/vendor/pub_grub/lib/pub_grub/term.rb, Gem::PubGrub::Term#empty? checks normalized_constraint.empty?, where normalized_constraint inverts negative constraints. For not ff any (Term.new(VersionConstraint.any(ff), false)), constraint.invert is empty, so Term#empty? returns true even though a negative any term is satisfied whenever ff is not selected. During VersionSolver#resolve_conflict, (not ff < 2.0.0).difference(ff >= 2.0.0) produces not ff any, difference.empty? discards it, and difference.invert (+ ff any) is omitted from the learned incompatibility, deriving {ll < 1 OR = 3} unconditionally instead of backtracking aa 2.0.0 -> aa 1.0.0 (compare reference PubGrub in dart-lang/pub lib/src/solver/term.dart).

Did you try upgrading rubygems & bundler?

Yes. Reproduces on RubyGems 4.1.0 and Bundler 4.1.0, as well as master (5879ffe34b, 4.2.0.dev), on Ruby 4.0.9. Bundler 2.3.7 and gem install on RubyGems 4.0.20 (before RubyGems switched to PubGrub) resolve aa 1.0.0.

Post steps to reproduce the problem
mkdir /tmp/repro-pubgrub && cd /tmp/repro-pubgrub
mkdir -p repo/gems repo/quick/Marshal.4.8 app

ruby - << 'RUBY'
require "rubygems/package"
require "zlib"

specs = [
  Gem::Specification.new { |s| s.name = "aa"; s.version = "1.0.0"; s.summary = "aa 1"; s.authors = ["test"] },
  Gem::Specification.new do |s|
    s.name = "aa"; s.version = "2.0.0"; s.summary = "aa 2"; s.authors = ["test"]
    s.add_dependency "ff"
    s.add_dependency "ll"
  end,
  Gem::Specification.new do |s|
    s.name = "ff"; s.version = "1.0.0"; s.summary = "ff 1"; s.authors = ["test"]
    s.add_dependency "ll", "< 1"
  end,
  Gem::Specification.new do |s|
    s.name = "ff"; s.version = "2.0.0"; s.summary = "ff 2"; s.authors = ["test"]
    s.add_dependency "ll", "= 3"
  end,
  Gem::Specification.new { |s| s.name = "ll"; s.version = "2.0.0"; s.summary = "ll 2"; s.authors = ["test"] },
]

specs.each do |s|
  gem_file = Gem::Package.build(s, true)
  File.rename(gem_file, "repo/gems/" + gem_file)
  File.binwrite("repo/quick/Marshal.4.8/" + s.original_name + ".gemspec.rz",
    Zlib::Deflate.deflate(Marshal.dump(s)))
end
File.binwrite("repo/specs.4.8.gz",
  Zlib.gzip(Marshal.dump(specs.map { |s| [s.name, s.version, "ruby"] })))
File.binwrite("repo/prerelease_specs.4.8.gz", Zlib.gzip(Marshal.dump([])))
RUBY

cat > app/Gemfile <<GEMFILE
source "file://$PWD/repo"
gem "aa"
GEMFILE

(cd app && BUNDLE_PATH=vendor/bundle bundle lock)
gem install aa -i "$PWD/gemhome" --clear-sources --source "file://$PWD/repo" --no-document
Which command did you run?

bundle lock and gem install aa -i "$PWD/gemhome" --clear-sources --source "file://$PWD/repo" --no-document.

What were you expecting to happen?

Both bundle lock and gem install aa backtrack past aa 2.0.0 and resolve aa 1.0.0.

What happened instead?

bundle lock exits with status 6 and gem install aa exits with status 2:

$ (cd app && BUNDLE_PATH=vendor/bundle bundle lock)
Writing lockfile to /tmp/repro-pubgrub/app/Gemfile.lock
Fetching source index from file:///tmp/repro-pubgrub/repo/
Resolving dependencies...
Could not find compatible versions

Because ff < 2.0.0 depends on ll < 1
  and ff >= 2.0.0 depends on ll = 3,
  ll < 1 OR = 3 is required.
So, because ll < 1 OR = 3 could not be found in rubygems repository
file:///tmp/repro-pubgrub/repo/ or installed locally,
  version solving has failed.

$ gem install aa -i "$PWD/gemhome" --clear-sources --source "file://$PWD/repo" --no-document
ERROR:  Error installing aa:
	Because ff < 2.0.0 depends on ll < 1
  and ff >= 2.0.0 depends on ll = 3,
  ll < 1 OR = 3 is required.
So, because no versions satisfy ll < 1 OR = 3,
  version solving has failed.
If not included with the output of your command, run bundle env and paste the output below
## Environment

```
Bundler       4.1.0
  Platforms   ruby, x86_64-linux
Ruby          4.0.9p0 (2026-10-23 revision 3e93b23afcec3433f6aecc34b5d832799d754238) [x86_64-linux]
  Full Path   /opt/ruby/bin/ruby
  Config Dir  /opt/ruby/etc
RubyGems      4.1.0
  Gem Home    /opt/ruby/lib/ruby/gems/4.0.0
  Gem Path    /home/user/.local/share/gem/ruby/4.0.0:/opt/ruby/lib/ruby/gems/4.0.0
  User Home   /home/user
  User Path   /home/user/.local/share/gem/ruby/4.0.0
  Bin Dir     /opt/ruby/bin
Git           2.39.5
```

## Bundler Build Metadata

```
Timestamp  2026-11-16
Git SHA    9af9267
```

## Bundler settings

```
path
  Set via BUNDLE_PATH: "vendor/bundle"
```

## Gemfile

### Gemfile

```ruby
source "file:///tmp/repro-pubgrub/repo"
gem "aa"
```

### Gemfile.lock

```
<No /tmp/repro-pubgrub/app/Gemfile.lock found>
```

Credit: https://ucsbplse.github.io/

主要言語
Ruby
スター
4k
フォーク
2k
平均マージ
1日 21時間
マージ済み PR(30日)
73

環境構築

Codespaces で開く

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

はじめの一歩

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

ruby/rubygems のほかの issue

ruby/rubygems の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

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

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