PubGrub drops negative `any` terms during conflict resolution, failing instead of backtracking to an older compatible gem version
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
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 小时
- 30 天内合并 PR
- 73
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ruby/rubygems 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
RubyGems
难度 3/5 1-2 天 新手友好度 67/100
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 65/100
维护者通常 1 天内回复
相似的 Issue
-
Payment details dialog shows "Did not pass" for AVS/CVV results that mean the check wasn't performed未关闭
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
-
autonome
难度 2/5 1-3 小时 新手友好度 83/100
demarche-numerique/demarche.numerique.gouv.fr#14566 ·
维护者通常 1 天内回复
-
area/web interface
难度 2/5 1-3 小时 新手友好度 64/100
mastodon/mastodon#41723 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 85/100
akitaonrails/ai-book-2026#15 ·