Skip to content

Restate available versions in error messages - #20809

Closed
notatallshaw wants to merge 6 commits into
astral-sh:mainfrom
notatallshaw:restate-available-versions
Closed

notatallshaw wants to merge 6 commits into
astral-sh:mainfrom
notatallshaw:restate-available-versions

Conversation

@notatallshaw

@notatallshaw notatallshaw commented Jul 30, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #20804, only the last commit is new.

With the widening, uv no longer asks for a version in a gap it created, so the no_versions incompatibility behind "only the following versions of X are available" is no longer created there. Steps that cross a gap then stop following from the premises next to them.

This adds the clause back while the tree is reduced: a step that reaches past what its causes report gets a NoVersions cause for the difference, on whichever cause rules the package out, or on the step itself when neither does. No solver change.

It also clamps a requires-python rejection to the listing. That rejection is recorded as a dependency on Python, so its widened range kept an unbounded end and the message named a range instead of the version, sphinx>=7.2.6 where main says sphinx==7.2.6, in the hint as well. A range like sphinx>=7.2.6 reads as a claim about every later release when only one version was rejected.

@astral-sh-bot

astral-sh-bot Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

uv test inventory changes

This PR changes the tests when compared with the main base revision.

  • Added tests: 7
  • Removed tests: 0
  • Changed suites: 1
uv-resolver: +7 / -0

Added:

  • uv-resolver::error::tests::collapses_sibling_unavailable_versions
  • uv-resolver::error::tests::keeps_sibling_unavailable_versions_concluding_about_another_package
  • uv-resolver::error::tests::narrows_widened_conclusion_of_one_version
  • uv-resolver::error::tests::narrows_widened_unavailable_version_of_one_version
  • uv-resolver::error::tests::narrows_widened_unavailable_versions
  • uv-resolver::resolver::tests::widens_a_version_to_its_gap
  • uv-resolver::resolver::tests::widens_a_version_without_known_versions_to_itself

Removed: none

@notatallshaw

Copy link
Copy Markdown
Collaborator Author

Force-pushed, so the commit sha linked from #20804 is stale (b00477d is now bf48641). It also clamps a requires-python rejection, so the line reads sphinx==7.2.6 rather than sphinx>=7.2.6, and the availability statement now attaches to a cause that rules the package out. The same defect turned up in nab, fixed there in notatallshaw/nab#620.

@notatallshaw

Copy link
Copy Markdown
Collaborator Author

Now I have a better handle on this issue, implementing a similar approach in nab, I'm marking it as ready for review. If uv maintainers would like me to merge it into #20804 I can do that also, but I do think the two issues are fairly separately reviewable.

@zsol
zsol self-requested a review August 3, 2026 11:04
Comment on lines 623 to 625
if narrowed == Range::full() {
return narrowed;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it'd be helpful to preserve singletons here no? Otherwise something like a==1.0 was yanked becomes all versions of 'a' were yanked which is less helpful

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment on lines +3981 to +3986
╰─▶ Because attrs==21.1.0 was yanked (reason: Installable but not importable on Python 3.4) and only the following versions of attrs are available:
attrs<=20.3.0
attrs==21.1.0
attrs>=21.2.0
we can conclude that attrs>20.3.0,<21.2.0 cannot be used.
And because you require attrs>20.3.0,<21.2.0, we can conclude that your requirements are unsatisfiable.

@konstin konstin Aug 5, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh I find the formatting we have on main not more helpful either, maybe:

Because attrs==21.1.0 was yanked (...) and there are no other versions in range, we can conclude that attrs>20.3.0,<21.2.0 cannot be used.

CC @zanieb

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never learnt the art of reading uv error messages, and they're still on my to-do list for nab, so I have literally no opinion here, they all look the same to me now that they're not clobbering specific information like indexes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is that we start with simple facts (e.g. a>=1,<2 depends on b>=1,<2 and that c>=2,<3 depends on b>=2,<3) to build the minimal case why requirements don't work. This usually tasks the shape of a DAG starting from (or ending in) root: root depends on a>=1,<2, so it also required b>=1,<2, and root depends on c>=2,<3, so b>=2,<3, and there are no version of b for that, so it's unfulfillable.

PubGrub's idea is to generate a prove for unfulfillability. We're treating each dependency as an implication (e.g. a>=1,<2 => b>=1,<2) and then chaining them (e.g. a>=1,<2 => b>=1,<2 and b>=1,<2 => c>=1,<2 implies a>=1,<2 => c>=1,<2) until reach that root (your dependencies) implies false. This prove only contains the packages and versions that are actually involved in the problem, so you know where to tweak. Through this prove we surface reasons why your resolution might be failing, such as the yanked version in the example above or a requires-python that is wider than that of your dependencies.

There's two ways to present those proves: Start from the root and chain yourself to leaves, or start from the leaves and build your case against root. uv does the latter.

The tricky parts are granularity and ordering: If we say that there are only incompatible wheels, should we list all the versions, or only the range that contains all the versions? Which implication do we want to highlight, what is the bound that the user wants to change, override or report upstream?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

astral-sh#566 addresses this but is a bit niche.

I have been iterating on the resolver errors in a stack over there.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as we're not losing information here or otherwise clearly regressing, we can address simplifying them separately

@notatallshaw
notatallshaw force-pushed the restate-available-versions branch from a30250e to 64ecb36 Compare August 5, 2026 13:06
@notatallshaw

Copy link
Copy Markdown
Collaborator Author

Merged this back into #20804 as it seems clear the resulting changing need to be reviewed as one unit (and there's no helpful stacking UI for contributing to an external repo).

charliermarsh pushed a commit that referenced this pull request Aug 8, 2026
This is a partial port of a technique I am adopting in nab, I have been
following @konstin's lead in
astral-sh/pubgrub#75 and extending the approach
into more places (notatallshaw/nab#357,
notatallshaw/nab#590,
notatallshaw/nab#592,
notatallshaw/nab#604).

This speeds up `uv lock` with `requires-python >= 3.8` over boto3 +
awscli by ~20% wall time, and the largest accumulated range in the run
drops from 287 segments to 2.

`add_unavailable_version` records one singleton incompatibility per
rejected version, so consecutive rejections never coalesce and the
accumulated range grows a hole per version. This widens each singleton
to the gap between its neighbors in the known versions, the same
interval decided-version dependencies use.

The win needs long runs of rejected versions. The main source is a
Python floor below the ecosystem's support boundary: boto3 and awscli
dropped 3.8 in April 2025 and now require >= 3.10, so a 3.8 floor
rejects hundreds of releases in one run, while a 3.10 floor rejects
almost nothing (14 rounds, 2 segments either way) and the change is a
no-op.

The first commit keys the pre-release hint on the requesting requirement
instead of the derived set's bounds: widened bounds land on whatever the
registry lists next, and a pre-release neighbor used to read as a
pre-release marker nobody wrote. Rejection widening makes that routine,
so the fix leads the series. The second commit merges unavailable
versions that are causes of the same derivation, and the third is the
widening itself. The fourth keeps the subsequent-index hint, which was
suppressed whenever the set covered all versions; after widening that
also covers "the index listed versions and none of them worked", which
is the case the hint is for.

The last two commits are #20809, merged in here so the error messages
land as one change. With the widening, uv no longer asks for a version
in a gap it created, so the `no_versions` incompatibility behind "only
the following versions of X are available" is no longer created there,
and steps that cross a gap stop following from the premises next to
them. The fifth commit adds that clause back while the tree is reduced,
on whichever cause rules the package out, or on the step itself when
neither does. The sixth reports the one version a package has as that
version rather than as a range over it, so a rejected `sphinx 7.2.6`
reads `sphinx==7.2.6` and not `sphinx>=7.2.6`. Neither touches the
solver.

<details>
<summary>MRE</summary>

```toml
[project]
name = "mre"
version = "0.1.0"
requires-python = ">=3.8"
dependencies = ["boto3", "awscli"]
```

Max accumulated segments (287 on main, 2 with this PR; `uv.lock`
identical):

```console
$ uv lock --exclude-newer 2026-07-01 -v 2>&1 | grep 'Searching for a compatible version' | awk -F'|' '{print NF}' | sort -n | tail -1
```

Wall (run without `-v`, which prints the accumulated ranges and
dominates the time):

```console
$ hyperfine --warmup 3 --min-runs 20 --prepare 'rm -f uv.lock' 'uv lock --exclude-newer 2026-07-01'
```

</details>
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.

4 participants