Skip to content

Explain requirement mismatches when lock resolution fails - #21284

Open
konstin wants to merge 2 commits into
mainfrom
konsti/lock-check-mismatch-context
Open

konstin wants to merge 2 commits into
mainfrom
konsti/lock-check-mismatch-context

Conversation

@konstin

@konstin konstin commented Aug 24, 2026 •

Copy link
Copy Markdown
Member

Show added and removed package requirements when a lock check fails while collecting package metadata, so a download failure does not hide why the lockfile is out of date (and we explain why there's network access in the first place).

@astral-sh-bot

astral-sh-bot Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

uv test inventory changes

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

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

Added:

  • uv::lock::lock::lock_check_mismatched_requirements

Removed: none

@konstin
konstin force-pushed the konsti/lock-check-mismatch-context branch from 7763503 to d571eae Compare September 8, 2026 14:16
@konstin
konstin force-pushed the konsti/lock-check-mismatch-context branch from d571eae to 6b96f5e Compare September 22, 2026 10:55
@konstin
konstin force-pushed the konsti/lock-check-mismatch-context branch from 56a85fb to 4ae7a06 Compare September 25, 2026 10:25
@konstin
konstin marked this pull request as ready for review September 25, 2026 10:34
@konstin konstin added the area:error-messages Messaging when something goes wrong label Sep 25, 2026
Comment thread crates/uv/src/commands/project/lock.rs Outdated
&existing_lock
{
let _ = writeln!(printer.stderr(), "{}", Hints::from(reason.to_string()));
}

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.

This seems wrong -- shouldn't it be using Hinted? The hint also appears before the error.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Changed it to Hinted; that type is younger than this PR :D. It's more consistent, but it also feels less helpful? Previously you got the relevant information last, and then the motivation if you looked higher, now you first get the motivation at the bottom and then have to like higher for the network error.

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.

I guess this doesn't quite make sense following our prior discussion of what a Hint should be, where we said we want hints to be actionable suggestions. It does match a lot of our current use, but I'd expect it to move to an info: block attached to the error long-term. Does that sound right to you?

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.

Reflecting on this as a whole, this is maybe the first info: style item I've seen that we'd want to put at the top-level since it's information about why we were performing a solve rather than an information about any particular error, I agree with Charlie that it'd be weird if it came before the error though?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This could become a good case study for info:, right now though it fits well with the existing use of hints.

Comment thread crates/uv/src/commands/project/lock.rs Outdated
write!(f, "\n Added: `{requirement}`")?;
}
for requirement in self.actual.difference(&self.expected) {
write!(f, "\n Removed: `{requirement}`")?;

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.

Should this use the same style from our dry-run reporter? Or even the same underlying formatter?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I tried that but to me it looks worse:

error: Failed to download `a @ http://[LOCALHOST]/files/a-1.0.0-py3-none-any.whl`
   cause: Network connectivity is disabled, but the requested data wasn't found in the cache for: `http://[LOCALHOST]/files/a-1.0.0-py3-none-any.whl`

hint: The lockfile needs to be updated because the requirements for `project` have changed:
  Remove project>=0.0.1
  Add project>=0.1.0

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I made the style more similar to the existing one, by formatting without colon and backticks.

@codspeed

codspeed Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 7 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

✅ 89 untouched benchmarks
⏩ 84 skipped benchmarks1


Comparing konsti/lock-check-mismatch-context (77a0719) with main (f6b0f08)

Open in CodSpeed

Footnotes

  1. 84 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. ↩

@konstin
konstin force-pushed the konsti/lock-check-mismatch-context branch from 459671d to 9d5ca61 Compare October 12, 2026 08:52
@konstin
konstin force-pushed the konsti/lock-check-mismatch-context branch from 9d5ca61 to 102b242 Compare October 12, 2026 09:08
@konstin
konstin force-pushed the konsti/lock-check-mismatch-context branch from 91194ef to 7788ff6 Compare October 12, 2026 09:28
@konstin
konstin force-pushed the konsti/lock-check-mismatch-context branch from 7788ff6 to d329dcf Compare November 17, 2026 08:16
Record the download-only diagnostic with a local wheel fixture when a workspace member changes without updating the lockfile.
Retain changed package requirements so a subsequent resolution error does not hide why the lockfile needs updating. Preserve the original error and successful lock-check behavior.
@konstin
konstin force-pushed the konsti/lock-check-mismatch-context branch from d329dcf to 77a0719 Compare November 30, 2026 19:35
Comment on lines +948 to +950
&& let LockSatisfactionError::MismatchedPackageRequirements(..) =
reason.as_ref()
{

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.

[P3] Signed download URLs can leak through the lock mismatch hint

When a metadata fetch fails during a locked check, the new hint can print a signed URL from an unrelated added or removed requirement. Requirement normalization retains the URL query, and SafeUrl leaves Google Cloud Storage’s X-Goog-Signature intact. If CI logs are visible to someone without access to the private wheel, that reader can download it until the signature expires, even if uv never fetched that wheel during the check.

Suggested change
&& let LockSatisfactionError::MismatchedPackageRequirements(..) =
reason.as_ref()
{
&& let LockSatisfactionError::MismatchedPackageRequirements(
package, _, requested, locked,
) = reason.as_ref()
{
let has_url_query = requested.symmetric_difference(locked).any(|requirement| {
matches!(
&requirement.source,
uv_distribution_types::RequirementSource::Url { location, .. }
if location.query().is_some()
)
});
let reason = if has_url_query {
format!("Requirements for `{package}` changed")
} else {
reason.to_string()
};

This branch was previously deployed

1 inactive (outdated) deployment
automations — d329dcfa Deployed Nov 17, 2026 by konstin via review | security / security review #54019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:error-messages Messaging when something goes wrong

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants