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

Aperta
#10,084 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
56/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
ruby
Ambito
backend, databases

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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/

Lingua principale
Ruby
Stelle
4k
Fork
2k
Merge medio
1g 21h
PR unite (30g)
73

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ruby/rubygems

Tutte le issue di ruby/rubygems

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.