Skip to content

Stop the upgrade pass trading a root's final for a pre-release - #108

Merged
jonyoder merged 1 commit into
mainfrom
upgrade-root-downgrade-106
Nov 18, 2026
Merged

jonyoder merged 1 commit into
mainfrom
upgrade-root-downgrade-106

Conversation

@jonyoder

Copy link
Copy Markdown
Collaborator

The UpgradeRoots pass could trade a root's final release for a pre-release and keep the result, because a level gained by another root outweighed the versions the first root lost. The pass's score now puts "roots moved from a final release to a pre-release" first, so such an answer is never kept.

Fixes #106


What changed

  • resolver/upgrade.go: the score is now (roots moved final → pre-release, levels behind, versions behind), compared in that order. The last two are unchanged.
  • No new option and no exported API change. Nothing changes with the pass off.

How each case is handled

Move Result
Root: final → pre-release, older or newer Never kept (new)
Root: final → older final As before: a loss in levels/versions, kept only if the roots together gain more
Root: pre-release → newer pre-release A gain, as before
Root: pre-release → final A gain, as before
Non-root moves down Not scored, as before

A stricter rule, "never keep an answer that lowers any root", was tried and not taken: it fails 25 existing TestUpgrade* tests, since lowering one root to raise another further is what the pass is for (TestUpgradeRootsRaisesARootThatIsMajorsBehind).

Proof

New test TestUpgradeRootsRootMovingDown checks the pass's decision on each candidate (kept or not), then the pins.

Before the fix:

--- FAIL: TestUpgradeRootsRootMovingDown/final_to_an_older_pre-release_is_not_kept
    candidate map[a:1.0rc1 n:2.0]: kept = true, want false
    pass on: map[a:1.0rc1 n:2.0], want map[a:1.1 n:1.2]
--- FAIL: TestUpgradeRootsRootMovingDown/final_to_a_newer_pre-release_is_not_kept
    candidate map[a:3.0rc1 n:2.0]: kept = true, want false
    pass on: map[a:3.0rc1 n:2.0], want map[a:1.0 n:1.0]
--- PASS: TestUpgradeRootsRootMovingDown/final_to_an_older_final_is_kept_on_a_net_gain
--- PASS: TestUpgradeRootsRootMovingDown/pre-release_to_a_newer_pre-release_is_kept
--- PASS: TestUpgradeRootsRootMovingDown/pre-release_to_a_newer_final_is_kept
--- PASS: TestUpgradeRootsRootMovingDown/a_package_that_is_not_a_root_may_move_down

After the fix, all six pass.

Real data: PyPI snapshot of 2026-11-12, roots tensorflow==2.13.* and numpy, CPython 3.11 on Linux x86_64, UpgradeRoots=40 (a two-root cut of the issue's example, run by hand with a throwaway test).

before:
  pass off:  tensorflow 2.13.1, numpy 1.24.3
  candidate: tensorflow 2.13.0rc2, numpy 2.4.6  kept=true
  pass on:   tensorflow 2.13.0rc2, numpy 2.4.6
after:
  pass off:  tensorflow 2.13.1, numpy 1.24.3
  candidate: tensorflow 2.13.0rc2, numpy 2.4.6  kept=false
  pass on:   tensorflow 2.13.1, numpy 1.24.3

go test ./..., go test -race ./..., go vet ./..., gofmt -l . and golangci-lint v2.11.2 are clean.

🤖 Generated with Claude Code

The pass scored only levels and versions behind, so a root dropping to a
pre-release cost a version or two and a level gained elsewhere outweighed it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@jonyoder

Copy link
Copy Markdown
Collaborator Author

Merging at ad1add02d75bb54ccd73a13586a247bdcfcdc293 under Jon's standing approval for go-pyresolver. Jon has not reviewed this code himself.

Reviews:

  • RoboRev job 5506 on the head commit: pass, no findings.
  • An independent reviewer (a separate Claude session that did not write the change): approve with nits. It turned the new score term off in a scratch copy and saw the two pre-release tests fail, and ran go test -race ./resolver/.
  • CI: build and lint green.

Left as-is, all low:

  • A root can still drop to an older final when the roots together gain more. The issue asks for a loss in the score, not a veto, and that move was already scored as a loss.
  • The CHANGELOG says 2.13.0rc2 (what a two-root run on the November snapshot picked); the issue's 18-root example picked rc1.
  • No test covers a .devN pin. IsPreRelease counts it as a pre-release, the same as the rest of the pass.

No exported API changed.

@jonyoder
jonyoder merged commit 4528a18 into main Nov 18, 2026
2 checks passed
@jonyoder
jonyoder deleted the upgrade-root-downgrade-106 branch November 18, 2026 18:14
@jonyoder jonyoder mentioned this pull request Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upgrade pass counts a move to an older pre-release as a gain

1 participant