Skip to content

Support transitive pre-release dependencies with a fixed universe - #19998

Closed
charliermarsh wants to merge 20 commits into
mainfrom
charlie/prerelease-fixed-universe
Closed

charliermarsh wants to merge 20 commits into
mainfrom
charlie/prerelease-fixed-universe

Conversation

@charliermarsh

Copy link
Copy Markdown
Member

Summary

Supersedes #19993.

Prior to this change, uv decided whether pre-releases were enabled for a package before dependency resolution began. An explicit pre-release requirement discovered in transitive metadata therefore did not authorize that package, while --prerelease=allow enabled pre-releases globally and could select unrelated pre-releases. The if-necessary modes also fell back only when a package had no stable releases at all, rather than when no stable candidate satisfied the active constraints.

This makes pre-release fallback range-relative and represents candidate preference directly in PubGrub's version universe. Each release has a stable-preferring solver variant and a pre-release-enabled variant. Ordinary requirements admit both variants, while an active requirement that names a pre-release admits only the enabled variant. PubGrub's existing range intersection and backtracking can therefore reconsider an earlier stable decision when transitive authorization appears, discard authorization when its parent is rejected, and keep marker forks isolated, without resolver restarts, mutable global authorization, proxy packages, or changes to PubGrub itself.

Metadata, availability facts, and dependency incompatibilities are shared between the two variants of the same release, while candidate selection and batch prefetch preserve the selected preference dimension. Final resolutions and derivation trees collapse the variants back to ordinary versions. This preserves existing diagnostics, avoids duplicate metadata work, and prevents speculative prefetches from crossing into the wrong preference dimension. if-necessary and the default if-necessary-or-explicit now prefer stable candidates relative to the active range; the standalone explicit mode is removed.

The regression coverage exercises transitive requirements, late authorization after a stable decision, extras, markers, cached metadata, multi-hop chains, rejected parents, universal-resolution forks, isolated build requirements, disallow, offline diagnostics, incorrect pre-release hints, and preference-aware prefetch. The resolution and compatibility documentation now describe the fixed-universe model.

Related to #3602 and #14851.

Closes #19593.
Closes #2685.
Closes #11483.
Closes #19324.
Closes #12589.
Closes #9395.
Closes #16494.
Closes #16893.

@codspeed

codspeed Bot commented Jun 26, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 16.3%

❌ 3 regressed benchmarks
✅ 10 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ WallTime resolve_warm_airflow 428.7 ms 586.8 ms -26.95%
❌ WallTime resolve_warm_jupyter_universal 138.2 ms 156.7 ms -11.81%
❌ Simulation resolve_warm_jupyter_universal 213.2 ms 234.2 ms -8.99%

Tip

Investigate this regression with the CodSpeed MCP and your agent.


Comparing charlie/prerelease-fixed-universe (f243dfb) with main (39b1823)

Open in CodSpeed

@charliermarsh
charliermarsh force-pushed the charlie/prerelease-fixed-universe branch from 9ac9895 to cb803fc Compare June 26, 2026 01:59
@astral-sh-bot

astral-sh-bot Bot commented Jun 26, 2026 •

Copy link
Copy Markdown

uv test inventory changes

This PR changes the tests when compared with the latest main baseline.

  • Added tests: 24
  • Removed tests: 1
  • Changed suites: 6
uv-resolver: +9 / -0

Added:

  • uv-resolver::error::tests::collapse_prerelease_preferences_drops_source_tree_without_recursion
  • uv-resolver::error::tests::collapse_prerelease_preferences_normalizes_ranges
  • uv-resolver::prerelease::tests::default_range_uses_preference_dimensions
  • uv-resolver::prerelease::tests::exclusion_does_not_enable_prereleases
  • uv-resolver::prerelease::tests::legacy_explicit_mode_deserializes_to_default
  • uv-resolver::prerelease::tests::legacy_explicit_mode_is_a_cli_alias_for_default
  • uv-resolver::pubgrub::version::tests::complement_and_intersection_obey_product_set_semantics
  • uv-resolver::pubgrub::version::tests::explicit_intersection_removes_stable_preference
  • uv-resolver::pubgrub::version::tests::singleton_selects_only_its_preference_dimension

Removed: none

uv::lock: +1 / -0

Added:

  • uv::lock::lock::lock_legacy_explicit_prerelease_mode

Removed: none

uv::lock_scenarios: +1 / -0

Added:

  • uv::lock_scenarios::lock_scenarios::transitive_prerelease_authorization_forks

Removed: none

uv::pip: +4 / -0

Added:

  • uv::pip::pip_install_scenarios::transitive_prerelease_authorization_after_decision
  • uv::pip::pip_install_scenarios::transitive_prerelease_authorization_backtracks
  • uv::pip::pip_install_scenarios::transitive_prerelease_authorization_before_no_versions
  • uv::pip::pip_install_scenarios::transitive_prerelease_authorizes_newer_prerelease

Removed: none

uv::pip_compile: +7 / -0

Added:

  • uv::pip_compile::pip_compile::offline_registry_prerelease
  • uv::pip_compile::pip_compile::transitive_prerelease_authorization_chain
  • uv::pip_compile::pip_compile::transitive_prerelease_cached_dependencies_reconsider_stable_decision
  • uv::pip_compile::pip_compile::transitive_prerelease_extra_reconsiders_stable_decision
  • uv::pip_compile::pip_compile::transitive_prerelease_marker_reconsiders_stable_decision
  • uv::pip_compile::pip_compile::transitive_prerelease_reconsiders_stable_decision
  • uv::pip_compile::pip_compile::transitive_prerelease_suppresses_disabled_hint

Removed: none

uv::pip_install: +2 / -1

Added:

  • uv::pip_install::pip_install::build_transitive_prerelease
  • uv::pip_install::pip_install::disallow_transitive_prerelease

Removed:

  • uv::pip_install::pip_install::build_prerelease_hint

charliermarsh added a commit that referenced this pull request Jul 14, 2026
## Summary

Prior to this change, we needed to know upfront whether a given package
was "allowed" to use a pre-release -- either by way of being a
first-party dependency with a pre-release marker on it (e.g., `flask >=
2.0.0a0`), or by _only_ having pre-releases available on PyPI at all, or
by the user _always_ allowing pre-releases via configuration. By
default, if transitive metadata later introduced a requirement like
`foo>=2.0.0b1`, that requirement did _not_ enable pre-releases for
`foo`, even though it should've (per the spec).

This PR adds support for actual transitive pre-release requirements: we
prefer stable candidates that satisfy the current range, then consider
pre-releases when those candidates are exhausted. An explicit
pre-release requirement discovered during resolution is represented by a
PubGrub proxy package.

For completeness, I also prototyped a
[nab](https://github.com/notatallshaw/nab)-style solution in #19998.
That design encoded stable- and pre-release-enabled variants directly in
PubGrub. It's arguably semantically nicer, but it was much more invasive
and caused more significant CodSpeed regressions on large graphs. I
ultimately decided that this solution is better for now, given that it's
both simpler and closer to how we model versions today.

This smaller, proxy-package solution does get at least one case wrong.
If a selected stable version of package A satisfies requirements, and we
then find a package that depends on A with a pre-release, PubGrub may
retain that version instead of "upgrading" it to a newer pre-release.
The net effect is that we may accept an older stable release rather than
upgrading to a newer pre-release if we see a pre-release requirement
later on in a solve. I think this is an acceptable limitation as
compared to the number of issues we'll be able to close here. And nab
suffers from some similar issues (as per
#19993 (comment)).

Finally, the former `--prerelease=explicit` policy has been deprecated.
`explicit` is the only mode we can't support here, because it requires
adding pre-release candidates after resolution has already begun. The
behavior is preserved, but unlike the other modes, it doesn't support
transitive pre-releases (i.e., it's ~unchanged vs. main). Personally, I
don't think that `explicit` vs. `if-necessary-or-explicit` is really an
important distinction.

Related: #3602.
Related: #14851.

Closes #19593.
Closes #2685.
Closes #11483.
Closes #19324.
Closes #12589.
Closes #9395.
Closes #16494.
Closes #16893.
konstin pushed a commit that referenced this pull request Jul 21, 2026
## Summary

Prior to this change, we needed to know upfront whether a given package
was "allowed" to use a pre-release -- either by way of being a
first-party dependency with a pre-release marker on it (e.g., `flask >=
2.0.0a0`), or by _only_ having pre-releases available on PyPI at all, or
by the user _always_ allowing pre-releases via configuration. By
default, if transitive metadata later introduced a requirement like
`foo>=2.0.0b1`, that requirement did _not_ enable pre-releases for
`foo`, even though it should've (per the spec).

This PR adds support for actual transitive pre-release requirements: we
prefer stable candidates that satisfy the current range, then consider
pre-releases when those candidates are exhausted. An explicit
pre-release requirement discovered during resolution is represented by a
PubGrub proxy package.

For completeness, I also prototyped a
[nab](https://github.com/notatallshaw/nab)-style solution in #19998.
That design encoded stable- and pre-release-enabled variants directly in
PubGrub. It's arguably semantically nicer, but it was much more invasive
and caused more significant CodSpeed regressions on large graphs. I
ultimately decided that this solution is better for now, given that it's
both simpler and closer to how we model versions today.

This smaller, proxy-package solution does get at least one case wrong.
If a selected stable version of package A satisfies requirements, and we
then find a package that depends on A with a pre-release, PubGrub may
retain that version instead of "upgrading" it to a newer pre-release.
The net effect is that we may accept an older stable release rather than
upgrading to a newer pre-release if we see a pre-release requirement
later on in a solve. I think this is an acceptable limitation as
compared to the number of issues we'll be able to close here. And nab
suffers from some similar issues (as per
#19993 (comment)).

Finally, the former `--prerelease=explicit` policy has been deprecated.
`explicit` is the only mode we can't support here, because it requires
adding pre-release candidates after resolution has already begun. The
behavior is preserved, but unlike the other modes, it doesn't support
transitive pre-releases (i.e., it's ~unchanged vs. main). Personally, I
don't think that `explicit` vs. `if-necessary-or-explicit` is really an
important distinction.

Related: #3602.
Related: #14851.

Closes #19593.
Closes #2685.
Closes #11483.
Closes #19324.
Closes #12589.
Closes #9395.
Closes #16494.
Closes #16893.
konstin pushed a commit that referenced this pull request Jul 24, 2026
Prior to this change, we needed to know upfront whether a given package
was "allowed" to use a pre-release -- either by way of being a
first-party dependency with a pre-release marker on it (e.g., `flask >=
2.0.0a0`), or by _only_ having pre-releases available on PyPI at all, or
by the user _always_ allowing pre-releases via configuration. By
default, if transitive metadata later introduced a requirement like
`foo>=2.0.0b1`, that requirement did _not_ enable pre-releases for
`foo`, even though it should've (per the spec).

This PR adds support for actual transitive pre-release requirements: we
prefer stable candidates that satisfy the current range, then consider
pre-releases when those candidates are exhausted. An explicit
pre-release requirement discovered during resolution is represented by a
PubGrub proxy package.

For completeness, I also prototyped a
[nab](https://github.com/notatallshaw/nab)-style solution in #19998.
That design encoded stable- and pre-release-enabled variants directly in
PubGrub. It's arguably semantically nicer, but it was much more invasive
and caused more significant CodSpeed regressions on large graphs. I
ultimately decided that this solution is better for now, given that it's
both simpler and closer to how we model versions today.

This smaller, proxy-package solution does get at least one case wrong.
If a selected stable version of package A satisfies requirements, and we
then find a package that depends on A with a pre-release, PubGrub may
retain that version instead of "upgrading" it to a newer pre-release.
The net effect is that we may accept an older stable release rather than
upgrading to a newer pre-release if we see a pre-release requirement
later on in a solve. I think this is an acceptable limitation as
compared to the number of issues we'll be able to close here. And nab
suffers from some similar issues (as per
#19993 (comment)).

Finally, the former `--prerelease=explicit` policy has been deprecated.
`explicit` is the only mode we can't support here, because it requires
adding pre-release candidates after resolution has already begun. The
behavior is preserved, but unlike the other modes, it doesn't support
transitive pre-releases (i.e., it's ~unchanged vs. main). Personally, I
don't think that `explicit` vs. `if-necessary-or-explicit` is really an
important distinction.

Related: #3602.
Related: #14851.

Closes #19593.
Closes #2685.
Closes #11483.
Closes #19324.
Closes #12589.
Closes #9395.
Closes #16494.
Closes #16893.
konstin pushed a commit that referenced this pull request Jul 28, 2026
Prior to this change, we needed to know upfront whether a given package
was "allowed" to use a pre-release -- either by way of being a
first-party dependency with a pre-release marker on it (e.g., `flask >=
2.0.0a0`), or by _only_ having pre-releases available on PyPI at all, or
by the user _always_ allowing pre-releases via configuration. By
default, if transitive metadata later introduced a requirement like
`foo>=2.0.0b1`, that requirement did _not_ enable pre-releases for
`foo`, even though it should've (per the spec).

This PR adds support for actual transitive pre-release requirements: we
prefer stable candidates that satisfy the current range, then consider
pre-releases when those candidates are exhausted. An explicit
pre-release requirement discovered during resolution is represented by a
PubGrub proxy package.

For completeness, I also prototyped a
[nab](https://github.com/notatallshaw/nab)-style solution in #19998.
That design encoded stable- and pre-release-enabled variants directly in
PubGrub. It's arguably semantically nicer, but it was much more invasive
and caused more significant CodSpeed regressions on large graphs. I
ultimately decided that this solution is better for now, given that it's
both simpler and closer to how we model versions today.

This smaller, proxy-package solution does get at least one case wrong.
If a selected stable version of package A satisfies requirements, and we
then find a package that depends on A with a pre-release, PubGrub may
retain that version instead of "upgrading" it to a newer pre-release.
The net effect is that we may accept an older stable release rather than
upgrading to a newer pre-release if we see a pre-release requirement
later on in a solve. I think this is an acceptable limitation as
compared to the number of issues we'll be able to close here. And nab
suffers from some similar issues (as per
#19993 (comment)).

Finally, the former `--prerelease=explicit` policy has been deprecated.
`explicit` is the only mode we can't support here, because it requires
adding pre-release candidates after resolution has already begun. The
behavior is preserved, but unlike the other modes, it doesn't support
transitive pre-releases (i.e., it's ~unchanged vs. main). Personally, I
don't think that `explicit` vs. `if-necessary-or-explicit` is really an
important distinction.

Related: #3602.
Related: #14851.

Closes #19593.
Closes #2685.
Closes #11483.
Closes #19324.
Closes #12589.
Closes #9395.
Closes #16494.
Closes #16893.
zanieb pushed a commit that referenced this pull request Jul 28, 2026
Prior to this change, we needed to know upfront whether a given package
was "allowed" to use a pre-release -- either by way of being a
first-party dependency with a pre-release marker on it (e.g., `flask >=
2.0.0a0`), or by _only_ having pre-releases available on PyPI at all, or
by the user _always_ allowing pre-releases via configuration. By
default, if transitive metadata later introduced a requirement like
`foo>=2.0.0b1`, that requirement did _not_ enable pre-releases for
`foo`, even though it should've (per the spec).

This PR adds support for actual transitive pre-release requirements: we
prefer stable candidates that satisfy the current range, then consider
pre-releases when those candidates are exhausted. An explicit
pre-release requirement discovered during resolution is represented by a
PubGrub proxy package.

For completeness, I also prototyped a
[nab](https://github.com/notatallshaw/nab)-style solution in #19998.
That design encoded stable- and pre-release-enabled variants directly in
PubGrub. It's arguably semantically nicer, but it was much more invasive
and caused more significant CodSpeed regressions on large graphs. I
ultimately decided that this solution is better for now, given that it's
both simpler and closer to how we model versions today.

This smaller, proxy-package solution does get at least one case wrong.
If a selected stable version of package A satisfies requirements, and we
then find a package that depends on A with a pre-release, PubGrub may
retain that version instead of "upgrading" it to a newer pre-release.
The net effect is that we may accept an older stable release rather than
upgrading to a newer pre-release if we see a pre-release requirement
later on in a solve. I think this is an acceptable limitation as
compared to the number of issues we'll be able to close here. And nab
suffers from some similar issues (as per
#19993 (comment)).

Finally, the former `--prerelease=explicit` policy has been deprecated.
`explicit` is the only mode we can't support here, because it requires
adding pre-release candidates after resolution has already begun. The
behavior is preserved, but unlike the other modes, it doesn't support
transitive pre-releases (i.e., it's ~unchanged vs. main). Personally, I
don't think that `explicit` vs. `if-necessary-or-explicit` is really an
important distinction.

Related: #3602.
Related: #14851.

Closes #19593.
Closes #2685.
Closes #11483.
Closes #19324.
Closes #12589.
Closes #9395.
Closes #16494.
Closes #16893.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment