Skip to content

Resolve URL dependencies without lookahead - #21763

Draft
charliermarsh wants to merge 10 commits into
mainfrom
charlie/resolver-url-sources
Draft

charliermarsh wants to merge 10 commits into
mainfrom
charlie/resolver-url-sources

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Sep 16, 2026 •

Copy link
Copy Markdown
Member

We currently discover transitive URLs before resolution and keep them after the dependency path that introduced them has been rejected. For example, if a rejected candidate activates provider[url], another dependency that just requires target still uses the URL from that extra. We now use the registry in that case, unless another selected dependency independently supplies a URL.

Move URL discovery into the resolver and make the source part of each PubGrub candidate. URLs can be introduced by the root or by another authorized URL dependency. A registry package cannot introduce a URL; it can request an extra on an independently authorized URL package, whose own metadata can then declare another URL. The markers along that path matter: if the extra is requested only on Linux, its URL or explicit index applies only on Linux. Registry, explicitly selected index, and URL candidates remain distinct even when they publish the same version. If the registry has no suitable candidate, we keep possible URL sources open and can revisit earlier decisions to select a valid provider. Required URLs report the original artifact error with the selected dependency path; errors from excluded branches are discarded. A registry requirement written with a different Git reference can reuse an authorized source when the repository, package location, and commit match. Comparing references does not check out the registry-supplied revision or fetch its submodules or Git LFS.

Local directories have separate normal and editable candidates, and Git checkouts have separate candidates with and without LFS; each mode has its own metadata and failures. A plain declaration cannot enable either alternative on its own, but another selected first-party dependency can require it. Dependencies reported only by the alternative mode cannot authorize that mode themselves. Conflicting editable and non-editable declarations cannot both be included, and a virtual declaration cannot suppress another included declaration that requires installation. We validate each directory against its requested package name. Archive hashes from selected declarations stay in compiled requirements, even when an equivalent declaration omits its hash; hashes from an old registry pin are not reused for a URL.

Apply the same source and marker rules when checking lockfiles and preserve conditional extras when exporting. Checks validate authorized mutable dependencies reached through immutable registry or Git packages. Source declarations from Git packages are retained for offline checks. The metadata-free preview lock records incoming requests for empty mutable dependency extras; older preview locks with immutable parents of mutable dependencies are re-resolved once. First-party prerelease and yank policies, trusted hashes, and lowest-direct selection also follow the selected graph, including universal resolution and --fork-strategy fewest. Ordinary registry candidate sets stay compact. For small sets of universal registry wheels, URL-provider searches can skip versions that have identical requirements and Python compatibility or whose dependencies cannot reach a possible first-party source or policy. This removes the lookahead pass from pip and build dependency resolution.

@codspeed

codspeed Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 48.12%

2 warnings

⚠️ 6 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ Base and head ran on different runner types

Some benchmarks with significant performance changes were compared across different runner types, so the changes might not come from the code. Run base and head on the same runner type, or use CodSpeed Macro Runners for more stable results.

Learn more about Macro Runners

Open the report in CodSpeed to investigate

❌ 5 regressed benchmarks
✅ 18 untouched benchmarks
⏩ 12 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ CPU Simulation run_python_version_synthetic_workspace 529.8 ms 2,609.4 ms -79.7%
❌ Walltime run_python_version_synthetic_workspace 262.4 ms 1,071.5 ms -75.51%
❌ Walltime resolve_warm_jupyter_universal 86.9 ms 98.4 ms -11.69%
❌ Walltime resolve_warm_airflow 236 ms 257.8 ms -8.46%
❌ CPU Simulation resolve_warm_jupyter_universal 311.7 ms 333.4 ms -6.49%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing charlie/resolver-url-sources (d3661ff) with main (6b40d9e)

Open in CodSpeed

Footnotes

  1. 12 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

PrereleasePolicy::Explicit(packages) => {
if packages.contains(package_name, env) {
if packages.contains(package_name, env)
|| self.possible_explicit.contains(package_name)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Speculative prerelease selection can execute an unauthorized build backend

Under --prerelease=explicit, this new possible_explicit fallback treats an as-yet ungrounded first-party pin as permission to select a prerelease. The resulting choose_version path immediately requests registry metadata; if the candidate is an attacker-controlled sdist with dynamic metadata, uv executes its PEP 517 backend before deciding whether the provider extra that grants prerelease permission is actually selected. The final grounding check can then reject the prerelease, but the backend has already run with the developer or CI worker's authority. Defer executable sdist metadata until the selected dependency graph authorizes the candidate, or restrict speculative inspection to non-executable metadata paths.

@astral-sh-bot

astral-sh-bot Bot commented Sep 17, 2026

Copy link
Copy Markdown

uv test inventory changes

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

  • Added tests: 41
  • Removed tests: 0
  • Changed suites: 3
uv-resolver: +3 / -0

Added:

  • uv-resolver::pubgrub::solver_version::tests::directory_candidate_modes_are_independent
  • uv-resolver::pubgrub::solver_version::tests::source_relationships_match_materialized_sets
  • uv-resolver::pubgrub::solver_version::tests::undiscovered_sources_participate_in_set_operations

Removed: none

uv::lock: +10 / -0

Added:

  • uv::lock::lock::lock_excluded_direct_source_provider_keeps_registry
  • uv::lock::lock::lock_index_from_registry_extra_validates_resolved_source
  • uv::lock::lock::lock_ordinary_conditional_pins_do_not_fork
  • uv::lock::lock::lock_url_directory_editability_conflict
  • uv::lock::lock::lock_url_directory_git_keeps_unspecified_editability
  • uv::lock::lock::lock_url_directory_mismatched_name
  • uv::lock::lock::lock_url_directory_remote_keeps_unspecified_editability
  • uv::lock::lock::lock_url_directory_virtual_and_installable
  • uv::lock::lock::lock_url_from_registry_extra_offline
  • uv::lock::lock::lock_url_override_and_constraint_markers

Removed: none

uv::pip_compile: +28 / -0

Added:

  • uv::pip_compile::pip_compile::deduplicate_editable_environment_variable
  • uv::pip_compile::pip_compile::lowest_direct_fork_max_python_fewest
  • uv::pip_compile::pip_compile::url_source_direct_metadata_candidate_policies
  • uv::pip_compile::pip_compile::url_source_directory_editability_conflict
  • uv::pip_compile::pip_compile::url_source_directory_editable_metadata
  • uv::pip_compile::pip_compile::url_source_directory_failed_normal_metadata
  • uv::pip_compile::pip_compile::url_source_directory_rejects_cached_metadata_for_other_name
  • uv::pip_compile::pip_compile::url_source_disjoint_markers_on_registry_extras
  • uv::pip_compile::pip_compile::url_source_excluded_provider_cannot_fail_on_conflicting_hashes
  • uv::pip_compile::pip_compile::url_source_excluded_provider_cannot_fail_on_missing_artifact
  • uv::pip_compile::pip_compile::url_source_excluded_provider_keeps_registry_index
  • uv::pip_compile::pip_compile::url_source_excluded_provider_keeps_registry_index_format
  • uv::pip_compile::pip_compile::url_source_excluded_provider_keeps_registry_metadata
  • uv::pip_compile::pip_compile::url_source_independent_provider_survives
  • uv::pip_compile::pip_compile::url_source_late_candidate_policies
  • uv::pip_compile::pip_compile::url_source_late_lowest_direct_policy
  • uv::pip_compile::pip_compile::url_source_late_provider_without_registry_candidate
  • uv::pip_compile::pip_compile::url_source_marker_limits_candidate_policies
  • uv::pip_compile::pip_compile::url_source_marker_limits_lowest_direct_policy
  • uv::pip_compile::pip_compile::url_source_marker_limits_registry_and_direct_metadata
  • uv::pip_compile::pip_compile::url_source_marker_on_registry_extra
  • uv::pip_compile::pip_compile::url_source_override_and_constraint_markers
  • uv::pip_compile::pip_compile::url_source_recomputes_registry_preference_hash_for_direct_source
  • uv::pip_compile::pip_compile::url_source_registry_cannot_authorize_an_inactive_extra
  • uv::pip_compile::pip_compile::url_source_registry_cannot_introduce_a_url
  • uv::pip_compile::pip_compile::url_source_registry_git_aliases
  • uv::pip_compile::pip_compile::url_source_registry_leaves_cannot_activate_provider
  • uv::pip_compile::pip_compile::url_source_reports_required_metadata_errors

Removed: none

@konstin konstin left a comment

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.

Did a skim

| ^^
invalid type: integer `42`, expected a string

hint: `child` was included because `project` (v0.1.0) depends on `child`

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 hint looks superfluous

# via
# -r requirements.in
# forkroot
forkdep==3.1 ; python_full_version >= '3.12'

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.

Was that intended to change?

Caused by: The .dist-info directory tomli-2.0.1 does not start with the normalized package name: foo
error: Failed to read `foo @ file://[TEMP_DIR]/foo-2.0.1-py3-none-any.whl`
cause: Failed to read metadata: `[TEMP_DIR]/foo-2.0.1-py3-none-any.whl`
cause: The .dist-info directory tomli-2.0.1 does not start with the normalized package name: foo

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.

That's a regression

Comment on lines +322 to +323
the branch. It can revisit earlier candidate decisions, including extras, when a different selection
might supply the missing URL. For small sets of universal registry wheels covering the active

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.

Can we avoid this by prioritizing URLs over registry packages?

This branch was previously deployed

1 inactive deployment
automations — d3661ff6 Deployed Sep 17, 2026 by charliermarsh via review / security review #46991
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.

2 participants